Initial import
This commit is contained in:
394
application/controllers/satu_sehat/Specimen.php
Normal file
394
application/controllers/satu_sehat/Specimen.php
Normal file
@@ -0,0 +1,394 @@
|
||||
<?php
|
||||
class Specimen extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->library('Satusehat');
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "Satu Sehat Spesimen";
|
||||
}
|
||||
|
||||
function getspecimen()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$orderheaderID = $prm['orderheaderID'];
|
||||
|
||||
//cek db one_healt spesimen sudah ada atau belum
|
||||
$sql = "SELECT *
|
||||
FROM one_health.specimen
|
||||
WHERE SpecimentT_OrderHeaderID = ?
|
||||
AND SpecimenIsActive = 'Y'";
|
||||
|
||||
$qry = $this->db->query($sql, [
|
||||
$orderheaderID
|
||||
]);
|
||||
|
||||
$last_qry = $this->db->last_query();
|
||||
|
||||
if (!$qry) {
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$result_cek = $qry->result_array();
|
||||
|
||||
//get organization
|
||||
$sql = "SELECT organizationID
|
||||
FROM one_health.organization
|
||||
WHERE organizationIsActive = 'Y'";
|
||||
|
||||
$qry = $this->db->query($sql, []);
|
||||
$last_qry = $this->db->last_query();
|
||||
|
||||
if (!$qry) {
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$organizationID = $qry->result_array()[0]['organizationID'];
|
||||
|
||||
// get T_OrderSampleID by T_OrderHeaderID
|
||||
$T_OrderSampleID = "";
|
||||
$sql_get_sampleID = "SELECT T_OrderSampleID
|
||||
FROM t_ordersample
|
||||
WHERE
|
||||
T_OrderSampleIsActive = 'Y'
|
||||
AND T_OrderSampleT_OrderHeaderID = $orderheaderID";
|
||||
|
||||
$qry_sampleID = $this->db->query($sql_get_sampleID, []);
|
||||
$last_qry = $this->db->last_query();
|
||||
|
||||
if (!$qry_sampleID) {
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$T_OrderSampleID = $qry_sampleID->result_array()[0]['T_OrderSampleID'];
|
||||
|
||||
if (count($result_cek) == 0) {
|
||||
//blm ada data di one_helath makan diinsertkan
|
||||
|
||||
// $spesimenJSON = [];
|
||||
|
||||
// get data for looping
|
||||
$sql_data_spesimen = "SELECT M_PatientName,
|
||||
T_OrderSampleID,
|
||||
T_OrderHeaderID,
|
||||
T_OrderSampleReceiveDate,
|
||||
T_OrderSampleReceiveTime,
|
||||
CONCAT(T_OrderSampleReceiveDate,' ',T_OrderSampleReceiveTime) as collectedDateTime,
|
||||
CONCAT(T_OrderSampleReceiveDate,' ',T_OrderSampleReceiveTime) as collectedDateTimeFormat,
|
||||
T_OrderDetailID,
|
||||
T_OrderSampleSamplingDate,
|
||||
T_OrderSampleSamplingTime,
|
||||
CONCAT(T_OrderSampleSamplingDate,' ',T_OrderSampleSamplingTime) as receivedTime,
|
||||
DATE_FORMAT(CONCAT(T_OrderSampleSamplingDate,' ',T_OrderSampleSamplingTime), '%Y-%m-%dT%H:%i:%s+00:00') as receivedTimeFormat,
|
||||
OHPatientMapIHSNumber,
|
||||
OHSPecimenMapTypeSystem,
|
||||
OHSPecimenMapTypeCode,
|
||||
OHSPecimenMapTypeDisplay,
|
||||
OHSPecimenMapCollectionMethodeSystem,
|
||||
OHSPecimenMapCollectionMethodeCode,
|
||||
OHSPecimenMapCollectionMethodeDisplay,
|
||||
T_OrderDetailT_TestSasCode as sas_code
|
||||
from t_orderheader
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderHeaderID = $orderheaderID
|
||||
join t_test
|
||||
ON T_OrderDetailT_TestID = T_TestID
|
||||
AND T_TestIsActive = 'Y'
|
||||
AND T_TestIsResult = 'Y'
|
||||
join t_ordersample
|
||||
on T_OrderHeaderID = T_OrderSampleT_OrderHeaderID
|
||||
AND T_OrderSampleT_SampleTypeID = T_TestT_SampleTypeID
|
||||
AND T_OrderSampleIsActive = 'Y'
|
||||
join t_sampletype
|
||||
ON T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
||||
AND T_SampleTypeIsActive = 'Y'
|
||||
join m_patient
|
||||
on T_OrderHeaderM_PatientID = M_PatientID
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
AND M_PatientIsActive = 'Y'
|
||||
LEFT JOIN one_health.oh_patient_map
|
||||
ON T_OrderHeaderM_PatientID = OHPatientMapM_PatientID
|
||||
AND OHPatientMapIsActive = 'Y'
|
||||
LEFT JOIN one_health.oh_specimen_map
|
||||
ON T_SampleTypeID = OHSPecimenMapT_SampleTypeID
|
||||
AND OHSPecimenMapIsActive = 'Y'
|
||||
GROUP BY T_OrderSampleID";
|
||||
|
||||
$qry_data_spesimen = $this->db->query($sql_data_spesimen);
|
||||
|
||||
$last_qry = $this->db->last_query();
|
||||
|
||||
if (!$qry_data_spesimen) {
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result_data_spesimen = $qry_data_spesimen->result_array();
|
||||
|
||||
// ServiceUUID
|
||||
// Berdasarkan t_sampletype dari T_OrderDetailID atau anakannya
|
||||
|
||||
// foreach ($result_data_spesimen as $key => $vx) {
|
||||
// $spesimenJSON[] = [
|
||||
// "fullUrl" => "urn:uuid:{$this->satusehat->gen_uuid()}",
|
||||
// "resource" => [
|
||||
// "resourceType" => "Specimen",
|
||||
// "identifier" => [
|
||||
// "system" => "http://sys-ids.kemkes.go.id/specimen/$organizationID",
|
||||
// "value" => $vx['T_OrderSampleID'],
|
||||
// "assigner" => [
|
||||
// "reference" => "Organization/$organizationID"
|
||||
// ]
|
||||
// ],
|
||||
// "status" => "available",
|
||||
// "type" => [
|
||||
// "coding" => [
|
||||
// "system" => $vx['OHSPecimenMapTypeSystem'],
|
||||
// "code" => $vx['OHSPecimenMapTypeCode'],
|
||||
// "display" => $vx['OHSPecimenMapTypeDisplay']
|
||||
// ]
|
||||
// ],
|
||||
// "collection" => [
|
||||
// "method" => [
|
||||
// "coding" => [
|
||||
// "system" => $vx['OHSPecimenMapCollectionMethodeSystem'],
|
||||
// "code" => $vx['OHSPecimenMapCollectionMethodeCode'],
|
||||
// "display" => $vx['OHSPecimenMapCollectionMethodeDisplay']
|
||||
// ]
|
||||
// ],
|
||||
// "collectedDateTime" => $vx['collectedDateTimeFormat']
|
||||
// ],
|
||||
// "subject" => [
|
||||
// "reference" => "Patient/{$vx['OHPatientMapIHSNumber']}",
|
||||
// "display" => $vx['M_PatientName']
|
||||
// ],
|
||||
// "request" => [
|
||||
// "reference" => $vx['ServiceRequestUUID']
|
||||
// ],
|
||||
// "receivedTime" => $vx['receivedTimeFormat']
|
||||
// ],
|
||||
// "request" => [
|
||||
// "method" => "POST",
|
||||
// "url" => "Specimen"
|
||||
// ],
|
||||
// ];
|
||||
// }
|
||||
|
||||
// // insert json looping
|
||||
// $sql = "INSERT INTO one_health.specimen
|
||||
// (
|
||||
// SpecimenUUID,
|
||||
// SpecimentT_OrderHeaderID,
|
||||
// SpecimentT_OrderSampleID,
|
||||
// SpecimenJSON,
|
||||
// SpecimenCreated
|
||||
// )
|
||||
// VALUES
|
||||
// (
|
||||
// ?,
|
||||
// ?,
|
||||
// ?,
|
||||
// ?,
|
||||
// NOW()
|
||||
// )";
|
||||
// $qry = $this->db->query($sql, [
|
||||
// $this->satusehat->gen_uuid(),
|
||||
// $orderheaderID,
|
||||
// $T_OrderSampleID,
|
||||
// json_encode($spesimenJSON)
|
||||
// ]);
|
||||
// $last_qry = $this->db->last_query();
|
||||
|
||||
// if (!$qry) {
|
||||
// $error = array(
|
||||
// "message" => $this->db->error()["message"],
|
||||
// "sql" => $last_qry
|
||||
// );
|
||||
// $this->sys_error_db($error);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
$spesimenJSON = [];
|
||||
|
||||
$receivedTime = "";
|
||||
|
||||
$fullUrl = [];
|
||||
$identifier = [];
|
||||
$typeCoding = [];
|
||||
$collectionMethodCoding = [];
|
||||
$collectedDateTime = "";
|
||||
$resourceSubject = [];
|
||||
$responseRequest = [];
|
||||
//echo count($result_data_spesimen);
|
||||
$results = [];
|
||||
foreach ($result_data_spesimen as $key => $vx) {
|
||||
$specimen_uuid = $this->satusehat->gen_uuid();
|
||||
$sql = "SELECT IFNULL(ServiceRequestUUID,'') as ServiceRequestUUID
|
||||
FROM t_orderdetail
|
||||
LEFT JOIN one_health.service_request ON ServiceRequestT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
ServiceRequestT_OrderDetailID = T_OrderDetailID
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = ? AND
|
||||
T_OrderDetailIsActive = 'Y' AND
|
||||
T_OrderDetailT_TestSasCode = LEFT(?,8)
|
||||
LIMIT 1";
|
||||
$qry_data_service_request = $this->db->query($sql,[$orderheaderID,$vx['sas_code']]);
|
||||
|
||||
//echo $this->db->last_query();
|
||||
if (!$qry_data_service_request) {
|
||||
$last_qry = $this->db->last_query();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_service_request = $qry_data_service_request->row_array();
|
||||
|
||||
$spesimenJSON = [
|
||||
"fullUrl" => "urn:uuid:{$specimen_uuid}",
|
||||
"resource" => [
|
||||
"resourceType" => "Specimen",
|
||||
"identifier" => [
|
||||
[
|
||||
"system" => "http://sys-ids.kemkes.go.id/specimen/$organizationID",
|
||||
"value" => $vx['T_OrderSampleID'],
|
||||
"assigner" => [
|
||||
"reference" => "Organization/$organizationID"
|
||||
],
|
||||
]
|
||||
],
|
||||
"status" => "available",
|
||||
"type" => [
|
||||
"coding" => [
|
||||
[
|
||||
"system" => $vx['OHSPecimenMapTypeSystem'],
|
||||
"code" => $vx['OHSPecimenMapTypeCode'],
|
||||
"display" => $vx['OHSPecimenMapTypeDisplay']
|
||||
]
|
||||
]
|
||||
],
|
||||
"collection" => [
|
||||
"method" => [
|
||||
"coding" => [
|
||||
[
|
||||
"system" => $vx['OHSPecimenMapCollectionMethodeSystem'],
|
||||
"code" => $vx['OHSPecimenMapCollectionMethodeCode'],
|
||||
"display" => $vx['OHSPecimenMapCollectionMethodeDisplay']
|
||||
]
|
||||
]
|
||||
],
|
||||
"collectedDateTime" => date('c', strtotime($vx['collectedDateTime']))
|
||||
],
|
||||
"subject" => [
|
||||
"reference" => "Patient/{$vx['OHPatientMapIHSNumber']}",
|
||||
"display" => $vx['M_PatientName']
|
||||
],
|
||||
"request" => [
|
||||
[
|
||||
"reference" => "ServiceRequest/".$data_service_request['ServiceRequestUUID']
|
||||
]
|
||||
],
|
||||
"receivedTime" => date('c', strtotime($vx['receivedTime']))
|
||||
],
|
||||
"request" => [
|
||||
"method" => "POST",
|
||||
"url" => "Specimen"
|
||||
],
|
||||
];
|
||||
|
||||
$results[] = $spesimenJSON;
|
||||
|
||||
$sql = "INSERT INTO one_health.specimen
|
||||
(
|
||||
SpecimenUUID,
|
||||
SpecimentT_OrderHeaderID,
|
||||
SpecimentT_OrderSampleID,
|
||||
SpecimenJSON,
|
||||
SpecimenCreated
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
NOW()
|
||||
)";
|
||||
$qry = $this->db->query($sql, [
|
||||
$specimen_uuid,
|
||||
$orderheaderID,
|
||||
$vx['T_OrderSampleID'],
|
||||
json_encode($spesimenJSON)
|
||||
]);
|
||||
$last_qry = $this->db->last_query();
|
||||
|
||||
if (!$qry) {
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// $spesimenJSON['fullUrl'] = $fullUrl;
|
||||
// $spesimenJSON['resource']['resourceType'] = "Specimen";
|
||||
// $spesimenJSON['resource']['identifier'] = $identifier;
|
||||
// $spesimenJSON['resource']['status'] = "available";
|
||||
// $spesimenJSON['resource']['type']['coding'] = $typeCoding;
|
||||
// $spesimenJSON['resource']['collection']['method']['coding'] = $collectionMethodCoding;
|
||||
// $spesimenJSON['resource']['collection']['method']['collectedDateTime'] = $collectedDateTime;
|
||||
// $spesimenJSON['resource']['subject'] = $resourceSubject;
|
||||
// $spesimenJSON['resource']['request'] = $responseRequest;
|
||||
// $spesimenJSON['resource']['receivedTime'] = $receivedTime;
|
||||
// $spesimenJSON['request'] = [
|
||||
// "method" => "POST",
|
||||
// "url" => "Specimen"
|
||||
// ];
|
||||
|
||||
// insert json looping
|
||||
|
||||
echo json_encode($results);
|
||||
|
||||
// echo $sql_data_spesimen;
|
||||
} else {
|
||||
//sudah ada data di one_helath makan langsung di returnkan jsonya ;
|
||||
echo $result_cek[0]['SpecimenJSON'];
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user