diff --git a/app/Config/Autoload.php b/app/Config/Autoload.php index 76cd926..75078fe 100644 --- a/app/Config/Autoload.php +++ b/app/Config/Autoload.php @@ -41,6 +41,8 @@ class Autoload extends AutoloadConfig */ public $psr4 = [ APP_NAMESPACE => APPPATH, + // Untuk UUID + 'Ramsey\Uuid' => ROOTPATH . 'vendor/ramsey/uuid/src', ]; /** diff --git a/app/Controllers/API_Results.php b/app/Controllers/API_Results.php index d0d395e..2a14805 100644 --- a/app/Controllers/API_Results.php +++ b/app/Controllers/API_Results.php @@ -4,17 +4,19 @@ namespace App\Controllers; use CodeIgniter\RESTful\ResourceController; use CodeIgniter\I18n\Time; +use Ramsey\Uuid\Uuid; class API_Results extends ResourceController { public function results($accessnumber) { $db = \Config\Database::connect(); - // $sql = "select HOSTORDERNUMBER as HISNO from SP_REQUESTS where SP_ACCESSNUMBER='$accessnumber'"; - // $query = $db->query($sql); - // $results = $query->getResultArray(); - // $data['LISNO'] = $accessnumber; - // $hisno = $results[0]['HISNO']; + $sql = "select HOSTORDERNUMBER as VISITNUMBER from SP_REQUESTS where SP_ACCESSNUMBER='$accessnumber'"; + $query = $db->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' @@ -22,18 +24,35 @@ class API_Results extends ResourceController { // $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, @@ -41,7 +60,6 @@ class API_Results extends ResourceController { cdt.TEXT2 as test_ind, cdt.UNIT as UNITTEXT, cdt.REFFTEXT, - t.DEPTH as text_depth, t.NOTPRINTABLE, t.TESTORDER, t.RESTYPE as code_type, @@ -59,36 +77,17 @@ class API_Results extends ResourceController { 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 t.TESTORDER"; + ORDER BY dc.CHAPID, depth_test, t.TESTORDER"; $query = $db->query($sql); $test_results = $query->getResultArray(); - - // $uuid24 = $this->generateUUID24(); - $response = [ - "headers" => [ - "Content-Type" => "application/json", - "Authorization" => "Transmedic api key" - ], - "data" => [ - "reference_id" => "", - "created" => "2024-10-19T02:11:06.424654Z", - "company_name" => $payer_name, - "branch" => $location, - "test_results" => [] - ] - ]; - + // 5010200007 // Digunakan Untuk Hasil test foreach ($test_results as $result) { - // var_dump($result);die(); - - if ($result['text_depth'] == 0) { - // $uuid32 = $this->generateUUID32(); - $uuid24 = $this->generateUUID24(); + if ($result['depth_test'] === 0) { $data = [ - "test_ref_id"=> $uuid24, + "test_ref_id"=> " - TM ", "service_id"=> "", "service_name"=> $result['test_eng'], "test_medium"=> $result['serum_type'], @@ -96,13 +95,34 @@ class API_Results extends ResourceController { "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); }