2411 lines
68 KiB
PHP
2411 lines
68 KiB
PHP
<?php
|
|
class Patient extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "Patient API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
$this->db_oneklinik = $this->load->database("onedev", true);
|
|
// $this->db_antrione = $this->load->database("antrione", true);
|
|
// $this->IP_SOCKET_IO = "devone.aplikasi.web.id";
|
|
|
|
$this->IP_SOCKET_IO = "localhost";
|
|
//$one_db = "one_aditya";
|
|
}
|
|
|
|
// country terminology
|
|
public function getCountryTerminology()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "SELECT
|
|
code,
|
|
display,
|
|
display_en,
|
|
code_system
|
|
FROM
|
|
terminology
|
|
WHERE status_cd = 'normal'
|
|
AND attribute_path = 'Address.country'
|
|
AND resource_type = 'Address'
|
|
AND code_system = 'urn:iso:std:iso:3166'
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("terminology select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
|
|
$result = array(
|
|
"records" => $rows,
|
|
"sql" => $this->db_onedev->last_query()
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// blood type terminology
|
|
public function getBloodTypeTerminology($code = '')
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$where = "";
|
|
|
|
if (!empty($code)) {
|
|
$where = " AND code = '$code'";
|
|
}
|
|
|
|
$sql = "SELECT
|
|
code,
|
|
display,
|
|
display_en,
|
|
code_system
|
|
FROM
|
|
terminology
|
|
WHERE status_cd = 'normal'
|
|
AND attribute_path = 'Person.blood.type'
|
|
AND resource_type = 'Person'
|
|
AND code_system = 'http://loinc.org'
|
|
$where
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("terminology select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
|
|
$result = array(
|
|
"records" => $rows,
|
|
"sql" => $this->db_onedev->last_query()
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// blood rhesus terminology
|
|
public function getBloodRhesusTerminology()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "SELECT
|
|
code,
|
|
display,
|
|
display_en,
|
|
code_system
|
|
FROM
|
|
terminology
|
|
WHERE status_cd = 'normal'
|
|
AND attribute_path = 'Person.blood.rhesus'
|
|
AND resource_type = 'Person'
|
|
AND code_system = 'http://snomed.info/sct'
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("terminology select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
|
|
$result = array(
|
|
"records" => $rows,
|
|
"sql" => $this->db_onedev->last_query()
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// education terminology
|
|
public function getEducationTerminology()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "SELECT
|
|
code,
|
|
display,
|
|
display_en,
|
|
code_system
|
|
FROM
|
|
terminology
|
|
WHERE status_cd = 'normal'
|
|
AND attribute_path = 'Person.education'
|
|
AND resource_type = 'Person'
|
|
AND code_system = 'xhis.code.education.level'
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("terminology select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
|
|
$result = array(
|
|
"records" => $rows,
|
|
"sql" => $this->db_onedev->last_query()
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// kewarganegaraan hardcode
|
|
public function getKewarganegaraanHarcode()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$result = array(
|
|
"records" => [
|
|
array("M_PatientCitizenship" => "WNI"),
|
|
array("M_PatientCitizenship" => "WNA")
|
|
]
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// jenis kelamin hardcode
|
|
public function getJenisKelaminHarcode($M_PatientGender = '')
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$result = [];
|
|
|
|
if (!empty($M_PatientGender)) {
|
|
if ($M_PatientGender === "male") {
|
|
$result = array(
|
|
"records" => [
|
|
array("M_PatientGender" => "male")
|
|
// array("M_PatientGender" => "female")
|
|
]
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$result = array(
|
|
"records" => [
|
|
// array("M_PatientGender" => "male"),
|
|
array("M_PatientGender" => "female")
|
|
]
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
}
|
|
} else {
|
|
$result = array(
|
|
"records" => [
|
|
array("M_PatientGender" => "male"),
|
|
array("M_PatientGender" => "female")
|
|
]
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// etnicity
|
|
public function getEtnicityTerminology()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "SELECT
|
|
code,
|
|
display,
|
|
display_en,
|
|
code_system
|
|
FROM
|
|
terminology
|
|
WHERE status_cd = 'normal'
|
|
AND attribute_path = 'Person.etnicity'
|
|
AND resource_type = 'Person'
|
|
AND code_system = 'xhis.code.etnicity'
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("terminology select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
|
|
$result = array(
|
|
"records" => $rows,
|
|
"sql" => $this->db_onedev->last_query()
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// religion
|
|
public function getReligionTerminology()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "SELECT
|
|
code,
|
|
display,
|
|
display_en,
|
|
code_system
|
|
FROM
|
|
terminology
|
|
WHERE status_cd = 'normal'
|
|
AND attribute_path = 'Person.religion.code'
|
|
AND resource_type = 'Person'
|
|
AND code_system = 'xcpone.code.religion'
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("terminology select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
|
|
$result = array(
|
|
"records" => $rows,
|
|
"sql" => $this->db_onedev->last_query()
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// identifier (tanda pengenal)
|
|
public function getIdentifierTerminology()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "SELECT
|
|
code,
|
|
display,
|
|
display_en,
|
|
code_system
|
|
FROM
|
|
terminology
|
|
WHERE status_cd = 'normal'
|
|
AND attribute_path = 'Person.identifier.type'
|
|
AND resource_type = 'Person'
|
|
AND code_system = 'http://terminology.hl7.org/CodeSystem/v2-0203'
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("terminology select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
|
|
$result = array(
|
|
"records" => $rows,
|
|
"sql" => $this->db_onedev->last_query()
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// sapaan
|
|
public function getSapaan()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$query = " SELECT *
|
|
FROM m_title
|
|
WHERE
|
|
M_TitleIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
// wilayah regional
|
|
public function searchwilayah()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$search = $prm['search'];
|
|
|
|
$sql = "SELECT
|
|
r.regional_cd,
|
|
r.regional_cd AS id,
|
|
r.regional_nm,
|
|
r.full_name AS text_nm,
|
|
r.pro_cd, IFNULL(pro.regional_nm,'') AS pro_nm,
|
|
r.kab_cd, IFNULL(kab.regional_nm,'') AS kab_nm,
|
|
r.kec_cd, IFNULL(kec.regional_nm,'') AS kec_nm,
|
|
r.kel_cd, IFNULL(kel.regional_nm,'') AS kel_nm,
|
|
r.status_cd, r.old_nm
|
|
FROM regional r
|
|
LEFT JOIN regional pro ON CONCAT(r.pro_cd, REPEAT('0', 8)) = pro.regional_cd
|
|
LEFT JOIN regional kab ON CONCAT(r.pro_cd, r.kab_cd, REPEAT('0', 6)) = kab.regional_cd
|
|
LEFT JOIN regional kec ON CONCAT(r.pro_cd, r.kab_cd, r.kec_cd, REPEAT('0', 3)) = kec.regional_cd
|
|
LEFT JOIN regional kel ON CONCAT(r.pro_cd, r.kab_cd, r.kec_cd, r.kel_cd) = kel.regional_cd
|
|
WHERE (MATCH(r.full_name) AGAINST('%$search%' IN BOOLEAN MODE)
|
|
OR r.full_name LIKE '%$search%'
|
|
OR r.regional_nm LIKE '%$search%'
|
|
OR r.full_name REGEXP '$search'
|
|
OR r.regional_nm REGEXP '$search'
|
|
OR LOWER(r.full_name) LIKE LOWER('%$search%')
|
|
OR LOWER(r.regional_nm) LIKE LOWER('%$search%'))
|
|
LIMIT 100
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("search wilayah select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
|
|
$result = array(
|
|
"records" => $rows,
|
|
"sql" => $this->db_onedev->last_query()
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
// search filter
|
|
public function search()
|
|
{
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 100;
|
|
$tot_count = 0;
|
|
$number_limit = 10;
|
|
$number_offset = (!isset($prm['current_page']) ? 1 : $prm['current_page'] - 1) * $number_limit;
|
|
|
|
// $q = [
|
|
// 'noreg' => "",
|
|
// 'name' => '',
|
|
// 'hp' => '',
|
|
// 'dob' => '',
|
|
// 'address' => '',
|
|
// 'nik' => ''
|
|
// ];
|
|
|
|
// $q_pid = "";
|
|
|
|
// if ($prm['noreg'] != '')
|
|
// $q['noreg'] = "AND M_PatientNoReg like '%{$prm['noreg']}%'";
|
|
|
|
// if ($prm['snorm'] == '') {
|
|
// if ($prm['search'] != '') {
|
|
// $e = explode('+', $prm['search']);
|
|
// if (isset($e[0])) {
|
|
// $e[0] = str_replace("'", "\\'", $e[0]);
|
|
// $q['name'] = "AND M_PatientName LIKE '%{$e[0]}%'";
|
|
// }
|
|
// if (isset($e[1]))
|
|
// $q['hp'] = "AND ((M_PatientHP LIKE '%{$e[1]}%' and M_PatientHP IS NOT NULL) OR (M_PatientHP IS NULL AND '{$e[1]}' = ''))";
|
|
// if (isset($e[2]))
|
|
// $q['dob'] = "AND ((DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE '%{$e[2]}%' and M_PatientDOB IS NOT NULL) OR (M_PatientDOB IS NULL AND '{$e[2]}' = ''))";
|
|
// if (isset($e[3]))
|
|
// $q['address'] = "AND M_PatientAddressDescription LIKE '%{$e[3]}%'";
|
|
// if (isset($e[4]))
|
|
// $q['nik'] = "AND M_PatientIDNumber = '{$e[4]}'";
|
|
// }
|
|
// } else {
|
|
// $q_pid = "AND M_PatientNoReg = '{$prm['snorm']}'";
|
|
// }
|
|
|
|
// if ($prm['snorm'] != '' || $prm['search'] != '') {
|
|
|
|
$where = " AND d.M_PatientName LIKE '%{$prm['search']}%'";
|
|
|
|
$sql = "SELECT
|
|
'N' AS divider,
|
|
d.M_PatientID,
|
|
d.M_PatientM_TitleID,
|
|
d.M_PatientNoReg,
|
|
d.M_PatientPrefix,
|
|
d.M_PatientName,
|
|
d.M_PatientSuffix,
|
|
d.M_PatientM_SexID,
|
|
DATE_FORMAT(d.M_PatientDOB, '%d-%m-%Y') AS M_PatientDOB,
|
|
d.M_PatientReligionCode,
|
|
d.M_PatientReligionSystem,
|
|
d.M_PatientBloodTypeCode,
|
|
d.M_PatientBloodTypeSystem,
|
|
d.M_PatientBloodRhCode,
|
|
d.M_PatientBloodRhSystem,
|
|
d.M_PatientEducationCode,
|
|
d.M_PatientEducationSystem,
|
|
d.M_PatientCitizenship,
|
|
d.M_PatientEtnicCode,
|
|
d.M_PatientEtnicSystem,
|
|
d.M_PatientIdentifierCode,
|
|
d.M_PatientIdentifierSystem,
|
|
d.M_PatientIdentifierValue,
|
|
d.M_PatientHp,
|
|
d.M_PatientEmail,
|
|
d.M_PatientPhoto,
|
|
d.M_PatientPhotoLastUpdated,
|
|
d.M_PatientPhotoLastUpdatedUserID,
|
|
pa.M_PatientAddressID,
|
|
pa.M_PatientAddressDescription,
|
|
pa.M_PatientAddressRegionalCd,
|
|
pa.M_PatientAddressRT,
|
|
pa.M_PatientAddressRW,
|
|
pa.M_PatientAddressCity,
|
|
pa.M_PatientAddressVillage,
|
|
pa.M_PatientAddressDistrict,
|
|
pa.M_PatientAddressState,
|
|
pa.M_PatientAddressCountry,
|
|
d.M_PatientIsActive,
|
|
d.M_PatientCreated,
|
|
d.M_PatientCreatedUserID,
|
|
d.M_PatientLastUpdated,
|
|
d.M_PatientLastUpdatedUserID,
|
|
d.M_PatientDeletedUserID,
|
|
d.M_PatientDeleted,
|
|
s.M_SexID,
|
|
s.M_SexCode,
|
|
s.m_sexname,
|
|
'' as title,
|
|
'' as bloodtype,
|
|
'' as bloodrhesus,
|
|
'' as education,
|
|
'' as kewarganegaraan,
|
|
'' as etnicity,
|
|
'' as religion,
|
|
'' as identifier,
|
|
'' as specialist,
|
|
'' as country,
|
|
'' as wilayah
|
|
FROM m_patient as d
|
|
LEFT JOIN m_sex s ON d.M_PatientM_SexID = s.M_SexID
|
|
LEFT JOIN m_patientaddress pa ON d.M_PatientID = pa.M_PatientAddressM_PatientID
|
|
AND M_PatientAddressIsActive = 'Y'
|
|
WHERE d.M_PatientIsActive = 'Y'
|
|
$where
|
|
GROUP BY d.M_PatientID
|
|
ORDER BY d.M_PatientID DESC
|
|
LIMIT $number_limit offset $number_offset";
|
|
|
|
// echo $sql;
|
|
// exit;
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
foreach ($rows as $k => $v) {
|
|
$M_PatientM_TitleID = $v['M_PatientM_TitleID'];
|
|
$rows[$k]['title'] = array();
|
|
$rows[$k]['gender'] = array();
|
|
$rows[$k]['bloodtype'] = array();
|
|
$rows[$k]['bloodrhesus'] = array();
|
|
$rows[$k]['education'] = array();
|
|
$rows[$k]['kewarganegaraan'] = array();
|
|
$rows[$k]['etnicity'] = array();
|
|
$rows[$k]['religion'] = array();
|
|
$rows[$k]['identifier'] = array();
|
|
$rows[$k]['specialist'] = array();
|
|
$rows[$k]['country'] = array();
|
|
$rows[$k]['wilayah'] = array();
|
|
|
|
// title / sapaan
|
|
$sql_title = "SELECT
|
|
M_TitleID,
|
|
M_TitleName,
|
|
M_TitleM_SexID,
|
|
M_TitleLangName,
|
|
M_TitleOrder,
|
|
M_TitleIsActive,
|
|
M_TitleCreated,
|
|
M_TitleLastUpdated
|
|
FROM
|
|
m_title
|
|
WHERE M_TitleIsActive = 'Y'
|
|
AND M_TitleID = $M_PatientM_TitleID";
|
|
|
|
$qry = $this->db_onedev->query($sql_title);
|
|
if (!$qry) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_title count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$row_t = $qry->result_array();
|
|
$rows[$k]['title'] = $row_t;
|
|
|
|
// gender
|
|
// $result_gender = [];
|
|
// if (!empty($v['M_PatientM_SexID'])) {
|
|
// if ($v['M_PatientM_SexID'] === "male") {
|
|
// $result_gender = array(
|
|
// "records" => [
|
|
// array("M_PatientGender" => "male")
|
|
// // array("M_PatientGender" => "female")
|
|
// ]
|
|
// );
|
|
// } else {
|
|
// $result_gender = array(
|
|
// "records" => [
|
|
// // array("M_PatientGender" => "male"),
|
|
// array("M_PatientGender" => "female")
|
|
// ]
|
|
// );
|
|
// }
|
|
// } else {
|
|
// $result_gender = array(
|
|
// "records" => [
|
|
// array("M_PatientGender" => "male"),
|
|
// array("M_PatientGender" => "female")
|
|
// ]
|
|
// );
|
|
// }
|
|
// $sql_sex = "SELECT M_SexID,
|
|
// M_SexCode,
|
|
// m_sexname,
|
|
// M_SexNameLang,
|
|
// M_SexCreated,
|
|
// M_SexLastUpdated,
|
|
// M_SexIsActive
|
|
// FROM m_sex
|
|
// WHERE M_SexIsActive = 'Y'
|
|
// AND M_SexID = ?";
|
|
// $qry_sex = $this->db_onedev->query($sql_sex, array($v['M_PatientM_SexID']));
|
|
// if (!$qry_sex) {
|
|
// $this->db_onedev->trans_rollback();
|
|
// $this->sys_error_db("m_sex count", $this->db_onedev);
|
|
// exit;
|
|
// }
|
|
// $row_s = $qry_sex->result_array();
|
|
// $rows[$k]['gender'] = $row_s;
|
|
|
|
// blood type
|
|
$sql = "SELECT
|
|
code,
|
|
display,
|
|
display_en,
|
|
code_system
|
|
FROM
|
|
terminology
|
|
WHERE status_cd = 'normal'
|
|
AND attribute_path = 'Person.blood.type'
|
|
AND resource_type = 'Person'
|
|
AND code_system = 'http://loinc.org'
|
|
AND code = '{$v['M_PatientBloodTypeCode']}'
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("terminology select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rows_blood_type = $qry->result_array();
|
|
$rows[$k]['bloodtype'] = $rows_blood_type;
|
|
|
|
// rhesus
|
|
$sql = "SELECT
|
|
code,
|
|
display,
|
|
display_en,
|
|
code_system
|
|
FROM
|
|
terminology
|
|
WHERE status_cd = 'normal'
|
|
AND attribute_path = 'Person.blood.rhesus'
|
|
AND resource_type = 'Person'
|
|
AND code_system = 'http://snomed.info/sct'
|
|
AND code = '{$v['M_PatientBloodRhCode']}'
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("terminology select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rows_blood_rh = $qry->result_array();
|
|
$rows[$k]['bloodrhesus'] = $rows_blood_rh;
|
|
|
|
// education
|
|
$sql = "SELECT
|
|
code,
|
|
display,
|
|
display_en,
|
|
code_system
|
|
FROM
|
|
terminology
|
|
WHERE status_cd = 'normal'
|
|
AND attribute_path = 'Person.education'
|
|
AND resource_type = 'Person'
|
|
AND code_system = 'xhis.code.education.level'
|
|
AND code = '{$v['M_PatientEducationCode']}'
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("terminology select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rows_education = $qry->result_array();
|
|
$rows[$k]['education'] = $rows_education;
|
|
|
|
// kewarganegaraan
|
|
$result_kewarganegaraan = [];
|
|
|
|
if (!empty($v['M_PatientCitizenship'])) {
|
|
if ($v['M_PatientCitizenship'] === "WNI") {
|
|
$result_kewarganegaraan = array(
|
|
"records" => [
|
|
array("M_PatientCitizenship" => "WNI"),
|
|
]
|
|
);
|
|
} else {
|
|
$result_kewarganegaraan = array(
|
|
"records" => [
|
|
array("M_PatientCitizenship" => "WNA")
|
|
]
|
|
);
|
|
}
|
|
} else {
|
|
$result_kewarganegaraan = array(
|
|
"records" => [
|
|
array("M_PatientCitizenship" => "WNI"),
|
|
array("M_PatientCitizenship" => "WNA")
|
|
]
|
|
);
|
|
}
|
|
|
|
$rows[$k]['kewarganegaraan'] = $result_kewarganegaraan;
|
|
|
|
// etnicity
|
|
$sql = "SELECT
|
|
code,
|
|
display,
|
|
display_en,
|
|
code_system
|
|
FROM
|
|
terminology
|
|
WHERE status_cd = 'normal'
|
|
AND attribute_path = 'Person.etnicity'
|
|
AND resource_type = 'Person'
|
|
AND code_system = 'xhis.code.etnicity'
|
|
AND code = '{$v['M_PatientEtnicCode']}'
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("terminology select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rows_etnicity = $qry->result_array();
|
|
$rows[$k]['etnicity'] = $rows_etnicity;
|
|
|
|
// religion
|
|
$sql = "SELECT
|
|
code,
|
|
display,
|
|
display_en,
|
|
code_system
|
|
FROM
|
|
terminology
|
|
WHERE status_cd = 'normal'
|
|
AND attribute_path = 'Person.religion.code'
|
|
AND resource_type = 'Person'
|
|
AND code_system = 'xcpone.code.religion'
|
|
AND code = '{$v['M_PatientReligionCode']}'
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("terminology select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rows_religion = $qry->result_array();
|
|
$rows[$k]['religion'] = $rows_religion;
|
|
|
|
// identifier
|
|
$sql = "SELECT
|
|
code,
|
|
display,
|
|
display_en,
|
|
code_system
|
|
FROM
|
|
terminology
|
|
WHERE status_cd = 'normal'
|
|
AND attribute_path = 'Person.identifier.type'
|
|
AND resource_type = 'Person'
|
|
AND code_system = 'http://terminology.hl7.org/CodeSystem/v2-0203'
|
|
AND code = '{$v['M_PatientIdentifierCode']}'
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("terminology select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rows_identifier = $qry->result_array();
|
|
$rows[$k]['identifier'] = $rows_identifier;
|
|
|
|
|
|
// country
|
|
$sql = "SELECT
|
|
code,
|
|
display,
|
|
display_en,
|
|
code_system
|
|
FROM
|
|
terminology
|
|
WHERE status_cd = 'normal'
|
|
AND attribute_path = 'Address.country'
|
|
AND resource_type = 'Address'
|
|
AND code_system = 'urn:iso:std:iso:3166'
|
|
AND code = '{$v['M_PatientAddressCountry']}'
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("terminology select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rows_country = $qry->result_array();
|
|
$rows[$k]['country'] = $rows_country;
|
|
|
|
// wilayah
|
|
$dataNewWilayah = [];
|
|
if ($v['M_PatientAddressRegionalCd'] != "") {
|
|
$sql = "SELECT
|
|
r.regional_cd,
|
|
r.regional_cd AS id,
|
|
r.regional_nm,
|
|
r.full_name AS text_nm,
|
|
r.pro_cd, IFNULL(pro.regional_nm,'') AS pro_nm,
|
|
r.kab_cd, IFNULL(kab.regional_nm,'') AS kab_nm,
|
|
r.kec_cd, IFNULL(kec.regional_nm,'') AS kec_nm,
|
|
r.kel_cd, IFNULL(kel.regional_nm,'') AS kel_nm,
|
|
r.status_cd, r.old_nm
|
|
FROM regional r
|
|
LEFT JOIN regional pro ON CONCAT(r.pro_cd, REPEAT('0', 8)) = pro.regional_cd
|
|
LEFT JOIN regional kab ON CONCAT(r.pro_cd, r.kab_cd, REPEAT('0', 6)) = kab.regional_cd
|
|
LEFT JOIN regional kec ON CONCAT(r.pro_cd, r.kab_cd, r.kec_cd, REPEAT('0', 3)) = kec.regional_cd
|
|
LEFT JOIN regional kel ON CONCAT(r.pro_cd, r.kab_cd, r.kec_cd, r.kel_cd) = kel.regional_cd
|
|
WHERE r.regional_cd = {$v['M_PatientAddressRegionalCd']}
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("search wilayah select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rows_wilayah = $qry->result_array();
|
|
$dataNewWilayah = $rows_wilayah;
|
|
}
|
|
|
|
$rows[$k]['wilayah'] = $rows_wilayah;
|
|
}
|
|
|
|
$result = array(
|
|
// "total" => $tot_page,
|
|
"records" => $rows,
|
|
"sql" => $this->db_onedev->last_query(),
|
|
"sql_data" => $sql
|
|
);
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("m_patient rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
// }
|
|
// else {
|
|
// $result = array("total" => 0, "records" => [], "sql" => $this->db_onedev->last_query());
|
|
// $this->sys_ok($result);
|
|
// }
|
|
}
|
|
|
|
public function search_x()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$norm = $prm["snorm"];
|
|
$nama = str_replace("'", "\\'", $prm["name"]);
|
|
|
|
// echo $norm;
|
|
|
|
$sql_where = "WHERE M_PatientIsActive = 'Y' ";
|
|
$sql_param = array();
|
|
if ($nama != "") {
|
|
if ($sql_where != "") {
|
|
$sql_where .= " and ";
|
|
}
|
|
$sql_where .= " M_PatientName like ? ";
|
|
$sql_param[] = "%$nama%";
|
|
}
|
|
if ($norm != "") {
|
|
if ($sql_where != "") {
|
|
$sql_where .= " and ";
|
|
}
|
|
$sql_where .= " M_PatientNoReg like ? ";
|
|
$sql_param[] = "%$norm%";
|
|
}
|
|
|
|
$limit = '';
|
|
if ($all == 'N') {
|
|
$limit = ' LIMIT 100';
|
|
}
|
|
$number_limit = 100;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
|
|
|
//echo $this->db_onedev->last_query();
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
|
|
|
|
$sql = "SELECT
|
|
M_PatientID,
|
|
M_PatientNoReg,
|
|
M_PatientPrefix,
|
|
M_PatientName,
|
|
M_PatientSuffix,
|
|
M_PatientHP,
|
|
M_PatientEmail,
|
|
M_PatientPOB,
|
|
M_PatientPhone,
|
|
M_PatientIDNumber,
|
|
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as M_PatientDOB,
|
|
M_PatientNote,
|
|
M_PatientNIK,
|
|
M_PatientJabatan,
|
|
M_PatientKedudukan,
|
|
M_PatientPJ,
|
|
M_PatientLocation,
|
|
M_PatientJob,
|
|
M_PatientM_SexID,
|
|
M_SexName,
|
|
M_PatientM_TitleID,
|
|
M_TitleName,
|
|
M_PatientM_ReligionID,
|
|
M_ReligionName,
|
|
M_PatientM_IdTypeID,
|
|
M_IdTypeName,
|
|
M_PatientIDNumber,
|
|
IF(ISNULL(M_PatientSuspendID),'active','suspend' ) as status
|
|
FROM m_patient
|
|
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
LEFT JOIN m_sex ON M_PatientM_SexID = M_SexID
|
|
LEFT JOIN m_religion ON M_PatientM_ReligionID = M_ReligionID
|
|
LEFT JOIN m_idtype ON M_PatientM_IdTypeID = M_IdTypeID
|
|
LEFT JOIN m_patientsuspend ON M_PatientSuspendM_PatientID = M_PatientID AND M_PatientSuspendIsActive = 'Y'
|
|
$sql_where
|
|
ORDER BY M_PatientName ASC
|
|
limit 100
|
|
";
|
|
// $sql;
|
|
$query = $this->db_onedev->query($sql, $sql_param);
|
|
$rows = $query->result_array();
|
|
if ($rows) {
|
|
foreach ($rows as $k => $v) {
|
|
$rows[$k]['M_PatientName'] = stripslashes($rows[$k]['M_PatientName']);
|
|
$rows[$k]['M_PatientPOB'] = stripslashes($rows[$k]['M_PatientPOB']);
|
|
//$rows[$k]['verification_px'] = $this->add_verification_test($v['M_PatientID']);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
//$this->_add_address($rows);
|
|
$result = array("total" => 1, "records" => $rows, "sql" => $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
|
|
function getsexreg()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
if ($prm["M_SexID"] != "") {
|
|
$filter = " AND M_SexID = {$prm["M_SexID"]}";
|
|
}
|
|
$rows = [];
|
|
$query = " SELECT *
|
|
FROM m_sex
|
|
WHERE
|
|
M_SexIsActive = 'Y'
|
|
$filter
|
|
";
|
|
//echo $query;
|
|
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function searchcity()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count = 0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '') {
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM m_city
|
|
WHERE
|
|
M_CityName like ?
|
|
AND M_CityIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, $q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
} else {
|
|
$this->sys_error_db("m_city count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT *
|
|
FROM m_city
|
|
WHERE
|
|
M_CityName like ?
|
|
AND M_CityIsActive = 'Y'
|
|
ORDER BY M_CityName DESC
|
|
";
|
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("m_city rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function getprovinces()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$query = " SELECT *
|
|
FROM m_province
|
|
WHERE
|
|
M_ProvinceIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getcities()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$query = " SELECT *
|
|
FROM m_city
|
|
WHERE
|
|
M_CityIsActive = 'Y' AND M_CityM_ProvinceID = ?
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query, array($prm['id']))->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
function getdistricts()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$query = " SELECT *
|
|
FROM m_district
|
|
WHERE
|
|
M_DistrictIsActive = 'Y' AND M_DistrictM_CityID = ?
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query, array($prm['id']))->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getkelurahans()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$query = " SELECT *
|
|
FROM m_kelurahan
|
|
WHERE
|
|
M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ?
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query, array($prm['id']))->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
// add new patient
|
|
function newpatient()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$M_PatientNoReg = "";
|
|
|
|
// get numbering
|
|
$sql_get_numbering = "SELECT fn_numbering_ibl('PA') as numberx";
|
|
$qry_get_numbering = $this->db_onedev->query($sql_get_numbering);
|
|
if (!$qry_get_numbering) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("packet numbering cpone", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$data_numbering = $qry_get_numbering->result_array();
|
|
|
|
$M_PatientNoReg = $data_numbering[0]['numberx'];
|
|
|
|
$M_PatientName = strtoupper($prm['M_PatientName']);
|
|
|
|
$pdob = date('Y-m-d', strtotime($prm['M_PatientDOB']));
|
|
|
|
|
|
$query = "INSERT INTO m_patient
|
|
(
|
|
M_PatientM_TitleID,
|
|
M_PatientNoReg,
|
|
M_PatientPrefix,
|
|
M_PatientName,
|
|
M_PatientSuffix,
|
|
M_PatientM_SexID,
|
|
M_PatientDOB,
|
|
M_PatientReligionCode,
|
|
M_PatientReligionSystem,
|
|
M_PatientBloodTypeCode,
|
|
M_PatientBloodTypeSystem,
|
|
M_PatientBloodRhCode,
|
|
M_PatientBloodRhSystem,
|
|
M_PatientEducationCode,
|
|
M_PatientEducationSystem,
|
|
M_PatientCitizenship,
|
|
M_PatientEtnicCode,
|
|
M_PatientEtnicSystem,
|
|
M_PatientIdentifierCode,
|
|
M_PatientIdentifierSystem,
|
|
M_PatientIdentifierValue,
|
|
M_PatientHp,
|
|
M_PatientEmail,
|
|
M_PatientPhoto,
|
|
M_PatientAddress,
|
|
M_PatientAddressRegionalCd,
|
|
M_PatientAddressRT,
|
|
M_PatientAddressRW,
|
|
M_PatientAddressCity,
|
|
M_PatientAddressVillage,
|
|
M_PatientAddressDistrict,
|
|
M_PatientAddressState,
|
|
M_PatientAddressCountry,
|
|
M_PatientIsActive,
|
|
M_PatientCreated,
|
|
M_PatientCreatedUserID
|
|
)
|
|
VALUES(
|
|
{$prm['M_PatientM_TitleID']},
|
|
'{$M_PatientNoReg}',
|
|
'{$prm['M_PatientPrefix']}',
|
|
'{$M_PatientName}',
|
|
'{$prm['M_PatientSuffix']}',
|
|
'{$prm['M_PatientM_SexID']}',
|
|
'{$pdob}',
|
|
'{$prm['M_PatientReligionCode']}',
|
|
'{$prm['M_PatientReligionSystem']}',
|
|
'{$prm['M_PatientBloodTypeCode']}',
|
|
'{$prm['M_PatientBloodTypeSystem']}',
|
|
'{$prm['M_PatientBloodRhCode']}',
|
|
'{$prm['M_PatientBloodRhSystem']}',
|
|
'{$prm['M_PatientEducationCode']}',
|
|
'{$prm['M_PatientEducationSystem']}',
|
|
'{$prm['M_PatientCitizenship']}',
|
|
'{$prm['M_PatientEtnicCode']}',
|
|
'{$prm['M_PatientEtnicSystem']}',
|
|
'{$prm['M_PatientIdentifierCode']}',
|
|
'{$prm['M_PatientIdentifierSystem']}',
|
|
'{$prm['M_PatientIdentifierValue']}',
|
|
'{$prm['M_PatientHp']}',
|
|
'{$prm['M_PatientEmail']}',
|
|
'{$prm['M_PatientPhoto']}',
|
|
'{$prm['M_PatientAddress']}',
|
|
'{$prm['M_PatientAddressRegionalCd']}',
|
|
'{$prm['M_PatientAddressRT']}',
|
|
'{$prm['M_PatientAddressRW']}',
|
|
'{$prm['M_PatientAddressCity']}',
|
|
'{$prm['M_PatientAddressVillage']}',
|
|
'{$prm['M_PatientAddressDistrict']}',
|
|
'{$prm['M_PatientAddressState']}',
|
|
'{$prm['M_PatientAddressCountry']}',
|
|
'Y',
|
|
NOW(),
|
|
$userid
|
|
)
|
|
";
|
|
//echo $query;
|
|
$qry = $this->db_onedev->query($query);
|
|
if (!$qry) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_patient insert", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
|
|
$last_id = $this->db_onedev->insert_id();
|
|
if ($last_id) {
|
|
$sql = "INSERT INTO m_patientaddress (
|
|
M_PatientAddressM_PatientID,
|
|
M_PatientAddressDescription,
|
|
M_PatientAddressRegionalCd,
|
|
M_PatientAddressRT,
|
|
M_PatientAddressRW,
|
|
M_PatientAddressVillage,
|
|
M_PatientAddressDistrict,
|
|
M_PatientAddressCity,
|
|
M_PatientAddressState,
|
|
M_PatientAddressCountry,
|
|
M_PatientAddressCreated,
|
|
M_PatientAddressCreatedUserID
|
|
)
|
|
VALUES(?,?,?,?,?,?,?,?,?,?,NOW(),?)";
|
|
$save_address = $this->db_onedev->query($sql, [
|
|
$last_id,
|
|
$prm['M_PatientAddress'],
|
|
$prm['M_PatientAddressRegionalCd'],
|
|
$prm['M_PatientAddressRT'],
|
|
$prm['M_PatientAddressRW'],
|
|
$prm['M_PatientAddressVillage'],
|
|
$prm['M_PatientAddressDistrict'],
|
|
$prm['M_PatientAddressCity'],
|
|
$prm['M_PatientAddressState'],
|
|
$prm['M_PatientAddressCountry'],
|
|
$userid
|
|
]);
|
|
|
|
if (!$save_address) {
|
|
$message = $this->db_onedev->error();
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array('status' => 'OK'),
|
|
"id" => $last_id
|
|
);
|
|
// $ptn = $prm;
|
|
// $ptn["M_PatientID"] = $last_id;
|
|
// $ptn["M_PatientDOB"] = $pdob;
|
|
// $ptn = json_encode($ptn);
|
|
//$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADD', '{$ptn}', $userid)");
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
// update patient
|
|
function save()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
// $sql = "SELECT * FROM m_patient WHERE M_PatientID = {$prm['M_PatientID']}";
|
|
// $rows_before = $this->db_onedev->query($sql)->row_array();
|
|
|
|
$M_PatientName = strtoupper($prm['M_PatientName']);
|
|
$M_PatientID = $prm['M_PatientID'];
|
|
|
|
$sql_data = "SELECT *
|
|
FROM m_patient
|
|
WHERE M_PatientIsActive = 'Y'
|
|
AND M_PatientID = $M_PatientID";
|
|
|
|
$qry_data = $this->db_onedev->query($sql_data);
|
|
if (!$qry_data) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_patient update", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rowdata = $qry_data->result_array();
|
|
|
|
// $M_PatientAddressRegionalCd = $row_data[0]['M_PatientAddressRegionalCd'];
|
|
// $M_PatientAddressRegionalCdNew = "";
|
|
|
|
// if(empty($prm['M_PatientAddressRegionalCd']) || $prm['M_PatientAddressRegionalCd'] == ""){
|
|
// $M_PatientAddressRegionalCdNew = $M_PatientAddressRegionalCd;
|
|
// } else{
|
|
// $M_PatientAddressRegionalCdNew = $prm['M_PatientAddressRegionalCd'];
|
|
// }
|
|
|
|
$M_PatientAddressRegionalCd = $prm['M_PatientAddressRegionalCd'];
|
|
$M_PatientAddressVillage = $prm['M_PatientAddressVillage'];
|
|
$M_PatientAddressDistrict = $prm['M_PatientAddressDistrict'];
|
|
$M_PatientAddressCity = $prm['M_PatientAddressCity'];
|
|
$M_PatientAddressState = $prm['M_PatientAddressState'];
|
|
|
|
// print_r($rowdata);
|
|
// print_r($M_PatientAddressRegionalCd);
|
|
// exit;
|
|
|
|
if ($M_PatientAddressRegionalCd == "") {
|
|
$M_PatientAddressRegionalCd = $rowdata[0]['M_PatientAddressRegionalCd'];
|
|
$M_PatientAddressVillage = $rowdata[0]['M_PatientAddressVillage'];
|
|
$M_PatientAddressDistrict = $rowdata[0]['M_PatientAddressDistrict'];
|
|
$M_PatientAddressCity = $rowdata[0]['M_PatientAddressCity'];
|
|
$M_PatientAddressState = $rowdata[0]['M_PatientAddressState'];
|
|
}
|
|
|
|
$pdob = date('Y-m-d', strtotime($prm['M_PatientDOB']));
|
|
|
|
$sql = "UPDATE m_patient
|
|
SET
|
|
M_PatientM_TitleID = {$prm['M_PatientM_TitleID']},
|
|
M_PatientPrefix = '{$prm['M_PatientPrefix']}',
|
|
M_PatientName = '{$M_PatientName}',
|
|
M_PatientSuffix = '{$prm['M_PatientSuffix']}',
|
|
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
|
|
M_PatientDOB = '{$pdob}',
|
|
M_PatientReligionCode = '{$prm['M_PatientReligionCode']}',
|
|
M_PatientReligionSystem = '{$prm['M_PatientReligionSystem']}',
|
|
M_PatientBloodTypeCode = '{$prm['M_PatientBloodTypeCode']}',
|
|
M_PatientBloodTypeSystem = '{$prm['M_PatientBloodTypeSystem']}',
|
|
M_PatientBloodRhCode = '{$prm['M_PatientBloodRhCode']}',
|
|
M_PatientBloodRhSystem = '{$prm['M_PatientBloodRhSystem']}',
|
|
M_PatientEducationCode = '{$prm['M_PatientEducationCode']}',
|
|
M_PatientEducationSystem = '{$prm['M_PatientEducationSystem']}',
|
|
M_PatientCitizenship = '{$prm['M_PatientCitizenship']}',
|
|
M_PatientEtnicCode = '{$prm['M_PatientEtnicCode']}',
|
|
M_PatientEtnicSystem = '{$prm['M_PatientEtnicSystem']}',
|
|
M_PatientIdentifierCode = '{$prm['M_PatientIdentifierCode']}',
|
|
M_PatientIdentifierSystem = '{$prm['M_PatientIdentifierSystem']}',
|
|
M_PatientIdentifierValue = '{$prm['M_PatientIdentifierValue']}',
|
|
M_PatientHp = '{$prm['M_PatientHp']}',
|
|
M_PatientEmail = '{$prm['M_PatientEmail']}',
|
|
M_PatientAddress = '{$prm['M_PatientAddress']}',
|
|
M_PatientAddressRegionalCd = '$M_PatientAddressRegionalCd',
|
|
M_PatientAddressRT = '{$prm['M_PatientAddressRT']}',
|
|
M_PatientAddressRW = '{$prm['M_PatientAddressRW']}',
|
|
M_PatientAddressCity = '$M_PatientAddressCity',
|
|
M_PatientAddressVillage = '$M_PatientAddressVillage',
|
|
M_PatientAddressDistrict = '$M_PatientAddressDistrict',
|
|
M_PatientAddressState = '$M_PatientAddressState',
|
|
M_PatientAddressCountry = '{$prm['M_PatientAddressCountry']}',
|
|
M_PatientLastUpdated = NOW(),
|
|
M_PatientLastUpdatedUserID = $userid
|
|
WHERE M_PatientID = {$prm['M_PatientID']}";
|
|
|
|
// echo $query;
|
|
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
if (!$query) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_patient update", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT * FROM m_patientaddress
|
|
WHERE
|
|
M_PatientAddressM_PatientID = ? AND
|
|
M_PatientAddressIsActive = 'Y' AND
|
|
M_PatientAddressNote = 'Utama'
|
|
ORDER BY M_PatientAddressCreated DESC
|
|
LIMIT 1";
|
|
$qry = $this->db_onedev->query($sql, [$prm['M_PatientID']]);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$dt_address = $qry->result_array();
|
|
|
|
if (count($dt_address) > 0) {
|
|
$sql = "UPDATE m_patientaddress SET
|
|
M_PatientAddressDescription = ?,
|
|
M_PatientAddressRegionalCd = ?,
|
|
M_PatientAddressRT = ?,
|
|
M_PatientAddressRW = ?,
|
|
M_PatientAddressVillage = ?,
|
|
M_PatientAddressDistrict = ?,
|
|
M_PatientAddressCity = ?,
|
|
M_PatientAddressState = ?,
|
|
M_PatientAddressCountry = ?,
|
|
M_PatientAddressLastUpdated = NOW(),
|
|
M_PatientAddressLastUpdatedUserID = ?
|
|
WHERE M_PatientAddressID = ?";
|
|
$qry = $this->db_onedev->query($sql, [
|
|
$prm['M_PatientAddress'],
|
|
$prm['M_PatientAddressRegionalCd'],
|
|
$prm['M_PatientAddressRT'],
|
|
$prm['M_PatientAddressRW'],
|
|
$M_PatientAddressVillage,
|
|
$M_PatientAddressDistrict,
|
|
$M_PatientAddressCity,
|
|
$M_PatientAddressState,
|
|
$prm['M_PatientAddressCountry'],
|
|
$userid,
|
|
$dt_address[0]['M_PatientAddressID']
|
|
]);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
} else {
|
|
$sql = "INSERT INTO m_patientaddress (
|
|
M_PatientAddressM_PatientID,
|
|
M_PatientAddressDescription,
|
|
M_PatientAddressRegionalCd,
|
|
M_PatientAddressRT,
|
|
M_PatientAddressRW,
|
|
M_PatientAddressVillage,
|
|
M_PatientAddressDistrict,
|
|
M_PatientAddressCity,
|
|
M_PatientAddressState,
|
|
M_PatientAddressCountry,
|
|
M_PatientAddressCreated,
|
|
M_PatientAddressCreatedUserID
|
|
) VALUES(?,?,?,?,?,?,?,?,?,?,NOW(),?)";
|
|
$qry = $this->db_onedev->query($sql, [
|
|
$prm['M_PatientID'],
|
|
$prm['M_PatientAddress'],
|
|
$prm['M_PatientAddressRegionalCd'],
|
|
$prm['M_PatientAddressRT'],
|
|
$prm['M_PatientAddressRW'],
|
|
$M_PatientAddressVillage,
|
|
$M_PatientAddressDistrict,
|
|
$M_PatientAddressCity,
|
|
$M_PatientAddressState,
|
|
$prm['M_PatientAddressCountry'],
|
|
$userid
|
|
]);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array('status' => 'OK')
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function deletev0()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$sql = "UPDATE m_patient
|
|
SET
|
|
M_PatientIsActive = 'N',
|
|
M_PatientDeleted = NOW(),
|
|
M_PatientDeletedUserID = $userid
|
|
WHERE M_PatientID = {$prm['M_PatientID']}
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
if (!$qry) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("m_patient update", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT * FROM m_patientaddress
|
|
WHERE
|
|
M_PatientAddressM_PatientID = ? AND
|
|
M_PatientAddressIsActive = 'Y' AND
|
|
M_PatientAddressNote = 'Utama'
|
|
ORDER BY M_PatientAddressCreated DESC
|
|
LIMIT 1";
|
|
$qry = $this->db_onedev->query($sql, [$prm['M_PatientID']]);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$dt_address = $qry->result_array();
|
|
|
|
if (count($dt_address) > 0) {
|
|
$sql = "UPDATE m_patientaddress SET
|
|
M_PatientAddressIsActive = 'N',
|
|
M_PatientAddressDeleted = NOW(),
|
|
M_PatientAddressDeletedUserID = ?
|
|
WHERE M_PatientAddressID = ?";
|
|
$qry = $this->db_onedev->query($sql, [
|
|
$userid,
|
|
$dt_address[0]['M_PatientAddressID']
|
|
]);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array('status' => 'OK')
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function newpatientold()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$pdob = date('Y-m-d', strtotime($prm['M_PatientDOB']));
|
|
$prm['M_PatientName'] = str_replace("'", "\\'", $prm['M_PatientName']);
|
|
$query = "INSERT INTO m_patient (
|
|
M_PatientM_TitleID,
|
|
M_PatientPrefix,
|
|
M_PatientName,
|
|
M_PatientSuffix,
|
|
M_PatientDOB,
|
|
M_PatientM_SexID,
|
|
M_PatientM_ReligionID,
|
|
M_PatientEmail,
|
|
M_PatientPOB,
|
|
M_PatientHP,
|
|
M_PatientPhone,
|
|
M_PatientM_IdTypeID,
|
|
M_PatientIDNumber,
|
|
M_PatientNote,
|
|
M_PatientNIK,
|
|
M_PatientJabatan,
|
|
M_PatientKedudukan,
|
|
M_PatientPJ,
|
|
M_PatientLocation,
|
|
M_PatientJob,
|
|
M_PatientUserID
|
|
)
|
|
VALUES(
|
|
'{$prm['M_PatientM_TitleID']}',
|
|
'{$prm['M_PatientPrefix']}',
|
|
'{$prm['M_PatientName']}',
|
|
'{$prm['M_PatientSuffix']}',
|
|
'{$pdob}',
|
|
'{$prm['M_PatientM_SexID']}',
|
|
'{$prm['M_PatientM_ReligionID']}',
|
|
'{$prm['M_PatientEmail']}',
|
|
'{$prm['M_PatientPOB']}',
|
|
'{$prm['M_PatientHP']}',
|
|
'{$prm['M_PatientPhone']}',
|
|
'{$prm['M_PatientM_IdTypeID']}',
|
|
'{$prm['M_PatientIDNumber']}',
|
|
'{$prm['M_PatientNote']}',
|
|
'{$prm['M_PatientNIK']}',
|
|
'{$prm['M_PatientJabatan']}',
|
|
'{$prm['M_PatientKedudukan']}',
|
|
'{$prm['M_PatientPJ']}',
|
|
'{$prm['M_PatientLocation']}',
|
|
'{$prm['M_PatientJob']}',
|
|
$userid
|
|
)
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
$last_id = $this->db_onedev->insert_id();
|
|
if ($last_id) {
|
|
$sql = "SELECT * FROM m_patient
|
|
LEFT JOIN m_branch ON M_BranchIsDefault = 'Y' AND M_BranchIsActive = 'Y'
|
|
WHERE M_PatientID = {$last_id}
|
|
LIMIT 1";
|
|
//echo $sql;
|
|
$data_patient = $this->db_onedev->query($sql)->row_array();
|
|
if ($data_patient) {
|
|
if (intval($prm['M_PatientM_IdTypeID']) == 4) {
|
|
$new_nik_varchar = "00" . $data_patient['M_BranchCode'] . str_pad($data_patient['M_PatientNoReg'], 12, "0", STR_PAD_LEFT);
|
|
$sql = "UPDATE m_patient SET M_PatientIDNumber = '{$new_nik_varchar}' WHERE M_PatientID = {$last_id}";
|
|
$this->db_onedev->query($sql);
|
|
//echo $sql;
|
|
}
|
|
}
|
|
|
|
$address_description = str_replace("'", "\\'", $prm['M_PatientAddressDescription']);
|
|
// save address
|
|
$add = [
|
|
'M_PatientAddressM_PatientID' => $last_id,
|
|
'M_PatientAddressDescription' => $address_description,
|
|
'M_PatientAddressUserID' => $userid,
|
|
'M_PatientAddressM_KelurahanID' => $prm['M_PatientAddressM_KelurahanID']
|
|
];
|
|
$this->db_onedev->insert('m_patientaddress', $add);
|
|
//echo $this->db_onedev->last_query();
|
|
}
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array('status' => 'OK'),
|
|
"id" => $last_id
|
|
);
|
|
$ptn = $prm;
|
|
$ptn["M_PatientID"] = $last_id;
|
|
$ptn["M_PatientDOB"] = $pdob;
|
|
$ptn = json_encode($ptn);
|
|
//$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADD', '{$ptn}', $userid)");
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function deletepatient()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$prm = $this->sys_input;
|
|
$query = "UPDATE m_patient SET
|
|
M_PatientIsActive = 'N',
|
|
M_PatientUserID = {$userid}
|
|
WHERE
|
|
M_PatientID = '{$prm['M_PatientID']}'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array('status' => 'OK')
|
|
);
|
|
$ptn = $prm;
|
|
$ptn["M_PatientDOB"] = $pdob;
|
|
$ptn = json_encode($ptn);
|
|
//$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.DELETE', '{$ptn}', $userid)");
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getaddress()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$query = " SELECT m_patientaddress.*,
|
|
M_KelurahanName,
|
|
M_DistrictID,
|
|
M_DistrictName,
|
|
M_CityID,
|
|
M_CityName,
|
|
'' as action
|
|
FROM m_patientaddress
|
|
JOIN m_kelurahan ON M_PatientAddressM_KelurahanID = M_KelurahanID
|
|
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
|
|
JOIN m_city ON M_DistrictM_CityID = M_CityID
|
|
WHERE
|
|
M_PatientAddressIsActive = 'Y' AND M_PatientAddressM_PatientID = ?
|
|
ORDER BY M_PatientAddressID ASC
|
|
LIMIT 1
|
|
|
|
";
|
|
//echo $query;
|
|
$address = $this->db_onedev->query($query, array($prm['id']))->row_array();
|
|
$address['M_PatientAddressDescription'] = stripslashes($address['M_PatientAddressDescription']);
|
|
$rows['address'] = $address;
|
|
|
|
$query = " SELECT *
|
|
FROM m_city
|
|
WHERE
|
|
M_CityIsActive = 'Y' AND M_CityID = ?
|
|
";
|
|
//echo $query;
|
|
$rows['city_address'] = $this->db_onedev->query($query, array($address['M_CityID']))->row_array();
|
|
|
|
|
|
$query = " SELECT *
|
|
FROM m_city
|
|
WHERE
|
|
M_CityIsActive = 'Y' AND M_CityM_ProvinceID = ?
|
|
";
|
|
//echo $query;
|
|
$rows['cities'] = $this->db_onedev->query($query, array($rows['city_address']['M_CityM_ProvinceID']))->result_array();
|
|
|
|
$query = " SELECT *
|
|
FROM m_province
|
|
WHERE
|
|
M_ProvinceIsActive = 'Y' AND M_ProvinceID = ?
|
|
";
|
|
//echo $query;
|
|
$rows['province_address'] = $this->db_onedev->query($query, array($rows['city_address']['M_CityM_ProvinceID']))->row_array();
|
|
|
|
$query = " SELECT *
|
|
FROM m_province
|
|
WHERE
|
|
M_ProvinceIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['provinces'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
$query = " SELECT *
|
|
FROM m_district
|
|
WHERE
|
|
M_DistrictIsActive = 'Y' AND M_DistrictM_CityID = ?
|
|
";
|
|
//echo $query;
|
|
$rows['districts'] = $this->db_onedev->query($query, array($rows['city_address']['M_CityID']))->result_array();
|
|
|
|
$query = " SELECT *
|
|
FROM m_district
|
|
WHERE
|
|
M_DistrictIsActive = 'Y' AND M_DistrictID = ?
|
|
";
|
|
//echo $query;
|
|
$rows['district_address'] = $this->db_onedev->query($query, array($address['M_DistrictID']))->row_array();
|
|
|
|
$query = " SELECT *
|
|
FROM m_kelurahan
|
|
WHERE
|
|
M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ?
|
|
";
|
|
//echo $query;
|
|
$rows['kelurahans'] = $this->db_onedev->query($query, array($address['M_DistrictID']))->result_array();
|
|
|
|
$query = " SELECT *
|
|
FROM m_kelurahan
|
|
WHERE
|
|
M_KelurahanIsActive = 'Y' AND M_KelurahanID = ?
|
|
";
|
|
//echo $query;
|
|
$rows['kelurahan_address'] = $this->db_onedev->query($query, array($address['M_PatientAddressM_KelurahanID']))->row_array();
|
|
|
|
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function savenewaddress()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$prm = $this->sys_input;
|
|
$count_addrs = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_patientaddress WHERE M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}' AND M_PatientAddressIsActive = 'Y'")->row()->countx;
|
|
|
|
//echo $this->db_onedev->last_query();
|
|
if ($count_addrs == 0) {
|
|
$prm['M_PatientAddressNote'] = 'Utama';
|
|
} else {
|
|
$count_addrs_utama = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_patientaddress WHERE M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}' AND M_PatientAddressNote = 'Utama' AND M_PatientAddressIsActive = 'Y'")->row()->countx;
|
|
if ($count_addrs_utama > 0 && strtolower($prm['M_PatientAddressNote']) == 'utama') {
|
|
$rx = date('YmdHis');
|
|
$prm['M_PatientAddressNote'] = 'Utama_' . $rx;
|
|
}
|
|
}
|
|
$prm['M_PatientAddressDescription'] = str_replace("'", "\\'", $prm['M_PatientAddressDescription']);
|
|
$query = "INSERT INTO m_patientaddress (
|
|
M_PatientAddressM_PatientID,
|
|
M_PatientAddressNote,
|
|
M_PatientAddressDescription,
|
|
M_PatientAddressM_KelurahanID,
|
|
M_PatientAddressCreated,
|
|
M_PatientAddressUserID
|
|
)
|
|
VALUES(
|
|
'{$prm['M_PatientAddressM_PatientID']}',
|
|
'{$prm['M_PatientAddressNote']}',
|
|
'{$prm['M_PatientAddressDescription']}',
|
|
'{$prm['M_PatientAddressM_KelurahanID']}',
|
|
NOW(),
|
|
'{$userid}'
|
|
)
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array('status' => 'OK')
|
|
);
|
|
$ptn = $prm;
|
|
$ptn["M_UserID"] = $pdob;
|
|
$ptn = json_encode($ptn);
|
|
//$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_ADD', '{$ptn}', $userid)");
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function saveeditaddress()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$prm = $this->sys_input;
|
|
$prm['M_PatientAddressDescription'] = str_replace("'", "\\'", $prm['M_PatientAddressDescription']);
|
|
$sql = "SELECT * FROM m_patientaddress WHERE M_PatientAddressID = {$prm['M_PatientAddressID']}";
|
|
$rows_before = $this->db_onedev->query($sql)->row_array();
|
|
$query = "UPDATE m_patientaddress SET
|
|
M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}',
|
|
M_PatientAddressNote = '{$prm['M_PatientAddressNote']}',
|
|
M_PatientAddressDescription = '{$prm['M_PatientAddressDescription']}',
|
|
M_PatientAddressM_KelurahanID = '{$prm['M_PatientAddressM_KelurahanID']}',
|
|
M_PatientAddressUserID = {$userid}
|
|
WHERE
|
|
M_PatientAddressID = '{$prm['M_PatientAddressID']}'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array('status' => 'OK')
|
|
);
|
|
$ptn = $prm;
|
|
$ptn["M_UserID"] = $pdob;
|
|
$xbefore = json_encode($rows_before);
|
|
$ptn = json_encode($ptn);
|
|
/*$this->db_onedev->query("INSERT INTO one_log.log_patient (
|
|
Log_PatientCode,
|
|
Log_PatientJson,
|
|
Log_PatientJsonBefore,
|
|
Log_PatientUserID
|
|
)
|
|
VALUES(
|
|
'PATIENT.ADDR_EDIT',
|
|
'{$ptn}',
|
|
'{$xbefore}',
|
|
'{$userid}'
|
|
)");*/
|
|
//$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_EDIT', '{$ptn}', $userid)");
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function deleteaddress()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$prm = $this->sys_input;
|
|
|
|
$query = "UPDATE m_patientaddress SET
|
|
M_PatientAddressIsActive = 'N',
|
|
M_PatientAddressUserID = {$userid}
|
|
WHERE
|
|
M_PatientAddressID = '{$prm['M_PatientAddressID']}'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array('status' => 'OK')
|
|
);
|
|
$ptn = $prm;
|
|
$ptn["M_UserID"] = $pdob;
|
|
$ptn = json_encode($ptn);
|
|
//$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_DELETE', '{$ptn}', $userid)");
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
public function searchold()
|
|
{
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 100;
|
|
$tot_count = 0;
|
|
$number_limit = 10;
|
|
$number_offset = (!isset($prm['current_page']) ? 1 : $prm['current_page'] - 1) * $number_limit;
|
|
|
|
$q = [
|
|
'noreg' => "",
|
|
'name' => '',
|
|
'hp' => '',
|
|
'dob' => '',
|
|
'address' => '',
|
|
'nik' => ''
|
|
];
|
|
|
|
$q_pid = "";
|
|
|
|
if ($prm['noreg'] != '')
|
|
$q['noreg'] = "AND M_PatientNoReg like '%{$prm['noreg']}%'";
|
|
|
|
if ($prm['snorm'] == '') {
|
|
if ($prm['search'] != '') {
|
|
$e = explode('+', $prm['search']);
|
|
if (isset($e[0])) {
|
|
$e[0] = str_replace("'", "\\'", $e[0]);
|
|
$q['name'] = "AND M_PatientName LIKE '%{$e[0]}%'";
|
|
}
|
|
if (isset($e[1]))
|
|
$q['hp'] = "AND ((M_PatientHP LIKE '%{$e[1]}%' and M_PatientHP IS NOT NULL) OR (M_PatientHP IS NULL AND '{$e[1]}' = ''))";
|
|
if (isset($e[2]))
|
|
$q['dob'] = "AND ((DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE '%{$e[2]}%' and M_PatientDOB IS NOT NULL) OR (M_PatientDOB IS NULL AND '{$e[2]}' = ''))";
|
|
if (isset($e[3]))
|
|
$q['address'] = "AND M_PatientAddressDescription LIKE '%{$e[3]}%'";
|
|
if (isset($e[4]))
|
|
$q['nik'] = "AND M_PatientIDNumber = '{$e[4]}'";
|
|
}
|
|
} else {
|
|
$q_pid = "AND M_PatientNoReg = '{$prm['snorm']}'";
|
|
}
|
|
|
|
if ($prm['snorm'] != '' || $prm['search'] != '') {
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT 'N' divider,M_PatientID,
|
|
M_PatientNoReg,
|
|
M_PatientPrefix,
|
|
M_PatientName,
|
|
M_PatientSuffix,
|
|
M_PatientHP,
|
|
M_PatientEmail,
|
|
M_PatientPOB,
|
|
M_PatientPhone,
|
|
M_PatientIDNumber,
|
|
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as M_PatientDOB,
|
|
M_PatientNote,
|
|
M_PatientNIK,
|
|
M_PatientJabatan,
|
|
M_PatientKedudukan,
|
|
M_PatientPJ,
|
|
M_PatientLocation,
|
|
M_PatientJob,
|
|
M_PatientM_SexID,
|
|
M_SexName,
|
|
M_PatientM_TitleID,
|
|
M_TitleName,
|
|
M_PatientM_ReligionID,
|
|
M_ReligionName,
|
|
M_PatientM_IdTypeID,
|
|
M_IdTypeName,
|
|
M_PatientIDNumber,
|
|
M_PatientPhoto,
|
|
IF(ISNULL(M_PatientSuspendID),'active','suspend' ) as status,
|
|
M_PatientAddressM_KelurahanID M_KelurahanID,
|
|
0 M_DistrictID, 0 M_CityID, 0 M_ProvinceID
|
|
FROM m_patient
|
|
JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
JOIN m_sex ON M_PatientM_SexID = M_SexID
|
|
JOIN m_branch ON M_BranchIsActive = 'Y' AND M_BranchIsDefault = 'Y'
|
|
JOIN m_patientaddress ON M_PatientAddressM_PatientID = M_PatientID AND M_PatientAddressIsActive = 'Y'
|
|
LEFT JOIN m_idtype ON M_IdTypeID = M_PatientM_IdTypeID AND M_IdTypeIsActive = 'Y'
|
|
LEFT JOIN m_religion ON m_patientm_religionid = m_religionid
|
|
LEFT JOIN m_patientsuspend ON M_PatientSuspendM_PatientID = M_PatientID AND M_PatientSuspendIsActive = 'Y'
|
|
WHERE
|
|
M_PatientSuspendID IS NULL AND M_PatientIsActive = 'Y'
|
|
{$q['address']}
|
|
{$q['noreg']}
|
|
{$q['name']}
|
|
{$q['hp']}
|
|
{$q['dob']}
|
|
{$q['nik']}
|
|
{$q_pid}
|
|
|
|
GROUP BY M_PatientID
|
|
LIMIT $number_limit offset $number_offset";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
foreach ($rows as $k => $v) {
|
|
$rows[$k]['M_PatientName'] = stripslashes($rows[$k]['M_PatientName']);
|
|
$rows[$k]['M_PatientAddressDescription'] = stripslashes($v['M_PatientAddressDescription']);
|
|
$patient_name = str_replace("'", "\\'", $prm['M_PatientName']);
|
|
$sql = "SELECT *, concat('{$rows[$k]['M_PatientAddressDescription']}', '\n\n',
|
|
m_kelurahanname, ', ',
|
|
m_districtname,'\n',
|
|
m_cityname, ', ',
|
|
m_provincename) as xaddress
|
|
FROM m_kelurahan
|
|
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
|
|
JOIN m_city ON M_DistrictM_CityID = M_CityID
|
|
JOIN m_province ON M_CityM_ProvinceID = M_ProvinceID
|
|
WHERE
|
|
M_KelurahanID = {$v['M_KelurahanID']} ";
|
|
//echo $sql;
|
|
$row_address = $this->db_onedev->query($sql)->row_array();
|
|
$rows[$k]['M_PatientAddress'] = stripslashes($row_address['xaddress']);
|
|
$rows[$k]['M_DistrictID'] = $row_address['M_DistrictID'];
|
|
$rows[$k]['M_CityID'] = $row_address['M_CityID'];
|
|
$rows[$k]['M_ProvinceID'] = $row_address['M_ProvinceID'];
|
|
$info = $this->db_onedev->query("SELECT fn_fo_patient_visit(?) info", [$v['M_PatientID']])->row();
|
|
$rows[$k]['info'] = json_decode($info->info);
|
|
}
|
|
|
|
$result = array("total" => $tot_page, "records" => $rows, "sql" => $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("m_patient rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
} else {
|
|
$result = array("total" => 0, "records" => [], "sql" => $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
}
|
|
}
|
|
|
|
function calculateAge($tanggal_lahir)
|
|
{
|
|
// Ambil tanggal sekarang
|
|
$tanggal_sekarang = new DateTime();
|
|
|
|
// Ubah tanggal lahir ke objek DateTime
|
|
$tanggal_lahir = new DateTime($tanggal_lahir);
|
|
|
|
// Hitung selisih antara tanggal sekarang dan tanggal lahir
|
|
$perbedaan = $tanggal_sekarang->diff($tanggal_lahir);
|
|
|
|
// Dapatkan tahun, bulan, dan hari dari selisih
|
|
$umur_tahun = $perbedaan->y;
|
|
$umur_bulan = $perbedaan->m;
|
|
$umur_hari = $perbedaan->d;
|
|
|
|
|
|
return array($umur_tahun, $umur_bulan, $umur_hari);
|
|
}
|
|
|
|
function saveorder()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$prm = $this->sys_input;
|
|
|
|
$exp_dob = explode("-", $prm['patient']['M_PatientDOB']);
|
|
$queueNumber = $prm['queueNumber'];
|
|
$queueID = $prm['queueID'];
|
|
|
|
list($umur_tahun, $umur_bulan, $umur_hari) = $this->calculateAge($exp_dob[2] . '-' . $exp_dob[1] . '-' . $exp_dob[0]);
|
|
|
|
$sql = "SELECT * FROM one_klinik.setting WHERE settingIsActive = 'Y' LIMIT 1";
|
|
$setting_data = $this->db_oneklinik->query($sql)->row_array();
|
|
|
|
/*$sql = "SELECT M_PatientID as patient_id,
|
|
CONCAT(IFNULL(M_PatientPrefix,''),IFNULL(M_PatientPrefix2,''),' ',M_PatientName,' ',IFNULL(M_PatientSufix,''),IFNULL(M_PatientSufix2,''),IFNULL(M_PatientSufix3,'')) as patient_name
|
|
FROM m_patient_schedule
|
|
JOIN one_aditya.m_patient ON M_PatientScheduleM_PatientID = M_PatientID
|
|
WHERE
|
|
M_PatientScheduleM_RegDayID = DAYOFWEEK(DATE(NOW())) AND
|
|
M_PatientScheduleIsActive = 'Y'";
|
|
$query = $this->db_oneklinik->query($sql);
|
|
|
|
if(!$query){
|
|
$this->sys_error("Invalid Query m_patient_schedule");
|
|
exit;
|
|
}
|
|
|
|
$patient_row = $query->row_array();*/
|
|
|
|
$sql = "INSERT INTO one_klinik.`order`
|
|
(`orderDate`,
|
|
`orderM_PatientID`,
|
|
`orderM_PatientID`,
|
|
`orderAge`,
|
|
`orderKeluhan`,
|
|
`orderSubtotal`,
|
|
`orderTotal`,
|
|
`orderUserID`,
|
|
`orderCreated`,
|
|
orderQueueNumber,
|
|
orderM_LocationID)
|
|
VALUES (NOW(),?,?,?,?,?,?,$userid,NOW(),?,?)";
|
|
|
|
$save_order = $this->db_oneklinik->query($sql, array(
|
|
$prm['patient']['M_PatientID'],
|
|
NULL,
|
|
$umur_tahun . ' Tahun ' . $umur_bulan . ' Bulan ' . $umur_hari . ' Hari',
|
|
$prm['keluhan'],
|
|
$setting_data['settingPriceDefault'],
|
|
$setting_data['settingPriceDefault'],
|
|
$queueNumber,
|
|
$setting_data['settingM_LocationID']
|
|
));
|
|
//echo $this->db_oneklinik->last_query();
|
|
if ($save_order) {
|
|
$last_id = $this->db_oneklinik->insert_id();
|
|
$sql = "INSERT INTO one_klinik.`order_status`(
|
|
orderStatusCode,
|
|
orderStatusOrderID,
|
|
orderStatusValue,
|
|
orderStatusUserID,
|
|
orderStatusCreated
|
|
)
|
|
VALUES(
|
|
'R',?,'D',?,NOW()
|
|
)";
|
|
$query = $this->db_oneklinik->query($sql, array($last_id, $userID));
|
|
if (!$query) {
|
|
$this->sys_error_db("error insert order status", $this->db_oneklinik);
|
|
exit;
|
|
}
|
|
|
|
$sql = "INSERT INTO one_klinik.`order_status`(
|
|
orderStatusCode,
|
|
orderStatusOrderID,
|
|
orderStatusValue,
|
|
orderStatusUserID,
|
|
orderStatusCreated
|
|
)
|
|
VALUES(
|
|
'SA',?,'D',?,NOW()
|
|
)";
|
|
$query = $this->db_oneklinik->query($sql, array($last_id, $userID));
|
|
if (!$query) {
|
|
$this->sys_error_db("error insert order status", $this->db_oneklinik);
|
|
exit;
|
|
}
|
|
//echo $last_id;
|
|
$sql = "SELECT * FROM one_klinik.`order` WHERE orderID = {$last_id}";
|
|
//echo $sql;
|
|
$data_order = $this->db_oneklinik->query($sql)->row_array();
|
|
if ($queueID != "0" && trim($queueNumber) != "") {
|
|
$this->done_today_by_queue_number($queueNumber, $queueID);
|
|
}
|
|
|
|
$this->sys_ok($data_order);
|
|
} else {
|
|
$this->sys_error_db("error order save", $this->db_oneklinik);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// public function done_today_by_queue_number($get_queue_number, $queueID)
|
|
// {
|
|
// try {
|
|
// // if (!$this->isLogin) {
|
|
// // $this->sys_error("Invalid Token");
|
|
// // exit;
|
|
// // }
|
|
|
|
// $prm = $this->sys_input;
|
|
// // $get_queue_number = $this->uri->segment('4');
|
|
// // $queueID = $this->uri->segment('5');
|
|
|
|
// // check IP ADDRESS
|
|
// $sql_cek_counter_ip = "select counterIsDedicated, counterID
|
|
// from counter
|
|
// where counterIsActive = 'Y'
|
|
// AND counterIP = ?";
|
|
// // echo $sql_cek_counter_ip;
|
|
|
|
// $qry_cek_counter_ip = $this->db_antrione->query($sql_cek_counter_ip, [$this->input->ip_address()]);
|
|
|
|
// $last_qry = $this->db_antrione->last_query();
|
|
|
|
// if (!$qry_cek_counter_ip) {
|
|
// $this->db_antrione->trans_rollback();
|
|
// $error = $this->db_antrione->error()["message"];
|
|
// $this->sys_error_db($error, $this->db_antrione);
|
|
// exit;
|
|
// }
|
|
|
|
// $data_cek_counter_ip = $qry_cek_counter_ip->result_array();
|
|
|
|
// if (count($data_cek_counter_ip) > 0) {
|
|
// // call sp_done(?,?)
|
|
|
|
// $counterID = $data_cek_counter_ip[0]['counterID'];
|
|
// $sql_sp_done = "call sp_done(?,?,?)";
|
|
// $qry_call_sp = $this->db_antrione->query($sql_sp_done, [$get_queue_number, $counterID, '']);
|
|
|
|
// if (!$qry_call_sp) {
|
|
// $this->db_antrione->trans_rollback();
|
|
// $error = $this->db_antrione->error()["message"];
|
|
// $this->sys_error_db($error, $this->db_antrione);
|
|
// exit;
|
|
// }
|
|
// $this->clean_mysqli_connection($this->db_antrione->conn_id);
|
|
|
|
// if ($qry_call_sp->result_array()[0]['status'] == "ERR") {
|
|
// echo json_encode(array(
|
|
// 'status' => $qry_call_sp->result_array()[0]['status'],
|
|
// 'message' => $qry_call_sp->result_array()[0]['message']
|
|
// ));
|
|
// } else {
|
|
// $sql_get_sID = "SELECT queueServiceID as serviceID,
|
|
// queueCounterID as counterID,
|
|
// serviceIsConsultPatient
|
|
// FROM queue
|
|
// left join service
|
|
// ON queueServiceID = ServiceID
|
|
// AND ServiceIsActive = 'Y'
|
|
// WHERE queueID = ?";
|
|
// $qry_get_sID = $this->db_antrione->query($sql_get_sID, [$queueID]);
|
|
|
|
// $last_qry = $this->db_antrione->last_query();
|
|
|
|
// if (!$qry_get_sID) {
|
|
// $error = $this->db_antrione->error()["message"];
|
|
// $this->sys_error_db($error, $this->db_antrione);
|
|
// exit;
|
|
// }
|
|
|
|
// $data = $qry_get_sID->row_array();
|
|
// $serviceID = $data['serviceID'];
|
|
// $counterID = $data['counterID'];
|
|
// $serviceIsConsultPatient = $data['serviceIsConsultPatient'];
|
|
|
|
// // check jk serviceIsConsultPatient Y mk antrian konsul dokter
|
|
|
|
// if ($serviceIsConsultPatient == 'Y') {
|
|
// file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/done.kd.$serviceID.$counterID");
|
|
// } else {
|
|
// file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/done.fo.$serviceID.$counterID");
|
|
// }
|
|
|
|
// return array(
|
|
// 'status' => $qry_call_sp->result_array()[0]['status'],
|
|
// 'message' => $qry_call_sp->result_array()[0]['message'],
|
|
// );
|
|
// }
|
|
// } else {
|
|
// return
|
|
// array(
|
|
// array(
|
|
// 'status' => 'ERR',
|
|
// 'message' => 'Invalid IP address ' . $this->input->ip_address()
|
|
// )
|
|
// );
|
|
// }
|
|
// } catch (Exception $exc) {
|
|
// $message = $exc->getMessage();
|
|
// $this->sys_error($message);
|
|
// exit;
|
|
// }
|
|
// }
|
|
}
|