378 lines
11 KiB
PHP
378 lines
11 KiB
PHP
<?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>";
|
|
}
|
|
}
|