clqms-be/app/Models/OrderTest/OrderTestModel.php

298 lines
11 KiB
PHP
Raw Normal View History

feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
<?php
namespace App\Models\OrderTest;
use App\Models\BaseModel;
class OrderTestModel extends BaseModel {
protected $table = 'ordertest';
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
protected $primaryKey = 'InternalOID';
protected $useAutoIncrement = true;
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
protected $allowedFields = [
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
'InternalOID',
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
'OrderID',
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
'PlacerID',
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
'InternalPID',
'SiteID',
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
'PVADTID',
'ReqApp',
'Priority',
'TrnDate',
'EffDate',
'CreateDate',
'EndDate',
'ArchiveDate',
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
'DelDate'
];
public function generateOrderID(string $siteCode = '00'): string {
$date = new \DateTime();
$year = $date->format('y');
$month = $date->format('m');
$day = $date->format('d');
$counter = $this->db->table('counter')
->where('CounterName', 'ORDER')
->get()
->getRow();
if (!$counter) {
$this->db->table('counter')->insert([
'CounterName' => 'ORDER',
'CounterValue' => 1
]);
$seq = 1;
} else {
$seq = $counter->CounterValue + 1;
$this->db->table('counter')
->where('CounterName', 'ORDER')
->update(['CounterValue' => $seq]);
}
$seqStr = str_pad($seq, 5, '0', STR_PAD_LEFT);
return $siteCode . $year . $month . $day . $seqStr;
}
public function generateSpecimenID(string $orderID, int $seq): string {
return $orderID . '-S' . str_pad($seq, 2, '0', STR_PAD_LEFT);
}
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
public function createOrder(array $data): string {
$this->db->transStart();
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
try {
$orderID = $data['OrderID'] ?? $this->generateOrderID($data['SiteCode'] ?? '00');
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
$orderData = [
'OrderID' => $orderID,
'PlacerID' => $data['PlacerID'] ?? null,
'InternalPID' => $data['InternalPID'],
'SiteID' => $data['SiteID'] ?? '1',
'PVADTID' => $data['PatVisitID'] ?? $data['PVADTID'] ?? 0,
'ReqApp' => $data['ReqApp'] ?? null,
'Priority' => $data['Priority'] ?? 'R',
'TrnDate' => $data['OrderDateTime'] ?? $data['TrnDate'] ?? date('Y-m-d H:i:s'),
'EffDate' => $data['EffDate'] ?? date('Y-m-d H:i:s'),
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
'CreateDate' => date('Y-m-d H:i:s')
];
$internalOID = $this->insert($orderData);
if (!$internalOID) {
throw new \Exception('Failed to create order');
}
// Handle Order Comments
if (!empty($data['Comment'])) {
$this->db->table('ordercom')->insert([
'InternalOID' => $internalOID,
'Comment' => $data['Comment'],
'CreateDate' => date('Y-m-d H:i:s')
]);
}
// Process Tests Expansion
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
$testToOrder = [];
$specimenConDefMap = []; // Map ConDefID to specimen info
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
if (isset($data['Tests']) && is_array($data['Tests'])) {
$testModel = new \App\Models\Test\TestDefSiteModel();
$grpModel = new \App\Models\Test\TestDefGrpModel();
$calModel = new \App\Models\Test\TestDefCalModel();
$testMapDetailModel = new \App\Models\Test\TestMapDetailModel();
$containerDefModel = new \App\Models\Specimen\ContainerDefModel();
foreach ($data['Tests'] as $test) {
$testSiteID = $test['TestSiteID'] ?? $test['TestID'] ?? null;
if ($testSiteID) {
$this->expandTest($testSiteID, $testToOrder, $testModel, $grpModel, $calModel);
}
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
}
// Group tests by container requirement
$testsByContainer = [];
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
foreach ($testToOrder as $tid => $tinfo) {
// Find container requirement for this test
$containerReq = $this->getContainerRequirement($tid, $testMapDetailModel, $containerDefModel);
$conDefID = $containerReq['ConDefID'] ?? null;
if (!isset($testsByContainer[$conDefID])) {
$testsByContainer[$conDefID] = [
'tests' => [],
'containerInfo' => $containerReq
];
}
$testsByContainer[$conDefID]['tests'][$tid] = $tinfo;
}
// Create specimens for each unique container requirement
$specimenSeq = 1;
foreach ($testsByContainer as $conDefID => $containerData) {
$specimenID = $this->generateSpecimenID($orderID, $specimenSeq++);
$specimenData = [
'SID' => $specimenID,
'SiteID' => $data['SiteID'] ?? '1',
'OrderID' => $internalOID,
'ConDefID' => $conDefID,
'Qty' => 1,
'Unit' => 'tube',
'GenerateBy' => 'ORDER',
'CreateDate' => date('Y-m-d H:i:s')
];
$this->db->table('specimen')->insert($specimenData);
$internalSID = $this->db->insertID();
// Create specimen status
$this->db->table('specimenstatus')->insert([
'SID' => $specimenID,
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
'OrderID' => $internalOID,
'SpcStatus' => 'PENDING',
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
'CreateDate' => date('Y-m-d H:i:s')
]);
// Store mapping for patres creation
foreach ($containerData['tests'] as $tid => $tinfo) {
$specimenConDefMap[$tid] = [
'InternalSID' => $internalSID,
'SID' => $specimenID,
'ConDefID' => $conDefID
];
}
}
// Insert unique tests into patres with specimen links
if (!empty($testToOrder)) {
$resModel = new \App\Models\PatResultModel();
foreach ($testToOrder as $tid => $tinfo) {
$specimenInfo = $specimenConDefMap[$tid] ?? null;
$patResData = [
'OrderID' => $internalOID,
'TestSiteID' => $tid,
'TestSiteCode' => $tinfo['TestSiteCode'],
'SID' => $orderID,
'SampleID' => $orderID,
'ResultDateTime' => $orderData['TrnDate'],
'CreateDate' => date('Y-m-d H:i:s')
];
if ($specimenInfo) {
$patResData['InternalSID'] = $specimenInfo['InternalSID'];
}
$resModel->insert($patResData);
}
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
}
}
$this->db->transComplete();
if ($this->db->transStatus() === false) {
throw new \Exception('Transaction failed');
}
return $orderID;
} catch (\Exception $e) {
$this->db->transRollback();
throw $e;
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
}
}
private function getContainerRequirement($testSiteID, $testMapDetailModel, $containerDefModel): array {
// Try to find container requirement from test mapping
$containerDef = $this->db->table('testmapdetail tmd')
->select('tmd.ConDefID, cd.ConCode, cd.ConName')
->join('containerdef cd', 'cd.ConDefID = tmd.ConDefID', 'left')
->where('tmd.ClientTestCode', function($builder) use ($testSiteID) {
return $builder->select('TestSiteCode')
->from('testdefsite')
->where('TestSiteID', $testSiteID);
})
->where('tmd.EndDate IS NULL')
->get()
->getRowArray();
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
if ($containerDef) {
return [
'ConDefID' => $containerDef['ConDefID'],
'ConCode' => $containerDef['ConCode'],
'ConName' => $containerDef['ConName']
];
}
return [
'ConDefID' => null,
'ConCode' => 'DEFAULT',
'ConName' => 'Default Container'
];
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
}
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
private function expandTest($testSiteID, &$testToOrder, $testModel, $grpModel, $calModel) {
if (isset($testToOrder[$testSiteID])) return;
$testInfo = $testModel->find($testSiteID);
if (!$testInfo) return;
$testToOrder[$testSiteID] = [
'TestSiteCode' => $testInfo['TestSiteCode'],
'TestType' => $testInfo['TestType']
];
// Handle Group Expansion
if ($testInfo['TestType'] === 'GROUP') {
$members = $grpModel->where('TestSiteID', $testSiteID)->findAll();
foreach ($members as $m) {
$this->expandTest($m['Member'], $testToOrder, $testModel, $grpModel, $calModel);
}
}
// Handle Calculated Test Dependencies
if ($testInfo['TestType'] === 'CALC') {
$calDetail = $calModel->where('TestSiteID', $testSiteID)->first();
if ($calDetail && !empty($calDetail['FormulaInput'])) {
$inputs = explode(',', $calDetail['FormulaInput']);
foreach ($inputs as $inputCode) {
$inputCode = trim($inputCode);
$inputTest = $testModel->where('TestSiteCode', $inputCode)->first();
if ($inputTest) {
$this->expandTest($inputTest['TestSiteID'], $testToOrder, $testModel, $grpModel, $calModel);
}
}
}
}
}
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
public function getOrder(string $orderID): ?array {
return $this->select('*')
->where('OrderID', $orderID)
->where('DelDate', null)
->get()
->getRowArray();
}
public function getOrdersByPatient(int $internalPID): array {
return $this->select('*')
->where('InternalPID', $internalPID)
->where('DelDate', null)
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
->orderBy('TrnDate', 'DESC')
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
->get()
->getResultArray();
}
public function updateStatus(string $orderID, string $status): bool {
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
$order = $this->getOrder($orderID);
if (!$order) return false;
return (bool)$this->db->table('orderstatus')->insert([
'InternalOID' => $order['InternalOID'],
'OrderStatus' => $status,
'CreateDate' => date('Y-m-d H:i:s')
]);
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
}
public function softDelete(string $orderID): bool {
feat(api): transition to headless architecture and enhance order management This commit marks a significant architectural shift, transitioning the CLQMS backend to a fully headless REST API. All view-related components have been removed to focus solely on providing a robust, stateless API for clinical laboratory workflows. ### Architectural Changes - **Headless API Transition:** - Removed all view files (`app/Views/v2`), associated page controllers (`PagesController`), and routes (`Routes.php`). The application no longer serves a front-end UI. - The root endpoint (`/`) now returns a simple "Backend Running" status message. - **Developer Tooling & Guidance:** - Replaced `CLAUDE.md` with `GEMINI.md` to provide updated context and instructional guidelines for Gemini agents. - Updated `.serena/project.yml` with project configuration. ### Feature Enhancements - **Advanced Order Management (`OrderTestModel`):** - **Test Expansion:** The `createOrder` process now automatically expands `GROUP` (panel) tests into their individual components and recursively includes all parameter dependencies for `CALC` (calculated) tests. - **Order Comments:** Added support for attaching comments to an order via the `ordercom` table. - **Status Tracking:** Order status updates are now correctly recorded in the `orderstatus` table. - **Schema Alignment:** Switched from `OrderID` to `InternalOID` as the primary key for internal operations. - **Reference Range Refactor (`TestsController`):** - Simplified reference range logic by consolidating `refthold` and `refvset` into the main `refnum` and `reftxt` tables. - Standardized `RefType` handling to support `NMRC`, `TEXT`, `THOLD`, and `VSET` codes from the `reference_type` ValueSet. ### Other Changes - **Documentation:** - `PRD.md`, `README.md`, and `TODO.md` were updated to reflect the headless architecture, refined scope, and current project priorities. - **Database:** - Removed obsolete `RefTHoldID` and `RefVSetID` columns from the `patres` table migration. - **Testing:** - Added new feature tests for `ContactController`, `OrganizationController`, and `TestsController`.
2026-01-31 09:27:32 +07:00
return $this->where('OrderID', $orderID)->update(null, ['DelDate' => date('Y-m-d H:i:s')]);
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
}
}