From aec00c113fa891ca2d0301165bf331efa51fb2d4 Mon Sep 17 00:00:00 2001 From: mikael-zakaria Date: Mon, 10 Mar 2025 14:15:43 +0800 Subject: [PATCH] update tm url, result username --- app/Controllers/API_TM.php | 118 +++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 44 deletions(-) diff --git a/app/Controllers/API_TM.php b/app/Controllers/API_TM.php index 95e21d1..5c81da8 100644 --- a/app/Controllers/API_TM.php +++ b/app/Controllers/API_TM.php @@ -6,6 +6,13 @@ use CodeIgniter\I18n\Time; class API_TM extends ResourceController { + public function __construct() { + $this->url_resultSBY = 'http://10.10.4.123:8001/api/webhook/lis?tenant=PadmaSurabaya'; + $this->url_resultDPS = 'http://10.10.4.123:8001/api/webhook/lis?tenant=PadmaBali'; + $this->url_masterSBY = "http://10.10.4.123:8001/api/webhook/lis-new-master?tenant=PadmaSurabaya"; + $this->url_masterDPS = "http://10.10.4.123:8001/api/webhook/lis-new-master?tenant=PadmaBali"; + } + public function sendHL7Message($host, $port, $message, $timeout = 5) { try { // Create a TCP/IP socket @@ -102,6 +109,7 @@ class API_TM extends ResourceController { $reffid = $qdata['reference_id']; $company = $qdata['company_name']; $loc = $qdata['branch']; + $status = $qdata['status']; $visitnum = $qpat['visit_number']; $visitdesc = $qpat['visit_description']; @@ -139,11 +147,11 @@ class API_TM extends ResourceController { // tests $tests = json_decode(json_encode($qpat['tests']), true);; $string = ''; + if($status=='order') { $teststatus = 0;} + else { $teststatus = 1; } foreach($tests as $test) { $testcode = $test['service_id']; $testreffid = $test['test_ref_id']; - if(isset($test['status'])) { $teststatus = $test['status'];} - else { $teststatus = ''; } $string .= "( '$testreffid', '$reqid', '$testcode', '$teststatus' ),"; } $string = rtrim($string, ','); @@ -230,8 +238,8 @@ class API_TM extends ResourceController { $liscode = $qdata['LISCODE']; $status = $qdata['TESTSTATUS']; if($liscode != '') { - //if($status!=1 || $status !=2) {$status="NW";} else {$status="CA";} - if($status!='CANCEL') {$status="NW";} else {$status="CA";} + if($status!=1 || $status !=2) {$status="NW";} else {$status="CA";} + //if($status!='CANCEL') {$status="NW";} else {$status="CA";} $orm .= "ORC|$status|$reffid||$reffid|||^^^$reqdate|||||$doc|$loc||$reqdate|||||||||\r"; if($i==1) { $orm .= "NTE|1||$hosp|\r"; } $orm .= "OBR|$i|||$liscode|||||||R|||||$doc|||||||||||||||||||||||||\r"; @@ -366,6 +374,7 @@ where r.ACCESSNUMBER='$accessnumber' and t.NOTPRINTABLE is null ORDER BY t.TESTO $resdate = $result['RESDATE']; if($resdate == "1900-01-01 00:00:00.000") { $resdate =''; } $userval = $result['USERVAL']; + $username = $result['USERNAME']; $data = [ "test_ref_id"=> "$refftestid", "hiscode"=> "$hiscode", @@ -380,7 +389,7 @@ where r.ACCESSNUMBER='$accessnumber' and t.NOTPRINTABLE is null ORDER BY t.TESTO "test_summary"=> "$testsum", "resdate"=> "$resdate", "userval"=> "$userval", - //"debug" => "d0=$d0 d1=$d1 d2=$d2", + "username"=> "$username", ]; if ( $depth == 0 || $depth == '' ) { // depth 0 $d0++; @@ -421,6 +430,7 @@ WHERE tu.SP_ACCESSNUMBER = '$accessnumber';"; } public function sendjson( $method, $url, $message ) { + $client = \Config\Services::curlrequest(); try { $response = $client->request($method, $url, $message); @@ -431,34 +441,24 @@ WHERE tu.SP_ACCESSNUMBER = '$accessnumber';"; } } catch (\Exception $e) { - echo "
$token \n".json_encode($json)."\n";
+			//echo "
 \n".json_encode($json)."\n";
             echo "Error: " . $e->getMessage();
             log_message('error', 'API request exception: ' . $e->getMessage());
         }
 	}
 	public function results_send($accessnumber) {
-		//$TM_url = "https://api-transmedic1.transmedic.co.id/api/webhook/lis";
-		$TMSby_url = "http://10.10.4.123:8001/api/webhook/lis";
-		$TMBali_url = "http://10.10.12.90:8001/api/webhook/lis?tenant=PadmaBali";
-		$TMBali_bearerToken = file_get_contents('tokens/pbmc_dps.txt');
-		$TMSby_bearerToken = file_get_contents('tokens/pbmc_sby.txt');
-		
-		$client = \Config\Services::curlrequest();
+		//$TMBali_bearerToken = file_get_contents('tokens/pbmc_dps.txt');
+		//$TMSby_bearerToken = file_get_contents('tokens/pbmc_sby.txt');
 		
 		$json = $this->create_result_json($accessnumber);
 		$location = $json['branch'];
+		$headers = [ "Content-Type" => "application/json" ];
 		if($location == 'PBMC Surabaya') { 
-			$token = $TMSby_bearerToken; 
-			$url = $TMSby_url;
-			$headers = [ 
-				"Content-Type" => "application/json",
-				"Authorization" => "Bearer $token",
-				"appCode" => "2"
-			];
+			//$token = $TMSby_bearerToken; 
+			$url = $this->url_resultSBY;
 		} else { 
-			$token = $TMBali_bearerToken; 
-			$url = $TMBali_url;
-			$headers = [ "Content-Type" => "application/json" ];
+			//$token = $TMBali_bearerToken;
+			$url = $this->url_resultDPS;
 		}
 		
 		$method = "POST";
@@ -468,32 +468,62 @@ WHERE tu.SP_ACCESSNUMBER = '$accessnumber';";
 			"body" => json_encode($json),
 			"verify" => false
 		];
-		
+		echo "
";
+		//print_r($message);
 		$this->sendjson($method, $url, $message);
-		/*
-		try { 
-			$response = $client->request('POST', $url, [
-				"headers" => $headers,
-				"body" => json_encode($json),
-				"verify" => false
-			]);
-			
-            if ($response->getStatusCode() == 200) { 
-				print_r($response);
-            } else {
-				print_r($response);
-            }
-			
-        } catch (\Exception $e) {
-			echo "
$token \n".json_encode($json)."\n";
-            echo "Error: " . $e->getMessage();
-            log_message('error', 'API request exception: ' . $e->getMessage());
-        }
-		*/
     }
 	
 	public function results_preview($accessnumber) {
 		$json = $this->create_result_json($accessnumber);
 		return $this->respond($json);
 	}
+	
+	public function oc ($hon, $test) {
+		$db = \Config\Database::connect();
+		$sql = "select r.*, p.*, t.* from cmod.dbo.CM_TM_REQUESTS r 
+			left join cmod.dbo.CM_TM_PATIENTS p on r.PATID=p.PATID 
+			left join cmod.dbo.CM_DICT_MAPPINGS m on m.LISCODE='$test'
+			left join cmod.dbo.CM_TM_TESTS t on t.REQID=r.REQID and t.HISCODE=m.HISCODE
+			where r.REFFID='$hon' ";
+		$query = $db->query($sql);
+		$results = $query->getResultArray();
+		$visitnumber = $results[0]['REQNUMBER'];
+		$location = $results[0]['LOC'];
+		$patnumber = $results[0]['PATNUMBER'];
+		$firstname = $results[0]['FIRSTNAME'];
+		$lastname = $results[0]['LASTNAME'];
+		$hiscode = $results[0]['HISCODE'];
+		$refftestid = $results[0]['REFFTESTID'];
+		
+		$method = "POST";
+		if($location == "PBMC Bali") { $url = $this->url_resultDPS; }
+		else { $url = $this->url_resultSBY; }
+		
+		$headers = [ "Content-Type" => "application/json" ];
+		$json = [
+			"reference_id" => "$hon",
+			"company_name" => "Padma Medical Group",
+			"branch" => "$location",
+			"status" => "cancel",
+			"patient" => [
+				"rm_number" => "$patnumber",
+				"patient_first_name" => "$firstname",
+				"patient_last_name" => "$lastname",
+				"visit_number" => "$visitnumber"
+			],
+			"tests" => [
+				"test_ref_id" => trim($refftestid),
+				"service_id" => "$hiscode"
+			]
+		];
+		
+		//return $this->respond($json);
+		$message = [
+			"headers" => $headers,
+			"body" => json_encode($json),
+			"verify" => false
+		];
+		
+		$this->sendjson($method, $url, $message);
+	}
 }