Files
2026-04-27 10:26:26 +07:00

256 lines
7.0 KiB
PHP

<?php
class Mapper extends MY_Controller
{
function __construct()
{
parent::__construct();
}
function nakes_doctor()
{
//get dr pj name
$sql = "select * from one_health.oh_doctor_map limit 0,1";
$qry = $this->db->query($sql);
$this->check_error($qry, "get 1st dokter");
$rows = $qry->result_array();
if (count($rows) > 0) {
$dokter = $rows[0];
} else {
echo "No Dokter found in oh map\n";
exit;
}
$nakes = $this->parse_csv("/home/one/project/one/nakes.csv");
print_r($nakes);
$perc = 0;
echo "check dokter : {$dokter["OhDoctorMapM_DoctorName"]}\n";
foreach ($nakes as $nk) {
if (
strpos($nk["JOB"], "DOKTER") !== false ||
strpos($nk["JOB"], "PJ Lab") !== false ||
strpos($nk["JOB"], "PENANGGUNG JAWAB ") !== false ||
strpos($nk["JOB"], "DPJP") !== false
) {
$sim = similar_text($nk["Nama"], $dokter["OhDoctorMapM_DoctorName"], $perc);
echo "\t{$nk["Nama"]} : {$nk["NIK"]} $sim | $perc \n";
if ($perc > 60) {
$nik = trim($nk["NIK"]);
$sql = "update one_health.oh_doctor_map
set OHDoctorMapNIK = ? where OHDoctorMapID = ?
and OHDoctorMapNIK = ''";
$qry = $this->db->query($sql, [$nik, $dokter["OHDoctorMapID"]]);
$this->check_error($qry, "update nik");
break;
}
}
}
}
function nakes_staff()
{
//get dr pj name
$nakes = $this->parse_csv("/home/one/project/one/nakes.csv");
$keys = ["OHStaffMapM_StaffNIK"];
foreach ($nakes as $nk) {
if (strlen($nk["NIK"]) != 16) continue;
$r = [
"OHStaffMapM_StaffNIK" => $nk["NIK"]
];
if (strpos($nk["Type_faskes"], "KLINIK") !== false) {
continue;
}
if (strpos($nk["JOB"], "DOKTER") == false) {
$this->insert_or_update("one_health.oh_staff_map", $r, $keys);
}
}
}
function ihs_doctor()
{
$sql = "select * from one_health.oh_doctor_map";
$qry = $this->db->query($sql);
$this->check_error($qry, "get un-map doctor");
$rows = $qry->result_array();
if (count($rows) == 0) {
echo " No Pending Doctor Without IHS No\n";
exit;
}
$this->load->library("Satu_sehat");
$sql_u = "update one_health.oh_doctor_map
set OHDoctorMapIhsNumber = ? where OHDoctorMapID = ?";
foreach ($rows as $r) {
$ihsNo = $r["OHDoctorMapIHSNumber"];
if ($ihsNo != "") {
echo " pj ok [$ihsNo]\n";
continue;
}
$ohMapDoctorID = $r["OHDoctorMapID"];
$nik = $r["OHDoctorMapNIK"];
echo "search nik : $nik\n";
if (strlen($nik) != 16) {
echo "*** invalid nik : $nik ***\n";
continue;
}
$j_resp = $this->satu_sehat->search_practicioner_by_nik($nik);
$resp = json_decode($j_resp, true);
if ($resp["status"] == "OK") {
$ihsID = $resp["ihsID"];
echo "ihs found $ihsID\n";
$qry = $this->db->query($sql_u, [$ihsID, $ohMapDoctorID]);
$this->check_error($qry, "update oh_doctor_map ihs number");
} else {
print_r($resp);
}
}
}
function ihs_staff()
{
$sql = "select * from one_health.oh_staff_map
where OHStaffMapIhsNumber= ''
limit 0,15";
$qry = $this->db->query($sql);
$this->check_error($qry, "get un-map staff");
$rows = $qry->result_array();
if (count($rows) == 0) {
echo " No Pending Staff Without IHS No\n";
exit;
}
$this->load->library("Satu_sehat");
$sql_u = "update one_health.oh_staff_map
set OHStaffMapIhsNumber = ? where OHStaffMapID = ?";
foreach ($rows as $r) {
$ohStaffMapID = $r["OHStaffMapID"];
$nik = $r["OHStaffMapM_StaffNIK"];
echo "search nik : $nik\n";
if (strlen($nik) != 16) {
echo "invalid nik $nik\n";
continue;
}
$j_resp = $this->satu_sehat->search_practicioner_by_nik($nik);
$resp = json_decode($j_resp, true);
if ($resp["status"] == "OK") {
$ihsID = $resp["ihsID"];
echo "ihs found $ihsID\n";
$qry = $this->db->query($sql_u, [$ihsID, $ohStaffMapID]);
$this->check_error($qry, "update oh_staff_map ihs number");
} else {
echo "ihs not found nik $nik\n";
}
}
}
function doctor_pj($date = "")
{
if ($date == "") $date = date("Y-m-d");
$sdate = $date . " 00:00:01";
$edate = $date . " 23:59:59";
$sql = "select distinct M_DoctorID OHDoctorMapM_DoctorID,
fn_get_doctor_fullname(M_DoctorID) OHDoctorMapM_DoctorName
from t_orderheader
join m_doctor on T_OrderHeaderDate >= ? and T_OrderHeaderDate <= ?
and T_OrderHeaderPjM_DoctorID= M_DoctorID";
$qry = $this->db->query($sql, [$sdate, $edate]);
$this->check_error($qry, "get disctinct dokter pj");
$rows = $qry->result_array();
$tot_dr = 0;
print_r($rows);
foreach ($rows as $r) {
$this->insert_or_update("one_health.oh_doctor_map", $r, [
"OHDoctorMapM_DoctorID"
]);
$tot_dr++;
}
$sql = "select * from one_health.oh_doctor_map";
$qry = $this->db->query($sql);
$this->check_error($qry, "show doctor map");
print_r($qry->result_array());
}
// helper
function insert_or_update($table, $dt, $keys)
{
$s_where = "";
$param = [];
foreach ($keys as $k) {
if ($s_where != "") {
$s_where .= " and ";
}
$s_where .= " $k = ?";
$param[] = $dt[$k];
}
$sql = "select count(*) as total
from $table
where $s_where ";
$qry = $this->db->query($sql, $param);
$this->check_error($qry, "check exist");
$rows = $qry->result_array();
$status = "Insert";
if (count($rows) > 0) {
if ($rows[0]["total"] > 0) {
foreach ($keys as $k) {
$this->db->where($k, $dt[$k]);
}
$qry = $this->db->update($table, $dt);
$this->check_error($qry, "update $table");
$status = "Update";
} else {
//insert
$qry = $this->db->insert($table, $dt);
$this->check_error($qry, "insert $table");
}
} else {
//insert
$qry = $this->db->insert($table, $dt);
$this->check_error($qry, "insert $table");
}
}
function parse_csv($fname)
{
$data = file_get_contents($fname);
$lines = explode("\r\n", $data);
$is_first = true;
$keys = [];
$result = [];
foreach ($lines as $l) {
if ($is_first) {
$keys = explode(",", $l);
$is_first = false;
continue;
}
$a_l = str_getcsv($l, ",", "\"");
$a_dt = [];
foreach ($keys as $idx => $k) {
$a_dt[$k] = strtoupper($a_l[$idx]);
}
$result[] = $a_dt;
}
return $result;
}
function reply_ok($data)
{
echo json_encode([
"status" => "OK",
"data" => $data
]);
}
function check_error($qry, $stage)
{
if (!$qry) {
echo json_encode([
"status" => "ERR",
"message" => $this->db->error(),
"sql" => $this->db->last_query()
]);
exit;
}
}
}