sys_debug(); try { if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } */ class Patient extends MY_Controller { var $db_smartone; public function index() { echo "Patient API"; } public function __construct() { parent::__construct(); $this->db_smartone = $this->load->database("onedev", true); } function _add_address(&$pat) { if (count($pat) == "0") { return array(); } foreach ($pat as $idx => $p) { $pat[$idx]["address"] = array($p["M_PatientAddress"]); } $this->_add_history($pat); } function _add_history(&$pat) { $pat_list = "-1"; foreach ($pat as $idx => $p) { $pat_list .= ", " . $p["M_PatientID"]; if (! isset($pat[$idx]["history"])) $pat[$idx]["history"] = array(); } $sql = "select T_OrderHeaderM_PatientID,T_OrderHeaderLabNumber,T_OrderHeaderDate, concat(T_OrderDetailT_TestName) T_TestName from t_orderheader join t_orderdetail on T_OrderHeaderID = T_OrderDetailID and T_OrderHeaderIsActive = 'Y' and T_OrderDetailIsActive = 'Y' and T_OrderHeaderM_PatientID in ( $pat_list ) join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsPrice = 'Y' order by T_OrderHeaderM_PatientID,T_OrderHeaderLabNumber"; $query = $this->db_smartone->query($sql); if ($query) { $rows = $query->result_array(); foreach ($rows as $r) { $patientID = $r["T_OrderHeaderM_PatientID"]; foreach ($pat as $idx => $p) { if ($p["M_PatientID"] == $patientID) { $pat[$idx]["history"][] = $r; } } } } else { $this->sys_error_db("m_patient history", $this->db_smartone); exit; } } function search_nasional() { if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $param = $prm['search']; $this->load->library("NatPatientLib"); $resp = $this->natpatientlib->search($param); echo json_encode($resp); } 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' => '' ]; if ($prm['noreg'] != '') { if (strpos($prm['noreg'], "-") !== false) { // SEARCH BY MEMBER $q['noreg'] = "AND MemberNumber like '%{$prm['noreg']}%'"; 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 = trim('{$e[4]}')"; } $sql = "SELECT 'N' divider,M_PatientID, M_PatientNoReg,M_PatientEmail,M_PatientPrefix,M_PatientSuffix,M_PatientJob, CONCAT(IFNULL(M_TitleName,''),' ',IFNULL(M_PatientPrefix,''),' ',IFNULL(M_PatientName,MemberName),' ',IFNULL(M_PatientSuffix,'')) M_PatientName, IFNULL(M_IdTypeName,'-') as idtype_name, IFNULL(M_PatientName,MemberName) M_PatientRealName, M_TitleID, M_TitleName, M_SexID, M_SexName, IFNULL(M_PatientHP,MemberHp) M_PatientHP, M_PatientPOB, M_PatientDOB, DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as dob_ina, '' M_PatientAddress,M_BranchCode, M_BranchName, M_PatientAddressDescription, M_PatientM_IdTypeID, IFNULL(M_PatientIDNumber,MemberNIK) M_PatientIDNumber,IFNULL(M_PatientNIK,'') as M_PatientNIK, IFNULL(M_PatientNote, '') M_PatientNote, M_PatientPhoto, IF(M_PatientPhone IS NULL OR M_PatientPhone = '', M_PatientHP, M_PatientPhone) hp, -- fn_fo_patient_visit(M_PatientID) info, IFNULL(M_PatientAddressM_KelurahanID,0) M_KelurahanID, 0 M_DistrictID, 0 M_CityID, 0 M_ProvinceID, M_PatientM_ReligionID, IFNULL(M_ReligionName, '-') M_ReligionName, IF(M_PatientNatVerifID IS NULL,'N','Y') as isverif_nas, IF(M_PatientID IS NULL,'N','Y') as is_patient FROM one_pointreward.member_national LEFT JOIN m_patient ON M_PatientIDNumber = MemberNIK LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID LEFT JOIN m_sex ON M_PatientM_SexID = M_SexID LEFT JOIN m_branch ON M_BranchIsActive = 'Y' AND M_BranchIsDefault = 'Y' LEFT 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' LEFT JOIN m_patient_nat_verif ON M_PatientNatVerifM_PatientID = M_PatientID WHERE MemberNumber = '{$prm['noreg']}' LIMIT $number_limit offset $number_offset"; //echo $this->db_smartone->last_query(); $query = $this->db_smartone->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'] = str_replace("'", "\\'", 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_smartone->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_smartone->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_smartone->last_query()); $this->sys_ok($result); } else { $this->sys_error_db("m_patient rows", $this->db_smartone); exit; } } else { // SEARCH BY PATIENT ID $q['noreg'] = "AND M_PatientNoReg like '%{$prm['noreg']}%'"; 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 = trim('{$e[4]}')"; } $sql = "SELECT 'N' divider,M_PatientID, M_PatientNoReg,M_PatientEmail,M_PatientPrefix,M_PatientSuffix,M_PatientJob, CONCAT(M_TitleName,' ',IFNULL(M_PatientPrefix,''),' ',M_PatientName,' ',IFNULL(M_PatientSuffix,'')) M_PatientName, IFNULL(M_IdTypeName,'-') as idtype_name, M_PatientName M_PatientRealName, M_TitleID, M_TitleName, M_SexID, M_SexName, M_PatientHP, M_PatientPOB, M_PatientDOB, DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as dob_ina, '' M_PatientAddress,M_BranchCode, M_BranchName, M_PatientAddressDescription, M_PatientM_IdTypeID, M_PatientIDNumber,IFNULL(M_PatientNIK,'') as M_PatientNIK, IFNULL(M_PatientNote, '') M_PatientNote, M_PatientPhoto, IF(M_PatientPhone IS NULL OR M_PatientPhone = '', M_PatientHP, M_PatientPhone) hp, -- fn_fo_patient_visit(M_PatientID) info, M_PatientAddressM_KelurahanID M_KelurahanID, 0 M_DistrictID, 0 M_CityID, 0 M_ProvinceID, M_PatientM_ReligionID, IFNULL(M_ReligionName, '-') M_ReligionName, IF(M_PatientNatVerifID IS NULL,'N','Y') as isverif_nas, 'Y' as is_patient 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' LEFT JOIN m_patient_nat_verif ON M_PatientNatVerifM_PatientID = M_PatientID WHERE M_PatientSuspendID IS NULL AND M_PatientIsActive = 'Y' {$q['address']} {$q['noreg']} {$q['name']} {$q['hp']} {$q['dob']} {$q['nik']} GROUP BY M_PatientID LIMIT $number_limit offset $number_offset"; //echo $sql; $query = $this->db_smartone->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'] = str_replace("'", "\\'", 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_smartone->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_smartone->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_smartone->last_query()); $this->sys_ok($result); } else { $this->sys_error_db("m_patient rows", $this->db_smartone); exit; } } } else { 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 = trim('{$e[4]}')"; } $sql = "SELECT 'N' divider,M_PatientID, M_PatientNoReg,M_PatientEmail,M_PatientPrefix,M_PatientSuffix,M_PatientJob, CONCAT(M_TitleName,' ',IFNULL(M_PatientPrefix,''),' ',M_PatientName,' ',IFNULL(M_PatientSuffix,'')) M_PatientName, IFNULL(M_IdTypeName,'-') as idtype_name, M_PatientName M_PatientRealName, M_TitleID, M_TitleName, M_SexID, M_SexName, M_PatientHP, M_PatientPOB, M_PatientDOB, DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as dob_ina, '' M_PatientAddress,M_BranchCode, M_BranchName, M_PatientAddressDescription, M_PatientM_IdTypeID, M_PatientIDNumber,IFNULL(M_PatientNIK,'') as M_PatientNIK, IFNULL(M_PatientNote, '') M_PatientNote, M_PatientPhoto, IF(M_PatientPhone IS NULL OR M_PatientPhone = '', M_PatientHP, M_PatientPhone) hp, -- fn_fo_patient_visit(M_PatientID) info, M_PatientAddressM_KelurahanID M_KelurahanID, 0 M_DistrictID, 0 M_CityID, 0 M_ProvinceID, M_PatientM_ReligionID, IFNULL(M_ReligionName, '-') M_ReligionName, IF(M_PatientNatVerifID IS NULL,'N','Y') as isverif_nas, 'Y' as is_patient 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' LEFT JOIN m_patient_nat_verif ON M_PatientNatVerifM_PatientID = M_PatientID WHERE M_PatientSuspendID IS NULL AND M_PatientIsActive = 'Y' {$q['address']} {$q['noreg']} {$q['name']} {$q['hp']} {$q['dob']} {$q['nik']} GROUP BY M_PatientID LIMIT $number_limit offset $number_offset"; //echo $sql; $query = $this->db_smartone->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'] = str_replace("'", "\\'", 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_smartone->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_smartone->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_smartone->last_query()); $this->sys_ok($result); } else { $this->sys_error_db("m_patient rows", $this->db_smartone); exit; } } } function add_new() { if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $prm = $this->sys_input; $prm['M_PatientDOB'] = date('Y-m-d', strtotime($prm['M_PatientDOB'])); //sipe $M_IdTypeID = 0; if ($prm['M_PatientM_IdTypeID'] > 0) { $M_IdTypeID = $prm['M_PatientM_IdTypeID']; } $patient_name = str_replace("'", "\\'", $prm['M_PatientName']); $ptn = [ 'M_PatientName' => $patient_name, 'M_PatientM_TitleID' => $prm['M_PatientM_TitleID'], 'M_PatientPrefix' => $prm['M_PatientPrefix'], 'M_PatientSuffix' => $prm['M_PatientSuffix'], 'M_PatientM_SexID' => $prm['M_PatientM_SexID'], 'M_PatientM_ReligionID' => $prm['M_PatientM_ReligionID'], 'M_PatientDOB' => $prm['M_PatientDOB'], 'M_PatientPOB' => $prm['M_PatientPOB'], 'M_PatientHP' => $prm['M_PatientHP'], 'M_PatientPhone' => $prm['M_PatientPhone'], 'M_PatientEmail' => $prm['M_PatientEmail'], 'M_PatientJob' => $prm['M_PatientJob'], 'M_PatientNIK' => $prm['M_PatientNIK'], 'M_PatientM_IdTypeID' => $M_IdTypeID, 'M_PatientIDNumber' => $prm['M_PatientIDNumber'], 'M_PatientNote' => $prm['M_PatientNote'], 'M_PatientUserID' => $userid ]; $this->db_smartone->insert('m_patient', $ptn); $err = $this->db_smartone->error(); if ($err['message'] != "") { $this->sys_error_db("m_patient rows", $this->db_smartone); return; } $id = $this->db_smartone->insert_id(); $sql = "SELECT * FROM m_patient LEFT JOIN m_branch ON M_BranchIsDefault = 'Y' AND M_BranchIsActive = 'Y' WHERE M_PatientID = {$id} LIMIT 1"; $data_patient = $this->db_smartone->query($sql)->row_array(); if ($data_patient) { if (intval($M_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 = {$id}"; $this->db_smartone->query($sql); } } // LOG FO $ptn = json_encode($ptn); // $this->db_smartone->query("CALL one_log.log_me('FO', 'FO.PATIENT.ADD', '{$ptn}', '0')"); $address_description = str_replace("'", "\\'", $prm['M_PatientAddressDescription']); // save address $add = [ 'M_PatientAddressM_PatientID' => $id, 'M_PatientAddressDescription' => $address_description, 'M_PatientAddressUserID' => $userid, 'M_PatientAddressM_KelurahanID' => $prm['M_PatientAddressM_KelurahanID'] ]; $this->db_smartone->insert('m_patientaddress', $add); //echo $this->db_smartone->last_query(); // LOG FO $add = json_encode($add); //$this->db_smartone->query("CALL one_log.log_me('FO', 'FO.PATIENT.ADDRESS.ADD', '{$add}', '0')"); // get $r = $this->db_smartone->where('M_PatientID', $id) ->get('m_patient') ->row(); $rst = array("id" => $id, 'noreg' => $r->M_PatientNoReg); $this->sys_ok($rst); } function edit() { $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $prm['M_PatientDOB'] = date('Y-m-d', strtotime($prm['M_PatientDOB'])); $patient_name = str_replace("'", "\\'", $prm['M_PatientName']); $this->db_smartone->set('M_PatientName', $patient_name) ->set('M_PatientM_TitleID', $prm['M_PatientM_TitleID']) ->set('M_PatientPrefix', $prm['M_PatientPrefix']) ->set('M_PatientSuffix', $prm['M_PatientSuffix']) ->set('M_PatientM_SexID', $prm['M_PatientM_SexID']) ->set('M_PatientM_ReligionID', $prm['M_PatientM_ReligionID']) ->set('M_PatientDOB', $prm['M_PatientDOB']) ->set('M_PatientPOB', $prm['M_PatientPOB']) ->set('M_PatientHP', $prm['M_PatientHP']) ->set('M_PatientPhone', $prm['M_PatientPhone']) ->set('M_PatientEmail', $prm['M_PatientEmail']) ->set('M_PatientJob', $prm['M_PatientJob']) ->set('M_PatientNIK', $prm['M_PatientNIK']) ->set('M_PatientM_IdTypeID', $prm['M_PatientM_IdTypeID']) ->set('M_PatientIDNumber', $prm['M_PatientIDNumber']) ->set('M_PatientNote', $prm['M_PatientNote']) ->set('M_PatientUserID', $userid) ->where('M_PatientID', $prm['id']) ->update('m_patient'); $err = $this->db_smartone->error(); if ($err['message'] != "") { $this->sys_error_db("m_patient rows", $this->db_smartone); return; } $id = $prm['id']; $sql = "SELECT * FROM m_patient LEFT JOIN m_branch ON M_BranchIsDefault = 'Y' AND M_BranchIsActive = 'Y' WHERE M_PatientID = {$id} LIMIT 1"; $data_patient = $this->db_smartone->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 = {$id}"; // echo $sql; $this->db_smartone->query($sql); } } // LOG FO unset($prm['token']); $ptn = json_encode($prm); //$this->db_smartone->query("CALL one_log.log_me('FO', 'FO.PATIENT.EDIT', '{$ptn}', '{$this->sys_user['M_UserID']}')"); $sql = "SELECT * FROM m_patientaddress WHERE M_PatientAddressM_PatientID = {$id} AND M_PatientAddressIsactive = 'Y' ORDER BY M_PatientAddressID ASC LIMIT 1"; $id_address = $this->db_smartone->query($sql)->row()->M_PatientAddressID; $address_description = str_replace("'", "\\'", $prm['M_PatientAddressDescription']); $this->db_smartone->set('M_PatientAddressM_KelurahanID', $prm['M_PatientAddressM_KelurahanID']) ->set('M_PatientAddressDescription', $address_description) ->set('M_PatientAddressUserID', $userid) ->where('M_PatientAddressID', $id_address) ->update('m_patientaddress'); // LOG FO $add = $this->db_smartone->last_query(); //$this->db_smartone->query("CALL one_log.log_me('FO', 'FO.PATIENT.ADDRESS.EDIT', '{$add}', '0')"); // get $r = $this->db_smartone->where('M_PatientID', $id) ->get('m_patient') ->row(); $rst = array("id" => $id, 'noreg' => $r->M_PatientNoReg); $this->sys_ok($rst); } public function search_idtype() { if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $sql = "SELECT M_IdTypeID, M_IdTypeName FROM m_idtype WHERE M_IdTypeIsActive = 'Y' ORDER BY M_IdTypeName ASC"; $query = $this->db_smartone->query($sql); if ($query) { $rows = $query->result_array(); $result = array("records" => $rows); $this->sys_ok($result); } else { $this->sys_error_db("m_idtype rows", $this->db_smartone); exit; } } function check_connection_national() { if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $this->load->library("NatPatientLib"); $result = $this->natpatientlib->check_connection(); echo json_encode($result); } function getdatalocations() { if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $query = " SELECT M_KelurahanID,M_KelurahanName FROM m_kelurahan WHERE M_KelurahanID = ? "; //echo $query; $kelurahan = $this->db_onedev->query($query, array($id))->row_array(); $query = " SELECT M_CityID, M_CityName FROM m_kelurahan JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID JOIN m_city ON M_DistrictM_CityID = M_CityID WHERE M_KelurahanID = ? GROUP BY M_CityID LIMIT 1 "; //echo $query; $city = $this->db_onedev->query($query, array($id))->row_array(); $cities[] = $city; $query = "SELECT M_DistrictID, M_DistrictName FROM m_kelurahan JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID WHERE M_DistrictM_CityID = ? GROUP BY M_DistrictID LIMIT 1 "; //echo $query; $district = $this->db_onedev->query($query, array($id))->row_array(); $query = "SELECT M_DistrictID, M_DistrictName FROM m_district WHERE M_DistrictM_CityID = ? "; //echo $query; $districts = $this->db_onedev->query($query, array($city['M_CityID']))->result_array(); $query = "SELECT M_KelurahanID,M_KelurahanName FROM m_kelurahan WHERE M_KelurahanM_DistrictID = ? "; //echo $query; $kelurahans = $this->db_onedev->query($query, array($district['M_DistrictID']))->result_array(); $result = array( "kelurahan" => $kelurahan, "kelurahans" => $kelurahans, "district" => $district, "districts" => $districts, "city" => $city, "cities" => $cities, ); $this->sys_ok($result); exit; } function get_address() { $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 = ? "; //echo $query; $rows = $this->db_onedev->query($query, array($prm['M_PatientID']))->result_array(); if ($rows) { foreach ($rows as $k => $v) { $rows[$k]['M_PatientAddressDescription'] = stripslashes($v['M_PatientAddressDescription']); } } else { $rows = []; } $result = array( "total" => count($rows), "records" => $rows, ); $this->sys_ok($result); exit; } function download_data() { if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prmx = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $prm = $prmx["patient"]; $address = $prmx["address"]; $sql = " SELECT * FROM m_patient LEFT JOIN m_patientsuspend ON M_PatientSuspendM_PatientID = M_PatientID AND M_PatientSuspendIsActive = 'Y' WHERE ISNULL(M_PatientSuspendID) AND M_PatientIDNumber = '{$prm['Nat_PatientIDNumber']}' AND M_PatientIsActive = 'Y' ORDER BY M_PatientID DESC LIMIT 1"; $exist_data = $this->db_smartone->query($sql)->row_array(); if (!$exist_data) { $prm['Nat_PatientDOB'] = date('Y-m-d', strtotime($prm['Nat_PatientDOB'])); $M_IdTypeID = 0; if ($prm['Nat_PatientM_IdTypeID'] > 0) { $M_IdTypeID = $prm['Nat_PatientM_IdTypeID']; } $patient_name = str_replace("'", "\\'", $prm['Nat_PatientName']); $ptn = [ 'M_PatientName' => $patient_name, 'M_PatientM_TitleID' => $prm['Nat_PatientM_TitleID'], 'M_PatientPrefix' => $prm['Nat_PatientPrefix'], 'M_PatientSuffix' => $prm['Nat_PatientSuffix'], 'M_PatientM_SexID' => $prm['Nat_PatientM_SexID'], 'M_PatientM_ReligionID' => $prm['Nat_PatientM_ReligionID'], 'M_PatientDOB' => $prm['Nat_PatientDOB'], 'M_PatientPOB' => $prm['Nat_PatientPOB'], 'M_PatientHP' => $prm['Nat_PatientHP'], 'M_PatientPhone' => $prm['Nat_PatientPhone'], 'M_PatientEmail' => $prm['Nat_PatientEmail'], 'M_PatientJob' => $prm['Nat_PatientJob'], 'M_PatientNIK' => $prm['Nat_PatientNIK'], 'M_PatientM_IdTypeID' => $M_IdTypeID, 'M_PatientIDNumber' => $prm['Nat_PatientIDNumber'], 'M_PatientNote' => $prm['Nat_PatientNote'], 'M_PatientJabatan' => $prm['Nat_PatientJabatan'], 'M_PatientJob' => $prm['Nat_PatientJob'], 'M_PatientKedudukan' => $prm['Nat_PatientKedudukan'], 'M_PatientNIK' => $prm['Nat_PatientNIK'], 'M_PatientPJ' => $prm['Nat_PatientPJ'], 'M_PatientM_CompanyStaffPositionID' => $prm['Nat_PatientM_CompanyStaffPositionID'], 'M_PatientLocation' => $prm['Nat_PatientLocation'], 'M_PatientUserID' => $userid ]; $this->db_smartone->insert('m_patient', $ptn); $err = $this->db_smartone->error(); if ($err['message'] != "") { $this->sys_error_db("m_patient rows", $this->db_smartone); return; } $id = $this->db_smartone->insert_id(); if (count($address) > 0) { foreach ($address as $key => $value) { $sql = "INSERT INTO m_patientaddress ( M_PatientAddressM_PatientID, M_PatientAddressNote, M_PatientAddressDescription, M_PatientAddressLocation, M_PatientAddressM_KelurahanID, M_PatientAddressPostCodeID, M_PatientAddressFax, M_PatientAddressEmail, M_PatientAddressPhone, M_PatientAddressCreated, M_PatientAddressLastUpdated, M_PatientAddressLat, M_PatientAddressLng, M_PatientAddressUserID ) VALUES( {$id}, '{$value['Nat_PatientAddressNote']}', '{$value['Nat_PatientAddressDescription']}', '{$value['Nat_PatientAddressLocation']}', '{$value['Nat_PatientAddressM_KelurahanID']}', '{$value['Nat_PatientAddressPostCodeID']}', '{$value['Nat_PatientAddressFax']}', '{$value['Nat_PatientAddressEmail']}', '{$value['Nat_PatientAddressPhone']}', NOW(), NOW(), '{$value['Nat_PatientAddressLat']}', '{$value['Nat_PatientAddressLng']}', {$userid} )"; $this->db_smartone->query($sql); } } $r = $this->db_smartone->where('M_PatientID', $id) ->get('m_patient') ->row(); $result = array("status" => 'OK', "id" => $id, 'noreg' => $r->M_PatientNoReg); } else { $sql = "SELECT * FROM m_patientaddress WHERE M_PatientAddressM_PatientID = ? AND M_PatientAddressIsActive = 'Y'"; $exist_address = $this->db_smartone->query($sql, array($exist_data['M_PatientID']))->result_array(); if ($exist_address) $result = array("status" => 'ERR', 'message' => 'Batal mengunduh ! Data pasien sudah ada'); else { if (count($address) > 0) { foreach ($address as $key => $value) { $sql = "INSERT INTO m_patientaddress ( M_PatientAddressM_PatientID, M_PatientAddressNote, M_PatientAddressDescription, M_PatientAddressLocation, M_PatientAddressM_KelurahanID, M_PatientAddressPostCodeID, M_PatientAddressFax, M_PatientAddressEmail, M_PatientAddressPhone, M_PatientAddressCreated, M_PatientAddressLastUpdated, M_PatientAddressLat, M_PatientAddressLng, M_PatientAddressUserID ) VALUES( {$exist_data['M_PatientID']}, '{$value['Nat_PatientAddressNote']}', '{$value['Nat_PatientAddressDescription']}', '{$value['Nat_PatientAddressLocation']}', '{$value['Nat_PatientAddressM_KelurahanID']}', '{$value['Nat_PatientAddressPostCodeID']}', '{$value['Nat_PatientAddressFax']}', '{$value['Nat_PatientAddressEmail']}', '{$value['Nat_PatientAddressPhone']}', NOW(), NOW(), '{$value['Nat_PatientAddressLat']}', '{$value['Nat_PatientAddressLng']}', {$userid} )"; $this->db_smartone->query($sql); } } $r = $this->db_smartone->where('M_PatientID', $exist_data['M_PatientID']) ->get('m_patient') ->row(); $result = array("status" => 'OK', "id" => $exist_data['M_PatientID'], 'noreg' => $r->M_PatientNoReg); } } // LOG FO $this->sys_ok($result); } function suspend() { if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $sql = "SELECT * FROM m_patientsuspend WHERE M_PatientSuspendM_PatientID = ? AND M_PatientSuspendIsActive = 'Y' LIMIT 1"; $query = $this->db_smartone->query($sql, array($prm['patient']['M_PatientID'])); if ($query) { if (!$query->row_array()) { $sql = "INSERT INTO m_patientsuspend ( M_PatientSuspendM_PatientID, M_PatientSuspendCreated, M_PatientSuspendCreatedBy ) VALUES( ?,NOW(),? )"; $query = $this->db_smartone->query($sql, array($prm['patient']['M_PatientID'], $userid)); $result = array("idx" => $this->db_smartone->insert_id()); $this->sys_ok($result); } else { $this->sys_error_db("Pasien sudah disuspend", $this->db_smartone); exit; } } else { $this->sys_error_db("Gagal query", $this->db_smartone); exit; } } function search_icd10() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userID = $this->sys_user['M_UserID']; //print_r($prm['subgroup']); $sql = "SELECT terminology.*, CONCAT(code,' | ', display) as display_name FROM one_terminology.terminology WHERE attribute_path = 'icd10' AND ( code LIKE CONCAT('%',?,'%') OR MATCH (display) AGAINST (? IN NATURAL LANGUAGE MODE) OR CONCAT(code,' | ', display) LIKE CONCAT('%',?,'%')) GROUP BY code"; $query = $this->db_onedev->query($sql, array($prm['search'], $prm['search'], $prm['search'])); if (!$query) { $this->sys_error("Gagal cari End"); } $result = $query->result_array(); $this->sys_ok($result); exit; } }