query($sql); $results = $query->getResultArray(); $visitnumber = $results[0]['VISITNUMBER']; // $sql = "select TESTCODE, TESTORDER, RESTYPE, RESVALUE, RESFLAG, UNIT, REFRANGE, USERVAL, RESDATE // from cmod.dbo.CM_RESULTS r // where ACCESSNUMBER='$accessnumber' // order by TESTORDER"; // $query = $db->query($sql); // $results = $query->getResultArray(); $sql = "SELECT sp.HOSTORDERNUMBER, hiso.LOC, hiso.PAYERNAME FROM dbo.SP_REQUESTS sp LEFT JOIN cmod.dbo.CM_HIS_ORDERS hiso ON hiso.VISITNUMBER = sp.HOSTORDERNUMBER WHERE SP_ACCESSNUMBER = '$accessnumber'"; $query = $db->query($sql); $results = $query->getResultArray(); $location = $results[0]['LOC'] == null ? 'PBMC Bali' : 'PBMC Surabaya'; $payer_name = $results[0]['PAYERNAME'] == null ? '' : $results[0]['PAYERNAME']; $response = [ "headers" => [ "Content-Type" => "application/json", "Authorization" => "Transmedic api key" ], "data" => [ "reference_id" => " - ", "created" => " - ", "company_name" => $payer_name, "branch" => $location, "test_results" => [] ] ]; $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.* 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 left join DICT_TEXTS tx on tx.TEXTID=t.CODEDRESULTID left join DICT_CHAPTERS dc on dc.CHAPID=dt.CHAPID and dc.ENDVALIDDATE is null left join DICT_TEST_SAMPLES ts on ts.TESTID=t.TESTID and dt.TESTID=ts.TESTID left join DICT_SAMPLES_TYPES st on st.SAMPTYPEID=ts.SAMPTYPEID left join cmod.dbo.CM_DICT_TESTS cdt on dt.TESTCODE=cdt.TESTCODE left join cmod.dbo.CM_RESULTS cr on cr.ACCESSNUMBER=r.ACCESSNUMBER and cr.TESTCODE=cdt.TESTCODE and cr.TESTCODE=dt.TESTCODE where r.ACCESSNUMBER='$accessnumber' ORDER BY dc.CHAPID, depth_test, t.TESTORDER"; $query = $db->query($sql); $test_results = $query->getResultArray(); // 5010200007 // Digunakan Untuk Hasil test foreach ($test_results as $result) { if ($result['depth_test'] === 0) { $data = [ "test_ref_id"=> " - TM ", "service_id"=> "", "service_name"=> $result['test_eng'], "test_medium"=> $result['serum_type'], "test_container"=> "", "chapter_type"=> $result['chap_eng'], "test_summary"=> "", "status"=> "", "subtest_results" => [], ]; array_push($response['data']['test_results'], $data); } else if ($result['depth_test'] === 1) { // $uuid = Uuid::uuid4()->toString(); // $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); } } return $this->respond($response,200); } }