add json result send
This commit is contained in:
parent
c251d095a6
commit
5e2ff68596
@ -9,6 +9,10 @@ use Ramsey\Uuid\Uuid;
|
||||
class API_Results extends ResourceController {
|
||||
|
||||
public function results($accessnumber) {
|
||||
$TM_url = "https://api-transmedic1.transmedic.co.id/webhook/lis";
|
||||
$TMBali_bearerToken = "4140|eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOm51bGwsImF1ZCI6IjEyNy4wLjAuMTo4MDAwIiwiaWF0IjoxNzM4MDYwNzcwLCJleHAiOjE3MzgxNDcxNzAsInN1YiI6bnVsbCwianRpIjoiMDcyODc4NmUtZGRiMy00OWQxLTlhOGEtYjFhNGM3ZTcwNWY5IiwiZGF0YSI6eyJ1c2VybmFtZSI6InBibWNfYmFsaSIsInBhc3N3b3JkIjoiSjhlMjlYakxtRENGdVFuayJ9fQ.nb8_SX2nGyq_5A5TmyVDNvuCm5wSovA1od9FcXhhvXw";
|
||||
$TMSby_bearerToken = "4141|eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOm51bGwsImF1ZCI6IjEyNy4wLjAuMTo4MDAwIiwiaWF0IjoxNzM4MDYwODg5LCJleHAiOjE3MzgxNDcyODksInN1YiI6bnVsbCwianRpIjoiZjY2Njc5MmItOTc2OS00ODY3LThlNmItNTBmZDM0MGRjYWZhIiwiZGF0YSI6eyJ1c2VybmFtZSI6InBibWNfc3VyYWJheWEiLCJwYXNzd29yZCI6InBnY1dmZHdYM3FFdDl6YUMifX0.j3ncwI9bZtPIhn3-p6cl3A91nIrZrmQLSGmhVdqSVsY";
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
|
||||
$sql = "select r.HOSTORDERNUMBER, r.SP_HOSPNUMBER, cr.LOC, cr.COMPANY, cr.AGENT from SP_REQUESTS r
|
||||
@ -23,20 +27,17 @@ class API_Results extends ResourceController {
|
||||
$payer_name = $results[0]['AGENT'];
|
||||
$company = $results[0]['COMPANY'];
|
||||
$createdt = gmdate('Y-m-d\TH:i:s.v\Z');
|
||||
|
||||
$response = [
|
||||
"headers" => [
|
||||
"Content-Type" => "application/json",
|
||||
"Authorization" => "MILUZAKARIA",
|
||||
"AppCode" => "2"
|
||||
],
|
||||
"data" => [
|
||||
"reference_id" => "$reffid",
|
||||
"created" => "$createdt",
|
||||
"company_name" => $company,
|
||||
"branch" => $location,
|
||||
"test_results" => []
|
||||
]
|
||||
|
||||
if($location == 'PBMC Surabaya') { $token = $TMSby_bearerToken; }
|
||||
else { $token = $TMBali_bearerToken; }
|
||||
|
||||
$client = \Config\Services::curlrequest();
|
||||
$json = [
|
||||
"reference_id" => "$reffid",
|
||||
"created" => "$createdt",
|
||||
"company_name" => $company,
|
||||
"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,
|
||||
@ -92,21 +93,52 @@ where r.ACCESSNUMBER='$accessnumber' ORDER BY t.TESTORDER";
|
||||
if ( $depth == 0 || $depth == '' ) { // depth 0
|
||||
if(isset($d0)) { $d0++; } else { $d0 = 0; }
|
||||
$d1=0;
|
||||
$response['data']['test_results'][] = $data;
|
||||
$json['data']['test_results'][] = $data;
|
||||
} else if ($depth == 1) { // depth 1
|
||||
if(isset($d1)) { $d1++; }
|
||||
$d2=0;
|
||||
$response['data']['test_results'][$d0]['subtest_results'][] = $data;
|
||||
$json['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;
|
||||
$json['data']['test_results'][$d0]['subtest_results'][$d1]['subtest_results'][] = $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$response = [
|
||||
"headers" => [
|
||||
"Content-Type" => "application/json",
|
||||
"Authorization" => "Bearer $token",
|
||||
"AppCode" => "2"
|
||||
],
|
||||
"data" => $json
|
||||
];
|
||||
|
||||
|
||||
return $this->respond($response,200);
|
||||
return $this->respond($response,200);
|
||||
|
||||
try {
|
||||
$response = $client->request('POST', $url, $response ) ;
|
||||
if ($response->getStatusCode() == 200) {
|
||||
$result = json_decode($response->getBody());
|
||||
echo "<pre>";
|
||||
print_r($result);
|
||||
echo "</pre>";
|
||||
} else {
|
||||
// Handle errors
|
||||
$error = [
|
||||
'status' => $response->getStatusCode(),
|
||||
'message' => $response->getReason(),
|
||||
'response' => $response->getBody()
|
||||
];
|
||||
echo "<pre>";
|
||||
print_r($error);
|
||||
echo "</pre>";
|
||||
log_message('error', 'API request failed: ' . $response->getStatusCode() . ' - ' . $response->getReason() . ' - Response: ' . $response->getBody());
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
echo "Error: " . $e->getMessage();
|
||||
log_message('error', 'API request exception: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user