336 lines
14 KiB
PHP
336 lines
14 KiB
PHP
<?php
|
|
class Newpatientv2 extends MY_Controller
|
|
{
|
|
var $db;
|
|
var $load;
|
|
var $satusehat;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->library('Satusehat');
|
|
}
|
|
function index()
|
|
{
|
|
echo "Satu Sehat New Patient";
|
|
}
|
|
function getnewpatient()
|
|
{
|
|
try {
|
|
$prm = $this->sys_input;
|
|
$patientID = $prm['patientID'];
|
|
$maritalStatusCode = $prm['maritalStatusCode'];
|
|
$maritalStatusName = $prm['maritalStatusName'];
|
|
$multipleBirth = $prm['multipleBirth'];
|
|
$citizeship = $prm['citizeship'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
//cek db one_health patient sudah ada atau belum
|
|
$sql = "SELECT * FROM one_health.oh_patient_map
|
|
WHERE OHPatientMapM_PatientID = ?
|
|
AND OHPatientMapIsActive = 'Y'";
|
|
$qry = $this->db->query($sql, [$patientID]);
|
|
$last_qry = $this->db->last_query();
|
|
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$result_cek = $qry->result_array();
|
|
|
|
|
|
if (count($result_cek) == 0) {
|
|
$patientJSON = [];
|
|
$sql = "SELECT M_PatientID,
|
|
M_PatientNoReg,
|
|
M_PatientMR,
|
|
M_PatientPrefix,
|
|
M_PatientName,
|
|
M_PatientM_TitleID,
|
|
M_PatientSuffix,
|
|
M_PatientM_SexID,
|
|
CASE
|
|
WHEN M_PatientM_SexID = '1' THEN 'male'
|
|
WHEN M_PatientM_SexID = '2' THEN 'female'
|
|
END AS gender,
|
|
M_PatientInitialVisit,
|
|
M_PatientLastVisit,
|
|
M_PatientM_ReligionID,
|
|
M_PatientPOB,
|
|
M_PatientDOB,
|
|
M_PatientHP,
|
|
M_PatientPhone,
|
|
M_PatientEmail,
|
|
M_PatientM_IdTypeID,
|
|
M_PatientIDNumber,
|
|
M_PatientAddressID,
|
|
M_PatientAddressDescription,
|
|
M_KelurahanID,
|
|
M_KelurahanName,
|
|
M_DistrictID,
|
|
M_DistrictName,
|
|
M_CityID,
|
|
M_CityName,
|
|
M_ProvinceID,
|
|
M_ProvinceName
|
|
FROM m_patient
|
|
JOIN m_patientaddress ON M_PatientAddressM_PatientID = M_PatientID AND M_PatientAddressIsActive = 'Y'
|
|
JOIN m_kelurahan ON M_KelurahanID = M_PatientAddressM_KelurahanID
|
|
JOIN m_district ON M_DistrictID = M_KelurahanM_DistrictID
|
|
JOIN m_city ON M_CityID = M_DistrictM_CityID
|
|
JOIN m_province ON M_ProvinceID = M_CityM_ProvinceID
|
|
WHERE M_PatientID = ?
|
|
ORDER BY M_PatientAddressID ASC
|
|
LIMIT 1";
|
|
$qry = $this->db->query($sql, [$patientID]);
|
|
$last_qry = $this->db->last_query();
|
|
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
|
|
$dataBisone = $qry->result_array()[0];
|
|
|
|
$province_ori = $dataBisone['M_ProvinceName'];
|
|
$city_ori = $dataBisone['M_CityName'];
|
|
$district_ori = $dataBisone['M_DistrictName'];
|
|
$village_ori = $dataBisone['M_KelurahanName'];
|
|
|
|
$province = 0;
|
|
$city = 0;
|
|
$district = 0;
|
|
$village = 0;
|
|
|
|
$sqlkel = "SELECT pro_cd,kab_cd,kec_cd,kel_cd
|
|
FROM
|
|
one_health.regional
|
|
WHERE
|
|
regional_nm = '{$village_ori}' AND
|
|
kel_cd <> '000'";
|
|
$qrykel = $this->db->query($sqlkel);
|
|
$last_qrykel = $this->db->last_query();
|
|
$kel_cek = $qrykel->result_array();
|
|
if(count($kel_cek) == 1){
|
|
|
|
$province = $kel_cek[0]['pro_cd'];
|
|
$city = $kel_cek[0]['kab_cd'];
|
|
$district = $kel_cek[0]['kec_cd'];
|
|
$village = $kel_cek[0]['kel_cd'];
|
|
|
|
}elseif(count($kel_cek) > 1){
|
|
|
|
$sqlprov = "SELECT pro_cd FROM one_health.regional WHERE regional_nm = '{$province_ori}' AND
|
|
kel_cd = '000' AND kec_cd = '000' AND kab_cd = '00'";
|
|
$qryprov = $this->db->query($sqlprov);
|
|
$last_qryprov = $this->db->last_query();
|
|
$prov_cek = $qryprov->result_array();
|
|
|
|
$sqlkab = "SELECT GROUP_CONCAT(kab_cd SEPARATOR ',') as xkab FROM one_health.regional
|
|
WHERE regional_nm
|
|
LIKE '%$city_ori%' AND `pro_cd` = $prov_cek[0]['pro_cd']
|
|
AND `kab_cd` != '00' AND `kec_cd` = '000' AND `kec_cd` = '000'";
|
|
$qrykab = $this->db->query($sqlkab);
|
|
$last_qrykab = $this->db->last_query();
|
|
$kab_cek = $qrykab->result_array();
|
|
|
|
$sqldistrict = "SELECT kec_cd FROM one_health.regional
|
|
WHERE regional_nm = '{$district_ori}' AND
|
|
kec_cd <> '000' AND kel_cd = '000'
|
|
AND pro_cd = $prov_cek[0]['pro_cd'] AND kab_cd IN($kab_cek[0]['xkab'])";
|
|
$qrydistrict = $this->db->query($sqldistrict);
|
|
$last_qrydistrict = $this->db->last_query();
|
|
$district_cek = $qrydistrict->result_array();
|
|
|
|
$sqlvillage = "SELECT pro_cd,kab_cd,kec_cd,kel_cd
|
|
FROM one_health.regional WHERE regional_nm = '{$village_ori}' AND
|
|
kel_cd <> '000' AND kec_cd = $district_cek[0]['kec_cd']";
|
|
$qryvillage = $this->db->query($sqlvillage);
|
|
$last_qryvillage = $this->db->last_query();
|
|
$village_cek = $qryvillage->result_array();
|
|
|
|
$province = $village_cek[0]['pro_cd'];
|
|
$city = $village_cek[0]['kab_cd'];
|
|
$district = $village_cek[0]['kec_cd'];
|
|
$village = $village_cek[0]['kel_cd'];
|
|
|
|
}
|
|
|
|
$identifier_system = '';
|
|
if($dataBisone['M_PatientM_IdTypeID'] == 1){
|
|
$identifier_system = "https://fhir.kemenkes.go.id/id/nik";
|
|
}elseif($dataBisone['M_PatientM_IdTypeID'] == 3){
|
|
$identifier_system = "https://fhir.kemenkes.go.id/id/paspor";
|
|
}
|
|
|
|
$patientJSON[] = [
|
|
"fullUrl" => "urn:uuid:{$this->satusehat->gen_uuid()}",
|
|
"resource" => [
|
|
"resourceType" => "Patient",
|
|
"meta" => [
|
|
"profile" => "https://fhir.kemenkes.go.id/r4/StructureDefinition/Patient"
|
|
],
|
|
"identifier"=> [
|
|
[
|
|
"use"=> "official",
|
|
"system"=> $identifier_system,
|
|
"value"=> $dataBisone['M_PatientIDNumber']
|
|
],
|
|
],
|
|
"active" => true,
|
|
"name" => [
|
|
[
|
|
"use" => "official",
|
|
"text" => $dataBisone['M_PatientName']
|
|
]
|
|
],
|
|
"telecom" => [[
|
|
"system" => "phone",
|
|
"value" => $dataBisone['M_PatientHP'],
|
|
"use"=> "mobile"
|
|
],
|
|
[
|
|
"system" => "email",
|
|
"value" => $dataBisone['M_PatientEmail'],
|
|
"use"=> "home"
|
|
]
|
|
],
|
|
"gender" => $dataBisone['gender'],
|
|
"birtDate" => $dataBisone['M_PatientDOB'],
|
|
"deceasedBoolean" => false,
|
|
"address" => [[
|
|
"use" => "home",
|
|
"line" => [$dataBisone['M_PatientAddressDescription']],
|
|
"city" => $dataBisone['M_CityName'],
|
|
"postalCode" => "",
|
|
"country" => "ID",
|
|
"extension" =>[
|
|
"url" => "https://fhir.kemenkes.go.id/r4/StructureDefinition/administrativeCode",
|
|
"extension" => [
|
|
[
|
|
"url" => "province",
|
|
"valueCode" => $province
|
|
],
|
|
[
|
|
"url" => "city",
|
|
"valueCode" => $city
|
|
],
|
|
[
|
|
"url" => "district",
|
|
"valueCode" => $district
|
|
],
|
|
[
|
|
"url" => "village",
|
|
"valueCode" => $village
|
|
],
|
|
[
|
|
"url" => "rt",
|
|
"valueCode" => "0"
|
|
],
|
|
[
|
|
"url" => "rw",
|
|
"valueCode" => "0"
|
|
]
|
|
]
|
|
]
|
|
]],
|
|
"maritalStatus" => [
|
|
"coding" => [[
|
|
"system" => "http://termonilogy.hl7.org/CodeSystem/v3-Marital-Status",
|
|
"code" => $maritalStatusCode,
|
|
"display" => $maritalStatusName
|
|
]],
|
|
"text" => $maritalStatusName
|
|
],
|
|
"multipleBirthInteger" => $multipleBirth,
|
|
"contact" => [[
|
|
"relationship" => [[
|
|
"coding" => [[
|
|
"system" => "",
|
|
"Code" => ""
|
|
]]
|
|
]],
|
|
"name" => [
|
|
"use" => "",
|
|
"text" => ""
|
|
],
|
|
"telecom" => [[
|
|
"system" => "phone",
|
|
"value" => "",
|
|
"use" => "mobile"
|
|
]]
|
|
]],
|
|
"communication" => [[
|
|
"language" => [
|
|
"coding" => [[
|
|
"system" => "urn:ietf:bcp:47",
|
|
"code" => "id-ID",
|
|
"display" => "Indonesian"
|
|
]],
|
|
"text" => "Indonesian"
|
|
],
|
|
"preferred" => true
|
|
]],
|
|
"extension" => [
|
|
["url" => "https://fhir.kemenkes.go.id/r4/StructureDefinition/birtPlace",
|
|
"valueAddress" => [
|
|
"city" => $dataBisone['M_CityName'],
|
|
"country" => "ID"]],
|
|
["url" => "https://fhir.kemenkes.go.id/r4/StructureDefinition/citizenshipStatus",
|
|
"valueCode" => $citizeship]
|
|
]
|
|
]
|
|
];
|
|
|
|
$sql = "INSERT INTO one_health.oh_patient_map
|
|
(OHPatientMapM_PatientID,
|
|
OHPatientMapMaritalStatusCode,
|
|
OHPatientMapMultipleBirth,
|
|
OHPatientMapCitizeship,
|
|
OHPatientMapCreated,
|
|
OHPatientMapUserID)
|
|
VALUES
|
|
(
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
NOW(),
|
|
?
|
|
)";
|
|
$qry = $this->db->query($sql, [
|
|
$patientID,
|
|
$maritalStatusCode,
|
|
$multipleBirth,
|
|
$citizeship,
|
|
0
|
|
]);
|
|
$last_qry = $this->db->last_query();
|
|
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
|
|
echo json_encode($patientJSON);
|
|
|
|
} else {
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|