502 lines
20 KiB
PHP
502 lines
20 KiB
PHP
<?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'];
|
|
|
|
//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 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,
|
|
IFNULL(OHSPecimenMapTypeSystem,'') as OHSPecimenMapTypeSystem,
|
|
IFNULL(OHSPecimenMapTypeCode,'') as OHSPecimenMapTypeCode,
|
|
IFNULL(OHSPecimenMapTypeDisplay,'') as OHSPecimenMapTypeDisplay,
|
|
IFNULL(OHSPecimenMapCollectionMethodeSystem,'') as OHSPecimenMapCollectionMethodeSystem,
|
|
IFNULL(OHSPecimenMapCollectionMethodeCode,'') as OHSPecimenMapCollectionMethodeCode,
|
|
IFNULL(OHSPecimenMapCollectionMethodeDisplay,'') as 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();
|
|
|
|
$spesimenJSON = [];
|
|
|
|
$receivedTime = "";
|
|
|
|
$fullUrl = [];
|
|
$identifier = [];
|
|
$typeCoding = [];
|
|
$collectionMethodCoding = [];
|
|
$collectedDateTime = "";
|
|
$resourceSubject = [];
|
|
$responseRequest = [];
|
|
//echo count($result_data_spesimen);
|
|
$results = [];
|
|
$status = 'complete';
|
|
foreach ($result_data_spesimen as $key => $vx) {
|
|
$sql = "SELECT *
|
|
FROM one_health.specimen
|
|
WHERE
|
|
SpecimentT_OrderHeaderID = ? AND
|
|
SpecimentT_OrderSampleID = ? AND
|
|
SpecimenIsActive = 'Y'";
|
|
|
|
$qry_check_specimen = $this->db->query($sql,[$orderheaderID,$vx['T_OrderSampleID']]);
|
|
|
|
//echo $this->db->last_query();
|
|
if (!$qry_check_specimen) {
|
|
$last_qry = $this->db->last_query();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
|
|
$exist_data = $qry_check_specimen->result_array();
|
|
|
|
if(count($exist_data) == 0){
|
|
$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();
|
|
|
|
if(!$vx['OHSPecimenMapTypeCode'] || $vx['OHSPecimenMapTypeCode'] == ''){
|
|
$status = 'uncomplete';
|
|
}
|
|
|
|
if(!$vx['OHSPecimenMapCollectionMethodeCode'] || $vx['OHSPecimenMapCollectionMethodeCode'] == ''){
|
|
$status = 'uncomplete';
|
|
}
|
|
|
|
$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"
|
|
],
|
|
];
|
|
|
|
$sql = "INSERT INTO one_health.specimen
|
|
(
|
|
SpecimenUUID,
|
|
SpecimentT_OrderHeaderID,
|
|
SpecimentT_OrderSampleID,
|
|
SpecimenJSON,
|
|
SpecimenStatus,
|
|
SpecimenCreated
|
|
)
|
|
VALUES
|
|
(
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
NOW()
|
|
)";
|
|
$qry = $this->db->query($sql, [
|
|
$specimen_uuid,
|
|
$orderheaderID,
|
|
$vx['T_OrderSampleID'],
|
|
json_encode($spesimenJSON),
|
|
$status
|
|
]);
|
|
$last_qry = $this->db->last_query();
|
|
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
|
|
$results[] = $spesimenJSON;
|
|
}else{
|
|
$results[] = $exist_data[0]['SpecimenJSON'];
|
|
}
|
|
}
|
|
|
|
echo json_encode($results);
|
|
|
|
// echo $sql_data_spesimen;
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_codesystems(){
|
|
try {
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "SELECT code_system
|
|
FROM one_terminology.`terminology`
|
|
WHERE `resource_type` = 'specimen' AND
|
|
`attribute_path` = 'specimen.type'
|
|
GROUP BY code_system";
|
|
|
|
$qry = $this->db->query($sql);
|
|
$last_qry = $this->db->last_query();
|
|
//echo $last_qry;
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
|
|
$results = $qry->result_array();
|
|
echo json_encode($results);
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_specimentypes(){
|
|
try {
|
|
$prm = $this->sys_input;
|
|
$search = $prm['search'];
|
|
$code_system = $prm['code_system'];
|
|
|
|
$sql = "SELECT code_system,code,display
|
|
FROM one_terminology.`terminology`
|
|
WHERE `resource_type` = 'specimen' AND
|
|
`attribute_path` = 'specimen.type' AND
|
|
code_system = ? AND
|
|
(
|
|
`display` LIKE CONCAT('%',?,'%') OR
|
|
`code` LIKE CONCAT('%',?,'%')
|
|
)
|
|
LIMIT 50";
|
|
|
|
$qry = $this->db->query($sql, [$code_system,$search,$search]);
|
|
$last_qry = $this->db->last_query();
|
|
//echo $last_qry;
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
|
|
$results = $qry->result_array();
|
|
echo json_encode($results);
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_specimencollections(){
|
|
try {
|
|
$prm = $this->sys_input;
|
|
$search = $prm['search'];
|
|
$code_system = $prm['code_system'];
|
|
|
|
$sql = "SELECT code_system,code,display
|
|
FROM one_terminology.`terminology`
|
|
WHERE `resource_type` = 'specimen' AND
|
|
`attribute_path` = 'specimen.collection' AND
|
|
code_system = ? AND
|
|
(
|
|
`display` LIKE CONCAT('%',?,'%') OR
|
|
`code` LIKE CONCAT('%',?,'%')
|
|
)
|
|
LIMIT 50";
|
|
|
|
$qry = $this->db->query($sql, [$code_system,$search,$search]);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
|
|
$results = $qry->result_array();
|
|
echo json_encode($results);
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function updatespecimen()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$SpecimenUUID = $prm['SpecimenUUID'];
|
|
$T_OrderSampleID = $prm['T_OrderSampleID'];
|
|
$sql = "SELECT T_OrderSampleT_SampleTypeID
|
|
FROM t_ordersample
|
|
WHERE
|
|
T_OrderSampleID = ? AND
|
|
T_OrderSampleIsActive = 'Y' LIMIT 1";
|
|
$qry = $this->db->query($sql, [$T_OrderSampleID]);
|
|
$last_qry = $this->db->last_query();
|
|
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
|
|
$T_SampleTypeID = $qry->row()->T_OrderSampleT_SampleTypeID;
|
|
|
|
$json_data = json_encode($prm['json_data']);
|
|
$param_json = $prm['json_data'];
|
|
$specimen_type = $param_json['resource']['type']['coding'][0];
|
|
$specimen_collection = $param_json['resource']['collection']['method']['coding'][0];
|
|
if($specimen_type['code'] && $specimen_type['code'] != '' && $specimen_collection['code'] && $specimen_collection['code'] != ''){
|
|
$sql = "UPDATE one_health.oh_specimen_map SET
|
|
OHSPecimenMapTypeSystem = ?,
|
|
OHSPecimenMapTypeCode = ?,
|
|
OHSPecimenMapTypeDisplay = ?,
|
|
OHSPecimenMapCollectionMethodeSystem = ?,
|
|
OHSPecimenMapCollectionMethodeCode = ?,
|
|
OHSPecimenMapCollectionMethodeDisplay = ?
|
|
WHERE
|
|
OHSPecimenMapT_SampleTypeID = ? AND
|
|
OHSPecimenMapIsActive = 'Y'
|
|
";
|
|
$qry = $this->db->query($sql, [
|
|
$specimen_type['system'],
|
|
$specimen_type['code'],
|
|
$specimen_type['display'],
|
|
$specimen_collection['system'],
|
|
$specimen_collection['code'],
|
|
$specimen_collection['display'],
|
|
$T_SampleTypeID
|
|
]);
|
|
$last_qry = $this->db->last_query();
|
|
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
$status = $prm['status'];
|
|
$sql = "UPDATE one_health.specimen
|
|
SET SpecimenJSON = ?, SpecimenStatus = ?
|
|
WHERE
|
|
SpecimentT_OrderSampleID = ? AND
|
|
SpecimenUUID = ? AND
|
|
SpecimenIsActive = 'Y'";
|
|
$qry = $this->db->query($sql, [$json_data, $status, $T_OrderSampleID, $SpecimenUUID]);
|
|
$last_qry = $this->db->last_query();
|
|
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT *
|
|
FROM one_health.specimen
|
|
WHERE SpecimentT_OrderSampleID = ? AND
|
|
SpecimenUUID = ? AND
|
|
SpecimenIsActive = 'Y'";
|
|
$qry = $this->db->query($sql, [$T_OrderSampleID,$SpecimenUUID]);
|
|
$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 = $qry->row_array();
|
|
echo json_encode($result['SpecimenJSON']);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|