first result commit

This commit is contained in:
mahdahar 2025-01-23 13:30:00 +07:00
parent e6750627c1
commit 89ac4fd55e

View File

@ -27,7 +27,7 @@ class API_Results extends ResourceController {
$response = [
"headers" => [
"Content-Type" => "application/json",
"Authorization" => "NasiGorengBambuRuncing",
"Authorization" => "MILUZAKARIA",
"AppCode" => "2"
],
"data" => [
@ -39,9 +39,10 @@ class API_Results extends ResourceController {
]
];
$sql = "select dc.CHAPID, t.DEPTH as depth_test, dc.FULLTEXT as chap_eng, dc.FULLTEXT as chap_ind, st.FULLTEXT as serum_type, cdt.TEXT1 as test_eng, cdt.TEXT2 as test_ind, cdt.UNIT as UNITTEXT, cdt.REFFTEXT, t.NOTPRINTABLE,
$sql = "select dc.CHAPID, t.DEPTH as depth_test, dc.FULLTEXT as chap_eng, dc.FULLTEXT as chap_ind, st.FULLTEXT as serum_type, cdt.TEXT1 as test_eng, cdt.TEXT2 as test_ind,
cdt.UNIT as UNITTEXT, cdt.REFFTEXT, t.NOTPRINTABLE,
t.TESTORDER, t.RESTYPE as code_type, t.VALIDATIONINITIALS as validator, dt.SHORTTEXT,
RESULT = case when t.RESVALUE is null then tx.FULLTEXT else t.RESVALUE end, cr.*, ct.*, tub.TUBENAME
RESULT = case when t.RESVALUE is null then tx.FULLTEXT else t.RESVALUE end, ct.REFFTESTID, m.HISCODE, m.LISCODE, tub.TUBENAME, cr.REFRANGE, dt.TESTCODE, t.TESTORDER
from REQUESTS r
left join TESTS t on t.REQUESTID = r.REQUESTID
left join DICT_TESTS dt on dt.ENDVALIDDATE is null and t.TESTID=dt.TESTID
@ -54,44 +55,52 @@ left join cmod.dbo.CM_RESULTS cr on cr.ACCESSNUMBER=r.ACCESSNUMBER and cr.TESTCO
left join cmod.dbo.CM_DICT_MAPPINGS m on m.LISCODE=cr.TESTCODE
left join cmod.dbo.CM_TM_TESTS ct on ct.HISCODE=m.HISCODE
left join cmod.dbo.CM_DICT_TUBES tub on tub.TUBEID=m.TUBEID
where r.ACCESSNUMBER='$accessnumber'
ORDER BY dc.CHAPID, depth_test, t.TESTORDER";
where r.ACCESSNUMBER='$accessnumber' ORDER BY t.TESTORDER";
$query = $db->query($sql);
$test_results = $query->getResultArray();
$d0 = 0;
foreach ($test_results as $result) {
$refftestid = trim($result['REFFTESTID']);
$testorder = $result['TESTORDER'];
if($refftestid == '') { $refftestid = $accessnumber . str_pad($testorder,3,0, STR_PAD_LEFT); }
$hiscode = $result['HISCODE'];
$tubename = $result['TUBENAME'];
$depth = $result['depth_test'];
if ( $depth == 0) {
$data = [
"test_ref_id"=> "$refftestid",
"service_id"=> "$hiscode",
"service_name"=> $result['test_eng'],
"test_medium"=> $result['serum_type'],
"test_container"=> "$tubename",
"chapter_type"=> $result['chap_eng'],
# "test_summary"=> "",
# "status"=> "",
"subtest_results" => [],
];
array_push($response['data']['test_results'], $data);
$d0++;
} else if ($depth == 1) {
// $data = [
// "subtest_ref_id"=> $uuid,
// "subtest_name"=> $result['SHORTTEXT'],
// "subtest_uom"=> $result['TESTCODE'],
// "subtest_lower_limit"=> "",
// "subtest_upper_limit"=> "",
// "subtest_critical_lower_limit"=> "",
// "subtest_critiacl_upper_limit"=> "",
// "subtest_result"=> "",
// "subtest_summary"=> "",
// "sub_subtest_results" => [],
// ];
// array_push($response['data']['test_results']['subtest_results'], $data);
$liscode = $result['LISCODE'];
$testcode = $result['TESTCODE'];
$testname = $result['test_eng'];
$sampletype = $result['serum_type'];
$chapter = $result['chap_eng'];
$testresult = $result['RESULT'];
$refrange = $result['REFRANGE'];
$refftext = $result['REFFTEXT'];
if($refftext != '') { $testreff = $refftext; }
else { $testreff = $refrange; }
if($liscode == '') {$liscode = $testcode;}
$data = [
"test_ref_id"=> "$refftestid",
"hiscode"=> "$hiscode",
"liscode"=> "$liscode",
"service_name"=> "$testname",
"test_medium"=> "$sampletype",
"test_container"=> "$tubename",
"chapter_type"=> "$chapter",
"test_result"=> "$testresult",
"test_reff" => "$testreff",
"test_summary"=> "",
"subtest_results" => [],
];
if ( $depth == 0 || $depth == '' ) { // depth 0
if(isset($d0)) { $d0++; } else { $d0 = 0; }
$d1=0;
$response['data']['test_results'][] = $data;
} else if ($depth == 1) { // depth 1
if(isset($d1)) { $d1++; }
$d2=0;
$response['data']['test_results'][$d0]['subtest_results'][] = $data;
} else if ($depth == 2) { // depth 2
if(isset($d2)) { $d2++; }
$d3=0;
$response['data']['test_results'][$d0]['subtest_results'][$d1]['subtest_results'][] = $data;
}
}