Initial import
This commit is contained in:
312
application/controllers/satu_sehat/Diagnosticreport.php
Normal file
312
application/controllers/satu_sehat/Diagnosticreport.php
Normal file
@@ -0,0 +1,312 @@
|
||||
<?php
|
||||
class Diagnosticreport extends MY_Controller{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->library('Satusehat');
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "Satu Sehat Diagnostic Report";
|
||||
}
|
||||
|
||||
function getdiagnosticreport()
|
||||
{
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$orderheaderID = $prm['orderheaderID'];
|
||||
|
||||
//cek db one_health diagnostic report sudah ada atau belum
|
||||
$sql = "SELECT *
|
||||
FROM one_health.diagnostic_report
|
||||
WHERE DiagnosticReportT_orderHeaderID = ?
|
||||
AND DiagnosticReportIsActive = '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'];
|
||||
|
||||
if (count($result_cek) == 0) {
|
||||
|
||||
$sql_data_diagnostic_report = "SELECT T_OrderHeaderID,T_OrderHeaderLabNumber,
|
||||
IFNULL(OHPatientMapIHSNumber,'') as OHPatientMapIHSNumber,
|
||||
IFNULL(OHDoctorMapIHSNumber,'') as doctor_ihsnumber,
|
||||
EncounterUUID, T_TestName,
|
||||
IFNULL(Nat_TestLoincCode,'') as code_loinc,
|
||||
IFNULL(Nat_TestLoincDisplay,'') as code_display,
|
||||
ServiceRequestUUID
|
||||
FROM one_health.service_request
|
||||
JOIN t_orderheader ON ServiceRequestT_OrderHeaderID = ? AND
|
||||
ServiceRequestT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON M_PatientID = T_OrderHeaderM_PatientID
|
||||
JOIN t_orderdetail ON ServiceRequestT_OrderDetailID = T_OrderDetailID
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
JOIN nat_test ON T_TestNat_TestID = Nat_TestID AND Nat_TestIsActive = 'Y'
|
||||
LEFT JOIN nat_test_loinc ON Nat_TestLoincNat_TestID = T_TestNat_TestID
|
||||
LEFT JOIN one_health.oh_patient_map ON OHPatientMapM_PatientID = M_PatientID
|
||||
AND OHPatientMapIsActive = 'Y'
|
||||
LEFT JOIN one_health.oh_doctor_map ON OHDoctorMapM_DoctorID = T_OrderHeaderPjM_DoctorID
|
||||
LEFT JOIN one_health.encounter ON EncounterT_orderHeaderID = T_orderHeaderID
|
||||
AND EncounterIsActive= 'Y'
|
||||
WHERE
|
||||
ServiceRequestIsActive = 'Y'";
|
||||
|
||||
$qry_data_diagnostic_report = $this->db->query($sql_data_diagnostic_report,[$orderheaderID]);
|
||||
|
||||
if (!$qry_data_diagnostic_report) {
|
||||
$last_qry = $this->db->last_query();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$ddr = $qry_data_diagnostic_report->result_array();
|
||||
|
||||
foreach ($ddr as $k_sr => $rdr) {
|
||||
$diagnosticreport_uuid = $this->satusehat->gen_uuid();
|
||||
$result["fullUrl"] = "urn:uuid:".$diagnosticreport_uuid;
|
||||
$data_result['resourceType'] = "DiagnosticReport";
|
||||
$data_result['identifier'] = array(
|
||||
array(
|
||||
"system" => "http://sys-ids.kemkes.go.id/observation/".$organizationID,
|
||||
"value" => $rdr['T_OrderHeaderLabNumber']
|
||||
)
|
||||
);
|
||||
$data_result['status'] = "final";
|
||||
$data_result['category'] = array(
|
||||
array(
|
||||
"coding" => array(
|
||||
array(
|
||||
"system" => "http://terminology.hl7.org/CodeSystem/v2-0074",
|
||||
"code" => "CH",
|
||||
"display" => "Chemistry"
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$sql = "SELECT T_OrderDetailValDate
|
||||
FROM t_orderdetail
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = $orderheaderID AND
|
||||
T_OrderDetailIsActive = 'Y' AND
|
||||
T_OrderDetailT_TestIsResult = 'Y'
|
||||
ORDER BY T_OrderDetailValDate ASC
|
||||
LIMIT 1";
|
||||
//echo $sql;
|
||||
$query = $this->db->query($sql);
|
||||
//echo $this->db->last_query();
|
||||
if(!$query){
|
||||
echo $this->db->last_query();
|
||||
$this->sys_error("error get t_orderdetail");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_validdate = $query->row()->T_OrderDetailValDate;
|
||||
$efectiveDate = $data_validdate;
|
||||
$issuedDate = $data_validdate;
|
||||
|
||||
$coding[] = [
|
||||
"system" => "http://loinc.org",
|
||||
"code" => $rdr['code_loinc'],
|
||||
"display" => $rdr['T_TestName']
|
||||
];
|
||||
|
||||
$data_result['code'] = array(
|
||||
"coding" => $coding
|
||||
);
|
||||
$data_result['subject'] = array(
|
||||
"reference" => "Patient/".$rdr['OHPatientMapIHSNumber']
|
||||
);
|
||||
$data_result['encounter'] = array(
|
||||
'reference' => "Encounter/".$rdr['EncounterUUID']
|
||||
);
|
||||
$data_result['effectiveDateTime'] = date('c', strtotime($efectiveDate));
|
||||
$data_result['issued'] = date('c', strtotime($issuedDate));
|
||||
$data_result['performer'] = array(
|
||||
array(
|
||||
'reference' => "Practitioner/".$rdr['doctor_ihsnumber']
|
||||
),
|
||||
array(
|
||||
'reference' => "Organization/".$organizationID
|
||||
)
|
||||
);
|
||||
|
||||
$sql = "SELECT IFNULL(OHStaffMapIhsNumber,'') as staff_ihsnumber
|
||||
FROM t_orderdetail
|
||||
JOIN m_user ON T_OrderDetailValUserID = M_UserID
|
||||
JOIN m_staff ON M_UserM_StaffID = M_StaffID
|
||||
LEFT JOIN one_health.oh_staff_map ON OHStaffMapM_StaffNIK = M_StaffNIK
|
||||
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = $orderheaderID AND
|
||||
T_OrderDetailIsActive = 'Y' AND
|
||||
T_OrderDetailT_TestIsResult = 'Y'
|
||||
ORDER BY T_OrderDetailValDate DESC
|
||||
LIMIT 1";
|
||||
$query = $this->db->query($sql);
|
||||
if(!$query){
|
||||
// echo $this->db->last_query();
|
||||
$this->sys_error("error get t_orderdetail");
|
||||
exit;
|
||||
}
|
||||
|
||||
$r_validator = $query->row_array();
|
||||
|
||||
$data_result['performer'] = array(
|
||||
array(
|
||||
'reference' => "Practitioner/".$r_validator['staff_ihsnumber']
|
||||
),
|
||||
array(
|
||||
'reference' => "Organization/".$organizationID
|
||||
)
|
||||
);
|
||||
|
||||
$sql = "SELECT observationUUID
|
||||
FROM t_orderdetail
|
||||
JOIN one_health.observation ON observationT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
observationT_TestID = T_OrderDetailT_TestID AND
|
||||
observationIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = $orderheaderID AND
|
||||
T_OrderDetailIsActive = 'Y' AND
|
||||
T_OrderDetailT_TestIsResult = 'Y'";
|
||||
$query = $this->db->query($sql);
|
||||
if(!$query){
|
||||
echo $this->db->last_query();
|
||||
$this->sys_error("error get t_orderdetail observation");
|
||||
exit;
|
||||
}
|
||||
|
||||
$r_observations = $query->result_array();
|
||||
|
||||
$rst_result = [];
|
||||
foreach ($r_observations as $idx => $val) {
|
||||
$idnew = $idx+1;
|
||||
$rst_result[] = array(
|
||||
"id" => "{$idnew}",
|
||||
"reference" => "Observation/".$val['observationUUID']
|
||||
);
|
||||
}
|
||||
$data_result['result'] = $rst_result;
|
||||
|
||||
$sql = "SELECT SpecimenUUID
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
JOIN t_ordersample ON T_OrderSampleT_SampleTypeID = T_TestT_SampleTypeID AND
|
||||
T_OrderSampleT_OrderHeaderID = {$prm['orderheaderID']} AND T_OrderSampleIsActive = 'Y'
|
||||
JOIN one_health.specimen ON SpecimentT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
SpecimentT_OrderSampleID = T_OrderSampleID AND
|
||||
SpecimenIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = {$prm['orderheaderID']} AND
|
||||
T_OrderDetailIsActive = 'Y' AND
|
||||
T_OrderDetailT_TestIsResult = 'Y'
|
||||
GROUP BY T_OrderSampleID";
|
||||
$query = $this->db->query($sql);
|
||||
if(!$query){
|
||||
echo $this->db->last_query();
|
||||
$this->sys_error("error get specimen uuid");
|
||||
exit;
|
||||
}
|
||||
|
||||
$r_specimens = $query->result_array();
|
||||
|
||||
$rst_specimen = [];
|
||||
foreach ($r_specimens as $idxx => $vall) {
|
||||
$idnew = $idxx+1;
|
||||
$rst_specimen[] = array(
|
||||
"id" => "{$idnew}",
|
||||
"reference" => "Specimen/".$vall['SpecimenUUID']
|
||||
);
|
||||
}
|
||||
$data_result['specimen'] = $rst_specimen;
|
||||
|
||||
$data_result['basedOn'] = array(
|
||||
array(
|
||||
"reference" => "urn:uuid:".$v_sr['ServiceRequestUUID']
|
||||
)
|
||||
);
|
||||
$data_result["conclusion"] = "";
|
||||
$result["resource"] = $data_result;
|
||||
$result["request"] = array("method" => "POST", "url" => "DiagnosticReport");
|
||||
|
||||
$sql = "INSERT INTO one_health.diagnostic_report
|
||||
(
|
||||
DiagnosticReportUUID,
|
||||
DiagnosticReportT_orderHeaderID,
|
||||
DiagnosticReportJSON,
|
||||
DiagnosticReportCreated
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
NOW()
|
||||
)";
|
||||
$qry = $this->db->query($sql, [
|
||||
$diagnosticreport_uuid,
|
||||
$orderheaderID,
|
||||
json_encode($result)
|
||||
]);
|
||||
$last_qry = $this->db->last_query();
|
||||
|
||||
if (!$qry) {
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($result);
|
||||
|
||||
} else {
|
||||
//sudah ada data di one_health maka langsung di returnkan jsonya ;
|
||||
echo $result_cek[0]['DiagnosticReportJSON'];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user