feat: implement audit logging and test management enhancements
Major Features: - Add comprehensive audit logging system with AuditService - Create AuditLogs database migration for tracking changes - Implement TestValidationService for test data validation - Add FRONTEND_TEST_MANAGEMENT_PROMPT.md documentation Controllers: - Update TestsController with improved test management Models: - Enhance PatientModel with additional functionality - Update TestDefSiteModel for better site management Database: - Add CreateAuditLogs migration (2026-02-20-000011) - Update TestSeeder with new test data Services: - Add AuditService for comprehensive audit trail logging Documentation: - Update AGENTS.md with improved guidelines - Update audit-logging-plan.md with implementation details - Add FRONTEND_TEST_MANAGEMENT_PROMPT.md for frontend guidance API Documentation: - Update api-docs.bundled.yaml - Update tests.yaml schema definitions - Update tests.yaml paths Testing: - Enhance TestsControllerTest with new test cases - Update TestDefModelsTest for model coverage
This commit is contained in:
parent
b896c0aaf8
commit
d173098652
177
AGENTS.md
177
AGENTS.md
@ -6,7 +6,6 @@
|
||||
|
||||
## Build, Test & Lint Commands
|
||||
|
||||
### Running Tests
|
||||
```bash
|
||||
# Run all tests
|
||||
./vendor/bin/phpunit
|
||||
@ -22,44 +21,17 @@
|
||||
|
||||
# Run tests by suite
|
||||
./vendor/bin/phpunit --testsuite App
|
||||
```
|
||||
|
||||
### CodeIgniter CLI Commands
|
||||
```bash
|
||||
# Run spark commands
|
||||
php spark <command>
|
||||
|
||||
# Generate migration
|
||||
# Generate scaffolding
|
||||
php spark make:migration <name>
|
||||
|
||||
# Generate model
|
||||
php spark make:model <name>
|
||||
|
||||
# Generate controller
|
||||
php spark make:controller <name>
|
||||
|
||||
# Generate seeder
|
||||
php spark make:seeder <name>
|
||||
|
||||
# Run migrations
|
||||
# Database migrations
|
||||
php spark migrate
|
||||
|
||||
# Rollback migrations
|
||||
php spark migrate:rollback
|
||||
```
|
||||
|
||||
### Composer Commands
|
||||
```bash
|
||||
# Install dependencies
|
||||
composer install
|
||||
|
||||
# Run tests via composer
|
||||
composer test
|
||||
|
||||
# Update autoloader
|
||||
composer dump-autoload
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Code Style Guidelines
|
||||
@ -81,28 +53,10 @@ composer dump-autoload
|
||||
| Columns | PascalCase (legacy) | `PatientID`, `NameFirst` |
|
||||
| JSON fields | PascalCase | `"PatientID": "123"` |
|
||||
|
||||
### File Organization
|
||||
```
|
||||
app/
|
||||
├── Config/ # Configuration files
|
||||
├── Controllers/ # API controllers (grouped by feature)
|
||||
│ ├── Patient/
|
||||
│ ├── Organization/
|
||||
│ └── Specimen/
|
||||
├── Models/ # Data models
|
||||
├── Filters/ # Request filters (Auth, CORS)
|
||||
├── Traits/ # Reusable traits
|
||||
├── Libraries/ # Custom libraries
|
||||
├── Helpers/ # Helper functions
|
||||
└── Database/
|
||||
├── Migrations/
|
||||
└── Seeds/
|
||||
```
|
||||
|
||||
### Imports & Namespaces
|
||||
- Always use fully qualified namespaces at the top
|
||||
- Fully qualified namespaces at the top
|
||||
- Group imports: Framework first, then App, then external
|
||||
- Use statements must be in alphabetical order within groups
|
||||
- Alphabetical order within groups
|
||||
|
||||
```php
|
||||
<?php
|
||||
@ -123,43 +77,36 @@ namespace App\Controllers;
|
||||
|
||||
use App\Traits\ResponseTrait;
|
||||
|
||||
class ExampleController extends BaseController
|
||||
class ExampleController extends Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $model;
|
||||
protected $db;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new \App\Models\ExampleModel();
|
||||
}
|
||||
|
||||
// GET /example
|
||||
public function index()
|
||||
{
|
||||
// Implementation
|
||||
}
|
||||
|
||||
// POST /example
|
||||
public function create()
|
||||
{
|
||||
// Implementation
|
||||
}
|
||||
public function index() { /* ... */ }
|
||||
public function create() { /* ... */ }
|
||||
}
|
||||
```
|
||||
|
||||
### Response Format
|
||||
All API responses must use the standardized format:
|
||||
All API responses use standardized format:
|
||||
|
||||
```php
|
||||
// Success response
|
||||
// Success
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Operation completed',
|
||||
'data' => $data
|
||||
], 200);
|
||||
|
||||
// Error response
|
||||
// Error
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'message' => 'Error description',
|
||||
@ -167,10 +114,12 @@ return $this->respond([
|
||||
], 400);
|
||||
```
|
||||
|
||||
**Note**: Custom `ResponseTrait` automatically converts empty strings to `null`.
|
||||
|
||||
### Error Handling
|
||||
- Use try-catch for JWT operations and external calls
|
||||
- Use try-catch for JWT and external calls
|
||||
- Log errors: `log_message('error', $message)`
|
||||
- Return structured error responses with appropriate HTTP status codes
|
||||
- Log errors using CodeIgniter's logging: `log_message('error', $message)`
|
||||
|
||||
```php
|
||||
try {
|
||||
@ -183,9 +132,9 @@ try {
|
||||
```
|
||||
|
||||
### Database Operations
|
||||
- Use CodeIgniter's Query Builder or Model methods
|
||||
- Prefer parameterized queries over raw SQL
|
||||
- Use transactions for multi-table operations
|
||||
- Use CodeIgniter Query Builder or Model methods
|
||||
- Use `helper('utc')` for UTC date conversion
|
||||
- Wrap multi-table operations in transactions
|
||||
|
||||
```php
|
||||
$this->db->transStart();
|
||||
@ -197,9 +146,32 @@ if ($this->db->transStatus() === false) {
|
||||
}
|
||||
```
|
||||
|
||||
### Model Patterns
|
||||
- Extend `BaseModel` for automatic UTC date handling
|
||||
- Use `checkDbError()` for database error detection
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class PatientModel extends BaseModel
|
||||
{
|
||||
protected $table = 'patients';
|
||||
protected $primaryKey = 'PatientID';
|
||||
protected $allowedFields = ['NameFirst', 'NameLast', ...];
|
||||
|
||||
private function checkDbError($db, string $context) {
|
||||
$error = $db->error();
|
||||
if (!empty($error['code'])) {
|
||||
throw new \Exception("{$context} failed: {$error['code']} - {$error['message']}");
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Testing Guidelines
|
||||
|
||||
#### Test Structure
|
||||
```php
|
||||
<?php
|
||||
|
||||
@ -207,6 +179,7 @@ namespace Tests\Feature\Patients;
|
||||
|
||||
use CodeIgniter\Test\FeatureTestTrait;
|
||||
use CodeIgniter\Test\CIUnitTestCase;
|
||||
use Faker\Factory;
|
||||
|
||||
class PatientCreateTest extends CIUnitTestCase
|
||||
{
|
||||
@ -216,36 +189,23 @@ class PatientCreateTest extends CIUnitTestCase
|
||||
|
||||
public function testCreatePatientSuccess()
|
||||
{
|
||||
$faker = Factory::create('id_ID');
|
||||
$payload = [...];
|
||||
$result = $this->withBodyFormat('json')
|
||||
->post($this->endpoint, $payload);
|
||||
|
||||
$result = $this->withBodyFormat('json')->post($this->endpoint, $payload);
|
||||
$result->assertStatus(201);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Test Naming
|
||||
- Use descriptive method names: `test<Action><Scenario><ExpectedResult>`
|
||||
- Example: `testCreatePatientValidationFail`, `testCreatePatientSuccess`
|
||||
**Test Naming**: `test<Action><Scenario><ExpectedResult>` (e.g., `testCreatePatientValidationFail`)
|
||||
|
||||
#### Test Status Codes
|
||||
- 200: Success (GET, PATCH)
|
||||
- 201: Created (POST)
|
||||
- 400: Validation Error
|
||||
- 401: Unauthorized
|
||||
- 404: Not Found
|
||||
- 500: Server Error
|
||||
**Test Status Codes**: 200 (GET/PATCH), 201 (POST), 400 (Validation), 401 (Unauthorized), 404 (Not Found), 500 (Server Error)
|
||||
|
||||
### API Design
|
||||
- **Base URL**: `/api/`
|
||||
- **Authentication**: JWT token via HttpOnly cookie
|
||||
- **Content-Type**: `application/json`
|
||||
- **HTTP Methods**:
|
||||
- `GET` - Read
|
||||
- `POST` - Create
|
||||
- `PATCH` - Update (partial)
|
||||
- `DELETE` - Delete
|
||||
- **Methods**: GET (read), POST (create), PATCH (partial update), DELETE (delete)
|
||||
|
||||
### Routes Pattern
|
||||
```php
|
||||
@ -258,45 +218,34 @@ $routes->group('api/patient', function ($routes) {
|
||||
});
|
||||
```
|
||||
|
||||
### Security Guidelines
|
||||
- Always use the `auth` filter for protected routes
|
||||
- Sanitize all user inputs
|
||||
- Use parameterized queries to prevent SQL injection
|
||||
- Store JWT secret in `.env` file
|
||||
- Never commit `.env` files
|
||||
### Security
|
||||
- Use `auth` filter for protected routes
|
||||
- Sanitize user inputs
|
||||
- Use parameterized queries
|
||||
- Store secrets in `.env`, never commit
|
||||
|
||||
---
|
||||
|
||||
## Project-Specific Conventions
|
||||
|
||||
### Legacy Field Naming
|
||||
Database uses PascalCase for column names (legacy convention):
|
||||
- `PatientID`, `NameFirst`, `NameLast`
|
||||
- `Birthdate`, `CreatedAt`, `UpdatedAt`
|
||||
Database uses PascalCase columns: `PatientID`, `NameFirst`, `Birthdate`, `CreatedAt`, `UpdatedAt`
|
||||
|
||||
### ValueSet System
|
||||
Use the `App\Libraries\Lookups` class for static dropdown values:
|
||||
```php
|
||||
use App\Libraries\Lookups;
|
||||
|
||||
$genders = Lookups::get('gender');
|
||||
$label = Lookups::getLabel('gender', '1'); // Returns 'Female'
|
||||
$options = Lookups::getOptions('gender');
|
||||
$labeled = Lookups::transformLabels($data, ['Sex' => 'gender']);
|
||||
```
|
||||
|
||||
### Models
|
||||
Extend `BaseModel` for automatic UTC date handling:
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class PatientModel extends BaseModel
|
||||
{
|
||||
protected $table = 'patients';
|
||||
protected $primaryKey = 'PatientID';
|
||||
protected $allowedFields = ['NameFirst', 'NameLast', ...];
|
||||
}
|
||||
```
|
||||
### Nested Data Handling
|
||||
For entities with nested data (PatIdt, PatCom, PatAtt):
|
||||
- Extract nested arrays before filtering
|
||||
- Use transactions for multi-table operations
|
||||
- Handle empty/null arrays appropriately
|
||||
|
||||
---
|
||||
|
||||
@ -320,7 +269,7 @@ JWT_SECRET = '5pandaNdutNdut'
|
||||
|
||||
## Additional Notes
|
||||
|
||||
- **API-Only**: No view layer - this is a headless REST API
|
||||
- **API-Only**: No view layer - headless REST API
|
||||
- **Frontend Agnostic**: Any client can consume these APIs
|
||||
- **Stateless**: JWT-based authentication per request
|
||||
- **UTC Dates**: All dates stored in UTC, converted for display
|
||||
|
||||
@ -4,6 +4,7 @@ namespace App\Controllers;
|
||||
use App\Traits\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Libraries\ValueSet;
|
||||
use App\Libraries\TestValidationService;
|
||||
|
||||
class TestsController extends BaseController
|
||||
{
|
||||
@ -31,7 +32,7 @@ class TestsController extends BaseController
|
||||
$this->modelRefTxt = new \App\Models\RefRange\RefTxtModel;
|
||||
|
||||
$this->rules = [
|
||||
'TestSiteCode' => 'required|min_length[3]|max_length[6]',
|
||||
'TestSiteCode' => 'required',
|
||||
'TestSiteName' => 'required',
|
||||
'TestType' => 'required',
|
||||
'SiteID' => 'required'
|
||||
@ -154,8 +155,10 @@ class TestsController extends BaseController
|
||||
if (!empty($row['testdeftech'])) {
|
||||
$techData = $row['testdeftech'][0];
|
||||
$refType = $techData['RefType'];
|
||||
$resultType = $techData['ResultType'] ?? '';
|
||||
|
||||
if ($refType === '1' || $refType === 'NMRC' || $refType === '3' || $refType === 'THOLD') {
|
||||
// Use TestValidationService to determine reference table
|
||||
if (TestValidationService::usesRefNum($resultType, $refType)) {
|
||||
$refnumData = $this->modelRefNum
|
||||
->where('TestSiteID', $id)
|
||||
->where('EndDate IS NULL')
|
||||
@ -186,7 +189,7 @@ class TestsController extends BaseController
|
||||
|
||||
}
|
||||
|
||||
if ($refType === '2' || $refType === 'TEXT' || $refType === '4' || $refType === 'VSET') {
|
||||
if (TestValidationService::usesRefTxt($resultType, $refType)) {
|
||||
$reftxtData = $this->modelRefTxt
|
||||
->where('TestSiteID', $id)
|
||||
->where('EndDate IS NULL')
|
||||
@ -225,6 +228,28 @@ class TestsController extends BaseController
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
|
||||
// Validate TestType, ResultType, and RefType combinations
|
||||
$testType = $input['TestType'] ?? '';
|
||||
$details = $input['details'] ?? $input;
|
||||
$resultType = $details['ResultType'] ?? '';
|
||||
$refType = $details['RefType'] ?? '';
|
||||
|
||||
// Set defaults for CALC, GROUP, TITLE types
|
||||
if (TestValidationService::isCalc($testType)) {
|
||||
$resultType = 'NMRIC';
|
||||
$refType = $refType ?: 'RANGE';
|
||||
} elseif (TestValidationService::isGroup($testType) || TestValidationService::isTitle($testType)) {
|
||||
$resultType = 'NORES';
|
||||
$refType = 'NOREF';
|
||||
}
|
||||
|
||||
if ($resultType && $refType) {
|
||||
$validation = TestValidationService::validate($testType, $resultType, $refType);
|
||||
if (!$validation['valid']) {
|
||||
return $this->failValidationErrors(['type_validation' => $validation['error']]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->transStart();
|
||||
|
||||
try {
|
||||
@ -284,6 +309,28 @@ class TestsController extends BaseController
|
||||
return $this->failNotFound('Test not found');
|
||||
}
|
||||
|
||||
// Validate TestType, ResultType, and RefType combinations if provided
|
||||
$testType = $input['TestType'] ?? $existing['TestType'] ?? '';
|
||||
$details = $input['details'] ?? $input;
|
||||
$resultType = $details['ResultType'] ?? $existing['ResultType'] ?? '';
|
||||
$refType = $details['RefType'] ?? $existing['RefType'] ?? '';
|
||||
|
||||
// Set defaults for CALC, GROUP, TITLE types
|
||||
if (TestValidationService::isCalc($testType)) {
|
||||
$resultType = 'NMRIC';
|
||||
$refType = $refType ?: 'RANGE';
|
||||
} elseif (TestValidationService::isGroup($testType) || TestValidationService::isTitle($testType)) {
|
||||
$resultType = 'NORES';
|
||||
$refType = 'NOREF';
|
||||
}
|
||||
|
||||
if ($resultType && $refType) {
|
||||
$validation = TestValidationService::validate($testType, $resultType, $refType);
|
||||
if (!$validation['valid']) {
|
||||
return $this->failValidationErrors(['type_validation' => $validation['error']]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->transStart();
|
||||
|
||||
try {
|
||||
@ -362,15 +409,15 @@ class TestsController extends BaseController
|
||||
$testType = $existing['TestType'];
|
||||
$typeCode = $testType;
|
||||
|
||||
if ($typeCode === 'CALC') {
|
||||
if (TestValidationService::isCalc($typeCode)) {
|
||||
$this->db->table('testdefcal')
|
||||
->where('TestSiteID', $id)
|
||||
->update(['EndDate' => $now]);
|
||||
} elseif ($typeCode === 'GROUP') {
|
||||
} elseif (TestValidationService::isGroup($typeCode)) {
|
||||
$this->db->table('testdefgrp')
|
||||
->where('TestSiteID', $id)
|
||||
->update(['EndDate' => $now]);
|
||||
} elseif (in_array($typeCode, ['TEST', 'PARAM'])) {
|
||||
} elseif (TestValidationService::isTechnicalTest($typeCode)) {
|
||||
|
||||
$this->modelRefNum->where('TestSiteID', $id)->set('EndDate', $now)->update();
|
||||
$this->modelRefTxt->where('TestSiteID', $id)->set('EndDate', $now)->update();
|
||||
@ -437,19 +484,21 @@ class TestsController extends BaseController
|
||||
|
||||
if (in_array($typeCode, ['TEST', 'PARAM']) && isset($details['RefType'])) {
|
||||
$refType = (string) $details['RefType'];
|
||||
$resultType = $details['ResultType'] ?? '';
|
||||
|
||||
if (($refType === '1' || $refType === 'NMRC' || $refType === '3' || $refType === 'THOLD') && isset($input['refnum']) && is_array($input['refnum'])) {
|
||||
// Use TestValidationService to determine which reference table to use
|
||||
if (TestValidationService::usesRefNum($resultType, $refType) && isset($input['refnum']) && is_array($input['refnum'])) {
|
||||
$this->saveRefNumRanges($testSiteID, $input['refnum'], $action, $input['SiteID'] ?? 1);
|
||||
}
|
||||
|
||||
if (($refType === '2' || $refType === 'TEXT' || $refType === '4' || $refType === 'VSET') && isset($input['reftxt']) && is_array($input['reftxt'])) {
|
||||
if (TestValidationService::usesRefTxt($resultType, $refType) && isset($input['reftxt']) && is_array($input['reftxt'])) {
|
||||
$this->saveRefTxtRanges($testSiteID, $input['reftxt'], $action, $input['SiteID'] ?? 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (in_array($typeCode, ['TEST', 'CALC']) && isset($input['testmap']) && is_array($input['testmap'])) {
|
||||
if ((TestValidationService::isTechnicalTest($typeCode) || TestValidationService::isCalc($typeCode)) && isset($input['testmap']) && is_array($input['testmap'])) {
|
||||
$this->saveTestMap($testSiteID, $input['testmap'], $action);
|
||||
}
|
||||
}
|
||||
@ -538,7 +587,8 @@ class TestsController extends BaseController
|
||||
'DepartmentID' => $data['DepartmentID'] ?? null,
|
||||
'FormulaInput' => $data['FormulaInput'] ?? null,
|
||||
'FormulaCode' => $data['FormulaCode'] ?? $data['Formula'] ?? null,
|
||||
'RefType' => $data['RefType'] ?? 'NMRC',
|
||||
'ResultType' => 'NMRIC', // CALC always has NMRIC result type
|
||||
'RefType' => $data['RefType'] ?? 'RANGE',
|
||||
'Unit1' => $data['Unit1'] ?? $data['ResultUnit'] ?? null,
|
||||
'Factor' => $data['Factor'] ?? null,
|
||||
'Unit2' => $data['Unit2'] ?? null,
|
||||
|
||||
162
app/Database/Migrations/2026-02-20-000011_CreateAuditLogs.php
Normal file
162
app/Database/Migrations/2026-02-20-000011_CreateAuditLogs.php
Normal file
@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class CreateAuditLogs extends Migration {
|
||||
public function up() {
|
||||
// Drop old audit tables if they exist
|
||||
$this->forge->dropTable('patreglog', true);
|
||||
$this->forge->dropTable('patvisitlog', true);
|
||||
$this->forge->dropTable('specimenlog', true);
|
||||
|
||||
// Create data_audit_log table
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'BIGINT', 'constraint' => 20, 'unsigned' => true, 'auto_increment' => true],
|
||||
'operation' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false],
|
||||
'entity_type' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false],
|
||||
'entity_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => false],
|
||||
'table_name' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
|
||||
'field_name' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
|
||||
'previous_value' => ['type' => 'JSON', 'null' => true],
|
||||
'new_value' => ['type' => 'JSON', 'null' => true],
|
||||
'mechanism' => ['type' => 'ENUM', 'constraint' => ['MANUAL', 'AUTOMATIC'], 'null' => false, 'default' => 'MANUAL'],
|
||||
'application_id' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
||||
'web_page' => ['type' => 'VARCHAR', 'constraint' => 500, 'null' => true],
|
||||
'session_id' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
|
||||
'event_type' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
|
||||
'site_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => true],
|
||||
'workstation_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => true],
|
||||
'pc_name' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
|
||||
'ip_address' => ['type' => 'VARCHAR', 'constraint' => 45, 'null' => true],
|
||||
'user_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => false],
|
||||
'created_at' => ['type' => 'DATETIME', 'null' => false],
|
||||
'reason' => ['type' => 'TEXT', 'null' => true],
|
||||
'context' => ['type' => 'JSON', 'null' => true]
|
||||
]);
|
||||
$this->forge->addKey('id', true);
|
||||
$this->forge->addKey('idx_operation_created', ['operation', 'created_at']);
|
||||
$this->forge->addKey('idx_entity', ['entity_type', 'entity_id', 'created_at']);
|
||||
$this->forge->addKey('idx_user_created', ['user_id', 'created_at']);
|
||||
$this->forge->addKey('idx_mechanism', ['mechanism', 'created_at']);
|
||||
$this->forge->addKey('idx_table', ['table_name', 'created_at']);
|
||||
$this->forge->addKey('idx_site', ['site_id', 'created_at']);
|
||||
$this->forge->addKey('idx_created', 'created_at');
|
||||
$this->forge->addKey('idx_session', ['session_id', 'created_at']);
|
||||
$this->forge->createTable('data_audit_log', true);
|
||||
|
||||
// Create service_audit_log table
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'BIGINT', 'constraint' => 20, 'unsigned' => true, 'auto_increment' => true],
|
||||
'operation' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false],
|
||||
'entity_type' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false],
|
||||
'entity_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => false],
|
||||
'service_class' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
||||
'resource_type' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
|
||||
'resource_details' => ['type' => 'JSON', 'null' => true],
|
||||
'previous_value' => ['type' => 'JSON', 'null' => true],
|
||||
'new_value' => ['type' => 'JSON', 'null' => true],
|
||||
'mechanism' => ['type' => 'ENUM', 'constraint' => ['MANUAL', 'AUTOMATIC'], 'null' => false, 'default' => 'AUTOMATIC'],
|
||||
'application_id' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
||||
'service_name' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
|
||||
'session_id' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
|
||||
'event_type' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
|
||||
'site_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => true],
|
||||
'workstation_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => true],
|
||||
'pc_name' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
|
||||
'ip_address' => ['type' => 'VARCHAR', 'constraint' => 45, 'null' => true],
|
||||
'port' => ['type' => 'INT', 'null' => true],
|
||||
'user_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => false],
|
||||
'created_at' => ['type' => 'DATETIME', 'null' => false],
|
||||
'reason' => ['type' => 'TEXT', 'null' => true],
|
||||
'context' => ['type' => 'JSON', 'null' => true]
|
||||
]);
|
||||
$this->forge->addKey('id', true);
|
||||
$this->forge->addKey('idx_operation_created', ['operation', 'created_at']);
|
||||
$this->forge->addKey('idx_entity', ['entity_type', 'entity_id', 'created_at']);
|
||||
$this->forge->addKey('idx_service_class', ['service_class', 'created_at']);
|
||||
$this->forge->addKey('idx_user_created', ['user_id', 'created_at']);
|
||||
$this->forge->addKey('idx_mechanism', ['mechanism', 'created_at']);
|
||||
$this->forge->addKey('idx_site', ['site_id', 'created_at']);
|
||||
$this->forge->addKey('idx_created', 'created_at');
|
||||
$this->forge->createTable('service_audit_log', true);
|
||||
|
||||
// Create security_audit_log table
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'BIGINT', 'constraint' => 20, 'unsigned' => true, 'auto_increment' => true],
|
||||
'operation' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false],
|
||||
'entity_type' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false],
|
||||
'entity_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => false],
|
||||
'security_class' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
||||
'resource_path' => ['type' => 'VARCHAR', 'constraint' => 500, 'null' => true],
|
||||
'previous_value' => ['type' => 'JSON', 'null' => true],
|
||||
'new_value' => ['type' => 'JSON', 'null' => true],
|
||||
'mechanism' => ['type' => 'ENUM', 'constraint' => ['MANUAL', 'AUTOMATIC'], 'null' => false, 'default' => 'MANUAL'],
|
||||
'application_id' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
||||
'web_page' => ['type' => 'VARCHAR', 'constraint' => 500, 'null' => true],
|
||||
'session_id' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
|
||||
'event_type' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
|
||||
'site_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => true],
|
||||
'workstation_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => true],
|
||||
'pc_name' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
|
||||
'ip_address' => ['type' => 'VARCHAR', 'constraint' => 45, 'null' => true],
|
||||
'user_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => false],
|
||||
'created_at' => ['type' => 'DATETIME', 'null' => false],
|
||||
'reason' => ['type' => 'TEXT', 'null' => true],
|
||||
'context' => ['type' => 'JSON', 'null' => true]
|
||||
]);
|
||||
$this->forge->addKey('id', true);
|
||||
$this->forge->addKey('idx_operation_created', ['operation', 'created_at']);
|
||||
$this->forge->addKey('idx_entity', ['entity_type', 'entity_id', 'created_at']);
|
||||
$this->forge->addKey('idx_security_class', ['security_class', 'created_at']);
|
||||
$this->forge->addKey('idx_user_created', ['user_id', 'created_at']);
|
||||
$this->forge->addKey('idx_event_type', ['event_type', 'created_at']);
|
||||
$this->forge->addKey('idx_site', ['site_id', 'created_at']);
|
||||
$this->forge->addKey('idx_created', 'created_at');
|
||||
$this->forge->addKey('idx_session', ['session_id', 'created_at']);
|
||||
$this->forge->createTable('security_audit_log', true);
|
||||
|
||||
// Create error_audit_log table
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'BIGINT', 'constraint' => 20, 'unsigned' => true, 'auto_increment' => true],
|
||||
'operation' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false],
|
||||
'entity_type' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false],
|
||||
'entity_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => false],
|
||||
'error_code' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
||||
'error_message' => ['type' => 'TEXT', 'null' => true],
|
||||
'error_details' => ['type' => 'JSON', 'null' => true],
|
||||
'previous_value' => ['type' => 'JSON', 'null' => true],
|
||||
'new_value' => ['type' => 'JSON', 'null' => true],
|
||||
'mechanism' => ['type' => 'ENUM', 'constraint' => ['MANUAL', 'AUTOMATIC'], 'null' => false, 'default' => 'MANUAL'],
|
||||
'application_id' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
||||
'web_page' => ['type' => 'VARCHAR', 'constraint' => 500, 'null' => true],
|
||||
'session_id' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
|
||||
'event_type' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
|
||||
'site_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => true],
|
||||
'workstation_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => true],
|
||||
'pc_name' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
|
||||
'ip_address' => ['type' => 'VARCHAR', 'constraint' => 45, 'null' => true],
|
||||
'user_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => false],
|
||||
'created_at' => ['type' => 'DATETIME', 'null' => false],
|
||||
'reason' => ['type' => 'TEXT', 'null' => true],
|
||||
'context' => ['type' => 'JSON', 'null' => true]
|
||||
]);
|
||||
$this->forge->addKey('id', true);
|
||||
$this->forge->addKey('idx_operation_created', ['operation', 'created_at']);
|
||||
$this->forge->addKey('idx_entity', ['entity_type', 'entity_id', 'created_at']);
|
||||
$this->forge->addKey('idx_error_code', ['error_code', 'created_at']);
|
||||
$this->forge->addKey('idx_event_type', ['event_type', 'created_at']);
|
||||
$this->forge->addKey('idx_user_created', ['user_id', 'created_at']);
|
||||
$this->forge->addKey('idx_site', ['site_id', 'created_at']);
|
||||
$this->forge->addKey('idx_created', 'created_at');
|
||||
$this->forge->createTable('error_audit_log', true);
|
||||
}
|
||||
|
||||
public function down() {
|
||||
$this->forge->dropTable('error_audit_log');
|
||||
$this->forge->dropTable('security_audit_log');
|
||||
$this->forge->dropTable('service_audit_log');
|
||||
$this->forge->dropTable('data_audit_log');
|
||||
}
|
||||
}
|
||||
@ -29,72 +29,72 @@ class TestSeeder extends Seeder
|
||||
// TEST TYPE - Actual Laboratory Tests
|
||||
// ========================================
|
||||
// Hematology Tests - Technical details merged into testdefsite
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'HB', 'TestSiteName' => 'Hemoglobin', 'TestType' => 'TEST', 'Description' => '', 'SeqScr' => '2', 'SeqRpt' => '2', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'g/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'HB', 'TestSiteName' => 'Hemoglobin', 'TestType' => 'TEST', 'Description' => '', 'SeqScr' => '2', 'SeqRpt' => '2', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'g/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['HB'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'HCT', 'TestSiteName' => 'Hematocrit', 'TestType' => 'TEST', 'Description' => '', 'SeqScr' => '3', 'SeqRpt' => '3', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => '%', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'HCT', 'TestSiteName' => 'Hematocrit', 'TestType' => 'TEST', 'Description' => '', 'SeqScr' => '3', 'SeqRpt' => '3', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => '%', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['HCT'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'RBC', 'TestSiteName' => 'Red Blood Cell', 'TestType' => 'TEST', 'Description' => 'Eritrosit', 'SeqScr' => '4', 'SeqRpt' => '4', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'x10^6/uL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '2', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'RBC', 'TestSiteName' => 'Red Blood Cell', 'TestType' => 'TEST', 'Description' => 'Eritrosit', 'SeqScr' => '4', 'SeqRpt' => '4', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'x10^6/uL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '2', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['RBC'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'WBC', 'TestSiteName' => 'White Blood Cell', 'TestType' => 'TEST', 'Description' => 'Leukosit', 'SeqScr' => '5', 'SeqRpt' => '5', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'x10^3/uL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '2', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'WBC', 'TestSiteName' => 'White Blood Cell', 'TestType' => 'TEST', 'Description' => 'Leukosit', 'SeqScr' => '5', 'SeqRpt' => '5', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'x10^3/uL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '2', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['WBC'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'PLT', 'TestSiteName' => 'Platelet', 'TestType' => 'TEST', 'Description' => 'Trombosit', 'SeqScr' => '6', 'SeqRpt' => '6', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'x10^3/uL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'PLT', 'TestSiteName' => 'Platelet', 'TestType' => 'TEST', 'Description' => 'Trombosit', 'SeqScr' => '6', 'SeqRpt' => '6', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'x10^3/uL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['PLT'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'MCV', 'TestSiteName' => 'MCV', 'TestType' => 'TEST', 'Description' => 'Mean Corpuscular Volume', 'SeqScr' => '7', 'SeqRpt' => '7', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'fL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'MCV', 'TestSiteName' => 'MCV', 'TestType' => 'TEST', 'Description' => 'Mean Corpuscular Volume', 'SeqScr' => '7', 'SeqRpt' => '7', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'fL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['MCV'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'MCH', 'TestSiteName' => 'MCH', 'TestType' => 'TEST', 'Description' => 'Mean Corpuscular Hemoglobin', 'SeqScr' => '8', 'SeqRpt' => '8', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'pg', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'MCH', 'TestSiteName' => 'MCH', 'TestType' => 'TEST', 'Description' => 'Mean Corpuscular Hemoglobin', 'SeqScr' => '8', 'SeqRpt' => '8', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'pg', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['MCH'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'MCHC', 'TestSiteName' => 'MCHC', 'TestType' => 'TEST', 'Description' => 'Mean Corpuscular Hemoglobin Concentration', 'SeqScr' => '9', 'SeqRpt' => '9', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'g/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'MCHC', 'TestSiteName' => 'MCHC', 'TestType' => 'TEST', 'Description' => 'Mean Corpuscular Hemoglobin Concentration', 'SeqScr' => '9', 'SeqRpt' => '9', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'g/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['MCHC'] = $this->db->insertID();
|
||||
|
||||
// Chemistry Tests
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'GLU', 'TestSiteName' => 'Glucose', 'TestType' => 'TEST', 'Description' => 'Glukosa Sewaktu', 'SeqScr' => '11', 'SeqRpt' => '11', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '0.0555', 'Unit2' => 'mmol/L', 'Decimal' => '0', 'Method' => 'Hexokinase', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'GLU', 'TestSiteName' => 'Glucose', 'TestType' => 'TEST', 'Description' => 'Glukosa Sewaktu', 'SeqScr' => '11', 'SeqRpt' => '11', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '0.0555', 'Unit2' => 'mmol/L', 'Decimal' => '0', 'Method' => 'Hexokinase', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['GLU'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'CREA', 'TestSiteName' => 'Creatinine', 'TestType' => 'TEST', 'Description' => 'Kreatinin', 'SeqScr' => '12', 'SeqRpt' => '12', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '88.4', 'Unit2' => 'umol/L', 'Decimal' => '2', 'Method' => 'Enzymatic', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'CREA', 'TestSiteName' => 'Creatinine', 'TestType' => 'TEST', 'Description' => 'Kreatinin', 'SeqScr' => '12', 'SeqRpt' => '12', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '88.4', 'Unit2' => 'umol/L', 'Decimal' => '2', 'Method' => 'Enzymatic', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['CREA'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'UREA', 'TestSiteName' => 'Blood Urea Nitrogen', 'TestType' => 'TEST', 'Description' => 'BUN', 'SeqScr' => '13', 'SeqRpt' => '13', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'Urease-GLDH', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'UREA', 'TestSiteName' => 'Blood Urea Nitrogen', 'TestType' => 'TEST', 'Description' => 'BUN', 'SeqScr' => '13', 'SeqRpt' => '13', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'Urease-GLDH', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['UREA'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'SGOT', 'TestSiteName' => 'AST (SGOT)', 'TestType' => 'TEST', 'Description' => 'Aspartate Aminotransferase', 'SeqScr' => '14', 'SeqRpt' => '14', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'U/L', 'Factor' => '0.017', 'Unit2' => 'ukat/L', 'Decimal' => '0', 'Method' => 'IFCC', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'SGOT', 'TestSiteName' => 'AST (SGOT)', 'TestType' => 'TEST', 'Description' => 'Aspartate Aminotransferase', 'SeqScr' => '14', 'SeqRpt' => '14', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'U/L', 'Factor' => '0.017', 'Unit2' => 'ukat/L', 'Decimal' => '0', 'Method' => 'IFCC', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['SGOT'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'SGPT', 'TestSiteName' => 'ALT (SGPT)', 'TestType' => 'TEST', 'Description' => 'Alanine Aminotransferase', 'SeqScr' => '15', 'SeqRpt' => '15', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'U/L', 'Factor' => '0.017', 'Unit2' => 'ukat/L', 'Decimal' => '0', 'Method' => 'IFCC', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'SGPT', 'TestSiteName' => 'ALT (SGPT)', 'TestType' => 'TEST', 'Description' => 'Alanine Aminotransferase', 'SeqScr' => '15', 'SeqRpt' => '15', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'U/L', 'Factor' => '0.017', 'Unit2' => 'ukat/L', 'Decimal' => '0', 'Method' => 'IFCC', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['SGPT'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'CHOL', 'TestSiteName' => 'Total Cholesterol', 'TestType' => 'TEST', 'Description' => 'Kolesterol Total', 'SeqScr' => '16', 'SeqRpt' => '16', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'Enzymatic', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'CHOL', 'TestSiteName' => 'Total Cholesterol', 'TestType' => 'TEST', 'Description' => 'Kolesterol Total', 'SeqScr' => '16', 'SeqRpt' => '16', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'Enzymatic', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['CHOL'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'TG', 'TestSiteName' => 'Triglycerides', 'TestType' => 'TEST', 'Description' => 'Trigliserida', 'SeqScr' => '17', 'SeqRpt' => '17', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'GPO-PAP', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'TG', 'TestSiteName' => 'Triglycerides', 'TestType' => 'TEST', 'Description' => 'Trigliserida', 'SeqScr' => '17', 'SeqRpt' => '17', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'GPO-PAP', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['TG'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'HDL', 'TestSiteName' => 'HDL Cholesterol', 'TestType' => 'TEST', 'Description' => 'Kolesterol HDL', 'SeqScr' => '18', 'SeqRpt' => '18', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'Direct', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'HDL', 'TestSiteName' => 'HDL Cholesterol', 'TestType' => 'TEST', 'Description' => 'Kolesterol HDL', 'SeqScr' => '18', 'SeqRpt' => '18', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'Direct', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['HDL'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'LDL', 'TestSiteName' => 'LDL Cholesterol', 'TestType' => 'TEST', 'Description' => 'Kolesterol LDL', 'SeqScr' => '19', 'SeqRpt' => '19', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'Direct', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'LDL', 'TestSiteName' => 'LDL Cholesterol', 'TestType' => 'TEST', 'Description' => 'Kolesterol LDL', 'SeqScr' => '19', 'SeqRpt' => '19', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'Direct', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['LDL'] = $this->db->insertID();
|
||||
|
||||
@ -127,25 +127,25 @@ class TestSeeder extends Seeder
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'BMI', 'TestSiteName' => 'Body Mass Index', 'TestType' => 'CALC', 'Description' => 'Indeks Massa Tubuh - weight/(height^2)', 'SeqScr' => '45', 'SeqRpt' => '45', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '0', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['BMI'] = $this->db->insertID();
|
||||
$data = ['TestSiteID' => $tIDs['BMI'], 'DisciplineID' => '10', 'DepartmentID' => '', 'FormulaInput' => 'WEIGHT,HEIGHT', 'FormulaCode' => 'WEIGHT / ((HEIGHT/100) * (HEIGHT/100))', 'Unit1' => 'kg/m2', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'CreateDate' => "$now"];
|
||||
$data = ['TestSiteID' => $tIDs['BMI'], 'DisciplineID' => '10', 'DepartmentID' => '', 'FormulaInput' => 'WEIGHT,HEIGHT', 'FormulaCode' => 'WEIGHT / ((HEIGHT/100) * (HEIGHT/100))', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'Unit1' => 'kg/m2', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefcal')->insert($data);
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'EGFR', 'TestSiteName' => 'eGFR (CKD-EPI)', 'TestType' => 'CALC', 'Description' => 'Estimated Glomerular Filtration Rate', 'SeqScr' => '20', 'SeqRpt' => '20', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '0', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['EGFR'] = $this->db->insertID();
|
||||
$data = ['TestSiteID' => $tIDs['EGFR'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'FormulaInput' => 'CREA,AGE,GENDER', 'FormulaCode' => 'CKD_EPI(CREA,AGE,GENDER)', 'Unit1' => 'mL/min/1.73m2', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'CreateDate' => "$now"];
|
||||
$data = ['TestSiteID' => $tIDs['EGFR'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'FormulaInput' => 'CREA,AGE,GENDER', 'FormulaCode' => 'CKD_EPI(CREA,AGE,GENDER)', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'Unit1' => 'mL/min/1.73m2', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefcal')->insert($data);
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'LDLCALC', 'TestSiteName' => 'LDL Cholesterol (Calculated)', 'TestType' => 'CALC', 'Description' => 'Friedewald formula: TC - HDL - (TG/5)', 'SeqScr' => '21', 'SeqRpt' => '21', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '0', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['LDLCALC'] = $this->db->insertID();
|
||||
$data = ['TestSiteID' => $tIDs['LDLCALC'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'FormulaInput' => 'CHOL,HDL,TG', 'FormulaCode' => 'CHOL - HDL - (TG/5)', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'CreateDate' => "$now"];
|
||||
$data = ['TestSiteID' => $tIDs['LDLCALC'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'FormulaInput' => 'CHOL,HDL,TG', 'FormulaCode' => 'CHOL - HDL - (TG/5)', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefcal')->insert($data);
|
||||
|
||||
// ========================================
|
||||
// GROUP TYPE - Panel/Profile Tests
|
||||
// ========================================
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'CBC', 'TestSiteName' => 'Complete Blood Count', 'TestType' => 'GROUP', 'Description' => 'Darah Lengkap', 'SeqScr' => '50', 'SeqRpt' => '50', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'CBC', 'TestSiteName' => 'Complete Blood Count', 'TestType' => 'GROUP', 'Description' => 'Darah Lengkap', 'SeqScr' => '50', 'SeqRpt' => '50', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'ResultType' => 'NORES', 'RefType' => 'NOREF', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['CBC'] = $this->db->insertID();
|
||||
$this->db->table('testdefgrp')->insertBatch([
|
||||
@ -159,7 +159,7 @@ class TestSeeder extends Seeder
|
||||
['TestSiteID' => $tIDs['CBC'], 'Member' => $tIDs['MCHC'], 'CreateDate' => "$now"]
|
||||
]);
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'LIPID', 'TestSiteName' => 'Lipid Profile', 'TestType' => 'GROUP', 'Description' => 'Profil Lipid', 'SeqScr' => '51', 'SeqRpt' => '51', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'LIPID', 'TestSiteName' => 'Lipid Profile', 'TestType' => 'GROUP', 'Description' => 'Profil Lipid', 'SeqScr' => '51', 'SeqRpt' => '51', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'ResultType' => 'NORES', 'RefType' => 'NOREF', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['LIPID'] = $this->db->insertID();
|
||||
$this->db->table('testdefgrp')->insertBatch([
|
||||
@ -170,7 +170,7 @@ class TestSeeder extends Seeder
|
||||
['TestSiteID' => $tIDs['LIPID'], 'Member' => $tIDs['LDLCALC'], 'CreateDate' => "$now"]
|
||||
]);
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'LFT', 'TestSiteName' => 'Liver Function Test', 'TestType' => 'GROUP', 'Description' => 'Fungsi Hati', 'SeqScr' => '52', 'SeqRpt' => '52', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'LFT', 'TestSiteName' => 'Liver Function Test', 'TestType' => 'GROUP', 'Description' => 'Fungsi Hati', 'SeqScr' => '52', 'SeqRpt' => '52', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'ResultType' => 'NORES', 'RefType' => 'NOREF', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['LFT'] = $this->db->insertID();
|
||||
$this->db->table('testdefgrp')->insertBatch([
|
||||
@ -178,7 +178,7 @@ class TestSeeder extends Seeder
|
||||
['TestSiteID' => $tIDs['LFT'], 'Member' => $tIDs['SGPT'], 'CreateDate' => "$now"]
|
||||
]);
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'RFT', 'TestSiteName' => 'Renal Function Test', 'TestType' => 'GROUP', 'Description' => 'Fungsi Ginjal', 'SeqScr' => '53', 'SeqRpt' => '53', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'RFT', 'TestSiteName' => 'Renal Function Test', 'TestType' => 'GROUP', 'Description' => 'Fungsi Ginjal', 'SeqScr' => '53', 'SeqRpt' => '53', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'ResultType' => 'NORES', 'RefType' => 'NOREF', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['RFT'] = $this->db->insertID();
|
||||
$this->db->table('testdefgrp')->insertBatch([
|
||||
@ -188,19 +188,19 @@ class TestSeeder extends Seeder
|
||||
]);
|
||||
|
||||
// Urinalysis Tests (with valueset result type)
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'UCOLOR', 'TestSiteName' => 'Urine Color', 'TestType' => 'TEST', 'Description' => 'Warna Urine', 'SeqScr' => '31', 'SeqRpt' => '31', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => 'VSET', 'RefType' => 'TEXT', 'VSet' => '1001', 'ReqQty' => '10', 'ReqQtyUnit' => 'mL', 'Unit1' => '', 'Factor' => '', 'Unit2' => '', 'Decimal' => '', 'Method' => 'Visual', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'UCOLOR', 'TestSiteName' => 'Urine Color', 'TestType' => 'TEST', 'Description' => 'Warna Urine', 'SeqScr' => '31', 'SeqRpt' => '31', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => 'VSET', 'RefType' => 'VSET', 'VSet' => '1001', 'ReqQty' => '10', 'ReqQtyUnit' => 'mL', 'Unit1' => '', 'Factor' => '', 'Unit2' => '', 'Decimal' => '', 'Method' => 'Visual', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['UCOLOR'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'UGLUC', 'TestSiteName' => 'Urine Glucose', 'TestType' => 'TEST', 'Description' => 'Glukosa Urine', 'SeqScr' => '32', 'SeqRpt' => '32', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => 'VSET', 'RefType' => 'TEXT', 'VSet' => '1002', 'ReqQty' => '10', 'ReqQtyUnit' => 'mL', 'Unit1' => '', 'Factor' => '', 'Unit2' => '', 'Decimal' => '', 'Method' => 'Dipstick', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'UGLUC', 'TestSiteName' => 'Urine Glucose', 'TestType' => 'TEST', 'Description' => 'Glukosa Urine', 'SeqScr' => '32', 'SeqRpt' => '32', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => 'VSET', 'RefType' => 'VSET', 'VSet' => '1002', 'ReqQty' => '10', 'ReqQtyUnit' => 'mL', 'Unit1' => '', 'Factor' => '', 'Unit2' => '', 'Decimal' => '', 'Method' => 'Dipstick', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['UGLUC'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'UPROT', 'TestSiteName' => 'Urine Protein', 'TestType' => 'TEST', 'Description' => 'Protein Urine', 'SeqScr' => '33', 'SeqRpt' => '33', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => 'VSET', 'RefType' => 'TEXT', 'VSet' => '1003', 'ReqQty' => '10', 'ReqQtyUnit' => 'mL', 'Unit1' => '', 'Factor' => '', 'Unit2' => '', 'Decimal' => '', 'Method' => 'Dipstick', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'UPROT', 'TestSiteName' => 'Urine Protein', 'TestType' => 'TEST', 'Description' => 'Protein Urine', 'SeqScr' => '33', 'SeqRpt' => '33', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => 'VSET', 'RefType' => 'VSET', 'VSet' => '1003', 'ReqQty' => '10', 'ReqQtyUnit' => 'mL', 'Unit1' => '', 'Factor' => '', 'Unit2' => '', 'Decimal' => '', 'Method' => 'Dipstick', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['UPROT'] = $this->db->insertID();
|
||||
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'PH', 'TestSiteName' => 'Urine pH', 'TestType' => 'TEST', 'Description' => 'pH Urine', 'SeqScr' => '34', 'SeqRpt' => '34', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '10', 'ReqQtyUnit' => 'mL', 'Unit1' => '', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'Dipstick', 'CreateDate' => "$now"];
|
||||
$data = ['SiteID' => '1', 'TestSiteCode' => 'PH', 'TestSiteName' => 'Urine pH', 'TestType' => 'TEST', 'Description' => 'pH Urine', 'SeqScr' => '34', 'SeqRpt' => '34', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'VSet' => '', 'ReqQty' => '10', 'ReqQtyUnit' => 'mL', 'Unit1' => '', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'Dipstick', 'CreateDate' => "$now"];
|
||||
$this->db->table('testdefsite')->insert($data);
|
||||
$tIDs['PH'] = $this->db->insertID();
|
||||
}
|
||||
|
||||
259
app/Libraries/TestValidationService.php
Normal file
259
app/Libraries/TestValidationService.php
Normal file
@ -0,0 +1,259 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries;
|
||||
|
||||
/**
|
||||
* Test Validation Service
|
||||
*
|
||||
* Validates TestType, ResultType, and RefType combinations
|
||||
* according to business rules for CLQMS test definitions.
|
||||
*/
|
||||
class TestValidationService
|
||||
{
|
||||
/**
|
||||
* Valid TestType to ResultType mappings
|
||||
*/
|
||||
private const TEST_TYPE_RESULT_TYPES = [
|
||||
'TEST' => ['NMRIC', 'RANGE', 'TEXT', 'VSET'],
|
||||
'PARAM' => ['NMRIC', 'RANGE', 'TEXT', 'VSET'],
|
||||
'CALC' => ['NMRIC'],
|
||||
'GROUP' => ['NORES'],
|
||||
'TITLE' => ['NORES'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Valid ResultType to RefType mappings
|
||||
*/
|
||||
private const RESULT_TYPE_REF_TYPES = [
|
||||
'NMRIC' => ['RANGE', 'THOLD'],
|
||||
'RANGE' => ['RANGE', 'THOLD'],
|
||||
'VSET' => ['VSET'],
|
||||
'TEXT' => ['TEXT'],
|
||||
'NORES' => ['NOREF'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Reference table mapping based on ResultType and RefType
|
||||
*/
|
||||
private const REFERENCE_TABLES = [
|
||||
'NMRIC' => [
|
||||
'RANGE' => 'refnum',
|
||||
'THOLD' => 'refnum',
|
||||
],
|
||||
'RANGE' => [
|
||||
'RANGE' => 'refnum',
|
||||
'THOLD' => 'refnum',
|
||||
],
|
||||
'VSET' => [
|
||||
'VSET' => 'reftxt',
|
||||
],
|
||||
'TEXT' => [
|
||||
'TEXT' => 'reftxt',
|
||||
],
|
||||
'NORES' => [
|
||||
'NOREF' => null,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Validate TestType and ResultType combination
|
||||
*
|
||||
* @param string $testType
|
||||
* @param string $resultType
|
||||
* @return array ['valid' => bool, 'error' => string|null]
|
||||
*/
|
||||
public static function validateTestTypeResultType(string $testType, string $resultType): array
|
||||
{
|
||||
$testType = strtoupper($testType);
|
||||
$resultType = strtoupper($resultType);
|
||||
|
||||
if (!isset(self::TEST_TYPE_RESULT_TYPES[$testType])) {
|
||||
return [
|
||||
'valid' => false,
|
||||
'error' => "Invalid TestType '{$testType}'. Allowed: TEST, PARAM, CALC, GROUP, TITLE"
|
||||
];
|
||||
}
|
||||
|
||||
$validResultTypes = self::TEST_TYPE_RESULT_TYPES[$testType];
|
||||
|
||||
if (!in_array($resultType, $validResultTypes, true)) {
|
||||
return [
|
||||
'valid' => false,
|
||||
'error' => "Invalid ResultType '{$resultType}' for TestType '{$testType}'. Allowed: " . implode(', ', $validResultTypes)
|
||||
];
|
||||
}
|
||||
|
||||
return ['valid' => true, 'error' => null];
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate ResultType and RefType combination
|
||||
*
|
||||
* @param string $resultType
|
||||
* @param string $refType
|
||||
* @return array ['valid' => bool, 'error' => string|null]
|
||||
*/
|
||||
public static function validateResultTypeRefType(string $resultType, string $refType): array
|
||||
{
|
||||
$resultType = strtoupper($resultType);
|
||||
$refType = strtoupper($refType);
|
||||
|
||||
if (!isset(self::RESULT_TYPE_REF_TYPES[$resultType])) {
|
||||
return [
|
||||
'valid' => false,
|
||||
'error' => "Invalid ResultType '{$resultType}'. Allowed: NMRIC, RANGE, TEXT, VSET, NORES"
|
||||
];
|
||||
}
|
||||
|
||||
$validRefTypes = self::RESULT_TYPE_REF_TYPES[$resultType];
|
||||
|
||||
if (!in_array($refType, $validRefTypes, true)) {
|
||||
return [
|
||||
'valid' => false,
|
||||
'error' => "Invalid RefType '{$refType}' for ResultType '{$resultType}'. Allowed: " . implode(', ', $validRefTypes)
|
||||
];
|
||||
}
|
||||
|
||||
return ['valid' => true, 'error' => null];
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate complete test type combination
|
||||
*
|
||||
* @param string $testType
|
||||
* @param string $resultType
|
||||
* @param string $refType
|
||||
* @return array ['valid' => bool, 'error' => string|null]
|
||||
*/
|
||||
public static function validate(string $testType, string $resultType, string $refType): array
|
||||
{
|
||||
// First validate TestType and ResultType
|
||||
$testResultValidation = self::validateTestTypeResultType($testType, $resultType);
|
||||
if (!$testResultValidation['valid']) {
|
||||
return $testResultValidation;
|
||||
}
|
||||
|
||||
// Then validate ResultType and RefType
|
||||
return self::validateResultTypeRefType($resultType, $refType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get valid ResultTypes for a TestType
|
||||
*
|
||||
* @param string $testType
|
||||
* @return array
|
||||
*/
|
||||
public static function getValidResultTypes(string $testType): array
|
||||
{
|
||||
$testType = strtoupper($testType);
|
||||
return self::TEST_TYPE_RESULT_TYPES[$testType] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get valid RefTypes for a ResultType
|
||||
*
|
||||
* @param string $resultType
|
||||
* @return array
|
||||
*/
|
||||
public static function getValidRefTypes(string $resultType): array
|
||||
{
|
||||
$resultType = strtoupper($resultType);
|
||||
return self::RESULT_TYPE_REF_TYPES[$resultType] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get reference table name based on ResultType and RefType
|
||||
*
|
||||
* @param string $resultType
|
||||
* @param string $refType
|
||||
* @return string|null Returns table name or null if no reference table needed
|
||||
*/
|
||||
public static function getReferenceTable(string $resultType, string $refType): ?string
|
||||
{
|
||||
$resultType = strtoupper($resultType);
|
||||
$refType = strtoupper($refType);
|
||||
|
||||
return self::REFERENCE_TABLES[$resultType][$refType] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a test needs reference ranges
|
||||
*
|
||||
* @param string $resultType
|
||||
* @return bool
|
||||
*/
|
||||
public static function needsReferenceRanges(string $resultType): bool
|
||||
{
|
||||
$resultType = strtoupper($resultType);
|
||||
return $resultType !== 'NORES';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a test uses refnum table
|
||||
*
|
||||
* @param string $resultType
|
||||
* @param string $refType
|
||||
* @return bool
|
||||
*/
|
||||
public static function usesRefNum(string $resultType, string $refType): bool
|
||||
{
|
||||
return self::getReferenceTable($resultType, $refType) === 'refnum';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a test uses reftxt table
|
||||
*
|
||||
* @param string $resultType
|
||||
* @param string $refType
|
||||
* @return bool
|
||||
*/
|
||||
public static function usesRefTxt(string $resultType, string $refType): bool
|
||||
{
|
||||
return self::getReferenceTable($resultType, $refType) === 'reftxt';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if TestType is CALC
|
||||
*
|
||||
* @param string $testType
|
||||
* @return bool
|
||||
*/
|
||||
public static function isCalc(string $testType): bool
|
||||
{
|
||||
return strtoupper($testType) === 'CALC';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if TestType is GROUP
|
||||
*
|
||||
* @param string $testType
|
||||
* @return bool
|
||||
*/
|
||||
public static function isGroup(string $testType): bool
|
||||
{
|
||||
return strtoupper($testType) === 'GROUP';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if TestType is TITLE
|
||||
*
|
||||
* @param string $testType
|
||||
* @return bool
|
||||
*/
|
||||
public static function isTitle(string $testType): bool
|
||||
{
|
||||
return strtoupper($testType) === 'TITLE';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if TestType is TEST or PARAM (technical tests)
|
||||
*
|
||||
* @param string $testType
|
||||
* @return bool
|
||||
*/
|
||||
public static function isTechnicalTest(string $testType): bool
|
||||
{
|
||||
$testType = strtoupper($testType);
|
||||
return in_array($testType, ['TEST', 'PARAM'], true);
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,8 @@ use App\Models\Patient\PatAttModel;
|
||||
use App\Models\Patient\PatComModel;
|
||||
use App\Models\Patient\PatIdtModel;
|
||||
|
||||
use App\Services\AuditService;
|
||||
|
||||
class PatientModel extends BaseModel {
|
||||
protected $table = 'patient';
|
||||
protected $primaryKey = 'InternalPID';
|
||||
@ -145,9 +147,22 @@ class PatientModel extends BaseModel {
|
||||
$db->transBegin();
|
||||
|
||||
try {
|
||||
$previousData = [];
|
||||
$this->insert($input);
|
||||
$newInternalPID = $this->getInsertID();
|
||||
$this->checkDbError($db, 'Insert patient');
|
||||
|
||||
AuditService::logData(
|
||||
'CREATE',
|
||||
'patient',
|
||||
(string) $newInternalPID,
|
||||
'patient',
|
||||
null,
|
||||
$previousData,
|
||||
$input,
|
||||
'Patient registration',
|
||||
['PatientID' => $input['PatientID'] ?? null]
|
||||
);
|
||||
|
||||
if (!empty($patIdt)) {
|
||||
$modelPatIdt->createPatIdt($patIdt, $newInternalPID);
|
||||
@ -198,10 +213,22 @@ class PatientModel extends BaseModel {
|
||||
$db->transBegin();
|
||||
|
||||
try {
|
||||
|
||||
$InternalPID = $input['InternalPID'];
|
||||
$previousData = $this->find($InternalPID);
|
||||
$this->where('InternalPID',$InternalPID)->set($input)->update();
|
||||
$this->checkDbError($db, 'Update patient');
|
||||
|
||||
AuditService::logData(
|
||||
'UPDATE',
|
||||
'patient',
|
||||
(string) $InternalPID,
|
||||
'patient',
|
||||
null,
|
||||
$previousData,
|
||||
$input,
|
||||
'Patient data updated',
|
||||
['changed_fields' => array_keys(array_diff_assoc($previousData, $input))]
|
||||
);
|
||||
|
||||
if (!empty($input['PatIdt'])) {
|
||||
$modelPatIdt->updatePatIdt($input['PatIdt'], $InternalPID);
|
||||
@ -330,6 +357,39 @@ class PatientModel extends BaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
public function deletePatient($InternalPID) {
|
||||
$db = \Config\Database::connect();
|
||||
$db->transBegin();
|
||||
|
||||
try {
|
||||
$previousData = $this->find($InternalPID);
|
||||
if (!$previousData) {
|
||||
throw new \Exception('Patient not found');
|
||||
}
|
||||
|
||||
$this->delete($InternalPID);
|
||||
$this->checkDbError($db, 'Delete patient');
|
||||
|
||||
AuditService::logData(
|
||||
'DELETE',
|
||||
'patient',
|
||||
(string) $InternalPID,
|
||||
'patient',
|
||||
null,
|
||||
$previousData,
|
||||
[],
|
||||
'Patient deleted',
|
||||
['PatientID' => $previousData['PatientID'] ?? null]
|
||||
);
|
||||
|
||||
$db->transCommit();
|
||||
return $InternalPID;
|
||||
} catch (\Exception $e) {
|
||||
$db->transRollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
private function isValidDateTime($datetime) {
|
||||
if (empty($datetime) || $datetime=="") {return null; }
|
||||
try {
|
||||
|
||||
@ -4,6 +4,7 @@ namespace App\Models\Test;
|
||||
|
||||
use App\Models\BaseModel;
|
||||
use App\Libraries\ValueSet;
|
||||
use App\Libraries\TestValidationService;
|
||||
|
||||
class TestDefSiteModel extends BaseModel {
|
||||
protected $table = 'testdefsite';
|
||||
@ -92,7 +93,7 @@ class TestDefSiteModel extends BaseModel {
|
||||
|
||||
$typeCode = $row['TestType'] ?? '';
|
||||
|
||||
if ($typeCode === 'CALC') {
|
||||
if (TestValidationService::isCalc($typeCode)) {
|
||||
$row['testdefcal'] = $db->table('testdefcal')
|
||||
->select('testdefcal.*, d.DisciplineName, dept.DepartmentName')
|
||||
->join('discipline d', 'd.DisciplineID=testdefcal.DisciplineID', 'left')
|
||||
@ -104,7 +105,7 @@ class TestDefSiteModel extends BaseModel {
|
||||
$testMapModel = new \App\Models\Test\TestMapModel();
|
||||
$row['testmap'] = $testMapModel->where('TestSiteID', $TestSiteID)->where('EndDate IS NULL')->findAll();
|
||||
|
||||
} elseif ($typeCode === 'GROUP') {
|
||||
} elseif (TestValidationService::isGroup($typeCode)) {
|
||||
$row['testdefgrp'] = $db->table('testdefgrp')
|
||||
->select('testdefgrp.*, t.TestSiteCode, t.TestSiteName, t.TestType')
|
||||
->join('testdefsite t', 't.TestSiteID=testdefgrp.Member', 'left')
|
||||
@ -120,11 +121,11 @@ class TestDefSiteModel extends BaseModel {
|
||||
$testMapModel = new \App\Models\Test\TestMapModel();
|
||||
$row['testmap'] = $testMapModel->where('TestSiteID', $TestSiteID)->where('EndDate IS NULL')->findAll();
|
||||
|
||||
} elseif ($typeCode === 'TITLE') {
|
||||
} elseif (TestValidationService::isTitle($typeCode)) {
|
||||
$testMapModel = new \App\Models\Test\TestMapModel();
|
||||
$row['testmap'] = $testMapModel->where('TestSiteID', $TestSiteID)->where('EndDate IS NULL')->findAll();
|
||||
|
||||
} elseif (in_array($typeCode, ['TEST', 'PARAM'])) {
|
||||
} elseif (TestValidationService::isTechnicalTest($typeCode)) {
|
||||
// Technical details are now flattened into the main row
|
||||
if ($row['DisciplineID']) {
|
||||
$discipline = $db->table('discipline')->where('DisciplineID', $row['DisciplineID'])->get()->getRowArray();
|
||||
@ -141,4 +142,40 @@ class TestDefSiteModel extends BaseModel {
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate test type combination
|
||||
*
|
||||
* @param string $testType
|
||||
* @param string $resultType
|
||||
* @param string $refType
|
||||
* @return array ['valid' => bool, 'error' => string|null]
|
||||
*/
|
||||
public function validateTypes(string $testType, string $resultType, string $refType): array
|
||||
{
|
||||
return TestValidationService::validate($testType, $resultType, $refType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test needs reference ranges
|
||||
*
|
||||
* @param string $resultType
|
||||
* @return bool
|
||||
*/
|
||||
public function needsReferenceRanges(string $resultType): bool
|
||||
{
|
||||
return TestValidationService::needsReferenceRanges($resultType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get reference table name
|
||||
*
|
||||
* @param string $resultType
|
||||
* @param string $refType
|
||||
* @return string|null
|
||||
*/
|
||||
public function getReferenceTable(string $resultType, string $refType): ?string
|
||||
{
|
||||
return TestValidationService::getReferenceTable($resultType, $refType);
|
||||
}
|
||||
}
|
||||
|
||||
196
app/Services/AuditService.php
Normal file
196
app/Services/AuditService.php
Normal file
@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use CodeIgniter\Database\BaseConnection;
|
||||
|
||||
class AuditService {
|
||||
protected BaseConnection $db;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
}
|
||||
|
||||
public static function logData(
|
||||
string $operation,
|
||||
string $entityType,
|
||||
string $entityId,
|
||||
?string $tableName = null,
|
||||
?string $fieldName = null,
|
||||
?array $previousValue = null,
|
||||
?array $newValue = null,
|
||||
?string $reason = null,
|
||||
?array $context = null
|
||||
): void {
|
||||
self::log('data_audit_log', [
|
||||
'operation' => $operation,
|
||||
'entity_type' => $entityType,
|
||||
'entity_id' => $entityId,
|
||||
'table_name' => $tableName,
|
||||
'field_name' => $fieldName,
|
||||
'previous_value' => $previousValue,
|
||||
'new_value' => $newValue,
|
||||
'mechanism' => 'MANUAL',
|
||||
'application_id' => 'CLQMS-WEB',
|
||||
'web_page' => self::getUri(),
|
||||
'session_id' => self::getSessionId(),
|
||||
'event_type' => strtoupper($entityType) . '_' . strtoupper($operation),
|
||||
'site_id' => self::getSiteId(),
|
||||
'workstation_id' => self::getWorkstationId(),
|
||||
'pc_name' => self::getPcName(),
|
||||
'ip_address' => self::getIpAddress(),
|
||||
'user_id' => self::getUserId(),
|
||||
'reason' => $reason,
|
||||
'context' => $context,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
public static function logService(
|
||||
string $operation,
|
||||
string $entityType,
|
||||
string $entityId,
|
||||
string $serviceClass,
|
||||
?string $resourceType = null,
|
||||
?array $resourceDetails = null,
|
||||
?array $previousValue = null,
|
||||
?array $newValue = null,
|
||||
?string $serviceName = null,
|
||||
?array $context = null
|
||||
): void {
|
||||
self::log('service_audit_log', [
|
||||
'operation' => $operation,
|
||||
'entity_type' => $entityType,
|
||||
'entity_id' => $entityId,
|
||||
'service_class' => $serviceClass,
|
||||
'resource_type' => $resourceType,
|
||||
'resource_details' => $resourceDetails,
|
||||
'previous_value' => $previousValue,
|
||||
'new_value' => $newValue,
|
||||
'mechanism' => 'AUTOMATIC',
|
||||
'application_id' => $serviceName ?? 'SYSTEM-SERVICE',
|
||||
'service_name' => $serviceName,
|
||||
'session_id' => self::getSessionId() ?: 'service_session',
|
||||
'event_type' => strtoupper($serviceClass) . '_' . strtoupper($operation),
|
||||
'site_id' => self::getSiteId(),
|
||||
'workstation_id' => self::getWorkstationId(),
|
||||
'pc_name' => self::getPcName(),
|
||||
'ip_address' => self::getIpAddress(),
|
||||
'port' => $resourceDetails['port'] ?? null,
|
||||
'user_id' => 'SYSTEM',
|
||||
'reason' => null,
|
||||
'context' => $context,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
public static function logSecurity(
|
||||
string $operation,
|
||||
string $entityType,
|
||||
string $entityId,
|
||||
string $securityClass,
|
||||
?string $eventType = 'SUCCESS',
|
||||
?string $resourcePath = null,
|
||||
?array $previousValue = null,
|
||||
?array $newValue = null,
|
||||
?string $reason = null,
|
||||
?array $context = null
|
||||
): void {
|
||||
self::log('security_audit_log', [
|
||||
'operation' => $operation,
|
||||
'entity_type' => $entityType,
|
||||
'entity_id' => $entityId,
|
||||
'security_class' => $securityClass,
|
||||
'resource_path' => $resourcePath,
|
||||
'previous_value' => $previousValue,
|
||||
'new_value' => $newValue,
|
||||
'mechanism' => 'MANUAL',
|
||||
'application_id' => 'CLQMS-WEB',
|
||||
'web_page' => self::getUri(),
|
||||
'session_id' => self::getSessionId(),
|
||||
'event_type' => $eventType,
|
||||
'site_id' => self::getSiteId(),
|
||||
'workstation_id' => self::getWorkstationId(),
|
||||
'pc_name' => self::getPcName(),
|
||||
'ip_address' => self::getIpAddress(),
|
||||
'user_id' => self::getUserId() ?? 'UNKNOWN',
|
||||
'reason' => $reason,
|
||||
'context' => $context,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
public static function logError(
|
||||
string $entityType,
|
||||
string $entityId,
|
||||
string $errorCode,
|
||||
string $errorMessage,
|
||||
string $eventType,
|
||||
?array $errorDetails = null,
|
||||
?array $previousValue = null,
|
||||
?array $newValue = null,
|
||||
?string $reason = null,
|
||||
?array $context = null
|
||||
): void {
|
||||
self::log('error_audit_log', [
|
||||
'operation' => 'ERROR',
|
||||
'entity_type' => $entityType,
|
||||
'entity_id' => $entityId,
|
||||
'error_code' => $errorCode,
|
||||
'error_message' => $errorMessage,
|
||||
'error_details' => $errorDetails,
|
||||
'previous_value' => $previousValue,
|
||||
'new_value' => $newValue,
|
||||
'mechanism' => 'AUTOMATIC',
|
||||
'application_id' => 'CLQMS-WEB',
|
||||
'web_page' => self::getUri(),
|
||||
'session_id' => self::getSessionId() ?: 'system',
|
||||
'event_type' => $eventType,
|
||||
'site_id' => self::getSiteId(),
|
||||
'workstation_id' => self::getWorkstationId(),
|
||||
'pc_name' => self::getPcName(),
|
||||
'ip_address' => self::getIpAddress(),
|
||||
'user_id' => self::getUserId() ?? 'SYSTEM',
|
||||
'reason' => $reason,
|
||||
'context' => $context,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
private static function log(string $table, array $data): void {
|
||||
$db = \Config\Database::connect();
|
||||
$db->table($table)->insert($data);
|
||||
}
|
||||
|
||||
private static function getUri(): ?string {
|
||||
return $_SERVER['REQUEST_URI'] ?? null;
|
||||
}
|
||||
|
||||
private static function getSessionId(): ?string {
|
||||
$session = session();
|
||||
return $session->get('session_id');
|
||||
}
|
||||
|
||||
private static function getSiteId(): ?string {
|
||||
$session = session();
|
||||
return $session->get('site_id');
|
||||
}
|
||||
|
||||
private static function getWorkstationId(): ?string {
|
||||
$session = session();
|
||||
return $session->get('workstation_id');
|
||||
}
|
||||
|
||||
private static function getPcName(): ?string {
|
||||
return gethostname();
|
||||
}
|
||||
|
||||
private static function getIpAddress(): ?string {
|
||||
return $_SERVER['REMOTE_ADDR'] ?? null;
|
||||
}
|
||||
|
||||
private static function getUserId(): ?string {
|
||||
$session = session();
|
||||
return $session->get('user_id');
|
||||
}
|
||||
}
|
||||
1581
docs/FRONTEND_TEST_MANAGEMENT_PROMPT.md
Normal file
1581
docs/FRONTEND_TEST_MANAGEMENT_PROMPT.md
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -2674,14 +2674,18 @@ paths:
|
||||
type: string
|
||||
enum:
|
||||
- NMRIC
|
||||
- RANGE
|
||||
- TEXT
|
||||
- VSET
|
||||
- NORES
|
||||
RefType:
|
||||
type: string
|
||||
enum:
|
||||
- NMRC
|
||||
- TEXT
|
||||
- RANGE
|
||||
- THOLD
|
||||
- VSET
|
||||
- TEXT
|
||||
- NOREF
|
||||
VSet:
|
||||
type: integer
|
||||
ReqQty:
|
||||
@ -2794,14 +2798,18 @@ paths:
|
||||
type: string
|
||||
enum:
|
||||
- NMRIC
|
||||
- RANGE
|
||||
- TEXT
|
||||
- VSET
|
||||
- NORES
|
||||
RefType:
|
||||
type: string
|
||||
enum:
|
||||
- NMRC
|
||||
- TEXT
|
||||
- RANGE
|
||||
- THOLD
|
||||
- VSET
|
||||
- TEXT
|
||||
- NOREF
|
||||
VSet:
|
||||
type: integer
|
||||
ReqQty:
|
||||
@ -4139,22 +4147,46 @@ components:
|
||||
type: string
|
||||
enum:
|
||||
- NMRIC
|
||||
- RANGE
|
||||
- TEXT
|
||||
- VSET
|
||||
- NORES
|
||||
description: |
|
||||
NMRIC: Numeric result
|
||||
VSET: Value set result
|
||||
Result type determines the format of test results:
|
||||
- NMRIC: Single numeric value
|
||||
- RANGE: Numeric range (min-max)
|
||||
- TEXT: Free text result
|
||||
- VSET: Value set/enum result
|
||||
- NORES: No result (for GROUP and TITLE types)
|
||||
|
||||
TestType to ResultType mapping:
|
||||
- TEST: NMRIC | RANGE | TEXT | VSET
|
||||
- PARAM: NMRIC | RANGE | TEXT | VSET
|
||||
- CALC: NMRIC (calculated result is always numeric)
|
||||
- GROUP: NORES (no result, container only)
|
||||
- TITLE: NORES (no result, header only)
|
||||
RefType:
|
||||
type: string
|
||||
enum:
|
||||
- NMRC
|
||||
- TEXT
|
||||
- RANGE
|
||||
- THOLD
|
||||
- VSET
|
||||
- TEXT
|
||||
- NOREF
|
||||
description: |
|
||||
NMRC: Numeric reference range
|
||||
TEXT: Text reference
|
||||
THOLD: Threshold reference
|
||||
VSET: Value set reference
|
||||
Reference type determines which reference range table to use:
|
||||
- RANGE: Numeric reference range
|
||||
- THOLD: Threshold/panic range
|
||||
- VSET: Value set reference
|
||||
- TEXT: Free text reference
|
||||
- NOREF: No reference (for NORES result type)
|
||||
|
||||
ResultType to RefType mapping:
|
||||
- NMRIC: RANGE | THOLD → refnum table
|
||||
- RANGE: RANGE | THOLD → refnum table
|
||||
- VSET: VSET → reftxt table
|
||||
- TEXT: TEXT → reftxt table
|
||||
- NORES: NOREF → (no reference table)
|
||||
VSet:
|
||||
type: integer
|
||||
description: Value set ID for VSET result type
|
||||
|
||||
@ -30,18 +30,38 @@ TestDefinition:
|
||||
type: string
|
||||
ResultType:
|
||||
type: string
|
||||
enum: [NMRIC, VSET]
|
||||
enum: [NMRIC, RANGE, TEXT, VSET, NORES]
|
||||
description: |
|
||||
NMRIC: Numeric result
|
||||
VSET: Value set result
|
||||
Result type determines the format of test results:
|
||||
- NMRIC: Single numeric value
|
||||
- RANGE: Numeric range (min-max)
|
||||
- TEXT: Free text result
|
||||
- VSET: Value set/enum result
|
||||
- NORES: No result (for GROUP and TITLE types)
|
||||
|
||||
TestType to ResultType mapping:
|
||||
- TEST: NMRIC | RANGE | TEXT | VSET
|
||||
- PARAM: NMRIC | RANGE | TEXT | VSET
|
||||
- CALC: NMRIC (calculated result is always numeric)
|
||||
- GROUP: NORES (no result, container only)
|
||||
- TITLE: NORES (no result, header only)
|
||||
RefType:
|
||||
type: string
|
||||
enum: [NMRC, TEXT, THOLD, VSET]
|
||||
enum: [RANGE, THOLD, VSET, TEXT, NOREF]
|
||||
description: |
|
||||
NMRC: Numeric reference range
|
||||
TEXT: Text reference
|
||||
THOLD: Threshold reference
|
||||
VSET: Value set reference
|
||||
Reference type determines which reference range table to use:
|
||||
- RANGE: Numeric reference range
|
||||
- THOLD: Threshold/panic range
|
||||
- VSET: Value set reference
|
||||
- TEXT: Free text reference
|
||||
- NOREF: No reference (for NORES result type)
|
||||
|
||||
ResultType to RefType mapping:
|
||||
- NMRIC: RANGE | THOLD → refnum table
|
||||
- RANGE: RANGE | THOLD → refnum table
|
||||
- VSET: VSET → reftxt table
|
||||
- TEXT: TEXT → reftxt table
|
||||
- NORES: NOREF → (no reference table)
|
||||
VSet:
|
||||
type: integer
|
||||
description: Value set ID for VSET result type
|
||||
|
||||
@ -99,10 +99,10 @@
|
||||
type: integer
|
||||
ResultType:
|
||||
type: string
|
||||
enum: [NMRIC, VSET]
|
||||
enum: [NMRIC, RANGE, TEXT, VSET, NORES]
|
||||
RefType:
|
||||
type: string
|
||||
enum: [NMRC, TEXT, THOLD, VSET]
|
||||
enum: [RANGE, THOLD, VSET, TEXT, NOREF]
|
||||
VSet:
|
||||
type: integer
|
||||
ReqQty:
|
||||
@ -208,10 +208,10 @@
|
||||
type: integer
|
||||
ResultType:
|
||||
type: string
|
||||
enum: [NMRIC, VSET]
|
||||
enum: [NMRIC, RANGE, TEXT, VSET, NORES]
|
||||
RefType:
|
||||
type: string
|
||||
enum: [NMRC, TEXT, THOLD, VSET]
|
||||
enum: [RANGE, THOLD, VSET, TEXT, NOREF]
|
||||
VSet:
|
||||
type: integer
|
||||
ReqQty:
|
||||
|
||||
@ -115,4 +115,303 @@ class TestsControllerTest extends CIUnitTestCase
|
||||
$this->assertEquals(5.5, $showData['data']['refnum'][0]['Low']);
|
||||
$this->assertEquals('High', $showData['data']['refnum'][0]['Interpretation']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test valid TestType and ResultType combinations
|
||||
* @dataProvider validTestTypeResultTypeProvider
|
||||
*/
|
||||
public function testValidTestTypeResultTypeCombinations($testType, $resultType, $refType, $shouldSucceed)
|
||||
{
|
||||
$testData = [
|
||||
'TestSiteCode' => 'TT' . substr(time(), -4) . rand(10, 99),
|
||||
'TestSiteName' => 'Type Test ' . time(),
|
||||
'TestType' => $testType,
|
||||
'SiteID' => 1,
|
||||
'details' => [
|
||||
'ResultType' => $resultType,
|
||||
'RefType' => $refType
|
||||
]
|
||||
];
|
||||
|
||||
// Add reference data if needed
|
||||
if ($refType === 'RANGE' || $refType === 'THOLD') {
|
||||
$testData['refnum'] = [
|
||||
[
|
||||
'NumRefType' => $refType,
|
||||
'RangeType' => 'VALUE',
|
||||
'Sex' => '1',
|
||||
'AgeStart' => 0,
|
||||
'AgeEnd' => 100,
|
||||
'LowSign' => '>',
|
||||
'Low' => 5.5,
|
||||
'Interpretation' => 'Normal'
|
||||
]
|
||||
];
|
||||
} elseif ($refType === 'VSET' || $refType === 'TEXT') {
|
||||
$testData['reftxt'] = [
|
||||
[
|
||||
'TxtRefType' => $refType,
|
||||
'Sex' => '1',
|
||||
'AgeStart' => 0,
|
||||
'AgeEnd' => 100,
|
||||
'RefTxt' => 'Normal range text',
|
||||
'Flag' => 'N'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
$result = $this->withHeaders(['Cookie' => 'token=' . $this->token])
|
||||
->withBody(json_encode($testData))
|
||||
->call('post', 'api/tests');
|
||||
|
||||
if ($shouldSucceed) {
|
||||
$result->assertStatus(201);
|
||||
$data = json_decode($result->getJSON(), true);
|
||||
$this->assertEquals('created', $data['status']);
|
||||
} else {
|
||||
// Invalid combinations should fail validation or return error
|
||||
$this->assertGreaterThanOrEqual(400, $result->getStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function validTestTypeResultTypeProvider()
|
||||
{
|
||||
return [
|
||||
// TEST type - can have NMRIC, RANGE, TEXT, VSET
|
||||
'TEST with NMRIC' => ['TEST', 'NMRIC', 'RANGE', true],
|
||||
'TEST with RANGE' => ['TEST', 'RANGE', 'RANGE', true],
|
||||
'TEST with TEXT' => ['TEST', 'TEXT', 'TEXT', true],
|
||||
'TEST with VSET' => ['TEST', 'VSET', 'VSET', true],
|
||||
'TEST with THOLD' => ['TEST', 'NMRIC', 'THOLD', true],
|
||||
|
||||
// PARAM type - can have NMRIC, RANGE, TEXT, VSET
|
||||
'PARAM with NMRIC' => ['PARAM', 'NMRIC', 'RANGE', true],
|
||||
'PARAM with RANGE' => ['PARAM', 'RANGE', 'RANGE', true],
|
||||
'PARAM with TEXT' => ['PARAM', 'TEXT', 'TEXT', true],
|
||||
'PARAM with VSET' => ['PARAM', 'VSET', 'VSET', true],
|
||||
|
||||
// CALC type - only NMRIC
|
||||
'CALC with NMRIC' => ['CALC', 'NMRIC', 'RANGE', true],
|
||||
|
||||
// GROUP type - only NORES
|
||||
'GROUP with NORES' => ['GROUP', 'NORES', 'NOREF', true],
|
||||
|
||||
// TITLE type - only NORES
|
||||
'TITLE with NORES' => ['TITLE', 'NORES', 'NOREF', true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ResultType to RefType mapping
|
||||
* @dataProvider resultTypeToRefTypeProvider
|
||||
*/
|
||||
public function testResultTypeToRefTypeMapping($resultType, $refType, $expectedRefTable)
|
||||
{
|
||||
$testData = [
|
||||
'TestSiteCode' => 'RT' . substr(time(), -4) . rand(10, 99),
|
||||
'TestSiteName' => 'RefType Test ' . time(),
|
||||
'TestType' => 'TEST',
|
||||
'SiteID' => 1,
|
||||
'details' => [
|
||||
'ResultType' => $resultType,
|
||||
'RefType' => $refType
|
||||
]
|
||||
];
|
||||
|
||||
// Add appropriate reference data
|
||||
if ($expectedRefTable === 'refnum') {
|
||||
$testData['refnum'] = [
|
||||
[
|
||||
'NumRefType' => $refType,
|
||||
'RangeType' => 'VALUE',
|
||||
'Sex' => '1',
|
||||
'AgeStart' => 18,
|
||||
'AgeEnd' => 99,
|
||||
'LowSign' => 'GE',
|
||||
'Low' => 10,
|
||||
'HighSign' => 'LE',
|
||||
'High' => 20,
|
||||
'Interpretation' => 'Normal'
|
||||
]
|
||||
];
|
||||
} elseif ($expectedRefTable === 'reftxt') {
|
||||
$testData['reftxt'] = [
|
||||
[
|
||||
'TxtRefType' => $refType,
|
||||
'Sex' => '1',
|
||||
'AgeStart' => 18,
|
||||
'AgeEnd' => 99,
|
||||
'RefTxt' => 'Reference text',
|
||||
'Flag' => 'N'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
$result = $this->withHeaders(['Cookie' => 'token=' . $this->token])
|
||||
->withBody(json_encode($testData))
|
||||
->call('post', 'api/tests');
|
||||
|
||||
$result->assertStatus(201);
|
||||
$data = json_decode($result->getJSON(), true);
|
||||
$id = $data['data']['TestSiteId'];
|
||||
|
||||
// Verify the reference data was stored in correct table
|
||||
$showResult = $this->callProtected('get', "api/tests/$id");
|
||||
$showData = json_decode($showResult->getJSON(), true);
|
||||
|
||||
if ($expectedRefTable === 'refnum') {
|
||||
$this->assertArrayHasKey('refnum', $showData['data']);
|
||||
$this->assertNotEmpty($showData['data']['refnum']);
|
||||
} elseif ($expectedRefTable === 'reftxt') {
|
||||
$this->assertArrayHasKey('reftxt', $showData['data']);
|
||||
$this->assertNotEmpty($showData['data']['reftxt']);
|
||||
}
|
||||
}
|
||||
|
||||
public function resultTypeToRefTypeProvider()
|
||||
{
|
||||
return [
|
||||
// NMRIC with RANGE → refnum table
|
||||
'NMRIC with RANGE uses refnum' => ['NMRIC', 'RANGE', 'refnum'],
|
||||
// NMRIC with THOLD → refnum table
|
||||
'NMRIC with THOLD uses refnum' => ['NMRIC', 'THOLD', 'refnum'],
|
||||
// RANGE with RANGE → refnum table
|
||||
'RANGE with RANGE uses refnum' => ['RANGE', 'RANGE', 'refnum'],
|
||||
// RANGE with THOLD → refnum table
|
||||
'RANGE with THOLD uses refnum' => ['RANGE', 'THOLD', 'refnum'],
|
||||
// VSET with VSET → reftxt table
|
||||
'VSET with VSET uses reftxt' => ['VSET', 'VSET', 'reftxt'],
|
||||
// TEXT with TEXT → reftxt table
|
||||
'TEXT with TEXT uses reftxt' => ['TEXT', 'TEXT', 'reftxt'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test CALC type always has NMRIC result type
|
||||
*/
|
||||
public function testCalcTypeAlwaysHasNmricResultType()
|
||||
{
|
||||
$testData = [
|
||||
'TestSiteCode' => 'CALC' . substr(time(), -4),
|
||||
'TestSiteName' => 'Calc Test ' . time(),
|
||||
'TestType' => 'CALC',
|
||||
'SiteID' => 1,
|
||||
'details' => [
|
||||
'DisciplineID' => 1,
|
||||
'DepartmentID' => 1,
|
||||
'FormulaInput' => 'WEIGHT,HEIGHT',
|
||||
'FormulaCode' => 'WEIGHT/(HEIGHT/100)^2',
|
||||
'Unit1' => 'kg/m2',
|
||||
'Decimal' => 1
|
||||
]
|
||||
];
|
||||
|
||||
$result = $this->withHeaders(['Cookie' => 'token=' . $this->token])
|
||||
->withBody(json_encode($testData))
|
||||
->call('post', 'api/tests');
|
||||
|
||||
$result->assertStatus(201);
|
||||
$data = json_decode($result->getJSON(), true);
|
||||
$id = $data['data']['TestSiteId'];
|
||||
|
||||
// Verify CALC test was created
|
||||
$showResult = $this->callProtected('get', "api/tests/$id");
|
||||
$showData = json_decode($showResult->getJSON(), true);
|
||||
|
||||
$this->assertEquals('CALC', $showData['data']['TestType']);
|
||||
$this->assertArrayHasKey('testdefcal', $showData['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test GROUP type has no result (NORES)
|
||||
*/
|
||||
public function testGroupTypeHasNoResult()
|
||||
{
|
||||
// First create member tests
|
||||
$member1Data = [
|
||||
'TestSiteCode' => 'M1' . substr(time(), -4),
|
||||
'TestSiteName' => 'Member 1 ' . time(),
|
||||
'TestType' => 'TEST',
|
||||
'SiteID' => 1,
|
||||
'details' => [
|
||||
'ResultType' => 'NMRIC',
|
||||
'RefType' => 'RANGE'
|
||||
],
|
||||
'refnum' => [
|
||||
[
|
||||
'NumRefType' => 'RANGE',
|
||||
'RangeType' => 'VALUE',
|
||||
'Sex' => '1',
|
||||
'AgeStart' => 0,
|
||||
'AgeEnd' => 100,
|
||||
'LowSign' => '>',
|
||||
'Low' => 5.5,
|
||||
'Interpretation' => 'Normal'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$result1 = $this->withHeaders(['Cookie' => 'token=' . $this->token])
|
||||
->withBody(json_encode($member1Data))
|
||||
->call('post', 'api/tests');
|
||||
$data1 = json_decode($result1->getJSON(), true);
|
||||
$member1Id = $data1['data']['TestSiteId'];
|
||||
|
||||
$member2Data = [
|
||||
'TestSiteCode' => 'M2' . substr(time(), -4),
|
||||
'TestSiteName' => 'Member 2 ' . time(),
|
||||
'TestType' => 'TEST',
|
||||
'SiteID' => 1,
|
||||
'details' => [
|
||||
'ResultType' => 'NMRIC',
|
||||
'RefType' => 'RANGE'
|
||||
],
|
||||
'refnum' => [
|
||||
[
|
||||
'NumRefType' => 'RANGE',
|
||||
'RangeType' => 'VALUE',
|
||||
'Sex' => '1',
|
||||
'AgeStart' => 0,
|
||||
'AgeEnd' => 100,
|
||||
'LowSign' => '>',
|
||||
'Low' => 5.5,
|
||||
'Interpretation' => 'Normal'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$result2 = $this->withHeaders(['Cookie' => 'token=' . $this->token])
|
||||
->withBody(json_encode($member2Data))
|
||||
->call('post', 'api/tests');
|
||||
$data2 = json_decode($result2->getJSON(), true);
|
||||
$member2Id = $data2['data']['TestSiteId'];
|
||||
|
||||
// Create group test
|
||||
$groupData = [
|
||||
'TestSiteCode' => 'GRP' . substr(time(), -4),
|
||||
'TestSiteName' => 'Group Test ' . time(),
|
||||
'TestType' => 'GROUP',
|
||||
'SiteID' => 1,
|
||||
'details' => [
|
||||
'ResultType' => 'NORES',
|
||||
'RefType' => 'NOREF'
|
||||
],
|
||||
'members' => [$member1Id, $member2Id]
|
||||
];
|
||||
|
||||
$result = $this->withHeaders(['Cookie' => 'token=' . $this->token])
|
||||
->withBody(json_encode($groupData))
|
||||
->call('post', 'api/tests');
|
||||
|
||||
$result->assertStatus(201);
|
||||
$data = json_decode($result->getJSON(), true);
|
||||
$id = $data['data']['TestSiteId'];
|
||||
|
||||
// Verify GROUP test was created with members
|
||||
$showResult = $this->callProtected('get', "api/tests/$id");
|
||||
$showData = json_decode($showResult->getJSON(), true);
|
||||
|
||||
$this->assertEquals('GROUP', $showData['data']['TestType']);
|
||||
$this->assertArrayHasKey('testdefgrp', $showData['data']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,6 +65,8 @@ class TestDefModelsTest extends CIUnitTestCase
|
||||
$this->assertContains('CreateDate', $allowedFields);
|
||||
$this->assertContains('StartDate', $allowedFields);
|
||||
$this->assertContains('EndDate', $allowedFields);
|
||||
$this->assertContains('ResultType', $allowedFields);
|
||||
$this->assertContains('RefType', $allowedFields);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user