Initial import

This commit is contained in:
sas.fajri
2026-04-27 10:26:26 +07:00
commit bf9b9097ee
2388 changed files with 3002242 additions and 0 deletions

View File

@@ -0,0 +1,549 @@
<?php
class 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()
{
$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"];
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 = "", $json = "")
{
$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:01";
$edate = "$date 23:59:59";
$sql = "select
oneOrderStatus Status, count(*) Jumlah
, '' Note
from one_health.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 : $date</H4>";
echo "<H4 style='margin-top:0px;margin-bottom:0px'>Total Order: {$total_order} </H4></br>";
$this->print_table($rows, array_keys($rows[0]));
}
function submit()
{
$sql = "select one_order.*, branchName
from one_order join branch on oneOrderBranchID = branchID
where oneOrderStatus = 'SubReady'
";
$qry = $this->db->query($sql);
$rows = $this->error_check($qry, "get one_order SubReady", true);
$this->load->library("Satu_sehat");
header("Content-Type: text/plain");
$sql_u = "update one_order set oneOrderEncounterID = ?,
oneOrderJsonReply=?, oneOrderStatus='SubOK' where oneOrderID = ?";
//insert
foreach ($rows as $r) {
//get encounter by subject
$branchID = $r["oneOrderBranchID"];
$branchName = $r["branchName"];
$orderID = $r["oneOrderID"];
$patientIhsID = $r["oneOrderM_PatientIhsID"];
$nolab = $r["oneOrderT_OrderHeaderLabNumber"];
echo "checking $branchName $nolab \n";
$resp = $this->satusehat->encounter_by_subject($branchID, $patientIhsID);
list($encounterID, $jsonReply) = $this->parse_encounter($resp, $nolab);
if ($encounterID != "") {
echo "success : $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->satusehat->encounter(
$branchID,
$h_date,
$patientIhsID,
$patientName,
$doctorIhsID,
$doctorName,
$locationID,
$locationName,
$nolab,
"+07:00"
);
if ($encounterID == "") {
echo "*** Error submit encounter : \n";
echo "$message \n";
}
$qry = $this->db->query($sql_u, [$encounterID, $response, $orderID]);
$this->error_check($qry, "update encounter new $encounterID\n");
echo "\t OK\n";
}
}
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 = "")
{
header("Content-Type: text/plain");
if ($date == "") {
$date = date("Y-m-d");
}
$sdate = "$date 00:00:00";
$edate = "$date 23:59:59";
$sql_i = "insert ignore 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 )
values(?,?,?,?, ?,?,?,?, ?,?,?, ?,?,?, ?,?,?,? )";
$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,
T_OrderHeaderPjM_DoctorID, OHDoctorMapIHSNumber,
fn_get_doctor_fullname(T_OrderHeaderPjM_DoctorID) doctor_name,
LocationID, LocationLocalID,LocationDescription
from t_orderheader
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
and T_OrderHeaderIsActive = 'Y'
and T_OrderHeaderDate >= ?
and T_OrderHeaderDate <= ?
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'
";
$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");
echo ">> Collect order at $date *** " . count($rows) . " \n";
$idx_ihs_counter = 0;
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\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", "", "", ""
]);
$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", "", "", ""
]);
$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", "", "", ""
]);
$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", "", "", ""
]);
$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", "", "", ""
]);
$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", "", "", ""
]);
$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, "",
$doctorID, $doctorName, $doctorIhsID,
$locationID, $locationIhsID, $locationName,
"SubReady", $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 " 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 "<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>";
}
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>
";
}
}

View File

@@ -0,0 +1,377 @@
<?php
class Ihs_location extends MY_Controller
{
function __construct()
{
parent::__construct();
}
function devone($stage = "")
{
if ($stage == "") {
$branches = [
"matraman", "bonjer", "samanhudi", "ragunan",
"riau", "toha", "pajajaran", "cimahi",
"ngagel", "aditya", "mulyo", "parkus", "hrm"
];
}
if ($stage == "jakarta") {
$branches = [
"matraman", "bonjer", "samanhudi", "ragunan",
];
}
if ($stage == "surabaya") {
$branches = [
"ngagel", "aditya", "mulyo", "parkus", "hrm"
];
}
if ($stage == "bandung") {
$branches = [
"riau", "toha", "pajajaran", "cimahi",
];
}
if ($stage == "jabar") {
$branches = [
"cirebon", "tasik", "summarecon",
];
}
if ($stage == "jateng") {
$branches = [
"tegal", "semarang", "salatiga", "magelang", "sultanagung", "cikditiro", "madiun"
];
}
if ($stage == "jatim") {
$branches = [
"dupang", "wonokusumo", "simokerto"
];
}
if ($stage == "sima") {
$branches = [
"kediri", "ciliwung", "tangkubanprahu", "jember", "tulungagung"
];
}
if ($stage == "timur") {
$branches = [
"balikpapan", "pontianak", "makassar", "hertasning", "denpasar", "manado"
];
}
if ($stage == "sumatra") {
$branches = [
"dipo", "yamin", "dahlan", "veteran", "plaju", "yani", "sudirman", "hasyim"
];
}
$result = [];
foreach ($branches as $b) {
$url = "http://$b/one-api/tools/satu_sehat/ihs_location/by_organization/x";
$j_resp = file_get_contents($url);
$resp = json_decode($j_resp, true);
foreach ($resp["data"] as $d) {
// $d["Branch ID"] .= "|$b";
$result[] = $d;
}
$resp["data"] = [];
}
$this->print_table($result, array_keys($result[0]));
}
function by_organization($json = "")
{
$sql = "select M_BranchID,M_BranchName,
organizationID, LocationID, LocationCode,
LocationDescription, LocationType
from m_branch
join one_health.organization
on M_BranchIsActive ='Y' and M_BranchIsDefault = 'Y'
and organizationIsActive = 'Y'
join one_health.location on locationIsActive = 'Y'
order by M_BranchCode
";
$qry = $this->db->query($sql);
$this->error_check($qry, "Get Default Branch Org Loc");
$this->load->library("Satu_sehat");
$rows = $qry->result_array();
if ($json != "") {
header("Content-Type: application/json");
}
$result = [];
$this->satu_sehat->get_organization_id();
foreach ($rows as $r) {
$branchID = $r["M_BranchID"];
$branchName = $r["M_BranchName"];
$dbOrgID = $r["organizationID"];
$dbLocID = $r["LocationID"];
$dbLocCode = $r["LocationCode"] . "|" . $r["LocationType"];
$dbLocName = $r["LocationDescription"];
$j_org = $this->satu_sehat->ss_organization($branchID);
$org = json_decode($j_org, true);
$orgType = $org["Type"];
$orgID = $org["ID"];
$orgName = $org["Name"];
$resp = $this->satu_sehat->location_by_organization($dbOrgID);
$result[] = [
"Branch Name" => $branchName,
"Reg Org Type" => $orgType,
"Reg Org ID" => $orgID,
"DB Org ID" => $dbOrgID,
"Reg Loc Managing Org" => "-",
"Reg Org Name" => "-",
"Reg Loc ID" => "-",
"DB Loc ID" => $dbLocID,
"Reg Loc Name" => "-",
"Reg Loc Code" => "-",
"DB Loc Code" => $dbLocCode,
"DB Loc Name" => $dbLocName,
"Reg Loc Status" => "-",
];
$result_idx = count($result) - 1;
foreach ($resp["entry"] as $lr) {
$resource = $lr["resource"];
$locId = $resource["id"];
$locIdentifier = $resource["identifier"][0]["value"];
$locDesc = $resource["description"];
$locStatus = $resource["status"];
if ($locStatus != "active") {
$locStatus = "<font style='color:red'>$locStatus</font>";
}
$managingOrg = $resource["managingOrganization"]["reference"];
$managingOrg = str_replace("Organization/", "", $managingOrg);
$result[$result_idx] = [
"Branch Name" => $branchName,
"Reg Org Type" => $orgType,
"Reg Org ID" => $orgID,
"DB Org ID" => $dbOrgID,
"Reg Loc Managing Org" => $managingOrg,
"Reg Org Name" => $orgName,
"Reg Loc ID" => $locId,
"DB Loc ID" => $dbLocID,
"DB Loc Name" => $dbLocName,
"Reg Loc Code" => $locIdentifier,
"DB Loc Code" => $dbLocCode,
"Reg Loc Status" => $locStatus,
];
}
}
if ($json != "") {
echo json_encode(["status" => "OK", "data" => $result]);
exit;
}
$this->print_table($result, array_keys($result[0]));
}
function un_register($locationID)
{
$sql = "select * from location where LocationLocalID = ?";
$qry = $this->db->query($sql, [$locationID]);
$rows = $this->error_check($qry, "get location [$locationID]", true);
$locationID = $rows[0]["LocationID"];
$branchID = $rows[0]["LocationBranchID"];
echo "unregistering location $locationID {$rows[0]["LocationDescription"]} at {$branchID} \n";
$this->load->library("Satu_sehat");
$resp = $this->satu_sehat->location_nonactive($locationID);
if (isset($resp["id"])) {
echo "success [OK]\n";
} else {
echo "failed : " . print_r($resp, true);
}
}
function register()
{
$sql = "select l.*,
case
when LocationPhysicalTypeCode = 'si' then 1
when LocationPhysicalTypeCode = 'bu' then 2
when LocationPhysicalTypeCode = 'lvl' then 3
when LocationPhysicalTypeCode = 'ro' then 4
end xid
from one_health.location l
where
locationIsActive = 'Y'
and trim(LocationID) = ''
order by xid";
$qry = $this->db->query($sql);
$this->error_check($qry, "get location order by phy type code");
$rows = $qry->result_array();
$this->load->library("Satu_sehat");
foreach ($rows as $r) {
$code = $r["LocationCode"];
$name = $r["LocationName"];
$description = $r["LocationDescription"];
$type = $r["LocationPhysicalTypeCode"] . "^" . $r["LocationPhysicalTypeDisplay"];
$lat = $r["LocationLatitude"];
$long = $r["LocationLongitude"];
$parentID = $r["LocationParentLocalID"];
$partOf = $this->get_parent_id($parentID);
// echo "$code | $name | $description | $type | $lat | $long | $parentID | $partOf \n";
list($phone, $fax, $email, $url) = $this->get_phone_email($r["LocationLocalID"]);
// echo "$phone | $fax | $email | $url \n";
list($line, $city, $admCode, $postalCode, $rt, $rw) = $this->get_address($r["LocationLocalID"]);
// echo "$line | $city | $admCode | $postalCode| $rt | $rw \n";
// register location
$resp = $this->satu_sehat->location_create(
"$code",
$name,
"$description",
"$line",
"$city",
"$postalCode",
"$admCode",
"$rt",
"$rw",
"$phone",
"$type",
$partOf,
$email,
$fax,
$url,
$long,
$lat
);
echo "\nid : " . $resp["id"];
echo "\nname : " . $resp["name"];
if (isset($resp["id"]) && $resp["id"] != "") {
$sql = "update one_health.location
set LocationID = ? where LocationLocalID = ?";
$qry = $this->db->query($sql, [$resp["id"], $r["LocationLocalID"]]);
$this->error_check($qry, "update location from ihs");
} else {
echo "\nError inguiry IHS Location ID: \n";
print_r($resp);
echo "\n";
exit;
}
}
}
function get_parent_id($parentID)
{
if ($parentID == 0) return "";
$sql = "select l.*
from one_health.location l
where LocationLocalID = ?";
$qry = $this->db->query($sql, [$parentID]);
$this->error_check($qry, "get parent location");
$rows = $qry->result_array();
if (count($rows) == 0) {
return "";
}
return $rows[0]["LocationID"];
}
function get_address($localID)
{
$sql = "select * from
one_health.location_address where LocationAddressLocationLocalID = ?
and LocationAddresIsActive = 'Y'";
$qry = $this->db->query($sql, [$localID]);
$this->error_check($qry, "get address");
$rows = $qry->result_array();
$line = "";
$city = "";
$code = "";
$postalCode = "";
$rt = "";
$rw = "";
foreach ($rows as $r) {
$line = $r["LocationAddresLine"];
$city = $r["LocationAddresCityName"];
$code = $r["LocationAddresVillage"];
$postalCode = $r["LocationAddresPostalCode"];
$rt = $r["LocationAddresRT"];
$rw = $r["LocationAddresRW"];
}
return [$line, $city, $code, $postalCode, $rt, $rw];
}
function get_phone_email($localID)
{
$sql = "select * from
one_health.location_telecom where LocationTelecomLocationID = ?
and LocationIsActive = 'Y'";
$qry = $this->db->query($sql, [$localID]);
$this->error_check($qry, "get telecom");
$rows = $qry->result_array();
$email = "";
$fax = "";
$url = "";
$phone = "";
foreach ($rows as $r) {
$system = $r["LocationSystem"];
switch ($system) {
case "phone":
$phone = $r["LocationValue"];
break;
case "fax":
$fax = $r["LocationValue"];
break;
case "email":
$email = $r["LocationValue"];
break;
case "url":
$url = $r["LocationValue"];
break;
}
}
return [$phone, $fax, $email, $url];
}
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" => $this->db->error(),
"sql" => $this->db->last_query()
]
);
exit;
}
return $rows;
}
}
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>";
}
}

View File

@@ -0,0 +1 @@
GET http://ngagel/one-api/tools/satu_sehat/mapper/doctor_pj/2024-03-21

View File

@@ -0,0 +1,255 @@
<?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;
}
}
}

View File

@@ -0,0 +1,363 @@
<?php
class Resource 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/>";
echo "Organization ID: " . $this->organizationID ;
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;
}
}

View File

@@ -0,0 +1,30 @@
create table one_order (
oneOrderID int not null auto_increment primary key,
oneOrderDate datetime,
oneOrderT_OrderHeaderID int,
oneOrderT_OrderHeaderLabNumber varchar(20),
oneOrderT_OrderHeaderLabNumberExt varchar(20),
oneOrderM_PatientID int,
oneOrderM_PatientIhsID varchar(100),
oneOrderM_PatientName varchar(300),
oneOrderM_PatientNIK varchar(32),
oneOrderM_DoctorID int,
oneOrderM_DoctorIhsID varchar(100),
oneOrderM_DoctorName varchar(300),
oneOrderLocationID int,
oneOrderLocationIhsID varchar(100),
oneOrderLocationName varchar(300),
oneOrderStatus varchar(10) default 'New' comment 'SubOK:Submit OK, SubERR: Submit Error, SubReady: Submit Ready,NonNIK: No NIK, InvNIK : Invalid NIK, NonIHS: No IHS ID, NonPJ: PJ belum terdaftar, NoIHSPj: PJ belum register, NoLoc: Location not registered,New: New Order',
oneOrderJsonPayload text,
oneOrderJsonReply text,
oneOrderEncounterID varchar(100),
oneOrderCreated datetime default current_timestamp(),
oneOrderLastUpdated datetime default current_timestamp()
on update current_timestamp(),
key(oneOrderT_OrderHeaderID),
key(oneOrderM_DoctorName),
key(oneOrderM_PatientName),
key(oneOrderStatus),
key(oneOrderEncounterID),
unique(oneOrderT_OrderHeaderID)
);