fix: preserve numeric ref range metadata

This commit is contained in:
mahdahar 2026-03-26 14:48:49 +07:00
parent a73b88bc05
commit 366572a0cb
5 changed files with 353 additions and 273 deletions

View File

@ -65,6 +65,7 @@ class RefNumModel extends BaseModel
'NumRefTypeLabel' => $r['NumRefType'] ? \App\Libraries\ValueSet::getLabel('numeric_ref_type', $r['NumRefType']) : '', 'NumRefTypeLabel' => $r['NumRefType'] ? \App\Libraries\ValueSet::getLabel('numeric_ref_type', $r['NumRefType']) : '',
'RangeType' => $r['RangeType'], 'RangeType' => $r['RangeType'],
'RangeTypeLabel' => $r['RangeType'] ? \App\Libraries\ValueSet::getLabel('range_type', $r['RangeType']) : '', 'RangeTypeLabel' => $r['RangeType'] ? \App\Libraries\ValueSet::getLabel('range_type', $r['RangeType']) : '',
'SpcType' => $r['SpcType'],
'Sex' => $r['Sex'], 'Sex' => $r['Sex'],
'SexLabel' => $r['Sex'] ? \App\Libraries\ValueSet::getLabel('gender', $r['Sex']) : '', 'SexLabel' => $r['Sex'] ? \App\Libraries\ValueSet::getLabel('gender', $r['Sex']) : '',
'LowSign' => $r['LowSign'], 'LowSign' => $r['LowSign'],
@ -77,6 +78,7 @@ class RefNumModel extends BaseModel
'AgeEnd' => (int) $r['AgeEnd'], 'AgeEnd' => (int) $r['AgeEnd'],
'Flag' => $r['Flag'], 'Flag' => $r['Flag'],
'Interpretation' => $r['Interpretation'], 'Interpretation' => $r['Interpretation'],
'Notes' => $r['Notes'],
]; ];
}, $rows ?? []); }, $rows ?? []);
} }
@ -108,6 +110,7 @@ class RefNumModel extends BaseModel
$this->insert([ $this->insert([
'TestSiteID' => $testSiteID, 'TestSiteID' => $testSiteID,
'SiteID' => $siteID, 'SiteID' => $siteID,
'SpcType' => $range['SpcType'] ?? 'GEN',
'NumRefType' => $range['NumRefType'], 'NumRefType' => $range['NumRefType'],
'RangeType' => $range['RangeType'], 'RangeType' => $range['RangeType'],
'Sex' => $range['Sex'], 'Sex' => $range['Sex'],
@ -119,6 +122,7 @@ class RefNumModel extends BaseModel
'High' => !empty($range['High']) ? (float) $range['High'] : null, 'High' => !empty($range['High']) ? (float) $range['High'] : null,
'Flag' => $range['Flag'] ?? null, 'Flag' => $range['Flag'] ?? null,
'Interpretation'=> $range['Interpretation'] ?? null, 'Interpretation'=> $range['Interpretation'] ?? null,
'Notes' => $range['Notes'] ?? null,
'Display' => $index, 'Display' => $index,
'CreateDate' => date('Y-m-d H:i:s'), 'CreateDate' => date('Y-m-d H:i:s'),
]); ]);

View File

@ -5182,12 +5182,49 @@ paths:
message: message:
type: string type: string
example: 'Invalid member TestSiteID(s): 185, 186. Make sure to use TestSiteID, not SeqScr or other values.' example: 'Invalid member TestSiteID(s): 185, 186. Make sure to use TestSiteID, not SeqScr or other values.'
/api/test/{id}:
get:
tags:
- Test
summary: Get test definition by ID
security:
- bearerAuth: []
parameters:
- name: id
in: path
required: true
schema:
type: integer
description: Test Site ID
responses:
'200':
description: Test definition details
content:
application/json:
schema:
type: object
properties:
status:
type: string
message:
type: string
data:
$ref: '#/components/schemas/TestDefinition'
'404':
description: Test not found
patch: patch:
tags: tags:
- Test - Test
summary: Update test definition summary: Update test definition
security: security:
- bearerAuth: [] - bearerAuth: []
parameters:
- name: id
in: path
required: true
schema:
type: integer
description: Test Site ID
requestBody: requestBody:
required: true required: true
content: content:
@ -5335,36 +5372,6 @@ paths:
message: message:
type: string type: string
example: 'Invalid member TestSiteID(s): 185, 186. Make sure to use TestSiteID, not SeqScr or other values.' example: 'Invalid member TestSiteID(s): 185, 186. Make sure to use TestSiteID, not SeqScr or other values.'
/api/test/{id}:
get:
tags:
- Test
summary: Get test definition by ID
security:
- bearerAuth: []
parameters:
- name: id
in: path
required: true
schema:
type: integer
description: Test Site ID
responses:
'200':
description: Test definition details
content:
application/json:
schema:
type: object
properties:
status:
type: string
message:
type: string
data:
$ref: '#/components/schemas/TestDefinition'
'404':
description: Test not found
delete: delete:
tags: tags:
- Test - Test
@ -7072,6 +7079,9 @@ components:
type: string type: string
RangeTypeLabel: RangeTypeLabel:
type: string type: string
SpcType:
type: string
description: Specimen type code (e.g., GEN, EDTA)
Sex: Sex:
type: string type: string
SexLabel: SexLabel:
@ -7098,6 +7108,9 @@ components:
type: string type: string
Interpretation: Interpretation:
type: string type: string
Notes:
type: string
description: Optional note attached to the numeric reference range
reftxt: reftxt:
type: array type: array
description: Text reference ranges (optional). Mutually exclusive with refnum - a test can only have ONE reference type. description: Text reference ranges (optional). Mutually exclusive with refnum - a test can only have ONE reference type.

View File

@ -241,6 +241,9 @@ TestDefinition:
type: string type: string
RangeTypeLabel: RangeTypeLabel:
type: string type: string
SpcType:
type: string
description: Specimen type code (e.g., GEN, EDTA)
Sex: Sex:
type: string type: string
SexLabel: SexLabel:
@ -267,6 +270,9 @@ TestDefinition:
type: string type: string
Interpretation: Interpretation:
type: string type: string
Notes:
type: string
description: Optional note attached to the numeric reference range
reftxt: reftxt:
type: array type: array
description: Text reference ranges (optional). Mutually exclusive with refnum - a test can only have ONE reference type. description: Text reference ranges (optional). Mutually exclusive with refnum - a test can only have ONE reference type.

View File

@ -698,11 +698,48 @@
type: string type: string
example: 'Invalid member TestSiteID(s): 185, 186. Make sure to use TestSiteID, not SeqScr or other values.' example: 'Invalid member TestSiteID(s): 185, 186. Make sure to use TestSiteID, not SeqScr or other values.'
/api/test/{id}:
get:
tags: [Test]
summary: Get test definition by ID
security:
- bearerAuth: []
parameters:
- name: id
in: path
required: true
schema:
type: integer
description: Test Site ID
responses:
'200':
description: Test definition details
content:
application/json:
schema:
type: object
properties:
status:
type: string
message:
type: string
data:
$ref: '../components/schemas/tests.yaml#/TestDefinition'
'404':
description: Test not found
patch: patch:
tags: [Test] tags: [Test]
summary: Update test definition summary: Update test definition
security: security:
- bearerAuth: [] - bearerAuth: []
parameters:
- name: id
in: path
required: true
schema:
type: integer
description: Test Site ID
requestBody: requestBody:
required: true required: true
content: content:
@ -836,36 +873,6 @@
type: string type: string
example: 'Invalid member TestSiteID(s): 185, 186. Make sure to use TestSiteID, not SeqScr or other values.' example: 'Invalid member TestSiteID(s): 185, 186. Make sure to use TestSiteID, not SeqScr or other values.'
/api/test/{id}:
get:
tags: [Test]
summary: Get test definition by ID
security:
- bearerAuth: []
parameters:
- name: id
in: path
required: true
schema:
type: integer
description: Test Site ID
responses:
'200':
description: Test definition details
content:
application/json:
schema:
type: object
properties:
status:
type: string
message:
type: string
data:
$ref: '../components/schemas/tests.yaml#/TestDefinition'
'404':
description: Test not found
delete: delete:
tags: [Test] tags: [Test]
summary: Soft delete test definition summary: Soft delete test definition

View File

@ -42,6 +42,52 @@ class TestCreateVariantsTest extends CIUnitTestCase
} }
} }
public function testNumericRefRangeNotesPersistAfterCreate(): void
{
$notes = 'Auto note ' . uniqid();
$refnum = $this->buildRefNumEntries('NMRC', false);
$refnum[0]['Notes'] = $notes;
$payload = $this->buildTechnicalPayload('TEST', [
'ResultType' => 'NMRIC',
'RefType' => 'RANGE',
]);
$payload['refnum'] = $refnum;
$response = $this->withBodyFormat('json')->call('post', $this->endpoint, $payload);
$response->assertStatus(201);
$json = json_decode($response->getJSON(), true);
$testSiteId = $json['data']['TestSiteId'];
$show = $this->call('get', $this->endpoint . '/' . $testSiteId);
$show->assertStatus(200);
$showJson = json_decode($show->getJSON(), true);
$this->assertSame($notes, $showJson['data']['refnum'][0]['Notes']);
}
public function testNumericRefRangeSpcTypePersistAfterCreate(): void
{
$spcType = 'EDTA';
$refnum = $this->buildRefNumEntries('NMRC', false);
$refnum[0]['SpcType'] = $spcType;
$payload = $this->buildTechnicalPayload('TEST', [
'ResultType' => 'NMRIC',
'RefType' => 'RANGE',
]);
$payload['refnum'] = $refnum;
$response = $this->withBodyFormat('json')->call('post', $this->endpoint, $payload);
$response->assertStatus(201);
$json = json_decode($response->getJSON(), true);
$testSiteId = $json['data']['TestSiteId'];
$show = $this->call('get', $this->endpoint . '/' . $testSiteId);
$show->assertStatus(200);
$showJson = json_decode($show->getJSON(), true);
$this->assertSame($spcType, $showJson['data']['refnum'][0]['SpcType']);
}
public function testCreateTechnicalWithThresholdReference(): void public function testCreateTechnicalWithThresholdReference(): void
{ {
$refnum = $this->buildRefNumEntries('THOLD', true); $refnum = $this->buildRefNumEntries('THOLD', true);
@ -321,6 +367,8 @@ class TestCreateVariantsTest extends CIUnitTestCase
'AgeEnd' => 120, 'AgeEnd' => 120,
'Flag' => 'N', 'Flag' => 'N',
'Interpretation' => 'Normal range', 'Interpretation' => 'Normal range',
'SpcType' => 'GEN',
'Notes' => 'Default numeric range note',
], ],
]; ];
@ -337,6 +385,8 @@ class TestCreateVariantsTest extends CIUnitTestCase
'AgeEnd' => 99, 'AgeEnd' => 99,
'Flag' => 'N', 'Flag' => 'N',
'Interpretation' => 'Alternate range', 'Interpretation' => 'Alternate range',
'SpcType' => 'GEN',
'Notes' => 'Alternate numeric range note',
]; ];
} }