Initial import
This commit is contained in:
208
application/controllers/satu_sehat/Bundle.php
Normal file
208
application/controllers/satu_sehat/Bundle.php
Normal file
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
class Bundle extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
var $load;
|
||||
var $satusehat;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->library('Satusehat');
|
||||
}
|
||||
|
||||
function createbundle()
|
||||
{
|
||||
try {
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$prm = $this->sys_input;
|
||||
$orderheaderID = $prm['orderheaderID'];
|
||||
|
||||
$result["resourceType"] = "Bundle";
|
||||
$result["type"] = "transaction";
|
||||
$entry = [];
|
||||
$sql = "SELECT *
|
||||
FROM one_health.encounter
|
||||
WHERE
|
||||
EncounterT_orderHeaderID = ? AND EncounterIsActive = 'Y'
|
||||
LIMIT 1";
|
||||
$qry = $this->db->query($sql, [$orderheaderID]);
|
||||
|
||||
if (!$qry) {
|
||||
$last_qry = $this->db->last_query();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rst_encounter = $qry->row_array();
|
||||
$entry[] = json_decode($rst_encounter['EncounterJSON']);
|
||||
|
||||
$service_requests = [];
|
||||
$sql = "SELECT *
|
||||
FROM one_health.service_request
|
||||
WHERE
|
||||
ServiceRequestT_OrderHeaderID = ? AND ServiceRequestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$orderheaderID]);
|
||||
|
||||
if (!$qry) {
|
||||
$last_qry = $this->db->last_query();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rst_service_request = $qry->result_array();
|
||||
if($rst_service_request){
|
||||
foreach ($rst_service_request as $key => $value) {
|
||||
$entry[] = json_decode($value['ServiceRequestJSON']);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM one_health.specimen
|
||||
WHERE
|
||||
SpecimentT_OrderHeaderID = ? AND SpecimenIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$orderheaderID]);
|
||||
|
||||
if (!$qry) {
|
||||
$last_qry = $this->db->last_query();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rst_specimen = $qry->result_array();
|
||||
if($rst_specimen){
|
||||
foreach ($rst_specimen as $key => $value) {
|
||||
$entry[] = json_decode($value['SpecimenJSON']);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM one_health.observation
|
||||
WHERE
|
||||
observationT_OrderHeaderID = ? AND observationIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$orderheaderID]);
|
||||
|
||||
if (!$qry) {
|
||||
$last_qry = $this->db->last_query();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rst_observation = $qry->result_array();
|
||||
if($rst_observation){
|
||||
foreach ($rst_observation as $key => $value) {
|
||||
$entry[] = json_decode($value['observationJSON']);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM one_health.diagnostic_report
|
||||
WHERE
|
||||
DiagnosticReportT_orderHeaderID = {$orderheaderID} AND DiagnosticReportIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
//echo $sql;
|
||||
|
||||
if (!$qry) {
|
||||
$last_qry = $this->db->last_query();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rst_diagnosticreport = $qry->row_array();
|
||||
//print_r($rst_diagnosticreport);
|
||||
$entry[] = json_decode($rst_diagnosticreport['DiagnosticReportJSON']);
|
||||
//print_r(json_decode($rst_diagnosticreport['DiagnosticReportJSON']));
|
||||
|
||||
$result["entry"] = $entry;
|
||||
|
||||
$sql = "SELECT COUNT(*) as xcount
|
||||
FROM one_health.bundle
|
||||
WHERE
|
||||
BundleT_orderHeaderID = ? AND BundleIsActive = 'Y'
|
||||
";
|
||||
$qry = $this->db->query($sql, [$orderheaderID]);
|
||||
|
||||
if (!$qry) {
|
||||
$last_qry = $this->db->last_query();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rst_count = $qry->row_array();
|
||||
if($rst_count['xcount'] > 0){
|
||||
$sql = "UPDATE one_health.bundle SET
|
||||
BundleResponseJSON = ?
|
||||
WHERE
|
||||
BundleT_orderHeaderID = ? AND
|
||||
BundleIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [json_encode($result),$orderheaderID]);
|
||||
|
||||
if (!$qry) {
|
||||
$last_qry = $this->db->last_query();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
}else{
|
||||
$sql = "INSERT INTO one_health.bundle (
|
||||
BundleJSON,
|
||||
BundleT_orderHeaderID,
|
||||
BundleCreated,
|
||||
BundleUserID
|
||||
)
|
||||
VALUES(
|
||||
?,?,NOW(),?
|
||||
)";
|
||||
$qry = $this->db->query($sql, [json_encode($result),$orderheaderID,$userid]);
|
||||
|
||||
if (!$qry) {
|
||||
$last_qry = $this->db->last_query();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($result);
|
||||
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
72
application/controllers/satu_sehat/Diagnose.php
Normal file
72
application/controllers/satu_sehat/Diagnose.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
class Diagnose extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
var $load;
|
||||
var $satusehat;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->satusehat = $this->load->library('Satusehat');
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "SATU SEHAT DIAGNOSE";
|
||||
}
|
||||
|
||||
function getdiagnose()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$orderheaderID = $prm['orderheaderID'];
|
||||
|
||||
$sql = "SELECT T_OrderHeaderID,
|
||||
T_OrderHeaderDiagnose
|
||||
FROM t_orderheader
|
||||
WHERE T_OrderHeaderIsActive = 'Y'
|
||||
AND T_OrderHeaderID = ?";
|
||||
$qry = $this->db->query($sql, [$orderheaderID]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("t_orderheader select error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getdiagnoserole()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$sql = "SELECT * FROM one_terminology.terminology WHERE `resource_type` = 'DiagnosisRole' ORDER BY `resource_type` LIMIT 50";
|
||||
$qry = $this->db->query($sql);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("terminology select error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
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'];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
433
application/controllers/satu_sehat/Encounter.php
Normal file
433
application/controllers/satu_sehat/Encounter.php
Normal file
@@ -0,0 +1,433 @@
|
||||
<?php
|
||||
class Encounter extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
var $load;
|
||||
var $satusehat;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->library('Satusehat');
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo "Satu Sehat Encounter";
|
||||
}
|
||||
function getencounter()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$orderheaderID = $prm['orderheaderID'];
|
||||
|
||||
//cek db one_healt encounter sudah ada atau belum
|
||||
$sql = "SELECT * FROM one_health.encounter
|
||||
WHERE EncounterT_orderHeaderID = ?
|
||||
AND EncounterIsActive = '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();
|
||||
|
||||
|
||||
if (count($result_cek) == 0) {
|
||||
//blm ada data di one_helath makan diinsertkan
|
||||
|
||||
$encounter_uuid = $this->satusehat->gen_uuid();
|
||||
//cek db one_hs eapakah order home service atau tidak
|
||||
$sql = "SELECT T_OrderT_OrderHeaderID FROM one_hs.t_order
|
||||
WHERE T_OrderT_OrderHeaderID = ?;";
|
||||
$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;
|
||||
}
|
||||
$cek_hs = $qry->result_array();
|
||||
$codeClass = "AMB";
|
||||
$codeDisplay = "ambulatory";
|
||||
if (count($cek_hs) > 0) {
|
||||
$codeClass = "HH";
|
||||
$codeDisplay = "home health";
|
||||
}
|
||||
$encounter = array(
|
||||
"fullUrl" => "urn:uuid:{$encounter_uuid}",
|
||||
"resource" => [
|
||||
"resourceType" => "Encounter",
|
||||
"status" => "finished",
|
||||
"class" => [
|
||||
"system" => "http://terminology.hl7.org/CodeSystem/v3-ActCode",
|
||||
"code" => $codeClass,
|
||||
"display" => $codeDisplay
|
||||
],
|
||||
]
|
||||
);
|
||||
//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'];
|
||||
$organization = [
|
||||
"reference" => "Organization/$organizationID"
|
||||
];
|
||||
|
||||
//get subject
|
||||
//subject reference
|
||||
$sql = "SELECT
|
||||
T_OrderHeaderCreated AS T_OrderHeaderCreated,
|
||||
T_OrderHeaderLabNumber,
|
||||
T_OrderHeaderM_PatientID,
|
||||
OHPatientMapIHSNumber,
|
||||
T_OrderHeaderDiagnose,
|
||||
T_OrderHeaderPjM_DoctorID,
|
||||
T_OrderHeaderSenderM_DoctorID,
|
||||
OHDoctorMapIHSNumber,
|
||||
M_PatientName,
|
||||
M_DoctorName
|
||||
FROM t_orderheader
|
||||
JOIN m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
AND T_OrderHeaderID = ?
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
AND M_PatientIsActive = 'Y'
|
||||
JOIN m_doctor
|
||||
ON T_OrderHeaderPjM_DoctorID = M_DoctorID
|
||||
AND M_DoctorIsActive ='Y'
|
||||
LEFT JOIN one_health.oh_doctor_map
|
||||
ON T_OrderHeaderPjM_DoctorID = OHDoctorMapM_DoctorID
|
||||
AND OHDoctorMapIsActive = 'Y'
|
||||
LEFT JOIN one_health.oh_patient_map
|
||||
ON T_OrderHeaderM_PatientID = OHPatientMapM_PatientID
|
||||
AND OHPatientMapIsActive = '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;
|
||||
}
|
||||
$dataBisone = $qry->result_array()[0];
|
||||
|
||||
$subject = array(
|
||||
"reference" => "Patient/{$dataBisone['OHPatientMapIHSNumber']}",
|
||||
"display" => $dataBisone['M_PatientName']
|
||||
);
|
||||
$participant = [
|
||||
[
|
||||
"type" => [
|
||||
[
|
||||
"coding" => [
|
||||
[
|
||||
"system" => "http://terminology.hl7.org/CodeSystem/v3-ParticipationType",
|
||||
"code" => "ATND",
|
||||
"display" => "attender"
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
"individual" => [
|
||||
"reference" => "Practitioner/{$dataBisone['OHDoctorMapIHSNumber']}",
|
||||
"display" => $dataBisone['M_DoctorName']
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
//get period end
|
||||
$sql = "SELECT
|
||||
Result_ProcessToOfficeSendTime AS Result_ProcessToOfficeSendTime
|
||||
FROM result_processtooffice
|
||||
WHERE Result_ProcessToOfficeT_OrderHeaderID = ?
|
||||
AND Result_ProcessToOfficeIsActive = '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;
|
||||
}
|
||||
|
||||
$periodEnd = $qry->result_array()[0]['Result_ProcessToOfficeSendTime'];
|
||||
|
||||
$period = [
|
||||
"start" => date('c', strtotime($dataBisone['T_OrderHeaderCreated'])),
|
||||
"end" =>date('c', strtotime($periodEnd))
|
||||
];
|
||||
|
||||
//get location
|
||||
$sql = "SELECT LocationID,
|
||||
LocationName
|
||||
FROM one_health.location
|
||||
WHERE
|
||||
LocationType = 'ENCOUNTER_LAB'
|
||||
AND LocationIsActive = '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;
|
||||
}
|
||||
$locationData = $qry->result_array()[0];
|
||||
$location = [
|
||||
[
|
||||
"location" => [
|
||||
"reference" => "Location/{$locationData['LocationID']}",
|
||||
"display" => $locationData['LocationName']
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
//diagnosis
|
||||
|
||||
$diagnosis = [
|
||||
[
|
||||
"condition" => [
|
||||
"reference" => "urn:uuid:{$this->satusehat->gen_uuid()}",
|
||||
"display" => $dataBisone['T_OrderHeaderDiagnose']
|
||||
],
|
||||
"use" => [
|
||||
"coding" => []
|
||||
],
|
||||
"rank" => 1
|
||||
]
|
||||
];
|
||||
//contoh isi diagnosisi->use->coidng
|
||||
// [
|
||||
// "system" => "http://terminology.hl7.org/CodeSystem/diagnosis-role",
|
||||
// "code" => "DD",
|
||||
// "display" => "Discharge diagnosis"
|
||||
// ]
|
||||
|
||||
|
||||
//status history
|
||||
//arrived
|
||||
$sql = "SELECT
|
||||
T_OrderHeaderAddonFoTimeStart AS `T_OrderHeaderAddonFoTimeStart`,
|
||||
T_OrderHeaderAddonFoTimeEnd AS `T_OrderHeaderAddonFoTimeEnd`
|
||||
FROM
|
||||
`t_orderheaderaddon`
|
||||
WHERE
|
||||
`T_OrderHeaderAddOnT_OrderHeaderID` = ?
|
||||
AND `T_OrderHeaderAddOnIsActive` = '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;
|
||||
}
|
||||
$arrivedData = $qry->result_array()[0];
|
||||
$arrived = [
|
||||
"status" => "arrived",
|
||||
"period" => [
|
||||
"start" => date('c', strtotime($arrivedData['T_OrderHeaderAddonFoTimeStart'])),
|
||||
"end" => date('c', strtotime($arrivedData['T_OrderHeaderAddonFoTimeEnd']))
|
||||
]
|
||||
];
|
||||
|
||||
// inprogress
|
||||
$sql = "SELECT
|
||||
T_OrderSampleProcessingDate,
|
||||
T_OrderSampleProcessingTime
|
||||
FROM `t_ordersample`
|
||||
WHERE `T_OrderSampleT_OrderHeaderID` = ?
|
||||
AND `T_OrderSampleIsActive` = '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;
|
||||
}
|
||||
$inProgressDataStart = $qry->result_array()[0];
|
||||
|
||||
$sql = "SELECT
|
||||
T_OrderDetailVerDate
|
||||
FROM `t_orderdetail`
|
||||
WHERE `T_OrderDetailT_OrderHeaderID` = ?
|
||||
AND T_OrderDetailT_TestIsResult = 'Y'
|
||||
AND `T_OrderDetailIsActive` = 'Y'
|
||||
ORDER BY T_OrderDetailVerDate ASC
|
||||
LIMIT 1";
|
||||
$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;
|
||||
}
|
||||
$inProgressDataEnd = $qry->row()->T_OrderDetailVerDate;
|
||||
$inProgress = [
|
||||
"status" => "in-progress",
|
||||
"period" => [
|
||||
"start" => date('c', strtotime($inProgressDataStart['T_OrderSampleProcessingDate']." ".$inProgressDataStart['T_OrderSampleProcessingTime'])) ,
|
||||
"end" => date('c', strtotime($inProgressDataEnd))
|
||||
]
|
||||
];
|
||||
|
||||
//finished
|
||||
$sql = "SELECT
|
||||
Result_ProcessToOfficeSendTime AS `Result_ProcessToOfficeSendTime`
|
||||
FROM `result_processtooffice`
|
||||
WHERE `Result_ProcessToOfficeT_OrderHeaderID` = ?
|
||||
AND `Result_ProcessToOfficeIsActive` = '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;
|
||||
}
|
||||
$finishedData = $qry->result_array();
|
||||
$finished = [
|
||||
"status" => "finished",
|
||||
"period" => [
|
||||
"start" => date('c', strtotime($finishedData[0]['Result_ProcessToOfficeSendTime'])),
|
||||
"end" => date('c', strtotime($finishedData[count($finishedData) - 1]['Result_ProcessToOfficeSendTime']))
|
||||
]
|
||||
];
|
||||
|
||||
$identifier = [[
|
||||
"system" => "http://sys-ids.kemkes.go.id/encounter/$organizationID",
|
||||
"value" => $dataBisone['T_OrderHeaderLabNumber']
|
||||
]];
|
||||
|
||||
|
||||
|
||||
$statusHistory = [$arrived, $inProgress, $finished];
|
||||
|
||||
$encounter['resource']['subject'] = $subject;
|
||||
$encounter['resource']['participant'] = $participant;
|
||||
$encounter['resource']['period'] = $period;
|
||||
$encounter['resource']['location'] = $location;
|
||||
//$encounter['resource']['diagnosis'] = $diagnosis;
|
||||
$encounter['resource']['statusHistory'] = $statusHistory;
|
||||
$encounter['resource']['serviceProvider'] = $organization;
|
||||
$encounter['resource']['identifier'] = $identifier;
|
||||
$encounter['request'] = [
|
||||
"method" => "POST",
|
||||
"url" => "Encounter"
|
||||
];
|
||||
|
||||
//insert json
|
||||
$sql = "INSERT INTO one_health.encounter
|
||||
(EncounterUUID,
|
||||
EncounterJSON,
|
||||
EncounterT_orderHeaderID,
|
||||
EncounterCreated)
|
||||
VALUES
|
||||
(?,?,?,NOW())";
|
||||
$qry = $this->db->query($sql, [$encounter_uuid, json_encode($encounter), $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;
|
||||
}
|
||||
|
||||
|
||||
// $this->sys_ok($dataBisone);
|
||||
// $this->sys_ok($encounter);
|
||||
echo json_encode($encounter);
|
||||
} else {
|
||||
//sudah ada data di one_helath makan langsung di returnkan jsonya ;
|
||||
echo $result_cek[0]['EncounterJSON'];
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function updatediagnose()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$orderheaderID = $prm['orderheaderID'];
|
||||
$system = $prm['system'];
|
||||
$code = $prm['code'];
|
||||
$display = $prm['display'];
|
||||
|
||||
$sql = "SELECT * FROM one_health.encounter
|
||||
WHERE EncounterT_orderHeaderID = ?
|
||||
AND EncounterIsActive = '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 = $qry->result_array()[0];
|
||||
$json = $result['EncounterJSON'];
|
||||
$data = (array)json_decode($json, true);
|
||||
$data['resource']['diagnosis'][0]['use']['coding'][] = [
|
||||
"system" => "http://terminology.hl7.org/CodeSystem/diagnosis-role",
|
||||
"code" => "DD",
|
||||
"display" => "Discharge diagnosis"
|
||||
];
|
||||
echo (json_encode($data));
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
193
application/controllers/satu_sehat/Listpatient.php
Normal file
193
application/controllers/satu_sehat/Listpatient.php
Normal file
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
class Listpatient extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
var $load;
|
||||
var $satusehat;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->satusehat = $this->load->library('Satusehat');
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "SATU SEHAT LIST PATIENT";
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$startdate = $prm["startdate"];
|
||||
$enddate = $prm["enddate"];
|
||||
$nomorlab = $prm["nomorlab"];
|
||||
$companyid = $prm["companyid"];
|
||||
$status = $prm["status"];
|
||||
if ($status == "NEW") {
|
||||
$filter_status = " AND (IFNULL(OHConsoleStatus, 'NEW') = '{$status}') ";
|
||||
} else {
|
||||
$filter_status = " AND (OHConsoleStatus = '{$status}') ";
|
||||
}
|
||||
|
||||
$filter_date = " AND DATE(T_OrderHeaderDate) BETWEEN '{$startdate}' AND '{$enddate}'";
|
||||
|
||||
$where = " T_OrderHeaderIsActive = 'Y' $filter_date ";
|
||||
|
||||
if ($nomorlab != "") {
|
||||
$where .= " AND ( T_OrderHeaderLabNumber LIKE '%{$nomorlab}%' )";
|
||||
}
|
||||
|
||||
if ($companyid != 0 || $companyid != "0") {
|
||||
$filter_company = " AND T_OrderHeaderM_CompanyID = {$companyid}";
|
||||
}
|
||||
|
||||
$number_offset = 0;
|
||||
$number_limit = 20;
|
||||
|
||||
if ($prm["current_page"] > 0) {
|
||||
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_total = "SELECT count(*) as total FROM (
|
||||
SELECT T_OrderHeaderID
|
||||
FROM t_orderheader
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
AND M_TitleIsActive = 'Y'
|
||||
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
JOIN result_processtooffice ON T_OrderHeaderID = Result_ProcessToOfficeT_OrderHeaderID
|
||||
AND Result_ProcessToOfficeIsActive = 'Y'
|
||||
LEFT JOIN one_health.oh_console ON T_OrderHeaderID = OHConsoleT_OrderHeaderID
|
||||
WHERE $where $filter_company $filter_status
|
||||
GROUP BY T_OrderHeaderID) x";
|
||||
$qry_total = $this->db->query($sql_total);
|
||||
// print_r($this->db->last_query());
|
||||
// exit;
|
||||
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($qry_total) {
|
||||
$tot_count = $qry_total->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("orderheader count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
// print_r($tot_count);
|
||||
// exit;
|
||||
|
||||
$sql = "SELECT * FROM(
|
||||
SELECT T_OrderHeaderID,
|
||||
T_OrderHeaderDate,
|
||||
T_OrderHeaderLabNumber,
|
||||
T_OrderHeaderLabNumberExt,
|
||||
M_PatientNoReg,
|
||||
M_PatientName,
|
||||
concat(M_TitleName,'. ',M_PatientName) as patient_fullname,
|
||||
M_CompanyID,
|
||||
M_CompanyName,
|
||||
OHConsoleID,
|
||||
IFNULL(OHConsoleStatus, NULL) as OHConsoleStatus,
|
||||
Result_ProcessToOfficeSendTime,
|
||||
Result_ProcessToOfficeStatus
|
||||
FROM t_orderheader
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
AND M_TitleIsActive = 'Y'
|
||||
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
JOIN result_processtooffice ON T_OrderHeaderID = Result_ProcessToOfficeT_OrderHeaderID
|
||||
AND Result_ProcessToOfficeIsActive = 'Y'
|
||||
LEFT JOIN one_health.oh_console ON T_OrderHeaderID = OHConsoleT_OrderHeaderID
|
||||
WHERE $where $filter_company $filter_status
|
||||
GROUP BY T_OrderHeaderID) x
|
||||
limit $number_limit offset $number_offset";
|
||||
$qry = $this->db->query($sql);
|
||||
// print_r($this->db->last_query());
|
||||
// exit;
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->db_regional->trans_rollback();
|
||||
$this->sys_error_db("Select order error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total_page" => $tot_page,
|
||||
"total_filter" => $tot_count,
|
||||
"records" => $rows,
|
||||
// "sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getcompany()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql_search = "SELECT M_CompanyID,
|
||||
M_CompanyName
|
||||
FROM m_company
|
||||
WHERE M_CompanyIsActive = 'Y'
|
||||
AND (M_CompanyName LIKE ?)
|
||||
limit ?";
|
||||
$query_search = $this->db->query($sql_search, [$search, $number_limit]);
|
||||
if ($query_search) {
|
||||
$rows = $query_search->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("m_company select error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_filter = "SELECT COUNT(*) as total
|
||||
FROM m_company
|
||||
WHERE M_CompanyIsActive = 'Y'
|
||||
AND (M_CompanyName LIKE ?)
|
||||
limit ?";
|
||||
|
||||
$tot_count = 0;
|
||||
$qry_filter = $this->db->query($sql_filter, [$search, $number_limit]);
|
||||
if ($qry_filter) {
|
||||
$tot_count = $qry_filter->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("company count");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $tot_count,
|
||||
"total_display" => sizeof($rows),
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
506
application/controllers/satu_sehat/Location.php
Normal file
506
application/controllers/satu_sehat/Location.php
Normal file
@@ -0,0 +1,506 @@
|
||||
<?php
|
||||
|
||||
class Location extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
var $load;
|
||||
var $satusehat;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->library('Satusehat');
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo "Satu Sehat Location";
|
||||
}
|
||||
|
||||
function getorganization()
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT organizationID,
|
||||
organizationName
|
||||
FROM one_health.organization
|
||||
JOIN m_branch ON organizationM_BranchID = M_BranchID AND M_BranchIsDefault = 'Y' AND M_BranchIsActive = 'Y'
|
||||
WHERE organizationIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
$last_query = $this->db->last_query();
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select organization error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"qry" => $last_query
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getsystem()
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT * FROM one_terminology.terminology WHERE `attribute_path` = 'Location.telecom.system'";
|
||||
$qry = $this->db->query($sql);
|
||||
$last_query = $this->db->last_query();
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select system error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"qry" => $last_query
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getuse()
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT * FROM one_terminology.terminology WHERE `attribute_path` = 'Location.telecom.use'";
|
||||
$qry = $this->db->query($sql);
|
||||
$last_query = $this->db->last_query();
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select use error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"qry" => $last_query
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getphysicallocation()
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT * FROM one_terminology.terminology WHERE `attribute_path` = 'location.type'";
|
||||
$qry = $this->db->query($sql);
|
||||
$last_query = $this->db->last_query();
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("select lokasi fisik error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"qry" => $last_query
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getlocation()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$code = $prm["code"];
|
||||
$name = $prm["name"];
|
||||
$description = $prm["description"];
|
||||
$longitude = $prm["longitude"];
|
||||
$latitude = $prm["latitude"];
|
||||
$altitude = $prm["altitude"];
|
||||
$value = $prm["value"];
|
||||
$line = $prm["line"];
|
||||
$searchaddress = $prm["searchaddress"];
|
||||
|
||||
$sql = "SELECT organizationID
|
||||
FROM one_health.organization
|
||||
JOIN m_branch ON organizationM_BranchID = M_BranchID AND M_BranchIsDefault = 'Y' AND M_BranchIsActive = 'Y'
|
||||
WHERE organizationIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db);
|
||||
exit;
|
||||
}
|
||||
$organizationID = $qry->result_array()[0]["organizationID"];
|
||||
|
||||
$sql = "SELECT * FROM one_terminology.terminology WHERE `attribute_path` = 'Location.telecom.system'";
|
||||
$qry = $this->db->query($sql);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db);
|
||||
exit;
|
||||
}
|
||||
$row_system = $qry->row_array();
|
||||
|
||||
$sql = "SELECT * FROM one_terminology.terminology WHERE `attribute_path` = 'Location.telecom.use'";
|
||||
$qry = $this->db->query($sql);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db);
|
||||
exit;
|
||||
}
|
||||
$row_use = $qry->row_array();
|
||||
|
||||
$sql = "SELECT * FROM one_terminology.terminology WHERE `attribute_path` = 'location.type'";
|
||||
$qry = $this->db->query($sql);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db);
|
||||
exit;
|
||||
}
|
||||
$row_physical = $qry->row_array();
|
||||
|
||||
$province = 0;
|
||||
$city = 0;
|
||||
$district = 0;
|
||||
$village = 0;
|
||||
|
||||
$sqlkel = "SELECT pro_cd,kab_cd,kec_cd,kel_cd
|
||||
FROM
|
||||
one_health.regional
|
||||
WHERE
|
||||
full_name like '%$searchaddress%'";
|
||||
$qrykel = $this->db->query($sqlkel);
|
||||
$kel_cek = $qrykel->result_array();
|
||||
|
||||
$province = $kel_cek[0]['pro_cd'];
|
||||
$city = $kel_cek[0]['kab_cd'];
|
||||
$district = $kel_cek[0]['kec_cd'];
|
||||
$village = $kel_cek[0]['kel_cd'];
|
||||
|
||||
$data_json = [];
|
||||
$data_json = [
|
||||
"fullUrl" => "urn:uuid:{$this->satusehat->gen_uuid()}",
|
||||
"resource" => array(
|
||||
"resourceType" => "Location",
|
||||
"address" => array(
|
||||
array(
|
||||
"city" => "",
|
||||
"extension" => array(
|
||||
"url" => "https://fhir.kemkes.go.id/r4/StructureDefinition/administrativeCode",
|
||||
"extension" => array(
|
||||
array(
|
||||
"url" => "province",
|
||||
"valueCode" => $province
|
||||
),
|
||||
array(
|
||||
"url" => "city",
|
||||
"valueCode" => $city
|
||||
),
|
||||
array(
|
||||
"url" => "district",
|
||||
"valueCode" => $district
|
||||
),
|
||||
array(
|
||||
"url" => "village",
|
||||
"valueCode" => $village
|
||||
),
|
||||
array(
|
||||
"url" => "rt",
|
||||
"valueCode" => "0"
|
||||
),
|
||||
array(
|
||||
"url" => "rw",
|
||||
"valueCode" => "0"
|
||||
)
|
||||
),
|
||||
),
|
||||
"line" => array(
|
||||
$line
|
||||
),
|
||||
"postalCode" => "",
|
||||
"use" => $row_use["code"]
|
||||
)
|
||||
),
|
||||
"description" => "",
|
||||
"code" => "",
|
||||
"identifier" => array(
|
||||
array(
|
||||
"system" => "http://sys-ids.kemkes.go.id/location/1000001",
|
||||
"value" => ""
|
||||
)
|
||||
),
|
||||
"managingOrganization" => array(
|
||||
"reference" => $organizationID
|
||||
),
|
||||
"name" => "",
|
||||
"physicalType" => array(
|
||||
"coding" => array(
|
||||
array(
|
||||
"code" => $row_physical["code"],
|
||||
"display" => $row_physical["display"]
|
||||
)
|
||||
)
|
||||
),
|
||||
"position" => array(
|
||||
"altitude" => $altitude,
|
||||
"latitude" => $latitude,
|
||||
"longitude" => $longitude
|
||||
),
|
||||
"status" => "active",
|
||||
"telecom" => array(
|
||||
array(
|
||||
"system" => $row_system["code"],
|
||||
"use" => $row_use["code"],
|
||||
"value" => $value
|
||||
)
|
||||
)
|
||||
)
|
||||
];
|
||||
|
||||
$sql = "INSERT INTO one_health.location(
|
||||
LocationID,
|
||||
LocationOrganizationID,
|
||||
LocationCode,
|
||||
LocationName,
|
||||
LocationDescription,
|
||||
LocationPhysicalTypeCode,
|
||||
LocationPhysicalTypeDisplay,
|
||||
LocationLongitude,
|
||||
LocationLatitude,
|
||||
LocationAltitude,
|
||||
LocationCreated) VALUES(?,?,?,?,?,?,?,?,?,?,NOW())";
|
||||
$qry = $this->db->query($sql, [
|
||||
$this->satusehat->gen_uuid(),
|
||||
$organizationID,
|
||||
$code,
|
||||
$name,
|
||||
$description,
|
||||
$$row_physical["code"],
|
||||
$row_physical["display"],
|
||||
$longitude,
|
||||
$latitude,
|
||||
$altitude
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
echo $this->db->last_query();
|
||||
$this->sys_error_db("save location error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$insertid = $this->db->insert_id();
|
||||
|
||||
$sql = "INSERT INTO one_health.location_telecom(
|
||||
LocationTelecomLocationID,
|
||||
LocationSystem,
|
||||
LocationUse,
|
||||
LocationValue,
|
||||
LocationCreated) VALUES(?,?,?,?,NOW())";
|
||||
$qry = $this->db->query($sql, [
|
||||
$insertid,
|
||||
$row_system["code"],
|
||||
$row_use["code"],
|
||||
$value
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
echo $this->db->last_query();
|
||||
$this->sys_error_db("save location telecom error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO one_health.location_address(
|
||||
LocationAddressLocationID,
|
||||
LocationAddressUse,
|
||||
LocationAddresLine,
|
||||
LocationAddresProvince,
|
||||
LocationAddresCity,
|
||||
LocationAddresDistrict,
|
||||
LocationAddresVillage,
|
||||
LocationAddresRT,
|
||||
LocationAddresRW,
|
||||
LocationAddresCreated) VALUES(?,?,?,?,?,?,?,?,?,NOW())";
|
||||
$qry = $this->db->query($sql, [
|
||||
$insertid,
|
||||
$row_use["code"],
|
||||
$line,
|
||||
$province,
|
||||
$city,
|
||||
$district,
|
||||
$village,
|
||||
0,
|
||||
0
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
echo $this->db->last_query();
|
||||
$this->sys_error_db("save location address error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$json_encodelocation = json_encode($data_json);
|
||||
echo $json_encodelocation;
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function addlocation()
|
||||
{
|
||||
try {
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$code = $prm["code"];
|
||||
$name = $prm["name"];
|
||||
$description = $prm["description"];
|
||||
$physicaltypecode = $prm["physicaltypecode"];
|
||||
$physicaltypedisplay = $prm["physicaltypedisplay"];
|
||||
$longitude = $prm["longitude"];
|
||||
$latitude = $prm["latitude"];
|
||||
$altitude = $prm["altitude"];
|
||||
|
||||
$sql = "SELECT organizationID
|
||||
FROM one_health.organization
|
||||
JOIN m_branch ON organizationM_BranchID = M_BranchID AND M_BranchIsDefault = 'Y' AND M_BranchIsActive = 'Y'
|
||||
WHERE organizationIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$organizationID = $qry->result_array()[0]["organizationID"];
|
||||
|
||||
$sql = "INSERT INTO one_health.location(
|
||||
LocationID,
|
||||
LocationOrganizationID,
|
||||
LocationCode,
|
||||
LocationName,
|
||||
LocationDescription,
|
||||
LocationPhysicalTypeCode,
|
||||
LocationPhysicalTypeDisplay,
|
||||
LocationLongitude,
|
||||
LocationLatitude,
|
||||
LocationAltitude,
|
||||
LocationCreated) VALUES(?,?,?,?,?,?,?,?,?,?,NOW())";
|
||||
$qry = $this->db->query($sql, [
|
||||
$this->satusehat->gen_uuid(),
|
||||
$organizationID,
|
||||
$code,
|
||||
$name,
|
||||
$description,
|
||||
$physicaltypecode,
|
||||
$physicaltypedisplay,
|
||||
$longitude,
|
||||
$latitude,
|
||||
$altitude
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
echo $this->db->last_query();
|
||||
$this->sys_error_db("save location error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$insertid = $this->db->insert_id();
|
||||
|
||||
$sql = "INSERT INTO one_health.location_telecom(
|
||||
LocationTelecomLocationID,
|
||||
LocationSystem,
|
||||
LocationUse,
|
||||
LocationValue,
|
||||
LocationCreated) VALUES(?,?,?,?,NOW())";
|
||||
$qry = $this->db->query($sql, [
|
||||
$insertid,
|
||||
$prm["system"],
|
||||
$prm["telecomuse"],
|
||||
$prm["value"]
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
echo $this->db->last_query();
|
||||
$this->sys_error_db("save location telecom error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO one_health.location_address(
|
||||
LocationAddressLocationID,
|
||||
LocationAddressUse,
|
||||
LocationAddresLine,
|
||||
LocationAddresProvince,
|
||||
LocationAddresCity,
|
||||
LocationAddresDistrict,
|
||||
LocationAddresVillage,
|
||||
LocationAddresRT,
|
||||
LocationAddresRW,
|
||||
LocationAddresCreated) VALUES(?,?,?,?,?,?,?,?,?,NOW())";
|
||||
$qry = $this->db->query($sql, [
|
||||
$insertid,
|
||||
$prm["addressuse"],
|
||||
$prm["line"],
|
||||
$prm["province"],
|
||||
$prm["city"],
|
||||
$prm["district"],
|
||||
$prm["village"],
|
||||
$prm["rt"],
|
||||
$prm["rw"]
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
echo $this->db->last_query();
|
||||
$this->sys_error_db("save location address error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"affected_rows" => $this->db->affected_rows()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
88
application/controllers/satu_sehat/Newpatient.php
Normal file
88
application/controllers/satu_sehat/Newpatient.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
class Newpatient extends MY_Controller{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->library('Satusehat');
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "Satu Sehat New Patient";
|
||||
}
|
||||
|
||||
function getnewpatient() {
|
||||
|
||||
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'];
|
||||
|
||||
$sql_data_nik = "SELECT M_PatientIDNumber
|
||||
FROM m_patient
|
||||
WHERE M_PatientM_IdTypeID = '1'";
|
||||
|
||||
$qry = $this->db->last_query($sql_data_nik, []);
|
||||
$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_data_new_patient = "SELECT
|
||||
(SELECT M_PatientIDNumber WHERE M_PatientM_IdTypeID = 1) As NIK,
|
||||
(SELECT M_PatientIDNumber WHERE M_PatientM_IdTypeID = 3) As PASPORT,
|
||||
M_PatientName,
|
||||
M_PatientHP,
|
||||
M_PatientEmail,
|
||||
CASE
|
||||
WHEN M_PatientM_SexID= '1' THEN 'male'
|
||||
WHEN M_PatientM_SexID= '2' THEN 'female'
|
||||
END AS M_SexCode,
|
||||
M_PatientDOB,
|
||||
M_PatientAddressDescription,
|
||||
OHPatientMapMaritalStatusCode,
|
||||
OHPatientMapCitizeship
|
||||
from t_orderheader
|
||||
JOIN m_patient
|
||||
ON M_PatientID = T_OrderHeaderM_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
JOIN m_patientaddress
|
||||
ON M_PatientAddressM_PatientID= M_PatientID
|
||||
AND M_PatientAddressIsActive= 'Y'
|
||||
LEFT JOIN one_health.oh_patient_map
|
||||
ON OHPatientMapM_PatientID = M_PatientID
|
||||
AND OHPatientMapIsActive
|
||||
Group by NIK, PASPORT
|
||||
Limit 40;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
335
application/controllers/satu_sehat/Newpatientv2.php
Normal file
335
application/controllers/satu_sehat/Newpatientv2.php
Normal file
@@ -0,0 +1,335 @@
|
||||
<?php
|
||||
class Newpatientv2 extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
var $load;
|
||||
var $satusehat;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->library('Satusehat');
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo "Satu Sehat New Patient";
|
||||
}
|
||||
function getnewpatient()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$patientID = $prm['patientID'];
|
||||
$maritalStatusCode = $prm['maritalStatusCode'];
|
||||
$maritalStatusName = $prm['maritalStatusName'];
|
||||
$multipleBirth = $prm['multipleBirth'];
|
||||
$citizeship = $prm['citizeship'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
//cek db one_health patient sudah ada atau belum
|
||||
$sql = "SELECT * FROM one_health.oh_patient_map
|
||||
WHERE OHPatientMapM_PatientID = ?
|
||||
AND OHPatientMapIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$patientID]);
|
||||
$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();
|
||||
|
||||
|
||||
if (count($result_cek) == 0) {
|
||||
$patientJSON = [];
|
||||
$sql = "SELECT M_PatientID,
|
||||
M_PatientNoReg,
|
||||
M_PatientMR,
|
||||
M_PatientPrefix,
|
||||
M_PatientName,
|
||||
M_PatientM_TitleID,
|
||||
M_PatientSuffix,
|
||||
M_PatientM_SexID,
|
||||
CASE
|
||||
WHEN M_PatientM_SexID = '1' THEN 'male'
|
||||
WHEN M_PatientM_SexID = '2' THEN 'female'
|
||||
END AS gender,
|
||||
M_PatientInitialVisit,
|
||||
M_PatientLastVisit,
|
||||
M_PatientM_ReligionID,
|
||||
M_PatientPOB,
|
||||
M_PatientDOB,
|
||||
M_PatientHP,
|
||||
M_PatientPhone,
|
||||
M_PatientEmail,
|
||||
M_PatientM_IdTypeID,
|
||||
M_PatientIDNumber,
|
||||
M_PatientAddressID,
|
||||
M_PatientAddressDescription,
|
||||
M_KelurahanID,
|
||||
M_KelurahanName,
|
||||
M_DistrictID,
|
||||
M_DistrictName,
|
||||
M_CityID,
|
||||
M_CityName,
|
||||
M_ProvinceID,
|
||||
M_ProvinceName
|
||||
FROM m_patient
|
||||
JOIN m_patientaddress ON M_PatientAddressM_PatientID = M_PatientID AND M_PatientAddressIsActive = 'Y'
|
||||
JOIN m_kelurahan ON M_KelurahanID = M_PatientAddressM_KelurahanID
|
||||
JOIN m_district ON M_DistrictID = M_KelurahanM_DistrictID
|
||||
JOIN m_city ON M_CityID = M_DistrictM_CityID
|
||||
JOIN m_province ON M_ProvinceID = M_CityM_ProvinceID
|
||||
WHERE M_PatientID = ?
|
||||
ORDER BY M_PatientAddressID ASC
|
||||
LIMIT 1";
|
||||
$qry = $this->db->query($sql, [$patientID]);
|
||||
$last_qry = $this->db->last_query();
|
||||
|
||||
if (!$qry) {
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$dataBisone = $qry->result_array()[0];
|
||||
|
||||
$province_ori = $dataBisone['M_ProvinceName'];
|
||||
$city_ori = $dataBisone['M_CityName'];
|
||||
$district_ori = $dataBisone['M_DistrictName'];
|
||||
$village_ori = $dataBisone['M_KelurahanName'];
|
||||
|
||||
$province = 0;
|
||||
$city = 0;
|
||||
$district = 0;
|
||||
$village = 0;
|
||||
|
||||
$sqlkel = "SELECT pro_cd,kab_cd,kec_cd,kel_cd
|
||||
FROM
|
||||
one_health.regional
|
||||
WHERE
|
||||
regional_nm = '{$village_ori}' AND
|
||||
kel_cd <> '000'";
|
||||
$qrykel = $this->db->query($sqlkel);
|
||||
$last_qrykel = $this->db->last_query();
|
||||
$kel_cek = $qrykel->result_array();
|
||||
if(count($kel_cek) == 1){
|
||||
|
||||
$province = $kel_cek[0]['pro_cd'];
|
||||
$city = $kel_cek[0]['kab_cd'];
|
||||
$district = $kel_cek[0]['kec_cd'];
|
||||
$village = $kel_cek[0]['kel_cd'];
|
||||
|
||||
}elseif(count($kel_cek) > 1){
|
||||
|
||||
$sqlprov = "SELECT pro_cd FROM one_health.regional WHERE regional_nm = '{$province_ori}' AND
|
||||
kel_cd = '000' AND kec_cd = '000' AND kab_cd = '00'";
|
||||
$qryprov = $this->db->query($sqlprov);
|
||||
$last_qryprov = $this->db->last_query();
|
||||
$prov_cek = $qryprov->result_array();
|
||||
|
||||
$sqlkab = "SELECT GROUP_CONCAT(kab_cd SEPARATOR ',') as xkab FROM one_health.regional
|
||||
WHERE regional_nm
|
||||
LIKE '%$city_ori%' AND `pro_cd` = $prov_cek[0]['pro_cd']
|
||||
AND `kab_cd` != '00' AND `kec_cd` = '000' AND `kec_cd` = '000'";
|
||||
$qrykab = $this->db->query($sqlkab);
|
||||
$last_qrykab = $this->db->last_query();
|
||||
$kab_cek = $qrykab->result_array();
|
||||
|
||||
$sqldistrict = "SELECT kec_cd FROM one_health.regional
|
||||
WHERE regional_nm = '{$district_ori}' AND
|
||||
kec_cd <> '000' AND kel_cd = '000'
|
||||
AND pro_cd = $prov_cek[0]['pro_cd'] AND kab_cd IN($kab_cek[0]['xkab'])";
|
||||
$qrydistrict = $this->db->query($sqldistrict);
|
||||
$last_qrydistrict = $this->db->last_query();
|
||||
$district_cek = $qrydistrict->result_array();
|
||||
|
||||
$sqlvillage = "SELECT pro_cd,kab_cd,kec_cd,kel_cd
|
||||
FROM one_health.regional WHERE regional_nm = '{$village_ori}' AND
|
||||
kel_cd <> '000' AND kec_cd = $district_cek[0]['kec_cd']";
|
||||
$qryvillage = $this->db->query($sqlvillage);
|
||||
$last_qryvillage = $this->db->last_query();
|
||||
$village_cek = $qryvillage->result_array();
|
||||
|
||||
$province = $village_cek[0]['pro_cd'];
|
||||
$city = $village_cek[0]['kab_cd'];
|
||||
$district = $village_cek[0]['kec_cd'];
|
||||
$village = $village_cek[0]['kel_cd'];
|
||||
|
||||
}
|
||||
|
||||
$identifier_system = '';
|
||||
if($dataBisone['M_PatientM_IdTypeID'] == 1){
|
||||
$identifier_system = "https://fhir.kemenkes.go.id/id/nik";
|
||||
}elseif($dataBisone['M_PatientM_IdTypeID'] == 3){
|
||||
$identifier_system = "https://fhir.kemenkes.go.id/id/paspor";
|
||||
}
|
||||
|
||||
$patientJSON[] = [
|
||||
"fullUrl" => "urn:uuid:{$this->satusehat->gen_uuid()}",
|
||||
"resource" => [
|
||||
"resourceType" => "Patient",
|
||||
"meta" => [
|
||||
"profile" => "https://fhir.kemenkes.go.id/r4/StructureDefinition/Patient"
|
||||
],
|
||||
"identifier"=> [
|
||||
[
|
||||
"use"=> "official",
|
||||
"system"=> $identifier_system,
|
||||
"value"=> $dataBisone['M_PatientIDNumber']
|
||||
],
|
||||
],
|
||||
"active" => true,
|
||||
"name" => [
|
||||
[
|
||||
"use" => "official",
|
||||
"text" => $dataBisone['M_PatientName']
|
||||
]
|
||||
],
|
||||
"telecom" => [[
|
||||
"system" => "phone",
|
||||
"value" => $dataBisone['M_PatientHP'],
|
||||
"use"=> "mobile"
|
||||
],
|
||||
[
|
||||
"system" => "email",
|
||||
"value" => $dataBisone['M_PatientEmail'],
|
||||
"use"=> "home"
|
||||
]
|
||||
],
|
||||
"gender" => $dataBisone['gender'],
|
||||
"birtDate" => $dataBisone['M_PatientDOB'],
|
||||
"deceasedBoolean" => false,
|
||||
"address" => [[
|
||||
"use" => "home",
|
||||
"line" => [$dataBisone['M_PatientAddressDescription']],
|
||||
"city" => $dataBisone['M_CityName'],
|
||||
"postalCode" => "",
|
||||
"country" => "ID",
|
||||
"extension" =>[
|
||||
"url" => "https://fhir.kemenkes.go.id/r4/StructureDefinition/administrativeCode",
|
||||
"extension" => [
|
||||
[
|
||||
"url" => "province",
|
||||
"valueCode" => $province
|
||||
],
|
||||
[
|
||||
"url" => "city",
|
||||
"valueCode" => $city
|
||||
],
|
||||
[
|
||||
"url" => "district",
|
||||
"valueCode" => $district
|
||||
],
|
||||
[
|
||||
"url" => "village",
|
||||
"valueCode" => $village
|
||||
],
|
||||
[
|
||||
"url" => "rt",
|
||||
"valueCode" => "0"
|
||||
],
|
||||
[
|
||||
"url" => "rw",
|
||||
"valueCode" => "0"
|
||||
]
|
||||
]
|
||||
]
|
||||
]],
|
||||
"maritalStatus" => [
|
||||
"coding" => [[
|
||||
"system" => "http://termonilogy.hl7.org/CodeSystem/v3-Marital-Status",
|
||||
"code" => $maritalStatusCode,
|
||||
"display" => $maritalStatusName
|
||||
]],
|
||||
"text" => $maritalStatusName
|
||||
],
|
||||
"multipleBirthInteger" => $multipleBirth,
|
||||
"contact" => [[
|
||||
"relationship" => [[
|
||||
"coding" => [[
|
||||
"system" => "",
|
||||
"Code" => ""
|
||||
]]
|
||||
]],
|
||||
"name" => [
|
||||
"use" => "",
|
||||
"text" => ""
|
||||
],
|
||||
"telecom" => [[
|
||||
"system" => "phone",
|
||||
"value" => "",
|
||||
"use" => "mobile"
|
||||
]]
|
||||
]],
|
||||
"communication" => [[
|
||||
"language" => [
|
||||
"coding" => [[
|
||||
"system" => "urn:ietf:bcp:47",
|
||||
"code" => "id-ID",
|
||||
"display" => "Indonesian"
|
||||
]],
|
||||
"text" => "Indonesian"
|
||||
],
|
||||
"preferred" => true
|
||||
]],
|
||||
"extension" => [
|
||||
["url" => "https://fhir.kemenkes.go.id/r4/StructureDefinition/birtPlace",
|
||||
"valueAddress" => [
|
||||
"city" => $dataBisone['M_CityName'],
|
||||
"country" => "ID"]],
|
||||
["url" => "https://fhir.kemenkes.go.id/r4/StructureDefinition/citizenshipStatus",
|
||||
"valueCode" => $citizeship]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$sql = "INSERT INTO one_health.oh_patient_map
|
||||
(OHPatientMapM_PatientID,
|
||||
OHPatientMapMaritalStatusCode,
|
||||
OHPatientMapMultipleBirth,
|
||||
OHPatientMapCitizeship,
|
||||
OHPatientMapCreated,
|
||||
OHPatientMapUserID)
|
||||
VALUES
|
||||
(
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
NOW(),
|
||||
?
|
||||
)";
|
||||
$qry = $this->db->query($sql, [
|
||||
$patientID,
|
||||
$maritalStatusCode,
|
||||
$multipleBirth,
|
||||
$citizeship,
|
||||
0
|
||||
]);
|
||||
$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($patientJSON);
|
||||
|
||||
} else {
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
377
application/controllers/satu_sehat/Observ.php
Normal file
377
application/controllers/satu_sehat/Observ.php
Normal file
@@ -0,0 +1,377 @@
|
||||
<?php
|
||||
class Observ extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "Observ API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
$this->load->library('Satusehat');
|
||||
}
|
||||
|
||||
|
||||
function getdata(){
|
||||
$prm = $this->sys_input;
|
||||
$orderHeaderID = $prm['orderheaderID'];
|
||||
$results = array();
|
||||
$sql = "SELECT IFNULL(OHPatientMapIHSNumber, 'Belum terdaftar') as patient_ihsnumber,
|
||||
EncounterUUID as encounter_uuid,
|
||||
IFNULL(OHDoctorMapIHSNumber,'Belum diinput') as doctor_ihsnumber,
|
||||
fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) age_in_day,
|
||||
M_PatientM_SexID as sex_id
|
||||
FROM t_orderheader
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
JOIN one_health.encounter ON EncounterT_orderHeaderID = T_orderHeaderID AND EncounterIsActive = 'Y'
|
||||
LEFT JOIN one_health.oh_doctor_map ON OHDoctorMapM_DoctorID = T_OrderHeaderPjM_DoctorID AND OHDoctorMapIsActive = 'Y'
|
||||
LEFT JOIN one_health.oh_patient_map ON OHPatientMapM_PatientID = T_OrderHeaderM_PatientID AND OHPatientMapIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderHeaderID = ?";
|
||||
$query = $this->db_onedev->query($sql,array($orderHeaderID));
|
||||
if(!$query){
|
||||
//echo $this->db_onedev->last_query();
|
||||
$this->sys_error("error get t_orderheader");
|
||||
exit;
|
||||
}
|
||||
|
||||
$r_order = $query->row_array();
|
||||
|
||||
$sql = "SELECT t_orderdetail.*, Group_ResultID, Group_ResultName,
|
||||
IFNULL(Nat_TestLoincCode,'') as code_loinc,
|
||||
IFNULL(Nat_TestLoincDisplay,'') as display_loinc,
|
||||
Nat_TestIsQuantitative as isQuantitatif,
|
||||
Nat_TestID,
|
||||
T_OrderDetailAddOnNormalFlag as code_interpretation,
|
||||
IF(T_OrderDetailAddOnNormalFlag = 'N','Normal',IF(T_OrderDetailAddOnNormalFlag = 'L','Low','High')) as display_interpretation
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestID in (1069,1070,1071)
|
||||
JOIN t_orderdetailaddon ON T_OrderDetailAddOnT_OrderDetailID = T_OrderDetailID
|
||||
JOIN nat_test ON T_TestNat_TestID = Nat_TestID AND Nat_TestIsActive = 'Y'
|
||||
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID AND Group_ResultDetailIsActive = 'Y'
|
||||
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N'
|
||||
LEFT JOIN nat_test_loinc ON Nat_TestLoincNat_TestID = T_TestNat_TestID
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = ? AND
|
||||
T_OrderDetailIsActive = 'Y' AND
|
||||
T_OrderDetailT_TestIsResult = 'Y'
|
||||
ORDER BY T_OrderDetailT_TestSasCode ASC";
|
||||
$query = $this->db_onedev->query($sql,array($orderHeaderID));
|
||||
if(!$query){
|
||||
// echo $this->db_onedev->last_query();
|
||||
$this->sys_error("error get t_orderdetail");
|
||||
exit;
|
||||
}
|
||||
|
||||
$r_details = $query->result_array();
|
||||
if($r_details){
|
||||
$sql = "SELECT *
|
||||
FROM one_health.organization
|
||||
JOIN m_branch ON organizationM_BranchID = M_BranchID AND M_BranchIsDefault = 'Y' AND M_BranchIsActive = 'Y'
|
||||
WHERE
|
||||
organizationIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql);
|
||||
if(!$query){
|
||||
//echo $this->db_onedev->last_query();
|
||||
$this->sys_error("error get m_branch");
|
||||
exit;
|
||||
}
|
||||
|
||||
$r_organization = $query->row_array();
|
||||
$organizationID = $r_organization['organizationID'];
|
||||
|
||||
$data_results = [];
|
||||
foreach ($r_details as $key => $value) {
|
||||
$observation_uuid = $this->satusehat->gen_uuid();
|
||||
$data_result = [];
|
||||
$result["fullUrl"] = "urn:uuid:".$observation_uuid;
|
||||
$data_result['resourceType'] = "Observation";
|
||||
$data_result['identifier'] = array(
|
||||
array(
|
||||
"system" => "http://sys-ids.kemkes.go.id/observation/".$organizationID,
|
||||
"value" => $value['T_OrderDetailID']
|
||||
)
|
||||
);
|
||||
$data_result['status'] = "final";
|
||||
$data_result['category'] = array(
|
||||
array(
|
||||
"coding" => array(
|
||||
array(
|
||||
"system" => "http://terminology.hl7.org/CodeSystem/observation-category",
|
||||
"code" => "laboratory",
|
||||
"display" => "Laboratory"
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$data_result['code'] = array(
|
||||
"coding" => array(
|
||||
array(
|
||||
"system" => "http://loinc.org",
|
||||
"code" => $value['code_loinc'],
|
||||
"display" => $value['display_loinc']
|
||||
)
|
||||
)
|
||||
);
|
||||
$data_result['subject'] = array(
|
||||
"reference" => "Patient/".$r_order['patient_ihsnumber']
|
||||
);
|
||||
$data_result['encounter'] = array(
|
||||
'reference' => "Encounter/".$r_order['encounter_uuid']
|
||||
);
|
||||
|
||||
$data_result['effectiveDateTime'] = date('c', strtotime($value['T_OrderDetailVerDate']));
|
||||
$data_result['issued'] = date('c', strtotime($value['T_OrderDetailValDate']));
|
||||
$data_result['performer'] = array(
|
||||
array(
|
||||
'reference' => "Practitioner/".$r_order['doctor_ihsnumber']
|
||||
),
|
||||
array(
|
||||
'reference' => "Organization/".$organizationID
|
||||
)
|
||||
);
|
||||
|
||||
$sql = "SELECT SpecimenUUID
|
||||
FROM t_ordersample
|
||||
JOIN t_test ON T_OrderSampleT_SampleTypeID = T_TestT_SampleTypeID AND
|
||||
T_TestID = ?
|
||||
JOIN one_health.specimen ON SpecimentT_OrderSampleID = T_OrderSampleID AND
|
||||
SpecimenIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderSampleT_OrderHeaderID = ? AND
|
||||
T_OrderSampleIsActive = 'Y'
|
||||
GROUP BY T_TestT_SampleTypeID
|
||||
LIMIT 1";
|
||||
$query = $this->db_onedev->query($sql,array($value['T_OrderDetailT_TestID'],$value['T_OrderDetailT_OrderHeaderID']));
|
||||
if(!$query){
|
||||
//echo $this->db_onedev->last_query();
|
||||
$this->sys_error("error get spescimen");
|
||||
exit;
|
||||
}
|
||||
|
||||
$r_specimen = $query->row_array();
|
||||
|
||||
$data_result['specimen'] = array(
|
||||
'reference' => "Specimen/".$r_specimen['SpecimenUUID']
|
||||
);
|
||||
|
||||
$serviceRequestUUID = "";
|
||||
if($value['T_OrderDetailT_TestIsPrice'] == "Y"){
|
||||
$sql = "SELECT ServiceRequestUUID
|
||||
FROM one_health.service_request
|
||||
WHERE
|
||||
ServiceRequestT_OrderDetailID = ? AND ServiceRequestIsActive = 'Y'
|
||||
LIMIT 1";
|
||||
$query_service_req = $this->db_onedev->query($sql,array($value['T_OrderDetailID']));
|
||||
if(!$query_service_req){
|
||||
//echo $this->db_onedev->last_query();
|
||||
$this->sys_error("error get service_request 1");
|
||||
exit;
|
||||
}
|
||||
|
||||
$serviceRequestUUID = $query_service_req->row()->ServiceRequestUUID;
|
||||
|
||||
}else{
|
||||
$sql = "SELECT ServiceRequestUUID
|
||||
FROM t_orderdetail
|
||||
JOIN one_health.service_request ON ServiceRequestT_OrderDetailID = T_OrderDetailID AND
|
||||
ServiceRequestIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = ? AND
|
||||
T_OrderDetailT_TestIsPrice = 'Y' AND
|
||||
T_OrderDetailT_TestSasCode LIKE CONCAT(SUBSTR(?, 0, 8),'%') AND
|
||||
T_OrderDetailIsActive = 'Y'";
|
||||
$query_service_req = $this->db_onedev->query($sql,array(
|
||||
$value['T_OrderDetailT_OrderHeaderID'],
|
||||
$value['T_OrderDetailID']
|
||||
));
|
||||
if(!$query_service_req){
|
||||
//echo $this->db_onedev->last_query();
|
||||
$this->sys_error("error get service_request 2");
|
||||
exit;
|
||||
}
|
||||
|
||||
$serviceRequestUUID = $query_service_req->row()->ServiceRequestUUID;
|
||||
}
|
||||
|
||||
$data_result['basedOn'] = array(
|
||||
array(
|
||||
"reference" => "ServiceRequest/".$serviceRequestUUID
|
||||
)
|
||||
);
|
||||
|
||||
$sql = "SELECT Nat_MethodeID, Nat_MethodeName,Nat_NormalValueMinValue,Nat_NormalValueMaxValue,
|
||||
Nat_NormalValueMinValueInclusive, Nat_NormalValueMaxValueInclusive
|
||||
FROM nat_normalvalue
|
||||
JOIN nat_methode ON Nat_NormalValueNat_MethodeID = Nat_MethodeID
|
||||
WHERE
|
||||
Nat_NormalValueID = ?
|
||||
";
|
||||
$query = $this->db_onedev->query($sql,array(
|
||||
$value['T_OrderDetailNat_NormalValueID']
|
||||
));
|
||||
if(!$query){
|
||||
$this->sys_error("error get Nat_MethodeName ");
|
||||
exit;
|
||||
}
|
||||
//echo $this->db_onedev->last_query();
|
||||
$r_normal_value = $query->row_array();
|
||||
//print_r($r_normal_value);
|
||||
//$data_result['methode_name'] = $r_normal_value['Nat_MethodeName'];
|
||||
|
||||
if($value['isQuantitatif'] == "N"){
|
||||
$data_result['valueString'] = $value['T_OrderDetailResult'];
|
||||
$data_result['valueCodeableConcept'] = array(
|
||||
'coding' => array(
|
||||
array(
|
||||
'system' => "http://snomed.info/sct",
|
||||
'code' => "",
|
||||
"display" => ""
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$data_result['referenceRange'] = array(
|
||||
array(
|
||||
'text' => $value['T_OrderDetailNormalValueNote']
|
||||
)
|
||||
);
|
||||
|
||||
}else{
|
||||
$data_result['valueQuantity'] = array(
|
||||
'value' => floatval($value['T_OrderDetailResult']),
|
||||
'unit' => "mmol/L",//$value['T_OrderDetailNat_UnitName'],
|
||||
'system' => "http://unitsofmeasure.org",
|
||||
'code' => "mmol/L",//$value['T_OrderDetailNat_UnitName']
|
||||
);
|
||||
$data_result['interpretation'] = array(
|
||||
array(
|
||||
'coding' => array(
|
||||
array(
|
||||
'system' => "http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation",
|
||||
'code' => $value['code_interpretation'],
|
||||
'display' => $value['display_interpretation']
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$data_normal_values = [];
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM nat_normalvaluetype
|
||||
WHERE
|
||||
Nat_NormalValueTypeIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql);
|
||||
|
||||
if(!$query){
|
||||
//echo $this->db_onedev->last_query();
|
||||
$this->sys_error("error get normalvalues types");
|
||||
exit;
|
||||
}
|
||||
|
||||
$normal_value_types = $query->result_array();
|
||||
|
||||
foreach ($normal_value_types as $k_nvt => $v_nvt) {
|
||||
$sql = "SELECT *
|
||||
FROM nat_normalvalue
|
||||
JOIN nat_flag ON Nat_NormalValueNat_FlagID = Nat_FlagID
|
||||
JOIN nat_test ON Nat_NormalValueNat_TestID = Nat_TestID
|
||||
JOIN nat_unit ON Nat_TestNat_UnitID = Nat_UnitID
|
||||
WHERE
|
||||
( Nat_NormalValueValidDate IS NULL OR Nat_NormalValueValidDate < NOW() ) AND
|
||||
Nat_NormalValueIsActive = 'Y' AND
|
||||
Nat_NormalValueNat_NormalValueTypeID = {$v_nvt['Nat_NormalValueTypeID']} AND
|
||||
Nat_NormalValueIsAbnormal = 'N' AND
|
||||
( Nat_NormalValueNat_MethodeID = {$r_normal_value["Nat_MethodeID"]} ) AND
|
||||
Nat_NormalValueNat_TestID = {$value["Nat_TestID"]} AND
|
||||
(
|
||||
( {$v_nvt['Nat_NormalValueTypeID']} in (1,3) AND Nat_NormalValueNat_SexID = {$r_order['sex_id']} ) OR
|
||||
{$v_nvt['Nat_NormalValueTypeID']} in (2,4)
|
||||
) AND
|
||||
(
|
||||
( Nat_NormalValueMinAgeInclusive = 'Y' AND fn_normal_get_age(Nat_NormalValueMinAge,Nat_NormalValueAgeUnit) <= {$r_order["age_in_day"]} ) OR
|
||||
( Nat_NormalValueMinAgeInclusive = 'N' AND fn_normal_get_age(Nat_NormalValueMinAge,Nat_NormalValueAgeUnit) < {$r_order["age_in_day"]} )
|
||||
)
|
||||
AND
|
||||
(
|
||||
( Nat_NormalValueMaxAgeInclusive = 'Y' AND fn_normal_get_age(Nat_NormalValueMaxAge,Nat_NormalValueAgeUnit) >= {$r_order["age_in_day"]} ) OR
|
||||
( Nat_NormalValueMaxAgeInclusive = 'N' AND fn_normal_get_age(Nat_NormalValueMaxAge,Nat_NormalValueAgeUnit) > {$r_order["age_in_day"]} )
|
||||
)
|
||||
";
|
||||
|
||||
$query = $this->db_onedev->query($sql);
|
||||
|
||||
if(!$query){
|
||||
echo $this->db_onedev->last_query();
|
||||
$this->sys_error("error get normalvalues type".$v_nvt['Nat_NormalValueTypeID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$normalvalues = $query->result_array();
|
||||
if($normalvalues){
|
||||
foreach ($normalvalues as $k_normalvalue => $v_normalvalue) {
|
||||
$data_normal_values[] = array(
|
||||
"text" => $v_normalvalue["Nat_FlagName"],
|
||||
"high" => array(
|
||||
"value" => floatval($v_normalvalue["Nat_NormalValueMaxValue"]),
|
||||
"unit" => "mmol/L",//$v_normalvalue["Nat_UnitName"],
|
||||
"system" => "http://unitsofmeasure.org",
|
||||
"code" => "mmol/L"//$v_normalvalue["Nat_UnitName"]
|
||||
),
|
||||
"low" => array(
|
||||
"value" => floatval($v_normalvalue["Nat_NormalValueMinValue"]),
|
||||
"unit" => "mmol/L",//$v_normalvalue["Nat_UnitName"],
|
||||
"system" => "http://unitsofmeasure.org",
|
||||
"code" => "mmol/L"//$v_normalvalue["Nat_UnitName"]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data_result['referenceRange'] = $data_normal_values;
|
||||
$result["resource"] = $data_result;
|
||||
$result["request"] = array("method" => "POST", "url" => "Observation");
|
||||
$data_results[] = $result;
|
||||
|
||||
$sql = "INSERT INTO one_health.observation (
|
||||
observationUUID,
|
||||
observationT_OrderHeaderID,
|
||||
observationT_TestID,
|
||||
observationType,
|
||||
observationJSON,
|
||||
observationCreated
|
||||
) VALUES(?,?,?,?,?,NOW())";
|
||||
|
||||
$query = $this->db_onedev->query($sql,array(
|
||||
$observation_uuid,
|
||||
$value['T_OrderDetailT_OrderHeaderID'],
|
||||
$value['T_OrderDetailT_TestID'],
|
||||
$value['isQuantitatif'] == 'Y'?'Kuantitatif':'Kualitatif',
|
||||
json_encode($result)
|
||||
));
|
||||
|
||||
if(!$query){
|
||||
echo $this->db_onedev->last_query();
|
||||
$this->sys_error("error insert observation");
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($data_results);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
267
application/controllers/satu_sehat/Observation.php
Normal file
267
application/controllers/satu_sehat/Observation.php
Normal file
@@ -0,0 +1,267 @@
|
||||
<?php
|
||||
class Observation extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
var $load;
|
||||
var $satusehat;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->library('Satusehat');
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo "Satu Sehat Observation";
|
||||
}
|
||||
|
||||
function getobservation()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
// $testInput = $prm["testInput"];
|
||||
// echo $testInput;
|
||||
|
||||
$orderheaderID = $prm['orderheaderID'];
|
||||
|
||||
$sql = "SELECT * FROM one_health.observation
|
||||
WHERE observationT_OrderHeaderID = ?
|
||||
AND observationIsActive = '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_check = $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'];
|
||||
|
||||
$T_OrderDetailID = "";
|
||||
$sql_get_detailID = "SELECT T_OrderDetailID
|
||||
FROM t_orderdetail
|
||||
WHERE T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderDetailT_OrderHeaderID = $orderheaderID";
|
||||
|
||||
$qry_detailID = $this->db->query($sql_get_detailID, []);
|
||||
$last_qry = $this->db->last_query();
|
||||
|
||||
if (!$qry_detailID) {
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$T_OrderDetailID = $qry_detailID->result_array()[0]['T_OrderDetailID'];
|
||||
|
||||
// uuid generate
|
||||
// $this->load->library(“Satusehat”);
|
||||
// $this->satusehat->gen_uuid();
|
||||
|
||||
if (count($result_check) == 0) {
|
||||
// $sql_data_observation =
|
||||
// "SELECT T_OrderDetailID,
|
||||
// T_OrderDetailVerDate,
|
||||
// DATE_FORMAT(T_OrderDetailValDate, '%Y-%m-%d') as effectiveDate,
|
||||
// T_OrderDetailValDate,
|
||||
// DATE_FORMAT(T_OrderDetailValDate, '%Y-%m-%dT%H:%i:%s+00:00') as issuedDate,
|
||||
// T_OrderDetailResult,
|
||||
// T_OrderDetailNat_UnitName,
|
||||
// Nat_TestLoincCode,
|
||||
// Nat_TestLoincDisplay,
|
||||
// IFNULL(OHPatientMapIHSNumber, 'Belum terdaftar') as patient_ihsnumber,
|
||||
// IFNULL(OHDoctorMapIHSNumber,'Belum diinput') as doctor_ihsnumber,
|
||||
// EncounterUUID,
|
||||
// SpecimenUUID,
|
||||
// ServiceRequestUUID
|
||||
// FROM t_orderheader
|
||||
// JOIN t_orderdetail
|
||||
// ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
// AND T_OrderDetailIsActive = 'Y'
|
||||
// AND T_OrderDetailT_TestIsResult = 'Y'
|
||||
// AND T_OrderHeaderID = $orderheaderID
|
||||
// JOIN t_test
|
||||
// ON T_OrderDetailT_TestID = T_TestID
|
||||
// AND T_TestIsActive = 'Y'
|
||||
// AND T_TestIsResult = 'Y'
|
||||
// JOIN nat_test_loinc
|
||||
// ON Nat_TestLoincNat_TestID = T_TestNat_TestID
|
||||
// LEFT JOIN one_health.oh_patient_map
|
||||
// ON T_OrderHeaderM_PatientID = OHPatientMapM_PatientID
|
||||
// AND OHPatientMapIsActive = 'Y'
|
||||
// LEFT JOIN one_health.oh_doctor_map
|
||||
// ON OHDoctorMapM_DoctorID = T_OrderHeaderPjM_DoctorID
|
||||
// AND OHDoctorMapIsActive = 'Y'
|
||||
// LEFT JOIN one_health.encounter
|
||||
// ON EncounterT_orderHeaderID = T_orderHeaderID
|
||||
// AND EncounterIsActive = 'Y'
|
||||
// LEFT JOIN one_health.service_request
|
||||
// ON ServiceRequestT_OrderHeaderID = T_OrderHeaderID
|
||||
// AND ServiceRequestIsActive = 'Y'
|
||||
// ";
|
||||
|
||||
// -- Nat_MethodeName,
|
||||
// -- Nat_NormalValueMaxValue,
|
||||
// -- OHDoctorMapIHSNumber,
|
||||
// -- OHNatFlagMapCode,
|
||||
// -- OHNatFlagMapDisplay,
|
||||
|
||||
$sql_data_observation =
|
||||
"SELECT T_OrderDetailID,
|
||||
T_OrderDetailVerDate,
|
||||
DATE_FORMAT(T_OrderDetailValDate, '%Y-%m-%d') as effectiveDate,
|
||||
T_OrderDetailValDate,
|
||||
DATE_FORMAT(T_OrderDetailValDate, '%Y-%m-%dT%H:%i:%s+00:00') as issuedDate,
|
||||
T_OrderDetailResult,
|
||||
T_OrderDetailNat_UnitName,
|
||||
Nat_TestLoincCode,
|
||||
Nat_TestLoincDisplay,
|
||||
IFNULL(OHPatientMapIHSNumber, 'Belum terdaftar') as patient_ihsnumber,
|
||||
IFNULL(OHDoctorMapIHSNumber,'Belum diinput') as doctor_ihsnumber,
|
||||
EncounterUUID,
|
||||
SpecimenUUID,
|
||||
ServiceRequestUUID
|
||||
FROM t_orderheader
|
||||
JOIN t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderDetailT_TestIsResult = 'Y'
|
||||
AND T_OrderHeaderID = $orderheaderID
|
||||
JOIN t_test
|
||||
ON T_OrderDetailT_TestID = T_TestID
|
||||
AND T_TestIsActive = 'Y'
|
||||
AND T_TestIsResult = 'Y'
|
||||
JOIN nat_test_loinc
|
||||
ON Nat_TestLoincNat_TestID = T_TestNat_TestID
|
||||
LEFT JOIN t_ordersample
|
||||
ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
|
||||
AND T_OrderSampleT_SampleTypeID = T_TestT_SampleTypeID
|
||||
AND T_OrderSampleIsActive = 'Y'
|
||||
LEFT JOIN one_health.specimen
|
||||
ON SpecimentT_OrderSampleID = T_OrderSampleID
|
||||
AND SpecimenIsActive = 'Y'
|
||||
LEFT JOIN one_health.oh_patient_map
|
||||
ON T_OrderHeaderM_PatientID = OHPatientMapM_PatientID
|
||||
AND OHPatientMapIsActive = 'Y'
|
||||
LEFT JOIN one_health.oh_doctor_map
|
||||
ON OHDoctorMapM_DoctorID = T_OrderHeaderPjM_DoctorID
|
||||
AND OHDoctorMapIsActive = 'Y'
|
||||
LEFT JOIN one_health.encounter
|
||||
ON EncounterT_orderHeaderID = T_orderHeaderID
|
||||
AND EncounterIsActive = 'Y'
|
||||
LEFT JOIN one_health.service_request
|
||||
ON ServiceRequestT_OrderDetailID = T_OrderDetailID
|
||||
AND ServiceRequestIsActive = 'Y'
|
||||
";
|
||||
|
||||
|
||||
|
||||
$qry_data_observation = $this->db->query($sql_data_observation);
|
||||
$last_qry = $this->db->last_query();
|
||||
|
||||
if (!$qry_data_observation) {
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result_data_observation = $qry_data_observation->result_array();
|
||||
// echo "\n";
|
||||
// print_r($result_data_observation);
|
||||
|
||||
$observationJSON = [];
|
||||
|
||||
foreach ($result_data_observation as $key => $val_idx) {
|
||||
$observationJSON[] = [
|
||||
"fullUrl" => "urn:uuid:{$this->satusehat->gen_uuid()}",
|
||||
"resource" => [
|
||||
"resourceType" => "Observation",
|
||||
"identifier" => [
|
||||
[
|
||||
"system" => "http://sys-ids.kemkes.go.id/observation/$organizationID",
|
||||
"value" => $val_idx['T_OrderDetailID']
|
||||
]
|
||||
],
|
||||
"status" => "final",
|
||||
"category" => [
|
||||
"coding" => [
|
||||
[
|
||||
"system" => "http://terminology.hl7.org/CodeSystem/observation-category",
|
||||
"code" => "laboratory",
|
||||
"display" => "Laboratory"
|
||||
]
|
||||
]
|
||||
],
|
||||
"code" => [
|
||||
"coding" => [
|
||||
[
|
||||
"system" => "http://loinc.org",
|
||||
"code" => $val_idx['Nat_TestLoincCode'],
|
||||
"display" => $val_idx['Nat_TestLoincDisplay']
|
||||
]
|
||||
]
|
||||
],
|
||||
"subject" => [
|
||||
"reference" => "Patient/{$val_idx['patient_ihsnumber']}"
|
||||
],
|
||||
"encounter" => [
|
||||
"reference" => "urn:uuid:{$val_idx['EncounterUUID']}"
|
||||
],
|
||||
"effectiveDateTime" => $val_idx['effectiveDate'],
|
||||
"issued" => $val_idx['issuedDate'],
|
||||
"performer" => [
|
||||
[
|
||||
"reference" => "Practicioner/{$val_idx['doctor_ihsnumber']}"
|
||||
],
|
||||
[
|
||||
"reference" => "Organization/$organizationID"
|
||||
]
|
||||
],
|
||||
"specimen" => [
|
||||
"reference" => "urn:uuid:{$val_idx['SpecimenUUID']}"
|
||||
],
|
||||
"basedOn" => [
|
||||
[
|
||||
"reference" => "ServiceRequest/{$val_idx['ServiceRequestUUID']}"
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
echo json_encode($observationJSON);
|
||||
} else {
|
||||
echo $result_check[0]['ObservationJSON'];
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
318
application/controllers/satu_sehat/Servicerequest.php
Normal file
318
application/controllers/satu_sehat/Servicerequest.php
Normal file
@@ -0,0 +1,318 @@
|
||||
<?php
|
||||
class Servicerequest extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->library('Satusehat');
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "Satu Sehat Service Request";
|
||||
}
|
||||
|
||||
//fungsi translate hari
|
||||
function translateDayToIndonesian($englishDay) {
|
||||
$englishDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
||||
$indonesianDays = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu'];
|
||||
$index = array_search($englishDay, $englishDays);
|
||||
if ($index !== false) {
|
||||
return $indonesianDays[$index];
|
||||
}
|
||||
|
||||
return 'Hari tidak valid';
|
||||
}
|
||||
|
||||
//fungsi translate bulan
|
||||
function translateMonthToIndonesian($englishMonth) {
|
||||
$englishMonths = [
|
||||
'January', 'February', 'March', 'April', 'May', 'June',
|
||||
'July', 'August', 'September', 'October', 'November', 'December'
|
||||
];
|
||||
$indonesianMonths = [
|
||||
'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni',
|
||||
'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'
|
||||
];
|
||||
|
||||
$index = array_search($englishMonth, $englishMonths);
|
||||
if ($index !== false) {
|
||||
return $indonesianMonths[$index];
|
||||
}
|
||||
|
||||
return 'Bulan tidak valid';
|
||||
}
|
||||
|
||||
function getservicerequest()
|
||||
{
|
||||
|
||||
$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 T_OrderDetail by T_OrderHeaderID
|
||||
$T_OrderDetailID = "";
|
||||
$sql_get_orderDetailID = "SELECT
|
||||
T_OrderDetailID,
|
||||
IFNULL(Nat_TestLoincCode,'') as Nat_TestLoincCode ,
|
||||
IFNULL(Nat_TestLoincDisplay,'') as Nat_TestLoincDisplay,
|
||||
T_OrderDetailT_TestName,
|
||||
T_OrderHeaderM_PatientID ,
|
||||
OHPatientMapIHSNumber,
|
||||
EncounterUUID,
|
||||
M_PatientName,
|
||||
DAYNAME(T_OrderHeaderDate) as OrderHeaderDay,
|
||||
DATE_FORMAT(DATE(T_OrderHeaderDate),'%d %M %Y') as OrderHeaderDate,
|
||||
TIME(T_OrderHeaderDate) as OrderHeaderTime,
|
||||
T_OrderHeaderDate,
|
||||
OHDoctorMapIHSNumber,
|
||||
M_DoctorName,
|
||||
OHStaffMapIhsNumber,
|
||||
M_StaffName
|
||||
|
||||
FROM t_orderheader
|
||||
JOIN t_orderdetail
|
||||
ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
AND T_OrderHeaderID = ?
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderDetailT_TestIsPrice ='Y'
|
||||
|
||||
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 = Nat_TestID
|
||||
|
||||
Join m_doctor
|
||||
ON M_DoctorID = T_OrderHeaderSenderM_DoctorID
|
||||
AND M_DoctorIsActive ='Y'
|
||||
|
||||
JOIN m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
AND M_PatientIsActive = 'Y'
|
||||
|
||||
JOIN order_log
|
||||
ON OrderLogT_OrderHeaderID = T_OrderHeaderID
|
||||
|
||||
JOIN m_user
|
||||
ON M_UserID = OrderLogUserID
|
||||
AND M_UserIsActive = 'Y'
|
||||
|
||||
JOIN m_staff
|
||||
ON M_StaffID = M_UserM_StaffID
|
||||
AND M_StaffIsActive = 'Y'
|
||||
|
||||
LEFT JOIN one_health.oh_patient_map
|
||||
ON T_OrderHeaderM_PatientID = OHPatientMapM_PatientID
|
||||
AND OHPatientMapIsActive = 'Y'
|
||||
|
||||
LEFT JOIN one_health.encounter
|
||||
ON EncounterT_orderHeaderID = T_orderHeaderID
|
||||
AND EncounterIsActive= 'Y'
|
||||
AND T_OrderDetailT_OrderHeaderID = EncounterT_orderHeaderID
|
||||
|
||||
LEFT JOIN one_health.oh_doctor_map
|
||||
ON OHDoctorMapM_DoctorID = M_DoctorID
|
||||
AND OHDoctorMapIsActive = 'Y'
|
||||
|
||||
LEFT JOIN one_health.oh_staff_map
|
||||
ON OHStaffMapM_StaffNIK = M_StaffNIK
|
||||
AND OHStaffMapIsActive = 'Y'";
|
||||
|
||||
$qry_orderDetailID = $this->db->query($sql_get_orderDetailID, $orderheaderID);
|
||||
$last_qry = $this->db->last_query();
|
||||
|
||||
if (!$qry_orderDetailID) {
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$orders = $qry_orderDetailID->result_array();
|
||||
|
||||
$results = array();
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM t_orderpromise
|
||||
WHERE
|
||||
T_OrderPromiseT_OrderHeaderID = ? AND T_OrderPromiseIsActive = 'Y'
|
||||
ORDER BY T_OrderPromiseDateTime ASC";
|
||||
$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;
|
||||
}
|
||||
$rst_promise = $qry->result_array();
|
||||
$T_OrderPromiseDateTime = $rst_promise[0]['T_OrderPromiseDateTime'];
|
||||
|
||||
foreach ($orders as $key => $value) {
|
||||
$T_OrderorderDetailID = $value['T_OrderDetailID'];
|
||||
$sql = "SELECT COUNT(*) as xcount
|
||||
FROM one_health.service_request
|
||||
WHERE
|
||||
ServiceRequestT_OrderDetailID = ? AND ServiceRequestIsActive = 'Y'";
|
||||
$qry_cek = $this->db->query($sql, $T_OrderorderDetailID);
|
||||
$last_qry = $this->db->last_query();
|
||||
|
||||
if (!$qry_cek) {
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($qry_cek->row()->xcount == 0) {
|
||||
//blm ada data di one_health maka diinsertkan
|
||||
$servicerequest_uuid = $this->satusehat->gen_uuid();
|
||||
//mengambil orderpromise yang paling awal
|
||||
|
||||
//mengubah hari dari inggris menjadi indonesia
|
||||
$dayInIndonesian = $this->translateDayToIndonesian($value['OrderHeaderDay']);
|
||||
|
||||
//mengubah bulan dalam tanggal menjadi ke bahasa indonesia
|
||||
$parts = explode(' ', $value['OrderHeaderDate']);
|
||||
$indonesianMonth = $this->translateMonthToIndonesian($parts[1]);
|
||||
$timeParts = explode(':', $value['OrderHeaderTime']);
|
||||
$hourMinute = $timeParts[0] . ':' . $timeParts[1];
|
||||
|
||||
// mengubah Nama menjadi Huruf besar ditiap awal kata dan kecil selanjutnya
|
||||
$formattedNamePatient = ucwords(strtolower($value['M_PatientName']));
|
||||
$formattedNameDoctor = ucwords(strtolower($value['M_DoctorName']));
|
||||
$formattedNamePerformer = ucwords(strtolower($value['M_StaffName']));
|
||||
|
||||
$serviceRequestJSON = [
|
||||
"fullUrl" => "urn:uuid:{$servicerequest_uuid}",
|
||||
"resource" => [
|
||||
"resourceType"=> "ServiceRequest",
|
||||
"identifier"=> [
|
||||
[
|
||||
"system"=> "http://sys-ids.kemkes.go.id/servicerequest/$organizationID",
|
||||
"value"=> $value['T_OrderDetailID']
|
||||
],
|
||||
],
|
||||
"status" => "active",
|
||||
"intent" => "original-order",
|
||||
"priority" => "routine",
|
||||
"code" => [
|
||||
"coding" => [
|
||||
[
|
||||
"system"=> "http://loinc.org",
|
||||
"code"=> $value['Nat_TestLoincCode'],
|
||||
"display"=> $value['Nat_TestLoincDisplay'],
|
||||
],
|
||||
],
|
||||
"text" => $value['T_OrderDetailT_TestName'],
|
||||
],
|
||||
"subject" => [
|
||||
"reference"=> "Patient/".$value['OHPatientMapIHSNumber'],
|
||||
],
|
||||
"encounter"=> [
|
||||
"reference"=> "Encounter/".$value['EncounterUUID'],
|
||||
"display"=> "Permintaan {$value['T_OrderDetailT_TestName']} {$formattedNamePatient} di hari {$dayInIndonesian}, {$parts[0]} $indonesianMonth {$parts[2]} pukul {$hourMinute} WIB"
|
||||
],
|
||||
"occurrenceDateTime"=> date('c', strtotime($T_OrderPromiseDateTime)),
|
||||
"authoredOn"=> date('c', strtotime($value['T_OrderHeaderDate'])),
|
||||
"requester"=>[
|
||||
"reference"=> "Practitioner/{$value['OHDoctorMapIHSNumber']}",
|
||||
"display"=> $formattedNameDoctor
|
||||
|
||||
],
|
||||
"performer"=> [
|
||||
[
|
||||
"reference"=> "Practitioner/{$value['OHStaffMapIhsNumber']}",
|
||||
"display"=> $formattedNamePerformer
|
||||
]
|
||||
],
|
||||
"reasonCode"=> [
|
||||
[
|
||||
"text"=> ""
|
||||
]
|
||||
]
|
||||
],
|
||||
"request" => [
|
||||
"method" => "POST",
|
||||
"url" => "ServiceRequest"
|
||||
]
|
||||
];
|
||||
|
||||
$sql = "INSERT INTO one_health.service_request
|
||||
(
|
||||
ServiceRequestUUID,
|
||||
ServiceRequestT_OrderHeaderID,
|
||||
ServiceRequestT_OrderDetailID,
|
||||
ServiceRequestJSON,
|
||||
ServiceRequestCreated
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
NOW()
|
||||
)";
|
||||
|
||||
$qry = $this->db->query($sql, [
|
||||
$servicerequest_uuid,
|
||||
$orderheaderID,
|
||||
$T_OrderorderDetailID,
|
||||
json_encode($serviceRequestJSON)
|
||||
]);
|
||||
$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[] = $serviceRequestJSON;
|
||||
}
|
||||
else {
|
||||
//sudah ada data di one_health maka langsung di returnkan jsonya ;
|
||||
echo "Data sudah diinsert";
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($results);
|
||||
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
316
application/controllers/satu_sehat/Ssapix.php
Normal file
316
application/controllers/satu_sehat/Ssapix.php
Normal file
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
class Ssapix extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("default", true);
|
||||
}
|
||||
|
||||
function test_auth()
|
||||
{
|
||||
//$this->load->library("Satusehat");
|
||||
$result = $this->put_token();
|
||||
echo $result;
|
||||
}
|
||||
|
||||
function test_gettoken()
|
||||
{
|
||||
//$this->load->library("Satusehat");
|
||||
$result = $this->get_token();
|
||||
echo $result;
|
||||
}
|
||||
|
||||
function test_search_practicioner_by_nik()
|
||||
{
|
||||
$nik = "367400001111202";
|
||||
$result = $this->search_practicioner_by_nik($nik);
|
||||
$birthDate = $result->entry[0]->resource->birthDate;
|
||||
$gender = $result->entry[0]->resource->gender;
|
||||
$ihsNumber = $result->entry[0]->resource->id;
|
||||
$dataPracticioner = array(
|
||||
'birthDate' => $birthDate,
|
||||
'gender' => $gender,
|
||||
'ihsNumber' => $ihsNumber
|
||||
);
|
||||
print_r($dataPracticioner);
|
||||
}
|
||||
|
||||
function test_search_patient_by_nik()
|
||||
{
|
||||
$nik = "9271060312000001";
|
||||
$result = $this->search_patient_by_nik($nik);
|
||||
$ihsNumber = $result->entry[0]->resource->id;
|
||||
$name = $result->entry[0]->resource->name[0]->text;
|
||||
$dataPatient = array(
|
||||
'name' => $name,
|
||||
'ihsNumber' => $ihsNumber
|
||||
);
|
||||
print_r($dataPatient);
|
||||
}
|
||||
|
||||
function get_client_key($debug = "")
|
||||
{
|
||||
$sql = "select * from one_health.client where clientIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
return [false, "", ""];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
if ($debug != "") {
|
||||
print_r([false, "", ""]);
|
||||
}
|
||||
return [false, "", ""];
|
||||
}
|
||||
if ($debug != "") {
|
||||
print_r([true, $rows[0]["clientKey"], $rows[0]["clientSecret"]]);
|
||||
}
|
||||
return [true, $rows[0]["clientKey"], $rows[0]["clientSecret"]];
|
||||
}
|
||||
|
||||
function put_token()
|
||||
{
|
||||
$auth_url = "https://api-satusehat-dev.dto.kemkes.go.id/oauth2/v1";
|
||||
//api url
|
||||
$url = $auth_url . "/accesstoken?grant_type=client_credentials";
|
||||
//echo $url;
|
||||
|
||||
$data = [
|
||||
"client_id" => "6pukkqo0rqqu0ckboc8ekgcxqysfpr4avkivmutgkx5xvva4",
|
||||
"client_secret" => "89zqsmy3z5w7rvschtp9gjoawwiazg4a2uns3matw3dxbfxtdarssetubd8mrn3p"
|
||||
];
|
||||
|
||||
|
||||
$ch = curl_init($url);
|
||||
# setup request to send json via post.
|
||||
|
||||
curl_setopt($ch, curlopt_postfields, http_build_query($data));
|
||||
curl_setopt($ch, curlopt_customrequest, "post");
|
||||
curl_setopt(
|
||||
$ch,
|
||||
curlopt_httpheader,
|
||||
array(
|
||||
'content-type: application/x-www-form-urlencoded'
|
||||
)
|
||||
);
|
||||
# return response instead of printing.
|
||||
curl_setopt($ch, curlopt_returntransfer, true);
|
||||
# send request.
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
# print response.
|
||||
//print_r($result);
|
||||
//echo $token_rst->access_token;
|
||||
if ($result) {
|
||||
$token_rst = json_decode($result);
|
||||
|
||||
$sql = "select count(*) as xcount, tokenid
|
||||
from one_health.token
|
||||
where
|
||||
tokenisactive = 'y'
|
||||
";
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
echo "get count token error";
|
||||
exit;
|
||||
}
|
||||
|
||||
$rst_count = $qry->row_array();
|
||||
|
||||
if ($rst_count['xcount'] > 0) {
|
||||
$sql = "update one_health.token set tokenvalue = ?, tokenexpired = date_add(now(), interval 50 minute)
|
||||
where tokenid = ?";
|
||||
$qry = $this->db_onedev->query($sql, [$token_rst->access_token, $rst_count['tokenid']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("refresh token error", $this->db_onedev->last_query());
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$sql = "update one_health.token set tokenisactive = 'n' where tokenisactive = 'y'";
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
echo "nonactive token error";
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "insert into one_health.token(tokenvalue,tokenexpired) values(?,date_add(now(), interval 50 minute))";
|
||||
$qry = $this->db_onedev->query($sql, [$token_rst->access_token]);
|
||||
if (!$qry) {
|
||||
echo "insert token error";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "select tokenvalue
|
||||
from one_health.token
|
||||
where
|
||||
tokenisactive = 'y' limit 1
|
||||
";
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
echo "get token error";
|
||||
exit;
|
||||
}
|
||||
|
||||
return $qry->row()->tokenValue;
|
||||
}
|
||||
}
|
||||
|
||||
function get_token()
|
||||
{
|
||||
$sql = "SELECT COUNT(*) as xcount, tokenValue
|
||||
FROM one_health.token
|
||||
WHERE tokenIsActive = 'Y' AND NOW() < tokenExpired AND tokenValue IS NOT NULL
|
||||
";
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
echo "select token error";
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_token = $qry->row_array();
|
||||
//print_r($data_token);
|
||||
if ($data_token['xcount'] > 0) {
|
||||
return $data_token['tokenValue'];
|
||||
} else {
|
||||
return $this->put_token();
|
||||
}
|
||||
}
|
||||
|
||||
function search_practicioner_by_nik($nik)
|
||||
{
|
||||
$token = $this->get_token();
|
||||
$authorization = "Authorization: Bearer " . $token;
|
||||
$xbase_url = "https://api-satusehat-dev.dto.kemkes.go.id/fhir-r4/v1";
|
||||
|
||||
//API URL
|
||||
$url = $xbase_url . "/Practitioner?identifier=https://fhir.kemkes.go.id/id/nik|" . $nik;
|
||||
//echo $url;
|
||||
|
||||
|
||||
$ch = curl_init($url);
|
||||
# Setup request to send json via POST.
|
||||
//$payload = json_encode($data);
|
||||
|
||||
//curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $authorization));
|
||||
# Return response instead of printing.
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
# Send request.
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
# Print response.
|
||||
$data_rst = json_decode($result);
|
||||
//print_r($result);
|
||||
|
||||
return $data_rst;
|
||||
}
|
||||
|
||||
function search_patient_by_nik($nik)
|
||||
{
|
||||
$token = $this->get_token();
|
||||
$authorization = "Authorization: Bearer " . $token;
|
||||
$xbase_url = "https://api-satusehat-dev.dto.kemkes.go.id/fhir-r4/v1";
|
||||
|
||||
//API URL
|
||||
$url = $xbase_url . "/Patient?identifier=https://fhir.kemkes.go.id/id/nik|" . $nik;
|
||||
//echo $url;
|
||||
|
||||
|
||||
$ch = curl_init($url);
|
||||
# Setup request to send json via POST.
|
||||
//$payload = json_encode($data);
|
||||
|
||||
//curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $authorization));
|
||||
# Return response instead of printing.
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
# Send request.
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
# Print response.
|
||||
$data_rst = json_decode($result);
|
||||
//print_r($result);
|
||||
|
||||
return $data_rst;
|
||||
}
|
||||
|
||||
function send_bundle($orderID)
|
||||
{
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM one_health.bundle
|
||||
WHERE BundleT_orderHeaderID = {$orderID} AND BundleIsActive = 'Y'
|
||||
LIMIT 1
|
||||
";
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
echo "select bundle error";
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_blundle = $qry->row_array();
|
||||
// print_r($data_blundle);
|
||||
$json_data = json_decode($data_blundle['BundleJSON']);
|
||||
$json_payload = json_encode($json_data);
|
||||
|
||||
$token = $this->get_token();
|
||||
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => 'https://api-satusehat-dev.dto.kemkes.go.id/fhir-r4/v1',
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => '',
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => 'POST',
|
||||
CURLOPT_POSTFIELDS => $json_payload,
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
'Content-Type: application/json',
|
||||
'Authorization: Bearer ' . $token
|
||||
),
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
curl_close($curl);
|
||||
//echo $response;
|
||||
|
||||
//$json_response = json_encode(json_decode($response));
|
||||
//echo $json_response;
|
||||
$sql = "UPDATE one_health.bundle SET BundleResponseJSON = '{$response}'
|
||||
WHERE BundleT_orderHeaderID = {$orderID} AND BundleIsActive = 'Y'
|
||||
";
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
//echo $sql;
|
||||
if (!$qry) {
|
||||
echo "update bundle error";
|
||||
exit;
|
||||
}
|
||||
|
||||
echo $response;
|
||||
}
|
||||
|
||||
protected function objToArray($obj)
|
||||
{
|
||||
// Not an object or array
|
||||
if (!is_object($obj) && !is_array($obj)) {
|
||||
return $obj;
|
||||
}
|
||||
|
||||
// Parse array
|
||||
foreach ($obj as $key => $value) {
|
||||
$arr[$key] = $this->objToArray($value);
|
||||
}
|
||||
|
||||
// Return parsed array
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
|
||||
1416
application/controllers/satu_sehat/Ssresource.php
Normal file
1416
application/controllers/satu_sehat/Ssresource.php
Normal file
File diff suppressed because it is too large
Load Diff
126
application/controllers/satu_sehat/Terminologi.php
Normal file
126
application/controllers/satu_sehat/Terminologi.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
class Terminologi extends MY_Controller{
|
||||
var $db;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->library('Satusehat');
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo "Terminologi";
|
||||
}
|
||||
|
||||
function getterminologicategory()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
try {
|
||||
$orderheaderID = $prm['orderheaderID'];
|
||||
|
||||
// get terminology category
|
||||
$sql = "SELECT code_system, code, display
|
||||
FROM one_terminology.terminology
|
||||
WHERE attribute_path = 'DiagnosticReport.category'
|
||||
";
|
||||
|
||||
$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;
|
||||
}
|
||||
$result_cek = $qry->result_array();
|
||||
|
||||
// Add auto-incremented ID
|
||||
$incrementedId = 1;
|
||||
foreach ($result_cek as &$row) {
|
||||
$row['id'] = (string)$incrementedId;
|
||||
$incrementedId++;
|
||||
}
|
||||
|
||||
echo json_encode($result_cek);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getterminologicategorycodesystem()
|
||||
{
|
||||
|
||||
$prm = $this->sys_input;
|
||||
try {
|
||||
$orderheaderID = $prm['orderheaderID'];
|
||||
|
||||
// get terminology conclusion
|
||||
$sql = "SELECT code_system, code, display
|
||||
FROM one_terminology.terminology
|
||||
WHERE resource_type = 'DiagnosticReport'
|
||||
AND code_system = ?
|
||||
AND (code LIKE ? OR display LIKE ?)
|
||||
";
|
||||
$qry = $this->db->query($sql, [$prm['code_system'], $prm['code'] . '%', $prm['code'] . '%']);
|
||||
$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();
|
||||
// Add auto-incremented ID
|
||||
foreach ($result_cek as &$row) {
|
||||
$row['id'] = $row['code'];
|
||||
}
|
||||
|
||||
echo json_encode($result_cek);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function groubbycodesystem() {
|
||||
try {
|
||||
$orderheaderID = $prm['orderheaderID'];
|
||||
|
||||
// get terminology conclusion
|
||||
$sql = "SELECT DISTINCT code_system
|
||||
FROM one_terminology.terminology
|
||||
WHERE resource_type= 'DiagnosticReport'
|
||||
Group by code_system
|
||||
";
|
||||
|
||||
$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;
|
||||
}
|
||||
$result_cek = $qry->result_array();
|
||||
// Add auto-incremented ID
|
||||
$incrementedId = 1;
|
||||
foreach ($result_cek as &$row) {
|
||||
$row['id'] = $row['code_system'];
|
||||
}
|
||||
|
||||
echo json_encode($result_cek);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
12
application/controllers/satu_sehat/Test.php
Normal file
12
application/controllers/satu_sehat/Test.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
class Test extends MY_Controller {
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
function auth() {
|
||||
echo json_encode($_POST);
|
||||
}
|
||||
function index() {
|
||||
echo json_encode($_POST);
|
||||
}
|
||||
}
|
||||
361
application/controllers/satu_sehat/Tool.php
Normal file
361
application/controllers/satu_sehat/Tool.php
Normal file
@@ -0,0 +1,361 @@
|
||||
<?php
|
||||
|
||||
class Tool extends MY_Controller
|
||||
{
|
||||
var $base_url, $base_consent_url, $base_oauth_url;
|
||||
var $is_staging, $organizationID;
|
||||
var $dbname;
|
||||
var $tz;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->tz = "+07:00";
|
||||
$this->is_staging = false;
|
||||
$this->db_onedev = $this->load->database("default", true);
|
||||
$this->base_url = "https://api-satusehat.kemkes.go.id/fhir-r4/v1";
|
||||
$this->base_oauth_url = "https://api-satusehat.kemkes.go.id/oauth2/v1";
|
||||
$this->base_consent_url = "https://api-satusehat.dto.kemkes.go.id/consent/v1";
|
||||
$this->dbname = "one_health";
|
||||
if ($this->is_staging) {
|
||||
$this->base_url = "https://api-satusehat-stg.kemkes.go.id/fhir-r4/v1";
|
||||
$this->base_oauth_url = "https://api-satusehat-stg.kemkes.go.id/oauth2/v1";
|
||||
$this->base_consent_url = "https://api-satusehat-stg.dto.kemkes.go.id/consent/v1";
|
||||
$this->dbname = "one_health_dev";
|
||||
}
|
||||
$this->get_organization_id();
|
||||
}
|
||||
// function get_organization
|
||||
function organization()
|
||||
{
|
||||
$sql = "select M_BranchName, M_BranchAddress
|
||||
from m_branch where M_BranchIsDefault ='Y' and M_BranchIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "ERR : " . $this->db->error()["message"];
|
||||
echo $this->db->last_query();
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0) {
|
||||
$this->print_table($rows, array_keys($rows[0]));
|
||||
}
|
||||
$o_resp = $this->ss_get("/Organization/{$this->organizationID}");
|
||||
$resp = $this->objToArray($o_resp);
|
||||
// "Type" => $resp["type"][0]["coding"][0]["display"]
|
||||
$id = $resp["id"];
|
||||
$name = $resp["name"];
|
||||
$x_type = $resp["type"][0]["coding"][0];
|
||||
$type = $x_type["display"];
|
||||
$code = $x_type["code"];
|
||||
$system= $x_type["system"];
|
||||
$rows = [
|
||||
[
|
||||
"ID" => $resp["id"],
|
||||
"Name" => $resp["name"],
|
||||
"Type" => $type . "<br/>" .
|
||||
$code . "<br/>" .
|
||||
$system
|
||||
]
|
||||
];
|
||||
echo "<br/>";
|
||||
$this->print_table($rows, array_keys($rows[0]));
|
||||
}
|
||||
// get subject in a date
|
||||
function get_encounter_by_date($date = "", $start = 0, $limit = 10)
|
||||
{
|
||||
if ($date == "") $date = date("Y-m-d");
|
||||
$sdate = $date . " 00:00:01";
|
||||
$edate = $date . " 23:59:59";
|
||||
$sql = "select T_OrderHeaderLabNumber LabNo, T_OrderHeaderDate Date,
|
||||
OHPatientMapIhsNumber PatientIHSNumber, M_PatientName,
|
||||
EncounterResponseID EncounterID
|
||||
from t_orderheader
|
||||
join {$this->dbname}.oh_doctor_map
|
||||
on T_OrderHeaderPjM_DoctorID = OHDoctorMapM_DoctorID
|
||||
and T_OrderHeaderDate >= ?
|
||||
and T_OrderHeaderDate <= ?
|
||||
join m_doctor on T_OrderHeaderPjM_DoctorID = M_DoctorID
|
||||
join {$this->dbname}.oh_patient_map
|
||||
on T_OrderHeaderM_PatientID = OHPatientMapM_PatientID
|
||||
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
||||
left join {$this->dbname}.encounter
|
||||
on T_OrderHeaderID = EncounterT_OrderHeaderID
|
||||
where EncounterID is not null
|
||||
limit $start,$limit
|
||||
";
|
||||
$qry = $this->db->query($sql, [$sdate, $edate]);
|
||||
if (!$qry) {
|
||||
echo "ERR : " . $this->db->error()["message"];
|
||||
echo $this->db->last_query();
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0) {
|
||||
$this->print_table($rows, array_keys($rows[0]));
|
||||
}
|
||||
}
|
||||
|
||||
// helper
|
||||
function get_env()
|
||||
{
|
||||
if ($this->is_staging) {
|
||||
echo "Environment is Staging \n";
|
||||
} else {
|
||||
echo "Environment is Production \n";
|
||||
}
|
||||
}
|
||||
function change_env()
|
||||
{
|
||||
$this->reset_token();
|
||||
$this->put_token();
|
||||
}
|
||||
function ss_post($service, $data)
|
||||
{
|
||||
$token = $this->get_token();
|
||||
$authorization = "Authorization: Bearer " . $token;
|
||||
$xbase_url = $this->base_url;
|
||||
$url = $xbase_url . "$service";
|
||||
$ch = curl_init($url);
|
||||
# Setup request to send json via POST.
|
||||
$payload = json_encode($data);
|
||||
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $authorization));
|
||||
# Return response instead of printing.
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
# Send request.
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
# Print response.
|
||||
$data_rst = json_decode($result);
|
||||
return $data_rst;
|
||||
}
|
||||
function ss_get($service, $debug = "")
|
||||
{
|
||||
$token = $this->get_token();
|
||||
$authorization = "Authorization: Bearer " . $token;
|
||||
$xbase_url = $this->base_url;
|
||||
$url = $xbase_url . "$service";
|
||||
$ch = curl_init($url);
|
||||
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $authorization));
|
||||
# Return response instead of printing.
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
# Send request.
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
# Print response.
|
||||
if ($debug != "") {
|
||||
echo "url : $url \n";
|
||||
print_r($result);
|
||||
}
|
||||
$data_rst = json_decode($result);
|
||||
return $data_rst;
|
||||
}
|
||||
|
||||
function get_organization_id()
|
||||
{
|
||||
|
||||
$sql = "SELECT organizationID
|
||||
FROM {$this->dbname}.organization
|
||||
JOIN m_branch ON organizationM_BranchID = M_BranchID AND M_BranchIsDefault = 'Y' AND M_BranchIsActive = 'Y'
|
||||
WHERE organizationIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
return;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0) {
|
||||
$this->organizationID = $rows[0]["organizationID"];
|
||||
}
|
||||
}
|
||||
function get_client_key($debug = "")
|
||||
{
|
||||
$sql = "select * from {$this->dbname}.client where clientIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
return [false, "", ""];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
if ($debug != "") {
|
||||
print_r([false, "", ""]);
|
||||
}
|
||||
return [false, "", ""];
|
||||
}
|
||||
if ($debug != "") {
|
||||
print_r([true, $rows[0]["clientKey"], $rows[0]["clientSecret"]]);
|
||||
}
|
||||
|
||||
return [true, $rows[0]["clientKey"], $rows[0]["clientSecret"]];
|
||||
}
|
||||
|
||||
function reset_token()
|
||||
{
|
||||
$sql = "delete from {$this->dbname}.token ";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "ERR : " . $this->db->error()["message"];
|
||||
echo " " . $this->db->last_query();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function put_token()
|
||||
{
|
||||
$auth_url = $this->base_oauth_url;
|
||||
//api url
|
||||
$url = $auth_url . "/accesstoken?grant_type=client_credentials";
|
||||
list($status, $key, $secret) = $this->get_client_key();
|
||||
$data = [
|
||||
"client_id" => $key,
|
||||
"client_secret" => $secret
|
||||
];
|
||||
$ch = curl_init($url);
|
||||
# setup request to send json via post.
|
||||
$post_data = http_build_query($data);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
// suppress return header
|
||||
// curl_setopt(
|
||||
// $ch,
|
||||
// CURLOPT_HEADER,
|
||||
// array(
|
||||
// 'content-type: application/x-www-form-urlencoded'
|
||||
// )
|
||||
// );
|
||||
# return response instead of printing.
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
# send request.
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
# print response.
|
||||
//echo $token_rst->access_token;
|
||||
if ($result) {
|
||||
$token_rst = json_decode($result);
|
||||
|
||||
$sql = "select count(*) as xcount, tokenID
|
||||
from {$this->dbname}.token
|
||||
where
|
||||
tokenIsActive = 'y'
|
||||
";
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
echo "get count token error";
|
||||
exit;
|
||||
}
|
||||
|
||||
$rst_count = $qry->row_array();
|
||||
// print_r($token_rst);
|
||||
if ($rst_count['xcount'] > 0) {
|
||||
$sql = "update {$this->dbname}.token set tokenValue = ?, tokenExpired = date_add(now(), interval 50 minute)
|
||||
where tokenID = ?";
|
||||
$qry = $this->db_onedev->query($sql, [$token_rst->access_token, $rst_count['tokenID']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("refresh token error", $this->db_onedev->last_query());
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$sql = "update {$this->dbname}.token set tokenIsActive = 'N' where tokenIsActive = 'Y'";
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
echo "nonactive token error";
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "insert into {$this->dbname}.token(tokenValue,tokenExpired) values(?,date_add(now(), interval 50 minute))";
|
||||
$qry = $this->db_onedev->query($sql, [$token_rst->access_token]);
|
||||
if (!$qry) {
|
||||
echo "insert token error";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "select tokenValue
|
||||
from {$this->dbname}.token
|
||||
where
|
||||
tokenIsActive = 'Y' limit 1
|
||||
";
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
echo "get token error";
|
||||
exit;
|
||||
}
|
||||
|
||||
return $qry->row()->tokenValue;
|
||||
}
|
||||
}
|
||||
|
||||
function get_token()
|
||||
{
|
||||
$sql = "SELECT COUNT(*) as xcount, tokenValue
|
||||
FROM {$this->dbname}.token
|
||||
WHERE tokenIsActive = 'Y' AND NOW() < tokenExpired AND tokenValue IS NOT NULL
|
||||
";
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
echo "select token error";
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_token = $qry->row_array();
|
||||
//print_r($data_token);
|
||||
if ($data_token['xcount'] > 0) {
|
||||
return $data_token['tokenValue'];
|
||||
} else {
|
||||
return $this->put_token();
|
||||
}
|
||||
}
|
||||
|
||||
public function print_table_style()
|
||||
{
|
||||
echo "
|
||||
<style>
|
||||
th, td {
|
||||
padding: 15px;
|
||||
text-align: left;
|
||||
}
|
||||
tr:nth-child(even) {background-color: #f2f2f2;}
|
||||
table {
|
||||
border: solid 1px ;
|
||||
min-width:600px;
|
||||
}
|
||||
</style>
|
||||
";
|
||||
}
|
||||
public function print_table($rows, $keys)
|
||||
{
|
||||
$this->print_table_style();
|
||||
echo "<table>";
|
||||
echo "<tr>";
|
||||
foreach ($keys as $k) {
|
||||
echo "<td>$k</td>";
|
||||
}
|
||||
echo "</tr>\n";
|
||||
foreach ($rows as $r) {
|
||||
echo "<tr>";
|
||||
foreach ($keys as $k) {
|
||||
echo "<td>" . $r[$k] . "</td>";
|
||||
}
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
}
|
||||
protected function objToArray($obj)
|
||||
{
|
||||
// Not an object or array
|
||||
if (!is_object($obj) && !is_array($obj)) {
|
||||
return $obj;
|
||||
}
|
||||
|
||||
// Parse array
|
||||
foreach ($obj as $key => $value) {
|
||||
$arr[$key] = $this->objToArray($value);
|
||||
}
|
||||
|
||||
// Return parsed array
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user