feat: update test management APIs and reference range models
This commit is contained in:
parent
49d3a69308
commit
e9c7beeb2b
@ -176,7 +176,7 @@ class PatVisitController extends BaseController {
|
||||
->join('contact admDoc', 'admDoc.ContactID = patvisitadt.AdmDoc', 'left')
|
||||
->join('contact cnsDoc', 'cnsDoc.ContactID = patvisitadt.CnsDoc', 'left')
|
||||
->where('patvisitadt.InternalPVID', $InternalPVID)
|
||||
->where('patvisitadt.DelDate IS NULL')
|
||||
->where('patvisitadt.DelDate', null)
|
||||
->orderBy('patvisitadt.CreateDate', 'ASC')
|
||||
->findAll();
|
||||
|
||||
@ -208,7 +208,7 @@ class PatVisitController extends BaseController {
|
||||
->join('contact admDoc', 'admDoc.ContactID = patvisitadt.AdmDoc', 'left')
|
||||
->join('contact cnsDoc', 'cnsDoc.ContactID = patvisitadt.CnsDoc', 'left')
|
||||
->where('patvisitadt.PVADTID', $PVADTID)
|
||||
->where('patvisitadt.DelDate IS NULL')
|
||||
->where('patvisitadt.DelDate', null)
|
||||
->first();
|
||||
|
||||
if (empty($row)) {
|
||||
|
||||
@ -39,7 +39,7 @@ class TestMapController extends BaseController {
|
||||
}
|
||||
|
||||
public function show($id = null) {
|
||||
$row = $this->model->where('TestMapID',$id)->where('EndDate IS NULL')->first();
|
||||
$row = $this->model->where('TestMapID',$id)->where('EndDate', null)->first();
|
||||
if (empty($row)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200); }
|
||||
|
||||
$row = ValueSet::transformLabels([$row], [
|
||||
@ -83,7 +83,7 @@ class TestMapController extends BaseController {
|
||||
if (!$id) { return $this->failValidationErrors('TestMapID is required.'); }
|
||||
|
||||
try {
|
||||
$row = $this->model->where('TestMapID', $id)->where('EndDate IS NULL')->first();
|
||||
$row = $this->model->where('TestMapID', $id)->where('EndDate', null)->first();
|
||||
if (empty($row)) { return $this->respond([ 'status' => 'failed', 'message' => "Data not found or already deleted.", 'data' => null ], 404); }
|
||||
|
||||
$this->db->transStart();
|
||||
@ -93,7 +93,7 @@ class TestMapController extends BaseController {
|
||||
|
||||
// Soft delete all related details
|
||||
$this->modelDetail->where('TestMapID', $id)
|
||||
->where('EndDate IS NULL')
|
||||
->where('EndDate', null)
|
||||
->set('EndDate', date('Y-m-d H:i:s'))
|
||||
->update();
|
||||
|
||||
@ -189,7 +189,7 @@ class TestMapController extends BaseController {
|
||||
|
||||
foreach ($ids as $id) {
|
||||
try {
|
||||
$row = $this->model->where('TestMapID', $id)->where('EndDate IS NULL')->first();
|
||||
$row = $this->model->where('TestMapID', $id)->where('EndDate', null)->first();
|
||||
if (empty($row)) {
|
||||
$results['failed'][] = ['TestMapID' => $id, 'error' => 'Not found or already deleted'];
|
||||
continue;
|
||||
|
||||
@ -32,7 +32,7 @@ class TestMapDetailController extends BaseController {
|
||||
if ($testMapID) {
|
||||
$rows = $this->model->getDetailsByTestMap($testMapID);
|
||||
} else {
|
||||
$rows = $this->model->where('EndDate IS NULL')->findAll();
|
||||
$rows = $this->model->where('EndDate', null)->findAll();
|
||||
}
|
||||
|
||||
if (empty($rows)) {
|
||||
@ -47,7 +47,7 @@ class TestMapDetailController extends BaseController {
|
||||
return $this->failValidationErrors('TestMapDetailID is required.');
|
||||
}
|
||||
|
||||
$row = $this->model->where('TestMapDetailID', $id)->where('EndDate IS NULL')->first();
|
||||
$row = $this->model->where('TestMapDetailID', $id)->where('EndDate', null)->first();
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
|
||||
@ -122,7 +122,7 @@ class TestMapDetailController extends BaseController {
|
||||
}
|
||||
|
||||
try {
|
||||
$row = $this->model->where('TestMapDetailID', $id)->where('EndDate IS NULL')->first();
|
||||
$row = $this->model->where('TestMapDetailID', $id)->where('EndDate', null)->first();
|
||||
|
||||
if (empty($row)) {
|
||||
return $this->respond([
|
||||
@ -228,7 +228,7 @@ class TestMapDetailController extends BaseController {
|
||||
|
||||
foreach ($ids as $id) {
|
||||
try {
|
||||
$row = $this->model->where('TestMapDetailID', $id)->where('EndDate IS NULL')->first();
|
||||
$row = $this->model->where('TestMapDetailID', $id)->where('EndDate', null)->first();
|
||||
|
||||
if (empty($row)) {
|
||||
$results['failed'][] = ['TestMapDetailID' => $id, 'error' => 'Not found or already deleted'];
|
||||
|
||||
@ -42,52 +42,16 @@ class TestsController extends BaseController
|
||||
|
||||
public function index()
|
||||
{
|
||||
$siteId = $this->request->getGet('SiteID');
|
||||
$testType = $this->request->getGet('TestType');
|
||||
$visibleScr = $this->request->getGet('VisibleScr');
|
||||
$visibleRpt = $this->request->getGet('VisibleRpt');
|
||||
$testSiteName = $this->request->getGet('TestSiteName');
|
||||
$testSiteCode = $this->request->getGet('TestSiteCode');
|
||||
$filters = [
|
||||
'SiteID' => $this->request->getGet('SiteID'),
|
||||
'TestType' => $this->request->getGet('TestType'),
|
||||
'VisibleScr' => $this->request->getGet('VisibleScr'),
|
||||
'VisibleRpt' => $this->request->getGet('VisibleRpt'),
|
||||
'TestSiteName' => $this->request->getGet('TestSiteName'),
|
||||
'TestSiteCode' => $this->request->getGet('TestSiteCode'),
|
||||
];
|
||||
|
||||
$builder = $this->db->table('testdefsite')
|
||||
->select(
|
||||
"testdefsite.TestSiteID, testdefsite.TestSiteCode, testdefsite.TestSiteName, testdefsite.TestType,
|
||||
testdefsite.SeqScr, testdefsite.SeqRpt, testdefsite.VisibleScr, testdefsite.VisibleRpt,
|
||||
testdefsite.CountStat, testdefsite.StartDate, testdefsite.EndDate,
|
||||
COALESCE(testdefsite.DisciplineID, cal.DisciplineID) as DisciplineID,
|
||||
COALESCE(testdefsite.DepartmentID, cal.DepartmentID) as DepartmentID,
|
||||
d.DisciplineName, dept.DepartmentName"
|
||||
)
|
||||
->join('testdefcal cal', 'cal.TestSiteID = testdefsite.TestSiteID AND cal.EndDate IS NULL', 'left')
|
||||
->join('discipline d', 'd.DisciplineID = COALESCE(testdefsite.DisciplineID, cal.DisciplineID)', 'left')
|
||||
->join('department dept', 'dept.DepartmentID = COALESCE(testdefsite.DepartmentID, cal.DepartmentID)', 'left')
|
||||
->where('testdefsite.EndDate IS NULL');
|
||||
|
||||
if ($siteId) {
|
||||
$builder->where('testdefsite.SiteID', $siteId);
|
||||
}
|
||||
|
||||
if ($testType) {
|
||||
$builder->where('testdefsite.TestType', $testType);
|
||||
}
|
||||
|
||||
if ($visibleScr !== null) {
|
||||
$builder->where('testdefsite.VisibleScr', $visibleScr);
|
||||
}
|
||||
|
||||
if ($visibleRpt !== null) {
|
||||
$builder->where('testdefsite.VisibleRpt', $visibleRpt);
|
||||
}
|
||||
|
||||
if ($testSiteName) {
|
||||
$builder->like('testdefsite.TestSiteName', $testSiteName);
|
||||
}
|
||||
|
||||
if ($testSiteCode) {
|
||||
$builder->like('testdefsite.TestSiteCode', $testSiteCode);
|
||||
}
|
||||
|
||||
$rows = $builder->orderBy('testdefsite.SeqScr', 'ASC')->get()->getResultArray();
|
||||
$rows = $this->model->getTestsWithRelations($filters);
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([
|
||||
@ -133,25 +97,9 @@ class TestsController extends BaseController
|
||||
$typeCode = $row['TestType'] ?? '';
|
||||
|
||||
if ($typeCode === 'CALC') {
|
||||
$row['testdefcal'] = $this->db->table('testdefcal')
|
||||
->select('testdefcal.*, d.DisciplineName, dept.DepartmentName')
|
||||
->join('discipline d', 'd.DisciplineID=testdefcal.DisciplineID', 'left')
|
||||
->join('department dept', 'dept.DepartmentID=testdefcal.DepartmentID', 'left')
|
||||
->where('testdefcal.TestSiteID', $id)
|
||||
->where('testdefcal.EndDate IS NULL')
|
||||
->get()->getResultArray();
|
||||
$row['testdefcal'] = $this->modelCal->getByTestSiteID($id);
|
||||
} elseif ($typeCode === 'GROUP') {
|
||||
$row['testdefgrp'] = $this->db->table('testdefgrp')
|
||||
->select('testdefgrp.*, t.TestSiteCode, t.TestSiteName, t.TestType')
|
||||
->join('testdefsite t', 't.TestSiteID=testdefgrp.Member', 'left')
|
||||
->where('testdefgrp.TestSiteID', $id)
|
||||
->where('testdefgrp.EndDate IS NULL')
|
||||
->orderBy('testdefgrp.TestGrpID', 'ASC')
|
||||
->get()->getResultArray();
|
||||
|
||||
$row['testdefgrp'] = ValueSet::transformLabels($row['testdefgrp'], [
|
||||
'TestType' => 'test_type',
|
||||
]);
|
||||
$row['testdefgrp'] = $this->modelGrp->getGroupMembers($id);
|
||||
} elseif ($typeCode === 'TITLE') {
|
||||
} else {
|
||||
$row['testdeftech'] = $this->db->table('testdefsite')
|
||||
@ -168,11 +116,7 @@ class TestsController extends BaseController
|
||||
$resultType = $techData['ResultType'] ?? '';
|
||||
|
||||
if (TestValidationService::usesRefNum($resultType, $refType)) {
|
||||
$refnumData = $this->modelRefNum
|
||||
->where('TestSiteID', $id)
|
||||
->where('EndDate IS NULL')
|
||||
->orderBy('Display', 'ASC')
|
||||
->findAll();
|
||||
$refnumData = $this->modelRefNum->getActiveByTestSiteID($id);
|
||||
|
||||
$row['refnum'] = array_map(function ($r) {
|
||||
return [
|
||||
@ -198,11 +142,7 @@ class TestsController extends BaseController
|
||||
}
|
||||
|
||||
if (TestValidationService::usesRefTxt($resultType, $refType)) {
|
||||
$reftxtData = $this->modelRefTxt
|
||||
->where('TestSiteID', $id)
|
||||
->where('EndDate IS NULL')
|
||||
->orderBy('RefTxtID', 'ASC')
|
||||
->findAll();
|
||||
$reftxtData = $this->modelRefTxt->getActiveByTestSiteID($id);
|
||||
|
||||
$row['reftxt'] = array_map(function ($r) {
|
||||
return [
|
||||
@ -416,21 +356,15 @@ class TestsController extends BaseController
|
||||
$typeCode = $testType;
|
||||
|
||||
if (TestValidationService::isCalc($typeCode)) {
|
||||
$this->db->table('testdefcal')
|
||||
->where('TestSiteID', $id)
|
||||
->update(['EndDate' => $now]);
|
||||
$this->modelCal->disableByTestSiteID($id);
|
||||
} elseif (TestValidationService::isGroup($typeCode)) {
|
||||
$this->db->table('testdefgrp')
|
||||
->where('TestSiteID', $id)
|
||||
->update(['EndDate' => $now]);
|
||||
$this->modelGrp->disableByTestSiteID($id);
|
||||
} elseif (TestValidationService::isTechnicalTest($typeCode)) {
|
||||
$this->modelRefNum->where('TestSiteID', $id)->set('EndDate', $now)->update();
|
||||
$this->modelRefTxt->where('TestSiteID', $id)->set('EndDate', $now)->update();
|
||||
}
|
||||
|
||||
$this->db->table('testmap')
|
||||
->where('TestSiteID', $id)
|
||||
->update(['EndDate' => $now]);
|
||||
$this->modelMap->disableByTestSiteID($id);
|
||||
|
||||
$this->db->transComplete();
|
||||
|
||||
@ -605,10 +539,7 @@ class TestsController extends BaseController
|
||||
];
|
||||
|
||||
if ($action === 'update') {
|
||||
$exists = $this->db->table('testdefcal')
|
||||
->where('TestSiteID', $testSiteID)
|
||||
->where('EndDate IS NULL')
|
||||
->get()->getRowArray();
|
||||
$exists = $this->modelCal->existsByTestSiteID($testSiteID);
|
||||
|
||||
if ($exists) {
|
||||
$this->modelCal->update($exists['TestCalID'], $calcData);
|
||||
@ -623,9 +554,7 @@ class TestsController extends BaseController
|
||||
private function saveGroupDetails($testSiteID, $data, $input, $action)
|
||||
{
|
||||
if ($action === 'update') {
|
||||
$this->db->table('testdefgrp')
|
||||
->where('TestSiteID', $testSiteID)
|
||||
->update(['EndDate' => date('Y-m-d H:i:s')]);
|
||||
$this->modelGrp->disableByTestSiteID($testSiteID);
|
||||
}
|
||||
|
||||
$members = $data['members'] ?? ($input['Members'] ?? []);
|
||||
@ -647,20 +576,17 @@ class TestsController extends BaseController
|
||||
{
|
||||
if ($action === 'update') {
|
||||
$existingMaps = $this->modelMap->where('TestSiteID', $testSiteID)
|
||||
->where('EndDate IS NULL')
|
||||
->where('EndDate', null)
|
||||
->findAll();
|
||||
|
||||
foreach ($existingMaps as $existingMap) {
|
||||
$this->modelMapDetail->where('TestMapID', $existingMap['TestMapID'])
|
||||
->where('EndDate IS NULL')
|
||||
->where('EndDate', null)
|
||||
->set('EndDate', date('Y-m-d H:i:s'))
|
||||
->update();
|
||||
}
|
||||
|
||||
$this->db->table('testmap')
|
||||
->where('TestSiteID', $testSiteID)
|
||||
->where('EndDate IS NULL')
|
||||
->update(['EndDate' => date('Y-m-d H:i:s')]);
|
||||
$this->modelMap->disableByTestSiteID($testSiteID);
|
||||
}
|
||||
|
||||
if (is_array($mappings)) {
|
||||
@ -690,4 +616,4 @@ class TestsController extends BaseController
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,4 +36,14 @@ class RefNumModel extends BaseModel
|
||||
protected $updatedField = '';
|
||||
protected $useSoftDeletes = true;
|
||||
protected $deletedField = "EndDate";
|
||||
|
||||
/**
|
||||
* Get active numeric reference ranges for a test
|
||||
*/
|
||||
public function getActiveByTestSiteID($testSiteID) {
|
||||
return $this->where('TestSiteID', $testSiteID)
|
||||
->where('EndDate', null)
|
||||
->orderBy('Display', 'ASC')
|
||||
->findAll();
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,4 +30,14 @@ class RefTxtModel extends BaseModel
|
||||
protected $updatedField = '';
|
||||
protected $useSoftDeletes = true;
|
||||
protected $deletedField = "EndDate";
|
||||
|
||||
/**
|
||||
* Get active text reference ranges for a test
|
||||
*/
|
||||
public function getActiveByTestSiteID($testSiteID) {
|
||||
return $this->where('TestSiteID', $testSiteID)
|
||||
->where('EndDate', null)
|
||||
->orderBy('RefTxtID', 'ASC')
|
||||
->findAll();
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,18 +30,35 @@ class TestDefCalModel extends BaseModel {
|
||||
protected $deletedField = "EndDate";
|
||||
|
||||
/**
|
||||
* Get calculation details for a test
|
||||
* Get calculation details for a test with relations
|
||||
*/
|
||||
public function getCalcDetails($testSiteID) {
|
||||
$db = \Config\Database::connect();
|
||||
|
||||
return $db->table('testdefcal')
|
||||
->select('testdefcal.*, d.DisciplineName, dept.DepartmentName')
|
||||
->join('discipline d', 'd.DisciplineID=testdefcal.DisciplineID', 'left')
|
||||
->join('department dept', 'dept.DepartmentID=testdefcal.DepartmentID', 'left')
|
||||
->where('testdefcal.TestSiteID', $testSiteID)
|
||||
->where('testdefcal.EndDate IS NULL')
|
||||
->get()->getResultArray();
|
||||
public function getByTestSiteID($testSiteID) {
|
||||
return $this->db->table('testdefcal')
|
||||
->select('testdefcal.*, d.DisciplineName, dept.DepartmentName')
|
||||
->join('discipline d', 'd.DisciplineID=testdefcal.DisciplineID', 'left')
|
||||
->join('department dept', 'dept.DepartmentID=testdefcal.DepartmentID', 'left')
|
||||
->where('testdefcal.TestSiteID', $testSiteID)
|
||||
->where('testdefcal.EndDate IS NULL')
|
||||
->get()->getResultArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if calculation exists for a test
|
||||
*/
|
||||
public function existsByTestSiteID($testSiteID) {
|
||||
return $this->db->table('testdefcal')
|
||||
->where('TestSiteID', $testSiteID)
|
||||
->where('EndDate IS NULL')
|
||||
->get()->getRowArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable calculation by TestSiteID
|
||||
*/
|
||||
public function disableByTestSiteID($testSiteID) {
|
||||
$this->db->table('testdefcal')
|
||||
->where('TestSiteID', $testSiteID)
|
||||
->update(['EndDate' => date('Y-m-d H:i:s')]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -46,4 +46,14 @@ class TestDefGrpModel extends BaseModel {
|
||||
->where('testdefgrp.EndDate IS NULL')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disable group members by TestSiteID
|
||||
*/
|
||||
public function disableByTestSiteID($testSiteID) {
|
||||
$this->db->table('testdefgrp')
|
||||
->where('TestSiteID', $testSiteID)
|
||||
->update(['EndDate' => date('Y-m-d H:i:s')]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,6 +78,51 @@ class TestDefSiteModel extends BaseModel {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tests list with discipline and department info
|
||||
*/
|
||||
public function getTestsWithRelations($filters = []) {
|
||||
$builder = $this->db->table('testdefsite')
|
||||
->select(
|
||||
"testdefsite.TestSiteID, testdefsite.TestSiteCode, testdefsite.TestSiteName, testdefsite.TestType,
|
||||
testdefsite.SeqScr, testdefsite.SeqRpt, testdefsite.VisibleScr, testdefsite.VisibleRpt,
|
||||
testdefsite.CountStat, testdefsite.StartDate, testdefsite.EndDate,
|
||||
COALESCE(testdefsite.DisciplineID, cal.DisciplineID) as DisciplineID,
|
||||
COALESCE(testdefsite.DepartmentID, cal.DepartmentID) as DepartmentID,
|
||||
d.DisciplineName, dept.DepartmentName"
|
||||
)
|
||||
->join('testdefcal cal', 'cal.TestSiteID = testdefsite.TestSiteID AND cal.EndDate IS NULL', 'left')
|
||||
->join('discipline d', 'd.DisciplineID = COALESCE(testdefsite.DisciplineID, cal.DisciplineID)', 'left')
|
||||
->join('department dept', 'dept.DepartmentID = COALESCE(testdefsite.DepartmentID, cal.DepartmentID)', 'left')
|
||||
->where('testdefsite.EndDate IS NULL');
|
||||
|
||||
if (!empty($filters['SiteID'])) {
|
||||
$builder->where('testdefsite.SiteID', $filters['SiteID']);
|
||||
}
|
||||
|
||||
if (!empty($filters['TestType'])) {
|
||||
$builder->where('testdefsite.TestType', $filters['TestType']);
|
||||
}
|
||||
|
||||
if (isset($filters['VisibleScr'])) {
|
||||
$builder->where('testdefsite.VisibleScr', $filters['VisibleScr']);
|
||||
}
|
||||
|
||||
if (isset($filters['VisibleRpt'])) {
|
||||
$builder->where('testdefsite.VisibleRpt', $filters['VisibleRpt']);
|
||||
}
|
||||
|
||||
if (!empty($filters['TestSiteName'])) {
|
||||
$builder->like('testdefsite.TestSiteName', $filters['TestSiteName']);
|
||||
}
|
||||
|
||||
if (!empty($filters['TestSiteCode'])) {
|
||||
$builder->like('testdefsite.TestSiteCode', $filters['TestSiteCode']);
|
||||
}
|
||||
|
||||
return $builder->orderBy('testdefsite.SeqScr', 'ASC')->get()->getResultArray();
|
||||
}
|
||||
|
||||
public function getTest($TestSiteID) {
|
||||
$db = \Config\Database::connect();
|
||||
|
||||
|
||||
@ -104,4 +104,13 @@ class TestMapModel extends BaseModel {
|
||||
->where('testmapdetail.EndDate IS NULL')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable test mappings by TestSiteID
|
||||
*/
|
||||
public function disableByTestSiteID($testSiteID) {
|
||||
$this->db->table('testmap')
|
||||
->where('TestSiteID', $testSiteID)
|
||||
->update(['EndDate' => date('Y-m-d H:i:s')]);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user