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 {
|
class API_Results extends ResourceController {
|
||||||
|
|
||||||
public function results($accessnumber) {
|
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();
|
$db = \Config\Database::connect();
|
||||||
|
|
||||||
$sql = "select r.HOSTORDERNUMBER, r.SP_HOSPNUMBER, cr.LOC, cr.COMPANY, cr.AGENT from SP_REQUESTS r
|
$sql = "select r.HOSTORDERNUMBER, r.SP_HOSPNUMBER, cr.LOC, cr.COMPANY, cr.AGENT from SP_REQUESTS r
|
||||||
@ -24,19 +28,16 @@ class API_Results extends ResourceController {
|
|||||||
$company = $results[0]['COMPANY'];
|
$company = $results[0]['COMPANY'];
|
||||||
$createdt = gmdate('Y-m-d\TH:i:s.v\Z');
|
$createdt = gmdate('Y-m-d\TH:i:s.v\Z');
|
||||||
|
|
||||||
$response = [
|
if($location == 'PBMC Surabaya') { $token = $TMSby_bearerToken; }
|
||||||
"headers" => [
|
else { $token = $TMBali_bearerToken; }
|
||||||
"Content-Type" => "application/json",
|
|
||||||
"Authorization" => "MILUZAKARIA",
|
$client = \Config\Services::curlrequest();
|
||||||
"AppCode" => "2"
|
$json = [
|
||||||
],
|
"reference_id" => "$reffid",
|
||||||
"data" => [
|
"created" => "$createdt",
|
||||||
"reference_id" => "$reffid",
|
"company_name" => $company,
|
||||||
"created" => "$createdt",
|
"branch" => $location,
|
||||||
"company_name" => $company,
|
"test_results" => []
|
||||||
"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,
|
$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 ( $depth == 0 || $depth == '' ) { // depth 0
|
||||||
if(isset($d0)) { $d0++; } else { $d0 = 0; }
|
if(isset($d0)) { $d0++; } else { $d0 = 0; }
|
||||||
$d1=0;
|
$d1=0;
|
||||||
$response['data']['test_results'][] = $data;
|
$json['data']['test_results'][] = $data;
|
||||||
} else if ($depth == 1) { // depth 1
|
} else if ($depth == 1) { // depth 1
|
||||||
if(isset($d1)) { $d1++; }
|
if(isset($d1)) { $d1++; }
|
||||||
$d2=0;
|
$d2=0;
|
||||||
$response['data']['test_results'][$d0]['subtest_results'][] = $data;
|
$json['data']['test_results'][$d0]['subtest_results'][] = $data;
|
||||||
} else if ($depth == 2) { // depth 2
|
} else if ($depth == 2) { // depth 2
|
||||||
if(isset($d2)) { $d2++; }
|
if(isset($d2)) { $d2++; }
|
||||||
$d3=0;
|
$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