refactor(api): standardize ValueSet label transformation across controllers

Replace manual label lookup code with ValueSet::transformLabels() helper
for consistent API responses across all controllers.

Updated controllers:
- ContactController: Specialty, Occupation
- OrderTestController: Priority, OrderStatus
- PatientController: Sex
- ContainerDefController: ConCategory, CapColor, ConSize
- SpecimenCollectionController: CollectionMethod, Additive, SpecimenRole
- SpecimenController: SpecimenType, SpecimenStatus, BodySite
- SpecimenStatusController: Status, Activity
- DemoOrderController: Priority, OrderStatus
- TestMapController: HostType, ClientType
- TestsController: Reference range fields

Also updated api-docs.yaml field naming convention to PascalCase
This commit is contained in:
mahdahar 2026-01-29 09:05:40 +07:00
parent 212ab4e80a
commit 6a20682d18
11 changed files with 125 additions and 277 deletions

View File

@ -28,19 +28,10 @@ class ContactController extends BaseController {
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
}
// Transform Specialty and Occupation
foreach ($rows as &$row) {
if (isset($row['Specialty'])) {
$row['specialty'] = $row['Specialty'];
$row['specialtyLabel'] = ValueSet::getLabel('specialty', $row['Specialty']) ?? '';
unset($row['Specialty']);
}
if (isset($row['Occupation'])) {
$row['occupation'] = $row['Occupation'];
$row['occupationLabel'] = ValueSet::getLabel('occupation', $row['Occupation']) ?? '';
unset($row['Occupation']);
}
}
$rows = ValueSet::transformLabels($rows, [
'Specialty' => 'specialty',
'Occupation' => 'occupation',
]);
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
}
@ -53,17 +44,10 @@ class ContactController extends BaseController {
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
}
// Transform Specialty and Occupation
if (isset($row['Specialty'])) {
$row['specialty'] = $row['Specialty'];
$row['specialtyLabel'] = ValueSet::getLabel('specialty', $row['Specialty']) ?? '';
unset($row['Specialty']);
}
if (isset($row['Occupation'])) {
$row['occupation'] = $row['Occupation'];
$row['occupationLabel'] = ValueSet::getLabel('occupation', $row['Occupation']) ?? '';
unset($row['Occupation']);
}
$row = ValueSet::transformLabels([$row], [
'Specialty' => 'specialty',
'Occupation' => 'occupation',
])[0];
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
}

View File

@ -41,19 +41,10 @@ class OrderTestController extends Controller {
->getResultArray();
}
// Transform Priority and OrderStatus
foreach ($rows as &$row) {
if (isset($row['Priority'])) {
$row['priority'] = $row['Priority'];
$row['priorityLabel'] = ValueSet::getLabel('priority', $row['Priority']) ?? '';
unset($row['Priority']);
}
if (isset($row['OrderStatus'])) {
$row['orderStatus'] = $row['OrderStatus'];
$row['orderStatusLabel'] = ValueSet::getLabel('order_status', $row['OrderStatus']) ?? '';
unset($row['OrderStatus']);
}
}
$rows = ValueSet::transformLabels($rows, [
'Priority' => 'order_priority',
'OrderStatus' => 'order_status',
]);
return $this->respond([
'status' => 'success',
@ -76,17 +67,10 @@ class OrderTestController extends Controller {
], 200);
}
// Transform Priority and OrderStatus
if (isset($row['Priority'])) {
$row['priority'] = $row['Priority'];
$row['priorityLabel'] = ValueSet::getLabel('priority', $row['Priority']) ?? '';
unset($row['Priority']);
}
if (isset($row['OrderStatus'])) {
$row['orderStatus'] = $row['OrderStatus'];
$row['orderStatusLabel'] = ValueSet::getLabel('order_status', $row['OrderStatus']) ?? '';
unset($row['OrderStatus']);
}
$row = ValueSet::transformLabels([$row], [
'Priority' => 'order_priority',
'OrderStatus' => 'order_status',
])[0];
return $this->respond([
'status' => 'success',

View File

@ -3,7 +3,7 @@ namespace App\Controllers\Patient;
use CodeIgniter\API\ResponseTrait;
use CodeIgniter\Controller;
use App\Libraries\ValueSet;
use App\Models\Patient\PatientModel;
class PatientController extends Controller {
@ -13,7 +13,6 @@ class PatientController extends Controller {
protected $model;
protected $rules;
use App\Libraries\ValueSet;
public function __construct() {
$this->db = \Config\Database::connect();
$this->model = new PatientModel();
@ -60,14 +59,9 @@ use App\Libraries\ValueSet;
try {
$rows = $this->model->getPatients($filters);
// Transform Sex to sex and sexLabel
foreach ($rows as &$row) {
if (isset($row['Sex'])) {
$row['sex'] = $row['Sex'];
$row['sexLabel'] = ValueSet::getLabel('sex', $row['Sex']) ?? '';
unset($row['Sex']);
}
}
$rows = ValueSet::transformLabels($rows, [
'Sex' => 'sex',
]);
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
} catch (\Exception $e) {
@ -80,12 +74,9 @@ use App\Libraries\ValueSet;
$row = $this->model->getPatient($InternalPID);
if (empty($row)) { return $this->respond([ 'status' => 'success', 'message' => "data not found.", 'data' => null ], 200); }
// Transform Sex to sex and sexLabel
if (isset($row['Sex'])) {
$row['sex'] = $row['Sex'];
$row['sexLabel'] = ValueSet::getLabel('sex', $row['Sex']) ?? '';
unset($row['Sex']);
}
$row = ValueSet::transformLabels([$row], [
'Sex' => 'sex',
])[0];
return $this->respond([ 'status' => 'success', 'message' => "data fetched successfully", 'data' => $row ], 200);
} catch (\Exception $e) {

View File

@ -31,24 +31,11 @@ class ContainerDefController extends BaseController {
];
$rows = $this->model->getContainers($filter);
// Transform ConCategory, CapColor, ConSize
foreach ($rows as &$row) {
if (isset($row['ConCategory'])) {
$row['conCategory'] = $row['ConCategory'];
$row['conCategoryLabel'] = ValueSet::getLabel('container_class', $row['ConCategory']) ?? '';
unset($row['ConCategory']);
}
if (isset($row['CapColor'])) {
$row['capColor'] = $row['CapColor'];
$row['capColorLabel'] = ValueSet::getLabel('container_cap_color', $row['CapColor']) ?? '';
unset($row['CapColor']);
}
if (isset($row['ConSize'])) {
$row['conSize'] = $row['ConSize'];
$row['conSizeLabel'] = ValueSet::getLabel('container_size', $row['ConSize']) ?? '';
unset($row['ConSize']);
}
}
$rows = ValueSet::transformLabels($rows, [
'ConCategory' => 'container_class',
'CapColor' => 'container_cap_color',
'ConSize' => 'container_size',
]);
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
} catch (\Exception $e) {
@ -63,22 +50,11 @@ class ContainerDefController extends BaseController {
return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => null ], 200);
}
// Transform ConCategory, CapColor, ConSize
if (isset($row['ConCategory'])) {
$row['conCategory'] = $row['ConCategory'];
$row['conCategoryLabel'] = ValueSet::getLabel('container_class', $row['ConCategory']) ?? '';
unset($row['ConCategory']);
}
if (isset($row['CapColor'])) {
$row['capColor'] = $row['CapColor'];
$row['capColorLabel'] = ValueSet::getLabel('container_cap_color', $row['CapColor']) ?? '';
unset($row['CapColor']);
}
if (isset($row['ConSize'])) {
$row['conSize'] = $row['ConSize'];
$row['conSizeLabel'] = ValueSet::getLabel('container_size', $row['ConSize']) ?? '';
unset($row['ConSize']);
}
$row = ValueSet::transformLabels([$row], [
'ConCategory' => 'container_class',
'CapColor' => 'container_cap_color',
'ConSize' => 'container_size',
])[0];
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $row ], 200);
} catch (\Exception $e) {

View File

@ -24,24 +24,11 @@ class SpecimenCollectionController extends BaseController {
try {
$rows = $this->model->findAll();
// Transform CollectionMethod, Additive, SpecimenRole
foreach ($rows as &$row) {
if (isset($row['CollectionMethod'])) {
$row['collectionMethod'] = $row['CollectionMethod'];
$row['collectionMethodLabel'] = ValueSet::getLabel('collection_method', $row['CollectionMethod']) ?? '';
unset($row['CollectionMethod']);
}
if (isset($row['Additive'])) {
$row['additive'] = $row['Additive'];
$row['additiveLabel'] = ValueSet::getLabel('additive', $row['Additive']) ?? '';
unset($row['Additive']);
}
if (isset($row['SpecimenRole'])) {
$row['specimenRole'] = $row['SpecimenRole'];
$row['specimenRoleLabel'] = ValueSet::getLabel('specimen_role', $row['SpecimenRole']) ?? '';
unset($row['SpecimenRole']);
}
}
$rows = ValueSet::transformLabels($rows, [
'CollectionMethod' => 'collection_method',
'Additive' => 'additive',
'SpecimenRole' => 'specimen_role',
]);
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
} catch (\Exception $e) {
@ -56,22 +43,11 @@ class SpecimenCollectionController extends BaseController {
return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => null ], 200);
}
// Transform CollectionMethod, Additive, SpecimenRole
if (isset($row['CollectionMethod'])) {
$row['collectionMethod'] = $row['CollectionMethod'];
$row['collectionMethodLabel'] = ValueSet::getLabel('collection_method', $row['CollectionMethod']) ?? '';
unset($row['CollectionMethod']);
}
if (isset($row['Additive'])) {
$row['additive'] = $row['Additive'];
$row['additiveLabel'] = ValueSet::getLabel('additive', $row['Additive']) ?? '';
unset($row['Additive']);
}
if (isset($row['SpecimenRole'])) {
$row['specimenRole'] = $row['SpecimenRole'];
$row['specimenRoleLabel'] = ValueSet::getLabel('specimen_role', $row['SpecimenRole']) ?? '';
unset($row['SpecimenRole']);
}
$row = ValueSet::transformLabels([$row], [
'CollectionMethod' => 'collection_method',
'Additive' => 'additive',
'SpecimenRole' => 'specimen_role',
])[0];
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $row ], 200);
} catch (\Exception $e) {

View File

@ -24,24 +24,11 @@ class SpecimenController extends BaseController {
try {
$rows = $this->model->findAll();
// Transform SpecimenType, SpecimenStatus, BodySite
foreach ($rows as &$row) {
if (isset($row['SpecimenType'])) {
$row['specimenType'] = $row['SpecimenType'];
$row['specimenTypeLabel'] = ValueSet::getLabel('specimen_type', $row['SpecimenType']) ?? '';
unset($row['SpecimenType']);
}
if (isset($row['SpecimenStatus'])) {
$row['specimenStatus'] = $row['SpecimenStatus'];
$row['specimenStatusLabel'] = ValueSet::getLabel('specimen_status', $row['SpecimenStatus']) ?? '';
unset($row['SpecimenStatus']);
}
if (isset($row['BodySite'])) {
$row['bodySite'] = $row['BodySite'];
$row['bodySiteLabel'] = ValueSet::getLabel('body_site', $row['BodySite']) ?? '';
unset($row['BodySite']);
}
}
$rows = ValueSet::transformLabels($rows, [
'SpecimenType' => 'specimen_type',
'SpecimenStatus' => 'specimen_status',
'BodySite' => 'body_site',
]);
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
} catch (\Exception $e) {
@ -56,22 +43,11 @@ class SpecimenController extends BaseController {
return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => null ], 200);
}
// Transform SpecimenType, SpecimenStatus, BodySite
if (isset($row['SpecimenType'])) {
$row['specimenType'] = $row['SpecimenType'];
$row['specimenTypeLabel'] = ValueSet::getLabel('specimen_type', $row['SpecimenType']) ?? '';
unset($row['SpecimenType']);
}
if (isset($row['SpecimenStatus'])) {
$row['specimenStatus'] = $row['SpecimenStatus'];
$row['specimenStatusLabel'] = ValueSet::getLabel('specimen_status', $row['SpecimenStatus']) ?? '';
unset($row['SpecimenStatus']);
}
if (isset($row['BodySite'])) {
$row['bodySite'] = $row['BodySite'];
$row['bodySiteLabel'] = ValueSet::getLabel('body_site', $row['BodySite']) ?? '';
unset($row['BodySite']);
}
$row = ValueSet::transformLabels([$row], [
'SpecimenType' => 'specimen_type',
'SpecimenStatus' => 'specimen_status',
'BodySite' => 'body_site',
])[0];
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $row ], 200);
} catch (\Exception $e) {

View File

@ -24,19 +24,10 @@ class ContainerDef extends BaseController {
try {
$rows = $this->model->findAll();
// Transform Status and Activity
foreach ($rows as &$row) {
if (isset($row['Status'])) {
$row['status'] = $row['Status'];
$row['statusLabel'] = ValueSet::getLabel('specimen_status', $row['Status']) ?? '';
unset($row['Status']);
}
if (isset($row['Activity'])) {
$row['activity'] = $row['Activity'];
$row['activityLabel'] = ValueSet::getLabel('specimen_activity', $row['Activity']) ?? '';
unset($row['Activity']);
}
}
$rows = ValueSet::transformLabels($rows, [
'Status' => 'specimen_status',
'Activity' => 'specimen_activity',
]);
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200);
} catch (\Exception $e) {
@ -51,17 +42,10 @@ class ContainerDef extends BaseController {
return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => null ], 200);
}
// Transform Status and Activity
if (isset($row['Status'])) {
$row['status'] = $row['Status'];
$row['statusLabel'] = ValueSet::getLabel('specimen_status', $row['Status']) ?? '';
unset($row['Status']);
}
if (isset($row['Activity'])) {
$row['activity'] = $row['Activity'];
$row['activityLabel'] = ValueSet::getLabel('specimen_activity', $row['Activity']) ?? '';
unset($row['Activity']);
}
$row = ValueSet::transformLabels([$row], [
'Status' => 'specimen_status',
'Activity' => 'specimen_activity',
])[0];
return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $row ], 200);
} catch (\Exception $e) {

View File

@ -70,19 +70,10 @@ class DemoOrderController extends Controller {
->get()
->getResultArray();
// Transform Priority and OrderStatus
foreach ($orders as &$order) {
if (isset($order['Priority'])) {
$order['priority'] = $order['Priority'];
$order['priorityLabel'] = ValueSet::getLabel('priority', $order['Priority']) ?? '';
unset($order['Priority']);
}
if (isset($order['OrderStatus'])) {
$order['orderStatus'] = $order['OrderStatus'];
$order['orderStatusLabel'] = ValueSet::getLabel('order_status', $order['OrderStatus']) ?? '';
unset($order['OrderStatus']);
}
}
$orders = ValueSet::transformLabels($orders, [
'Priority' => 'order_priority',
'OrderStatus' => 'order_status',
]);
return $this->respond([
'status' => 'success',

View File

@ -22,19 +22,10 @@ class TestMapController extends BaseController {
$rows = $this->model->findAll();
if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); }
// Transform HostType and ClientType
foreach ($rows as &$row) {
if (isset($row['HostType'])) {
$row['hostType'] = $row['HostType'];
$row['hostTypeLabel'] = ValueSet::getLabel('entity_type', $row['HostType']) ?? '';
unset($row['HostType']);
}
if (isset($row['ClientType'])) {
$row['clientType'] = $row['ClientType'];
$row['clientTypeLabel'] = ValueSet::getLabel('entity_type', $row['ClientType']) ?? '';
unset($row['ClientType']);
}
}
$rows = ValueSet::transformLabels($rows, [
'HostType' => 'entity_type',
'ClientType' => 'entity_type',
]);
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
}
@ -43,17 +34,10 @@ class TestMapController extends BaseController {
$row = $this->model->where('TestMapID',$id)->first();
if (empty($row)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200); }
// Transform HostType and ClientType
if (isset($row['HostType'])) {
$row['hostType'] = $row['HostType'];
$row['hostTypeLabel'] = ValueSet::getLabel('entity_type', $row['HostType']) ?? '';
unset($row['HostType']);
}
if (isset($row['ClientType'])) {
$row['clientType'] = $row['ClientType'];
$row['clientTypeLabel'] = ValueSet::getLabel('entity_type', $row['ClientType']) ?? '';
unset($row['ClientType']);
}
$row = ValueSet::transformLabels([$row], [
'HostType' => 'entity_type',
'ClientType' => 'entity_type',
])[0];
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $row ], 200);
}

View File

@ -158,19 +158,21 @@ class TestsController extends BaseController
$row['refnum'] = array_map(function ($r) {
return [
'RefNumID' => $r['RefNumID'],
'NumRefTypeKey' => $r['NumRefType'],
'NumRefType' => ValueSet::getLabel('numeric_ref_type', $r['NumRefType']),
'RangeType' => ValueSet::getLabel('range_type', $r['RangeType']),
'SexKey' => $r['Sex'],
'Sex' => ValueSet::getLabel('gender', $r['Sex']),
'LowSign' => ValueSet::getLabel('math_sign', $r['LowSign']),
'HighSign' => ValueSet::getLabel('math_sign', $r['HighSign']),
'NumRefType' => $r['NumRefType'],
'NumRefTypeLabel' => ValueSet::getLabel('numeric_ref_type', $r['NumRefType']),
'RangeType' => $r['RangeType'],
'RangeTypeLabel' => ValueSet::getLabel('range_type', $r['RangeType']),
'Sex' => $r['Sex'],
'SexLabel' => ValueSet::getLabel('gender', $r['Sex']),
'LowSign' => $r['LowSign'],
'LowSignLabel' => ValueSet::getLabel('math_sign', $r['LowSign']),
'HighSign' => $r['HighSign'],
'HighSignLabel' => ValueSet::getLabel('math_sign', $r['HighSign']),
'High' => $r['High'] !== null ? (int) $r['High'] : null,
'Flag' => $r['Flag']
];
}, $refnumData ?? []);
// $row['numRefTypeOptions'] = ValueSet::getOptions('numeric_ref_type');
$row['rangeTypeOptions'] = ValueSet::getOptions('range_type');
}
@ -184,10 +186,10 @@ class TestsController extends BaseController
$row['reftxt'] = array_map(function ($r) {
return [
'RefTxtID' => $r['RefTxtID'],
'TxtRefTypeKey' => $r['TxtRefType'],
'TxtRefType' => ValueSet::getLabel('text_ref_type', $r['TxtRefType']),
'SexKey' => $r['Sex'],
'Sex' => ValueSet::getLabel('gender', $r['Sex']),
'TxtRefType' => $r['TxtRefType'],
'TxtRefTypeLabel' => ValueSet::getLabel('text_ref_type', $r['TxtRefType']),
'Sex' => $r['Sex'],
'SexLabel' => ValueSet::getLabel('gender', $r['Sex']),
'AgeStart' => (int) $r['AgeStart'],
'AgeEnd' => (int) $r['AgeEnd'],
'RefTxt' => $r['RefTxt'],

View File

@ -343,33 +343,33 @@ components:
type: string
PatientID:
type: string
specimenType:
SpecimenType:
type: string
description: Specimen type code
specimenTypeLabel:
SpecimenTypeLabel:
type: string
description: Specimen type display text
CollectionDate:
type: string
format: date-time
collectionMethod:
CollectionMethod:
type: string
description: Collection method code
collectionMethodLabel:
CollectionMethodLabel:
type: string
description: Collection method display text
ContainerID:
type: integer
specimenStatus:
SpecimenStatus:
type: string
description: Specimen status code
specimenStatusLabel:
SpecimenStatusLabel:
type: string
description: Specimen status display text
bodySite:
BodySite:
type: string
description: Body site code
bodySiteLabel:
BodySiteLabel:
type: string
description: Body site display text
@ -382,22 +382,22 @@ components:
type: string
ContainerName:
type: string
conCategory:
ConCategory:
type: string
description: Container category code
conCategoryLabel:
ConCategoryLabel:
type: string
description: Container category display text
conSize:
ConSize:
type: string
description: Container size code
conSizeLabel:
ConSizeLabel:
type: string
description: Container size display text
capColor:
CapColor:
type: string
description: Cap color code
capColorLabel:
CapColorLabel:
type: string
description: Cap color display text
@ -424,16 +424,16 @@ components:
type: string
Description:
type: string
status:
Status:
type: string
description: Status code (lowercase)
statusLabel:
description: Status code
StatusLabel:
type: string
description: Status display text
activity:
Activity:
type: string
description: Activity code (lowercase)
activityLabel:
description: Activity code
ActivityLabel:
type: string
description: Activity display text
@ -448,22 +448,22 @@ components:
type: string
Description:
type: string
collectionMethod:
CollectionMethod:
type: string
description: Collection method code
collectionMethodLabel:
CollectionMethodLabel:
type: string
description: Collection method display text
additive:
Additive:
type: string
description: Additive code
additiveLabel:
AdditiveLabel:
type: string
description: Additive display text
specimenRole:
SpecimenRole:
type: string
description: Specimen role code
specimenRoleLabel:
SpecimenRoleLabel:
type: string
description: Specimen role display text
@ -514,16 +514,16 @@ components:
type: string
ClientName:
type: string
hostType:
HostType:
type: string
description: Host type code
hostTypeLabel:
HostTypeLabel:
type: string
description: Host type display text
clientType:
ClientType:
type: string
description: Client type code
clientTypeLabel:
ClientTypeLabel:
type: string
description: Client type display text
@ -540,16 +540,16 @@ components:
OrderDate:
type: string
format: date-time
orderStatus:
OrderStatus:
type: string
description: Order status code
orderStatusLabel:
OrderStatusLabel:
type: string
description: Order status display text
priority:
Priority:
type: string
description: Priority code
priorityLabel:
PriorityLabel:
type: string
description: Priority display text
SiteID:
@ -709,16 +709,16 @@ components:
type: string
Address:
type: string
specialty:
Specialty:
type: string
description: Specialty code
specialtyLabel:
SpecialtyLabel:
type: string
description: Specialty display text
occupation:
Occupation:
type: string
description: Occupation code
occupationLabel:
OccupationLabel:
type: string
description: Occupation display text