Files
BE_IBL/application/controllers/tools/satu_sehat/Clinic_encounter.php
2026-04-15 15:23:57 +07:00

779 lines
25 KiB
PHP

<?php
class Clinic_encounter extends MY_Controller
{
function __construct()
{
parent::__construct();
}
function status01()
{
$branches = [
"matramam", "bonjer", "samanhudi", "ragunan",
"riau", "toha", "pajajaran", "cimahi",
"ngagel", "aditya", "mulyo", "parkus", "hrm"
];
$result = [];
echo "multi branch:<br/>";
print_r($branches);
foreach ($branches as $b) {
echo "$b\n";
$json = file_get_contents("/xtmp/$b.json");
print_r(json_decode($json));
echo "\n";
}
}
function devone($date = "")
{
$branches = [
"matraman", "bonjer", "samanhudi", "ragunan",
"riau", "toha", "pajajaran", "cimahi",
"ngagel", "aditya", "mulyo", "parkus", "hrm"
];
$result = [];
foreach ($branches as $b) {
$date = date("Y-m-d");
$url = "http://$b/one-api/tools/satu_sehat/clinic_encounter/status/$date/x";
$json = file_get_contents($url);
$resp = json_decode($json, true);
if ($resp["status"] != "OK") {
continue;
}
$data = $resp["data"];
$organization = $resp["satu_sehat"];
$blank_nik = 0;
$inv_nik = 0;
$non_ihs = 0;
$no_loc = 0;
$no_ihs_pj = 0;
$ready_encounter = 0;
$total_order = $resp["total"];
foreach ($data as $r) {
switch ($r["Status"]) {
case "InvNIK":
$inv_nik = $r["Jumlah"];
break;
case "NoLoc":
$no_loc = $r["Jumlah"];
break;
case "NonIHS":
$non_ihs = $r["Jumlah"];
break;
case "NonNIK":
$blank_nik = $r["Jumlah"];
break;
case "SubReady":
$ready_encounter = $r["Jumlah"];
break;
case "NoIHSPJ":
$no_ihs_pj = $r["Jumlah"];
break;
}
}
$percentage = round($ready_encounter / $total_order * 100, 2) . " %";
if ($organization == "N" || $no_loc > 0) {
$percentage = "***";
}
$result[] = [
"Cabang" => $b,
"Organization IHS" => $organization,
"Tanpa NIK" => $blank_nik,
"Invalid NIK" => $inv_nik,
"NIK belum terdaftar" => $non_ihs,
"Belum ada location" => $no_loc > 0 ? "***" : "0",
"Belum ada PJ" => $no_ihs_pj,
"Ready Encounter" => $ready_encounter,
"Total Order" => $total_order,
"Percentage" => $percentage
];
}
$this->print_table($result, array_keys($result[0]));
}
function status($date = "", $edate = "", $json = "")
{
$sql = "select * from one_health_clinic.client";
$qry = $this->db->query($sql);
$satu_sehat = "N";
if ($qry) {
$rows = $qry->result_array();
if (count($rows) > 0) $satu_sehat = "Y";
};
if ($date == "") {
$date = date("Y-m-d");
}
$sdate = "$date 00:00:00";
if ($edate == "") {
$edate = date("Y-m-d");
}
$edate = "$edate 23:59:59";
$sql = "select
date(oneOrderDate) oneOrderDate,
oneOrderStatus Status, count(*) Jumlah
, '' Note
,oneOrderEncounterID
from one_health_clinic.one_order
join m_branch on M_BranchIsActive = 'Y'
and M_BranchIsDefault = 'Y'
and oneOrderDate >= ?
and oneOrderDate <= ?
group by date(oneOrderDate),M_BranchCode,oneOrderStatus";
$qry = $this->db->query($sql, [$sdate, $edate]);
$this->error_check($qry, "get status");
$rows = $qry->result_array();
$arr_code = [];
$result = [];
$idx = 0;
$total_order = 0;
$dt_total = [];
foreach ($rows as $r) {
$total_order += $r["Jumlah"];
$rdate = $r["oneOrderDate"];
if (!isset($dt_total[$rdate])) {
$dt_total[$rdate] = 0;
}
$dt_total[$rdate] += $r["Jumlah"];
}
if ($json != "") {
Header("Content-Type: application/json");
echo json_encode(["status" => "OK", "data" => $rows, "satu_sehat" => $satu_sehat, "total" => $total_order]);
exit;
}
$total_order = 0;
$result = [];
$rec_no_pj = [];
$discharge_status = [];
$result_klinisi = [];
$total_order_klinisi = [];
foreach ($rows as $idx => $r) {
$status = $r["Status"];
$rdate = $r["oneOrderDate"];
$encounterID = $r["oneOrderEncounterID"];
$jumlah = $r["Jumlah"];
if (!isset($result[$rdate])) {
$result[$rdate] = [
"Date" => $rdate,
"Tanpa NIK" => 0,
"Invalid NIK" => 0,
"Pasien No IHS" => 0,
"No IHS" => 0,
"Encounter Ready" => 0,
"Submitted" => 0,
"NO PJ" => 0,
];
}
switch ($status) {
case "NonNIK":
$result[$rdate]["Tanpa NIK"] += $jumlah;
break;
case "InvNIK":
$result[$rdate]["Invalid NIK"] += $jumlah;
break;
case "NonIHS":
$result[$rdate]["Pasien No IHS"] += $jumlah;
break;
case "SubReady":
$result[$rdate]["Encounter Ready"] += $jumlah;
break;
case "SubOK":
$result[$rdate]["Submitted"] += $jumlah;
//Ok pasti ready
$result[$rdate]["Encounter Ready"] += $jumlah;
break;
case "NoIHSPJ":
$result[$rdate]["NO PJ"] += $jumlah;
$rec_no_pj[] = $r;
break;
default:
$result[$rdate]["Other"] += $jumlah;
break;
}
}
$xrows = [];
$pre_s = "<font style='color:brown'>";
$pre_k = "<font style='color:blue'>";
$post_f = "</font>";
foreach ($result as $k => $r) {
$r["Total Order"] = $dt_total[$k] . " $post_f";
$r["Tanpa NIK"] = $r["Tanpa NIK"] . " $post_f ";
$r["Invalid NIK"] = $r["Invalid NIK"] . " $post_f";
$r["Pasien No IHS"] = $r["Pasien No IHS"] . " $post_f";
$r["Encounter Ready"] = $r["Encounter Ready"] . " $post_f";
$r["Percentage"] = number_format(($r["Submitted"]) / ($dt_total[$k]) * 100, 0);
unset($r["Discharge Ready"]);
unset($r["Discharge Not Ready"]);
unset($r["Encounter Ready"]);
$xrows[] = $r;
}
$month = date("F", strtotime($sdate));
echo "<H3 class='pe-status'>Status Encounter </H3>";
echo "<H4 class='pe-status'>Bulan: $month </H4>";
// echo "<H4 class='pe-status'>* : order , $pre_s * $post_f : w/o sample, Percentage : Submitted / Total Order ( sample only tidak di hitung) </H4>";
$this->print_table($xrows, array_keys($xrows[0]));
if (count($rec_no_pj) > 0) {
$sql = "select oneOrderDate, oneOrderOrderID, oneOrderOrderNumber,
oneOrderM_DoctorName, oneOrderM_DoctorID,oneOrderM_DoctorIhsID
from one_health_clinic.one_order
where oneOrderDate>= ? and oneOrderDate <= ?
and oneOrderStatus = 'NoIHSPJ' ";
$qry = $this->db->query($sql, [$sdate, $edate]);
$this->error_check($qry, "get status");
$rows = $qry->result_array();
echo "<H4 style='margin-top:0px;margin-bottom:20px'>PJ Issue</H4>";
$this->print_table($rows, array_keys($rows[0]));
}
}
function status_old($date = "", $json = "")
{
$sql = "select * from one_health_clinic.client";
$qry = $this->db->query($sql);
$satu_sehat = "N";
if ($qry) {
$rows = $qry->result_array();
if (count($rows) > 0) $satu_sehat = "Y";
};
$inp_date = $date;
if ($date == "") {
$date = date("Y-m-d");
}
$sdate = "$date 00:00:00";
$edate = "$date 23:59:59";
if ($date == "x") {
$sdate = date("Y-m-d", strtotime("now - 30 day")) . " 00:00:00";
$edate = date("Y-m-d 23:59:59");
}
$sql = "select
oneOrderStatus Status, count(*) Jumlah
, '' Note
from one_health_clinic.one_order
join m_branch on M_BranchIsActive = 'Y'
and M_BranchIsDefault = 'Y'
and oneOrderDate >= ?
and oneOrderDate <= ?
group by M_BranchCode,oneOrderStatus";
$qry = $this->db->query($sql, [$sdate, $edate]);
$this->error_check($qry, "get status");
$rows = $qry->result_array();
$arr_code = [];
$result = [];
$idx = 0;
$total_order = 0;
foreach ($rows as $r) {
$total_order += $r["Jumlah"];
}
if ($json != "") {
Header("Content-Type: application/json");
echo json_encode(["status" => "OK", "data" => $rows, "satu_sehat" => $satu_sehat, "total" => $total_order]);
exit;
}
$total_order = 0;
foreach ($rows as $idx => $r) {
$status = $r["Status"];
switch ($status) {
case "NonNIK":
$rows[$idx]["Note"] = "Tanpa NIK";
break;
case "InvNIK":
$rows[$idx]["Note"] = "Invalid NIK";
break;
case "NonIHS":
$rows[$idx]["Note"] = "NIK belum terdaftar IHS";
break;
case "SubReady":
$rows[$idx]["Note"] = "Ready Encounter";
break;
case "SubOK":
$rows[$idx]["Note"] = "Encounter OK";
break;
}
$total_order += $r["Jumlah"];
}
echo "<H3 style='margin-bottom:0px;'>Status Encounter </H3>";
echo "<H4 style='margin-top:0px;margin-bottom:0px'>Tanggal : $sdate - $edate</H4>";
echo "<H4 style='margin-top:0px;margin-bottom:0px'>Total Order: {$total_order} </H4></br>";
$this->print_table($rows, array_keys($rows[0]));
$sql = "select OHDoctorMapM_DoctorID M_DoctorID, OhDoctorMapM_DoctorName M_DoctorName,
OHDoctorMapIHSNumber IHSNumber, OHDoctorMapNIK NIK from one_health_clinic.oh_doctor_map";
$qry = $this->db->query($sql, [$sdate, $edate]);
$this->error_check($qry, "get register doctor");
$rows = $qry->result_array();
echo "<H4 style='margin-top:0px;margin-bottom:0px'>Dokter terdaftar </H4></br>";
$this->print_table($rows, array_keys($rows[0]));
$sql = "select distinct oneOrderM_DoctorID M_DoctorID, oneOrderM_DoctorName M_DoctorName
from one_health_clinic.one_order
where oneOrderStatus = 'NoIHSPJ'
and oneOrderDate >= ? and oneOrderDate <= ?";
$qry = $this->db->query($sql, [$sdate, $edate]);
$this->error_check($qry, "get register doctor");
$rows = $qry->result_array();
echo "<H4 style='margin-top:0px;margin-bottom:0px'>Dokter tanpa IHS</H4></br>";
$this->print_table($rows, array_keys($rows[0]));
}
function submit($sdate, $edate = "")
{
if ($edate == "") {
$edate = $sdate;
}
$sdate = "$sdate 00:00:00";
$edate = "$edate 23:59:59";
$sql = "select one_order.*
from one_health_clinic.one_order
where oneOrderStatus = 'SubReady'
and oneOrderDate >= ? and oneOrderDate <= ?
";
$qry = $this->db->query($sql, [$sdate, $edate]);
$rows = $this->error_check($qry, "get one_order SubReady", true);
if (count($rows) == 0) {
echo "\t No Order ";
}
$this->load->library("Satu_sehat");
$this->satu_sehat->load_clinic();
header("Content-Type: text/plain");
$sql_u = "update one_health_clinic.one_order set oneOrderEncounterID = ?,
oneOrderJsonReply=?, oneOrderStatus='SubOK' where oneOrderID = ?";
//insert
$idx = 0;
foreach ($rows as $r) {
//get encounter by subject
$orderID = $r["oneOrderID"];
$patientIhsID = $r["oneOrderM_PatientIhsID"];
$nolab = $r["oneOrderOrderNumber"];
echo "checking $nolab - IHS ID : $patientIhsID \n";
if ($patientIhsID == "") {
echo "\tNo Patient IHS ID\n";
continue;
}
$resp = $this->satu_sehat->encounter_by_subject($patientIhsID);
list($encounterID, $jsonReply) = $this->parse_encounter($resp, $nolab);
if ($encounterID != "") {
echo "\tAlready registered , with encounterID : $encounterID \n";
$qry = $this->db->query($sql_u, [$encounterID, $jsonReply, $orderID]);
$this->error_check($qry, "update encounter\n");
continue;
}
//submit encounter
$h_date = $r["oneOrderDate"];
$patientName = $r["oneOrderM_PatientName"];
$doctorIhsID = $r["oneOrderM_DoctorIhsID"];
$doctorName = $r["oneOrderM_DoctorName"];
$locationID = $r["oneOrderLocationIhsID"];
$locationName = $r["oneOrderLocationName"];
list($encounterID, $message, $payload, $response) = $this->satu_sehat->encounter(
$h_date,
$patientIhsID,
$patientName,
$doctorIhsID,
$doctorName,
$locationID,
$locationName,
$nolab,
"+07:00"
);
if ($encounterID == "") {
echo "*** Error submit encounter : \n";
echo "\t$message \n";
}
$qry = $this->db->query($sql_u, [$encounterID, $response, $orderID]);
$this->error_check($qry, "update encounter new $encounterID\n");
echo "\t OK, EncounterID : $encounterID\n";
$idx++;
if ($idx == 10) {
$idx = 0;
echo "*** sleep 2s ***\n";
sleep(2);
}
}
}
function parse_encounter($resp, $nolab)
{
$entries = $resp["entry"];
foreach ($entries as $e) {
$res = $e["resource"];
//get encounterID
$encounterID = $res["id"];
$r_nolab = $res["identifier"][0]["value"];
if ($r_nolab == $nolab) {
return [$encounterID, json_encode($res)];
}
}
return ["", ""];
}
function run($date = "", $edate = "")
{
header("Content-Type: text/plain");
if ($date == "") {
$date = "2024-04-01";
}
if ($edate == "") {
$edate = date("Y-m-d");
}
$sdate = "$date 00:00:00";
$edate = "$edate 23:59:59";
$sql_i = "insert into one_health_clinic.one_order(
oneOrderDate,oneOrderOrderID,oneOrderOrderNumber, oneOrderOrderNumberExt,
oneOrderM_PatientID, oneOrderM_PatientName, oneOrderM_PatientNIK, oneOrderM_PatientIhsID,
oneOrderM_DoctorID, oneOrderM_DoctorName,oneOrderM_DoctorIhsID,
oneOrderLocationID, oneOrderLocationIhsID, oneOrderLocationName,
oneOrderStatus, oneOrderJsonPayLoad,oneOrderJsonReply,oneOrderEncounterID )
values(?,?,?,?, ?,?,?,?, ?,?,?, ?,?,?, ?,?,?,? )
on duplicate key update
oneOrderLocationID = ?, oneOrderLocationIhsID = ?, oneOrderLocationName = ?,
oneOrderStatus = ?, oneOrderM_DoctorIhsID = ?, oneOrderM_PatientIhsID = ?,
oneOrderJsonPayLoad=?";
$sql = "select orderDate T_OrderHeaderDate,
orderID T_OrderHeaderID,
orderNumber T_OrderHeaderLabNumber,
orderNumber T_OrderHeaderLabNumberExt,
orderM_PatientID T_OrderHeaderM_PatientID,
OHPatientMapIHSNumber,
fn_get_name(orderM_PatientID) patient_name,
if(M_PatientM_IdTypeID = 1, M_PatientIDNumber, '') patientNIK,
orderM_DoctorID T_OrderHeaderPjM_DoctorID, OHDoctorMapIHSNumber,
fn_get_doctor_fullname(orderM_DoctorID) doctor_name,
LocationID, LocationLocalID,LocationDescription
from one_klinik.order
join m_patient on orderM_PatientID = M_PatientID
and orderIsActive = 'Y'
and orderDate >= ?
and orderDate <= ?
left join one_health_clinic.oh_doctor_map
on orderM_DoctorID = OHDoctorMapM_DoctorID
and OHDoctorMapIsActive = 'Y'
left join one_health_clinic.oh_patient_map
on orderM_PatientID = OhPatientMapM_PatientID
and OHPatientMapIsActive = 'Y'
left join one_health_clinic.location on LocationIsActive = 'Y'
and LocationType ='ENCOUNTER_CLINIC'
";
$qry = $this->db->query($sql, [$sdate, $edate]);
$this->error_check($qry, "get order");
$rows = $qry->result_array();
$idx_encounter = 0;
$idx_order = 0;
$idx_blank_nik = 0;
$idx_invalid_nik = 0;
$idx_not_register_nik = 0;
$idx_no_pj = 0;
$idx_no_pj_ihs = 0;
$idx_no_loc = 0;
$this->load->library("Satu_sehat");
$this->satu_sehat->load_clinic();
echo ">> Collect order at $sdate to $edate *** " . count($rows) . " \n";
$idx_ihs_counter = 0;
$new_doctor = [];
foreach ($rows as $r) {
$nolab_internal = $r["T_OrderHeaderLabNumber"];
$nolab = $r["T_OrderHeaderLabNumberExt"];
$h_id = $r["T_OrderHeaderID"];
$h_date = $r["T_OrderHeaderDate"];
$patientID = $r["T_OrderHeaderM_PatientID"];
$patientNIK = trim($r["patientNIK"]);
$patientIhsID = trim($r["OHPatientMapIHSNumber"]);
$patientName = $r["patient_name"];
$doctorID = $r["T_OrderHeaderPjM_DoctorID"];
$doctorName = $r["doctor_name"];
$doctorIhsID = $r["OHDoctorMapIHSNumber"];
$locationID = $r["LocationLocalID"];
$locationName = $r["LocationDescription"];
$locationIhsID = $r["LocationID"];
echo "\tLab No. $nolab_internal : @ $locationIhsID\n";
$idx_order++;
if ($doctorIhsID == "") {
//insert only to new_doctor
if ($doctorID != "") {
$new_doctor[] = [
"M_DoctorID" => $doctorID,
"M_DoctorName" => $doctorName,
];
}
}
if ($patientNIK == "") {
echo "\tblank NIK \n";
$qry = $this->db->query($sql_i, [
$h_date, $h_id, $nolab_internal, $nolab,
$patientID, $patientName, $patientNIK, "",
$doctorID, $doctorName, $doctorIhsID,
$locationID, $locationIhsID, $locationName,
"NonNIK", "", "", "",
$locationID, $locationIhsID, $locationName, "NonNIK", "", "", ""
]);
$this->error_check($qry, "insert one_order NonNIK");
$idx_blank_nik++;
continue;
}
if (strlen($patientNIK) != 16) {
echo "\tInvalid NIK \n";
$qry = $this->db->query($sql_i, [
$h_date, $h_id, $nolab_internal, $nolab,
$patientID, $patientName, $patientNIK, "",
$doctorID, $doctorName, $doctorIhsID,
$locationID, $locationIhsID, $locationName,
"InvNIK", "", "", "",
$locationID, $locationIhsID, $locationName, "InvNIK", "", "", ""
]);
$this->error_check($qry, "insert one_order InvNIK");
$idx_invalid_nik++;
continue;
}
if ($patientIhsID == "") {
echo "\tMapping NIK $patientNIK\n";
$patientIhsID = $this->map_patient(
$patientID,
$patientNIK
);
if ($patientIhsID == "") {
//check patient IHS
echo "\tNon IHS Patient \n";
$qry = $this->db->query($sql_i, [
$h_date, $h_id, $nolab_internal, $nolab,
$patientID, $patientName, $patientNIK, "",
$doctorID, $doctorName, $doctorIhsID,
$locationID, $locationIhsID, $locationName,
"NonIHS", "", "", "",
$locationID, $locationIhsID, $locationName, "NonIHS", "", "", ""
]);
$this->error_check($qry, "insert one_order NonIHS");
$idx_not_register_nik++;
continue;
}
echo "\tHasil patient IHS : $patientIhsID\n";
$idx_ihs_counter++;
if ($idx_ihs_counter == 6) {
$idx_ihs_counter = 0;
echo "\t*** Wait 2s\n";
sleep(2);
}
}
if ($doctorID == "") {
echo "\tNon PJ\n";
$qry = $this->db->query($sql_i, [
$h_date, $h_id, $nolab_internal, $nolab,
$patientID, $patientName, $patientNIK, $patientIhsID,
$doctorID, $doctorName, $doctorIhsID,
$locationID, $locationIhsID, $locationName,
"NonPJ", "", "", "",
$locationID, $locationIhsID, $locationName, "NonPJ", "", $patientIhsID, ""
]);
$this->error_check($qry, "insert one_order NonPJ");
$idx_no_pj++;
continue;
}
if ($doctorIhsID == "") {
echo "\tNon IHS PJ : $patientIhsID \n";
$qry = $this->db->query($sql_i, [
$h_date, $h_id, $nolab_internal, $nolab,
$patientID, $patientName, $patientNIK, $patientIhsID,
$doctorID, $doctorName, $doctorIhsID,
$locationID, $locationIhsID, $locationName,
"NoIHSPJ", "", "", "",
$locationID, $locationIhsID, $locationName, "NoIHSPJ", "", $patientIhsID, ""
]);
$this->error_check($qry, "insert one_order NoIHSPJ");
$idx_no_pj_ihs++;
continue;
}
if ($locationIhsID == "") {
echo "\tNon Location IHS\n";
$qry = $this->db->query($sql_i, [
$h_date, $h_id, $nolab_internal, $nolab,
$patientID, $patientName, $patientNIK, $patientIhsID,
$doctorID, $doctorName, $doctorIhsID,
$locationID, $locationIhsID, $locationName,
"NoLoc", "", "", "",
$locationID, $locationIhsID, $locationName, "NoLoc", $doctorIhsID, $patientIhsID, ""
]);
$this->error_check($qry, "insert one_order NoLoc");
$idx_no_loc++;
continue;
}
list($encounterID, $message, $payload, $response) = $this->satu_sehat->encounter(
$h_date,
$patientIhsID,
$patientName,
$doctorIhsID,
$doctorName,
$locationID,
$locationName,
$nolab,
"+07:00",
true
);
$qry = $this->db->query($sql_i, [
$h_date, $h_id, $nolab_internal, $nolab,
$patientID, $patientName, $patientNIK, $patientIhsID,
$doctorID, $doctorName, $doctorIhsID,
$locationID, $locationIhsID, $locationName,
"SubReady", $payload, "", "",
$locationID, $locationIhsID, $locationName, "SubReady", $doctorIhsID, $patientIhsID, $payload
]);
$this->error_check($qry, "insert ignore one_order SubReady");
$idx_encounter++;
echo "\tReady Encounter\n";
}
echo "Tanggal\t\t\t\t: $date\n";
echo "Tot Order\t\t\t\t: $idx_order\n";
echo " Tanpa NIK\t\t\t\t: $idx_blank_nik\n";
echo " Invalid NIK\t\t\t\t: $idx_invalid_nik\n";
echo " Not register NIK\t\t\t: $idx_not_register_nik\n";
echo " Doctor belum ada\t\t\t\t: $idx_no_pj\n";
echo " Doctor belum terdaftar\t\t\t: $idx_no_pj_ihs\n";
echo "Siap Encounter\t\t\t\t: $idx_encounter\n";
if (count($new_doctor) > 0) {
echo "\nDoctor belum terdaftar\t\t\t: \n";
print_r($new_doctor);
//inject doctor
$this->clinic_add_doctor($new_doctor);
}
}
function clinic_add_doctor($doctors)
{
$sql = "insert ignore into one_health_clinic.oh_doctor_map(OHDoctorMapM_DoctorID,OHDoctorMapM_DoctorName)
value (?,?)";
foreach ($doctors as $d) {
$qry = $this->db->query($sql, [$d["M_DoctorID"], $d["M_DoctorName"]]);
$this->error_check($qry, "Add Doctor Clinic");
}
}
function check_location($branchID)
{
$sql = "select * from location
where locationBranchID = ?
and locationIsActive='Y'
and locationType = 'ENCOUNTER_LAB'
order by locationID desc";
$qry = $this->db->query($sql, [$branchID]);
$this->error_check($qry, "check location map $branchID");
$rows = $qry->result_array();
if (count($rows) > 0) {
return [
$rows[0]["LocationLocalID"],
$rows[0]["LocationID"],
$rows[0]["LocationDescription"]
];
}
return ["", ""];
}
function check_pj($branchID)
{
$sql = "select * from map_doctor
where mapDoctorBranchID = ?
and mapDoctorIsActive='Y'
order by mapDoctorID desc";
$qry = $this->db->query($sql, [$branchID]);
$this->error_check($qry, "check doctor map $branchID");
$rows = $qry->result_array();
if (count($rows) > 0) {
return [
$rows[0]["mapDoctorM_DoctorID"], $rows[0]["mapDoctorName"],
$rows[0]["mapDoctorIhsID"]
];
}
return [0, "", ""];
}
function map_patient($patientID, $patientNIK)
{
$ihsID = $this->satu_sehat->search_patient_by_nik($patientNIK);
if ($ihsID != "") {
$sql = "insert into one_health.oh_patient_map(OHPatientMapM_PatientID,
OHPatientMapIHSNumber)
values(?,?)";
$qry = $this->db->query($sql, [$patientID, $ihsID]);
$this->error_check($qry, "insert oh_patient_map");
if (!$qry) return "";
}
return $ihsID;
}
//helper
//
function error_check($qry, $stage, $check_empty = false)
{
if (!$qry) {
echo json_encode(
[
"status" => "ERR",
"stage" => $stage,
"message" => $this->db->error(),
"sql" => $this->db->last_query()
]
);
exit;
}
if ($check_empty) {
$rows = $qry->result_array();
if (count($rows) == 0) {
echo json_encode(
[
"status" => "ERR",
"stage" => $stage,
"message" => "No record found",
"sql" => $this->db->last_query()
]
);
exit;
}
return $rows;
}
}
function print_table($rows, $keys)
{
$this->print_table_style();
echo "<table class='pe-status'>";
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>";
}
function print_table_style()
{
echo "
<style>
.pe-status th, .pe-status td {
padding: 15px;
text-align: left;
}
.pe-status tr:nth-child(even) {background-color: #f2f2f2;}
table.pe_status {
border: solid 1px ;
min-width:600px;
}
</style>
";
}
}