"; 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/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"]; $rec_no_pj = []; 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"]; $rec_no_pj[] = $r; 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, "Encounter Ready" => $ready_encounter, "Total Order" => $total_order, "Percentage" => $percentage ]; } $this->print_table($result, array_keys($result[0])); } function check_organization() { $sql = "select * from one_health.organization"; $qry = $this->db->query($sql); $this->error_check($qry, "get organization"); $rows = $qry->result_array(); if (count($rows) == 0) { echo "Organization not Registered Yet !"; exit; } if ($rows[0]["organizationID"] == "") { echo "Organization not Registered Yet !"; exit; } $sql = "select * from one_health.client"; $qry = $this->db->query($sql); $rows = $qry->result_array(); $this->error_check($qry, "get client"); if (count($rows) == 0) { echo "Client not Registered Yet !"; exit; } } //discard status sample only and rujukan internal function status_discard($date = "", $edate = "", $json = "") { 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, sum(if(oneOrderReadyDischarged = 'Y',1,0)) Ready, sum(if(oneOrderReadyDischarged = 'Y',0,1)) NotReady, sum(if(oneOrderIsRujukanInternal= 'Y',0,1)) RujukanInternal, sum(if(oneOrderIsSampleOnly= 'Y',0,1)) SampleOnly from one_health.one_order join m_branch on M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y' and oneOrderDate >= ? and oneOrderDate <= ? and (oneOrderStatus = 'SubReady' or oneOrderStatus = 'SubOk' ) group by date(oneOrderDate)"; $qry = $this->db->query($sql, [$sdate, $edate]); $this->error_check($qry, "get discharged status"); $rows = $qry->result_array(); $result = []; foreach ($rows as $r) { $rdate = $r["oneOrderDate"]; $result[$rdate] = [ "ready" => $r["Ready"], "not_ready" => $r["NotReady"], "rujukan_internal" => $r["RujukanInternal"], "sample_only" => $r["SampleOnly"], "is_klinisi" => $r["IsKlinisi"], ]; } return $result; } function status($date = "", $edate = "", $json = "") { $this->check_organization(); $sql = "select * from one_health.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 , oneOrderIsSampleOnly, '' Note , oneOrderIsRadiologi, oneOrderIsElektromedis, oneOrderIsMedisLain, oneOrderEncounterID from one_health.one_order join m_branch on M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y' and oneOrderDate >= ? and oneOrderDate <= ? group by date(oneOrderDate),M_BranchCode,oneOrderStatus,oneOrderIsSampleOnly"; $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 = $this->status_discard($sdate, $edate); $result_sample_only = []; $total_order_wo_sample = []; $result_klinisi = []; $total_order_klinisi = []; foreach ($rows as $idx => $r) { $status = $r["Status"]; $sampleOnly = $r["oneOrderIsSampleOnly"]; $rdate = $r["oneOrderDate"]; $encounterID = $r["oneOrderEncounterID"]; $jumlah = $r["Jumlah"]; if (!isset($total_order_wo_sample[$rdate])) { $total_order_wo_sample[$rdate] = 0; } if (!isset($total_order_klinisi[$rdate])) { $total_order_klinisi[$rdate] = 0; } if ($sampleOnly == "Y") { $total_order_wo_sample[$rdate] += $jumlah; } $isGroupKlinisi = "N"; if ( $r["oneOrderIsRadiologi"] == "Y" || $r["oneOrderIsElektromedis"] == "Y" || $r["oneOrderIsMedisLain"] == "Y" ) { $total_order_klinisi[$rdate] += $jumlah; $isGroupKlinisi = "Y"; } if (!isset($result[$rdate])) { $result[$rdate] = [ "Date" => $rdate, "Tanpa NIK" => 0, "Invalid NIK" => 0, "Pasien No IHS" => 0, "Encounter Ready" => 0, "Submitted" => 0, "NO PJ" => 0, "Discharge Ready" => $discharge_status[$rdate]["ready"], "Discharge Not Ready" => $discharge_status[$rdate]["not_ready"], ]; $result_sample_only[$rdate] = [ "Tanpa NIK" => 0, "Invalid NIK" => 0, "Pasien No IHS" => 0, "Encounter Ready" => 0, ]; $result_klinisi[$rdate] = [ "Tanpa NIK" => 0, "Invalid NIK" => 0, "Pasien No IHS" => 0, "Encounter Ready" => 0, ]; } switch ($status) { case "NonNIK": $result[$rdate]["Tanpa NIK"] += $jumlah; if ($sampleOnly == "Y") { $result_sample_only[$rdate]["Tanpa NIK"] += $jumlah; } if ($isGroupKlinisi == "Y") { $result_klinisi[$rdate]["Tanpa NIK"] += $jumlah; } break; case "InvNIK": $result[$rdate]["Invalid NIK"] += $jumlah; if ($sampleOnly == "Y") { $result_sample_only[$rdate]["Invalid NIK"] += $jumlah; } if ($isGroupKlinisi == "Y") { $result_klinisi[$rdate]["Invalid NIK"] += $jumlah; } break; case "NonIHS": $result[$rdate]["Pasien No IHS"] += $jumlah; if ($sampleOnly == "Y") { $result_sample_only[$rdate]["Pasien No IHS"] += $jumlah; } if ($isGroupKlinisi == "Y") { $result_klinisi[$rdate]["Pasien No IHS"] += $jumlah; } break; case "SubReady": $result[$rdate]["Encounter Ready"] += $jumlah; if ($sampleOnly == "Y") { $result_sample_only[$rdate]["Encounter Ready"] += $jumlah; } if ($isGroupKlinisi == "Y") { $result_klinisi[$rdate]["Encounter Ready"] += $jumlah; } break; case "SubOK": $result[$rdate]["Submitted"] += $jumlah; //Ok pasti ready $result[$rdate]["Encounter Ready"] += $jumlah; if ($sampleOnly == "Y") { $result_sample_only[$rdate]["Encounter Ready"] += $jumlah; } if ($isGroupKlinisi == "Y") { $result_klinisi[$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 = ""; $pre_k = ""; $post_f = ""; foreach ($result as $k => $r) { $r["Total Order"] = $dt_total[$k] . " / $pre_s {$total_order_wo_sample[$k]} $post_f"; $r["Tanpa NIK"] = $r["Tanpa NIK"] . " / $pre_s" . $result_sample_only[$k]["Tanpa NIK"] . "$post_f "; $r["Invalid NIK"] = $r["Invalid NIK"] . " / $pre_s " . $result_sample_only[$k]["Invalid NIK"] . "$post_f"; $r["Pasien No IHS"] = $r["Pasien No IHS"] . " / $pre_s" . $result_sample_only[$k]["Pasien No IHS"] . "$post_f"; $r["Encounter Ready"] = $r["Encounter Ready"] . " / $pre_s" . $result_sample_only[$k]["Encounter Ready"] . "$post_f"; $r["Percentage"] = number_format(($r["Submitted"]) / ($dt_total[$k] - $total_order_wo_sample[$k]) * 100, 0); unset($r["NO PJ"]); unset($r["Discharge Ready"]); unset($r["Discharge Not Ready"]); unset($r["Encounter Ready"]); $xrows[] = $r; } $month = date("F", strtotime($sdate)); echo "

Status Encounter

"; echo "

Bulan: $month

"; echo "

* : order , $pre_s * $post_f : w/o sample, Percentage : Submitted / Total Order ( sample only tidak di hitung)

"; $this->print_table($xrows, array_keys($xrows[0])); if (count($rec_no_pj) > 0) { $sql = "select oneOrderDate, oneOrderT_OrderHeaderID, oneOrderT_OrderHeaderLabNumber, oneOrderM_DoctorName, oneOrderM_DoctorID,oneOrderM_DoctorIhsID from one_health.one_order where oneOrderDate>= ? and oneOrderDate <= ? and oneOrderStatus = 'NoIHSPJ' "; $qry = $this->db->query($sql, [$sdate, $edate]); $rows = $qry->result_array(); echo "

PJ Issue

"; $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.one_order where oneOrderStatus = 'SubReady' and oneOrderIsSampleOnly='N' and oneOrderDate >= ? and oneOrderDate <= ? "; $qry = $this->db->query($sql, [$sdate, $edate]); $this->error_check($qry, "get one_order SubReady and sampleOnly N", false); $rows = $qry->result_array(); if (count($rows) == 0) { echo "\t No Order "; } $this->load->library("Satu_sehat"); header("Content-Type: text/plain"); $sql_u = "update one_health.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["oneOrderT_OrderHeaderLabNumber"]; 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 get_doctor_pj() { $sql = "select * from one_health.oh_doctor_map where OHDoctorMapIsActive = 'Y'"; $qry = $this->db->query($sql); $this->error_check($qry, "get doctoc pj"); $rows = $qry->result_array(); if (count($rows) == 0) { return [0, "", ""]; } return [$rows[0]["OHDoctorMapM_DoctorID"], $rows[0]["OhDoctorMapM_DoctorName"], $rows[0]["OHDoctorMapIHSNumber"]]; } // kriteria : sudah valid semua // PromiseDate terakhir + 2 jam atau fixed time at 21:00 for example function close($date = "") { if ($date == "") { $date = date("Y-m-d"); } $date = "$date 00:00:00"; $sql = "select T_OrderHeaderID, T_OrderHeaderDate, max(T_OrderPromiseDateTime) T_OrderPromiseDate, max(T_OrderDetailValDate) T_OrderDetailValDate, group_concat(distinct T_OrderDetailValidation) GroupValidation from t_orderheader join one_health.one_order on T_OrderHeaderID=oneOrderT_OrderHeaderID and T_OrderHeaderDate >= ? and oneOrderIsDischarged = 'N' join t_orderpromise on T_OrderHeaderID = T_OrderPromiseT_OrderHeaderID and T_OrderPromiseIsActive ='Y' join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID and T_OrderDetailIsActive = 'Y' and T_OrderDetailT_TestIsResult = 'Y' group by T_OrderHeaderID order by T_OrderHeaderDate"; $qry = $this->db->query($sql, [$date]); $this->error_check($qry, "Get Promise Validation"); $rows = $qry->result_array(); $sql_u = "update one_health.one_order set oneOrderMaxPromise = ?,oneOrderReadyDischarged = ? where oneOrderT_OrderHeaderID = ?"; $total_row = 0; $total_ready = 0; echo "Checking Encounter Discharged for " . count($rows) . " order.\n"; foreach ($rows as $r) { $orderID = $r["T_OrderHeaderID"]; $groupValidation = $r["GroupValidation"]; $maxPromiseDate = $r["T_OrderPromiseDate"]; $readyDischarge = "N"; if ($groupValidation == "Y") { $readyDischarge = "Y"; $total_ready++; } echo "."; $qry = $this->db->query($sql_u, [$maxPromiseDate, $readyDischarge, $orderID]); $this->error_check($qry, "update one_order $orderID"); $total_row++; } echo "\nUpdate Encounter total : $total_row , ready discharged $total_ready\n"; } function get_natgroup($sdate, $edate) { $sql = "select T_OrderHeaderID, group_concat( distinct if(T_TestNat_GroupID = 2,'Y','') ) IsRadiologi, group_concat( distinct if(T_TestNat_GroupID = 3,'Y','') ) IsElektromedis, group_concat( distinct if(T_TestNat_GroupID = 4,'Y','') ) IsMedisLain from t_orderheader join t_orderdetail on T_OrderHeaderIsActive = 'Y' and T_OrderHeaderDate >= ? and T_OrderHeaderDate <= ? and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID and T_OrderDetailIsActive = 'Y' join t_test on T_OrderDetailT_TestID = T_TestID group by T_OrderHeaderID "; $qry = $this->db->query($sql, [$sdate, $edate]); $this->error_check($qry, "get order"); $rows = $qry->result_array(); $result = []; foreach ($rows as $r) { $id = $r["T_OrderHeaderID"]; if (!isset($result[$id])) $result[$id] = []; $result[$id]["IsRadiologi"] = $r["IsRadiologi"] == "" ? "N" : "Y"; $result[$id]["IsElektromedis"] = $r["IsElektromedis"] == "" ? "N" : "Y"; $result[$id]["IsMedisLain"] = $r["IsMedisLain"] == "" ? "N" : "Y"; } return $result; } function run($date = "", $edate = "") { header("Content-Type: text/plain"); $this->check_organization(); 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.one_order( oneOrderDate,oneOrderT_OrderHeaderID,oneOrderT_OrderHeaderLabNumber, oneOrderT_OrderHeaderLabNumberExt, oneOrderM_PatientID, oneOrderM_PatientName, oneOrderM_PatientNIK, oneOrderM_PatientIhsID, oneOrderM_DoctorID, oneOrderM_DoctorName,oneOrderM_DoctorIhsID, oneOrderLocationID, oneOrderLocationIhsID, oneOrderLocationName, oneOrderStatus, oneOrderJsonPayLoad,oneOrderJsonReply,oneOrderEncounterID, oneOrderIsSampleOnly, oneOrderIsRujukanInternal, oneOrderSendToFO, oneOrderIsRadiologi, oneOrderIsElektromedis, oneOrderIsMedisLain ) values(?,?,?,?, ?,?,?,?, ?,?,?, ?,?,?, ?,?,?,?, ?,?,? ,?,?,?) on duplicate key update oneOrderLocationID = ?, oneOrderLocationIhsID = ?, oneOrderLocationName = ?, oneOrderM_DoctorID = ?, oneOrderM_DoctorName = ?,oneOrderM_DoctorIhsID = ? , oneOrderStatus = ?, oneOrderIsSampleOnly = ? , oneOrderIsRujukanInternal = ?, oneOrderSendToFO = ?, oneOrderIsRadiologi = ?, oneOrderIsElektromedis = ? , oneOrderIsMedisLain = ?, oneOrderM_PatientIhsID = ? "; $sql = "select T_OrderHeaderDate, T_OrderHeaderID, T_OrderHeaderLabNumber, T_OrderHeaderLabNumberExt, T_OrderHeaderM_PatientID, OHPatientMapIHSNumber, fn_get_name(T_OrderHeaderM_PatientID) patient_name, if(M_PatientM_IdTypeID = 1, M_PatientIDNumber, '') patientNIK, LocationID, LocationLocalID,LocationDescription, T_OrderHeaderReceivedSample IsSampleOnly, if (T_OrderHeaderAddOnLabNumberOrigin is null, 'N', 'Y') IsRujukanInternal, max(Result_ProcessToOfficeSendTime) SendToFO from t_orderheader join m_patient on T_OrderHeaderM_PatientID = M_PatientID and T_OrderHeaderIsActive = 'Y' and T_OrderHeaderDate >= ? and T_OrderHeaderDate <= ? join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID left join result_processtooffice on T_OrderHeaderID = Result_ProcessToOfficeT_OrderHeaderID and Result_ProcessToOfficeIsActive = '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' left join one_health.location on LocationIsActive = 'Y' and LocationType ='ENCOUNTER_LAB' where T_OrderHeaderID not in ( select oneOrderT_OrderHeaderID from one_health.one_order where oneOrderDate >= ? and oneOrderDate <= ? and oneOrderStatus = 'SubOK' ) group by T_OrderHeaderID "; $qry = $this->db->query($sql, [$sdate, $edate, $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; $arr_nonlab = $this->get_natgroup($sdate, $edate); $this->load->library("Satu_sehat"); echo ">> Collect order $sdate to $edate *** " . count($rows) . " \n"; $idx_ihs_counter = 0; list($doctorID, $doctorName, $doctorIhsID) = $this->get_doctor_pj(); 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"]; $sendToFO = $r["SendToFO"]; $isRadiologi = $arr_nonlab[$h_id]["IsRadiologi"]; $isElektromedis = $arr_nonlab[$h_id]["IsElektromedis"]; $isMedisLain = $arr_nonlab[$h_id]["IsMedisLain"]; // $doctorID = $r["T_OrderHeaderPjM_DoctorID"]; // $doctorName = $r["doctor_name"]; // $doctorIhsID = $r["OHDoctorMapIHSNumber"]; $IsSampleOnly = $r["IsSampleOnly"]; $IsRujukanInternal = $r["IsRujukanInternal"]; $locationID = $r["LocationLocalID"]; $locationName = $r["LocationDescripti n"]; $locationIhsID = $r["LocationID"]; echo "\tLab No. $nolab_internal $h_id [$isRadiologi $isElektromedis $isMedisLain] \n"; $idx_order++; 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", "", "", "", $IsSampleOnly, $IsRujukanInternal, $sendToFO, $isRadiologi, $isElektromedis, $isMedisLain, $locationID, $locationIhsID, $locationName, $doctorID, $doctorName, $doctorIhsID, "NonNIK", $IsSampleOnly, $IsRujukanInternal, $sendToFO, $isRadiologi, $isElektromedis, $isMedisLain, $patientIhsID ]); $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", "", "", "", $IsSampleOnly, $IsRujukanInternal, $sendToFO, $isRadiologi, $isElektromedis, $isMedisLain, $locationID, $locationIhsID, $locationName, $doctorID, $doctorName, $doctorIhsID, "InvNIK", $IsSampleOnly, $IsRujukanInternal, $sendToFO, $isRadiologi, $isElektromedis, $isMedisLain, $patientIhsID ]); $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", "", "", "", $IsSampleOnly, $IsRujukanInternal, $sendToFO, $isRadiologi, $isElektromedis, $isMedisLain, $locationID, $locationIhsID, $locationName, $doctorID, $doctorName, $doctorIhsID, "NonIHS", $IsSampleOnly, $IsRujukanInternal, $sendToFO, $isRadiologi, $isElektromedis, $isMedisLain, $patientIhsID ]); $this->error_check($qry, "insert one_order NonIHS"); $idx_not_register_nik++; continue; } $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", "", "", "", $IsSampleOnly, $IsRujukanInternal, $sendToFO, $isRadiologi, $isElektromedis, $isMedisLain, $locationID, $locationIhsID, $locationName, $doctorID, $doctorName, $doctorIhsID, "NonPJ", $IsSampleOnly, $IsRujukanInternal, $sendToFO, $isRadiologi, $isElektromedis, $isMedisLain, $patientIhsID ]); $this->error_check($qry, "insert one_order NonPJ"); $idx_no_pj++; continue; } if ($doctorIhsID == "") { echo "\tNon IHS 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, "NoIHSPJ", "", "", "", $IsSampleOnly, $IsRujukanInternal, $sendToFO, $isRadiologi, $isElektromedis, $isMedisLain, $locationID, $locationIhsID, $locationName, $doctorID, $doctorName, $doctorIhsID, "NoIHSPJ", $IsSampleOnly, $IsRujukanInternal, $sendToFO, $isRadiologi, $isElektromedis, $isMedisLain, $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", "", "", "", $IsSampleOnly, $IsRujukanInternal, $sendToFO, $isRadiologi, $isElektromedis, $isMedisLain, $locationID, $locationIhsID, $locationName, $doctorID, $doctorName, $doctorIhsID, "NoLoc", $IsSampleOnly, $IsRujukanInternal, $sendToFO, $isRadiologi, $isElektromedis, $isMedisLain, $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, "", "", $IsSampleOnly, $IsRujukanInternal, $sendToFO, $isRadiologi, $isElektromedis, $isMedisLain, $locationID, $locationIhsID, $locationName, $doctorID, $doctorName, $doctorIhsID, "SubReady", $IsSampleOnly, $IsRujukanInternal, $sendToFO, $isRadiologi, $isElektromedis, $isMedisLain, $patientIhsID ]); $this->error_check($qry, "insert duplicate one_order SubReady"); $idx_encounter++; echo "\tEncounter Ready\n"; } echo "Tanggal\t\t\t\t: $sdate to $edate\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 " PJ belum ada\t\t\t\t: $idx_no_pj\n"; echo " PJ belum terdaftar\t\t\t: $idx_no_pj_ihs\n"; echo "Siap Encounter\t\t\t\t: $idx_encounter\n"; } 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 ""; echo ""; foreach ($keys as $k) { echo ""; } echo "\n"; foreach ($rows as $r) { echo ""; foreach ($keys as $k) { echo ""; } echo ""; } echo "
$k
" . $r[$k] . "
"; } function print_table_style() { echo " "; } }