507 lines
18 KiB
PHP
507 lines
18 KiB
PHP
<?php
|
|
|
|
class Location extends MY_Controller
|
|
{
|
|
var $db;
|
|
var $load;
|
|
var $satusehat;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->library('Satusehat');
|
|
}
|
|
function index()
|
|
{
|
|
echo "Satu Sehat Location";
|
|
}
|
|
|
|
function getorganization()
|
|
{
|
|
try {
|
|
$sql = "SELECT organizationID,
|
|
organizationName
|
|
FROM one_health.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);
|
|
$last_query = $this->db->last_query();
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db("select organization error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"records" => $rows,
|
|
"qry" => $last_query
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function getsystem()
|
|
{
|
|
try {
|
|
$sql = "SELECT * FROM one_terminology.terminology WHERE `attribute_path` = 'Location.telecom.system'";
|
|
$qry = $this->db->query($sql);
|
|
$last_query = $this->db->last_query();
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db("select system error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"records" => $rows,
|
|
"qry" => $last_query
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function getuse()
|
|
{
|
|
try {
|
|
$sql = "SELECT * FROM one_terminology.terminology WHERE `attribute_path` = 'Location.telecom.use'";
|
|
$qry = $this->db->query($sql);
|
|
$last_query = $this->db->last_query();
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db("select use error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"records" => $rows,
|
|
"qry" => $last_query
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function getphysicallocation()
|
|
{
|
|
try {
|
|
$sql = "SELECT * FROM one_terminology.terminology WHERE `attribute_path` = 'location.type'";
|
|
$qry = $this->db->query($sql);
|
|
$last_query = $this->db->last_query();
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db("select lokasi fisik error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"records" => $rows,
|
|
"qry" => $last_query
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function getlocation()
|
|
{
|
|
try {
|
|
$prm = $this->sys_input;
|
|
|
|
$code = $prm["code"];
|
|
$name = $prm["name"];
|
|
$description = $prm["description"];
|
|
$longitude = $prm["longitude"];
|
|
$latitude = $prm["latitude"];
|
|
$altitude = $prm["altitude"];
|
|
$value = $prm["value"];
|
|
$line = $prm["line"];
|
|
$searchaddress = $prm["searchaddress"];
|
|
|
|
$sql = "SELECT organizationID
|
|
FROM one_health.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);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error, $this->db);
|
|
exit;
|
|
}
|
|
$organizationID = $qry->result_array()[0]["organizationID"];
|
|
|
|
$sql = "SELECT * FROM one_terminology.terminology WHERE `attribute_path` = 'Location.telecom.system'";
|
|
$qry = $this->db->query($sql);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error, $this->db);
|
|
exit;
|
|
}
|
|
$row_system = $qry->row_array();
|
|
|
|
$sql = "SELECT * FROM one_terminology.terminology WHERE `attribute_path` = 'Location.telecom.use'";
|
|
$qry = $this->db->query($sql);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error, $this->db);
|
|
exit;
|
|
}
|
|
$row_use = $qry->row_array();
|
|
|
|
$sql = "SELECT * FROM one_terminology.terminology WHERE `attribute_path` = 'location.type'";
|
|
$qry = $this->db->query($sql);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error, $this->db);
|
|
exit;
|
|
}
|
|
$row_physical = $qry->row_array();
|
|
|
|
$province = 0;
|
|
$city = 0;
|
|
$district = 0;
|
|
$village = 0;
|
|
|
|
$sqlkel = "SELECT pro_cd,kab_cd,kec_cd,kel_cd
|
|
FROM
|
|
one_health.regional
|
|
WHERE
|
|
full_name like '%$searchaddress%'";
|
|
$qrykel = $this->db->query($sqlkel);
|
|
$kel_cek = $qrykel->result_array();
|
|
|
|
$province = $kel_cek[0]['pro_cd'];
|
|
$city = $kel_cek[0]['kab_cd'];
|
|
$district = $kel_cek[0]['kec_cd'];
|
|
$village = $kel_cek[0]['kel_cd'];
|
|
|
|
$data_json = [];
|
|
$data_json = [
|
|
"fullUrl" => "urn:uuid:{$this->satusehat->gen_uuid()}",
|
|
"resource" => array(
|
|
"resourceType" => "Location",
|
|
"address" => array(
|
|
array(
|
|
"city" => "",
|
|
"extension" => array(
|
|
"url" => "https://fhir.kemkes.go.id/r4/StructureDefinition/administrativeCode",
|
|
"extension" => array(
|
|
array(
|
|
"url" => "province",
|
|
"valueCode" => $province
|
|
),
|
|
array(
|
|
"url" => "city",
|
|
"valueCode" => $city
|
|
),
|
|
array(
|
|
"url" => "district",
|
|
"valueCode" => $district
|
|
),
|
|
array(
|
|
"url" => "village",
|
|
"valueCode" => $village
|
|
),
|
|
array(
|
|
"url" => "rt",
|
|
"valueCode" => "0"
|
|
),
|
|
array(
|
|
"url" => "rw",
|
|
"valueCode" => "0"
|
|
)
|
|
),
|
|
),
|
|
"line" => array(
|
|
$line
|
|
),
|
|
"postalCode" => "",
|
|
"use" => $row_use["code"]
|
|
)
|
|
),
|
|
"description" => "",
|
|
"code" => "",
|
|
"identifier" => array(
|
|
array(
|
|
"system" => "http://sys-ids.kemkes.go.id/location/1000001",
|
|
"value" => ""
|
|
)
|
|
),
|
|
"managingOrganization" => array(
|
|
"reference" => $organizationID
|
|
),
|
|
"name" => "",
|
|
"physicalType" => array(
|
|
"coding" => array(
|
|
array(
|
|
"code" => $row_physical["code"],
|
|
"display" => $row_physical["display"]
|
|
)
|
|
)
|
|
),
|
|
"position" => array(
|
|
"altitude" => $altitude,
|
|
"latitude" => $latitude,
|
|
"longitude" => $longitude
|
|
),
|
|
"status" => "active",
|
|
"telecom" => array(
|
|
array(
|
|
"system" => $row_system["code"],
|
|
"use" => $row_use["code"],
|
|
"value" => $value
|
|
)
|
|
)
|
|
)
|
|
];
|
|
|
|
$sql = "INSERT INTO one_health.location(
|
|
LocationID,
|
|
LocationOrganizationID,
|
|
LocationCode,
|
|
LocationName,
|
|
LocationDescription,
|
|
LocationPhysicalTypeCode,
|
|
LocationPhysicalTypeDisplay,
|
|
LocationLongitude,
|
|
LocationLatitude,
|
|
LocationAltitude,
|
|
LocationCreated) VALUES(?,?,?,?,?,?,?,?,?,?,NOW())";
|
|
$qry = $this->db->query($sql, [
|
|
$this->satusehat->gen_uuid(),
|
|
$organizationID,
|
|
$code,
|
|
$name,
|
|
$description,
|
|
$$row_physical["code"],
|
|
$row_physical["display"],
|
|
$longitude,
|
|
$latitude,
|
|
$altitude
|
|
]);
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
echo $this->db->last_query();
|
|
$this->sys_error_db("save location error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$insertid = $this->db->insert_id();
|
|
|
|
$sql = "INSERT INTO one_health.location_telecom(
|
|
LocationTelecomLocationID,
|
|
LocationSystem,
|
|
LocationUse,
|
|
LocationValue,
|
|
LocationCreated) VALUES(?,?,?,?,NOW())";
|
|
$qry = $this->db->query($sql, [
|
|
$insertid,
|
|
$row_system["code"],
|
|
$row_use["code"],
|
|
$value
|
|
]);
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
echo $this->db->last_query();
|
|
$this->sys_error_db("save location telecom error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$sql = "INSERT INTO one_health.location_address(
|
|
LocationAddressLocationID,
|
|
LocationAddressUse,
|
|
LocationAddresLine,
|
|
LocationAddresProvince,
|
|
LocationAddresCity,
|
|
LocationAddresDistrict,
|
|
LocationAddresVillage,
|
|
LocationAddresRT,
|
|
LocationAddresRW,
|
|
LocationAddresCreated) VALUES(?,?,?,?,?,?,?,?,?,NOW())";
|
|
$qry = $this->db->query($sql, [
|
|
$insertid,
|
|
$row_use["code"],
|
|
$line,
|
|
$province,
|
|
$city,
|
|
$district,
|
|
$village,
|
|
0,
|
|
0
|
|
]);
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
echo $this->db->last_query();
|
|
$this->sys_error_db("save location address error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$json_encodelocation = json_encode($data_json);
|
|
echo $json_encodelocation;
|
|
exit;
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
function addlocation()
|
|
{
|
|
try {
|
|
$this->db->trans_begin();
|
|
$prm = $this->sys_input;
|
|
|
|
$code = $prm["code"];
|
|
$name = $prm["name"];
|
|
$description = $prm["description"];
|
|
$physicaltypecode = $prm["physicaltypecode"];
|
|
$physicaltypedisplay = $prm["physicaltypedisplay"];
|
|
$longitude = $prm["longitude"];
|
|
$latitude = $prm["latitude"];
|
|
$altitude = $prm["altitude"];
|
|
|
|
$sql = "SELECT organizationID
|
|
FROM one_health.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);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error, $this->db);
|
|
exit;
|
|
}
|
|
|
|
$organizationID = $qry->result_array()[0]["organizationID"];
|
|
|
|
$sql = "INSERT INTO one_health.location(
|
|
LocationID,
|
|
LocationOrganizationID,
|
|
LocationCode,
|
|
LocationName,
|
|
LocationDescription,
|
|
LocationPhysicalTypeCode,
|
|
LocationPhysicalTypeDisplay,
|
|
LocationLongitude,
|
|
LocationLatitude,
|
|
LocationAltitude,
|
|
LocationCreated) VALUES(?,?,?,?,?,?,?,?,?,?,NOW())";
|
|
$qry = $this->db->query($sql, [
|
|
$this->satusehat->gen_uuid(),
|
|
$organizationID,
|
|
$code,
|
|
$name,
|
|
$description,
|
|
$physicaltypecode,
|
|
$physicaltypedisplay,
|
|
$longitude,
|
|
$latitude,
|
|
$altitude
|
|
]);
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
echo $this->db->last_query();
|
|
$this->sys_error_db("save location error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$insertid = $this->db->insert_id();
|
|
|
|
$sql = "INSERT INTO one_health.location_telecom(
|
|
LocationTelecomLocationID,
|
|
LocationSystem,
|
|
LocationUse,
|
|
LocationValue,
|
|
LocationCreated) VALUES(?,?,?,?,NOW())";
|
|
$qry = $this->db->query($sql, [
|
|
$insertid,
|
|
$prm["system"],
|
|
$prm["telecomuse"],
|
|
$prm["value"]
|
|
]);
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
echo $this->db->last_query();
|
|
$this->sys_error_db("save location telecom error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$sql = "INSERT INTO one_health.location_address(
|
|
LocationAddressLocationID,
|
|
LocationAddressUse,
|
|
LocationAddresLine,
|
|
LocationAddresProvince,
|
|
LocationAddresCity,
|
|
LocationAddresDistrict,
|
|
LocationAddresVillage,
|
|
LocationAddresRT,
|
|
LocationAddresRW,
|
|
LocationAddresCreated) VALUES(?,?,?,?,?,?,?,?,?,NOW())";
|
|
$qry = $this->db->query($sql, [
|
|
$insertid,
|
|
$prm["addressuse"],
|
|
$prm["line"],
|
|
$prm["province"],
|
|
$prm["city"],
|
|
$prm["district"],
|
|
$prm["village"],
|
|
$prm["rt"],
|
|
$prm["rw"]
|
|
]);
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
echo $this->db->last_query();
|
|
$this->sys_error_db("save location address error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"affected_rows" => $this->db->affected_rows()
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|