diff --git a/application/controllers/mockup/mcuoffline/Preregisterappcponev5.php b/application/controllers/mockup/mcuoffline/Preregisterappcponev5.php index f0b626d..cdc29ee 100644 --- a/application/controllers/mockup/mcuoffline/Preregisterappcponev5.php +++ b/application/controllers/mockup/mcuoffline/Preregisterappcponev5.php @@ -1,214 +1,215 @@ db_onedev = $this->load->database("onedev", true); - } - public function getsetup() - { - try { - // if (!$this->isLogin) { - // $this->sys_error("Invalid Token"); - // exit; - // } - $sql = "SELECT * - FROM mgm_mcu + public function __construct() + { + parent::__construct(); + $this->db_onedev = $this->load->database("onedev", true); + } + public function getsetup() + { + try { + // if (!$this->isLogin) { + // $this->sys_error("Invalid Token"); + // exit; + // } + $sql = "SELECT * + FROM mgm_mcu WHERE Mgm_McuIsActive = 'Y' AND ( CURDATE() BETWEEN Mgm_McuStartDate AND Mgm_McuEndDate ) ORDER BY Mgm_McuStartDate ASC, Mgm_McuEndDate ASC"; - $qry = $this->db_onedev->query($sql, []); - $last_qry = $this->db_onedev->last_query(); - if (!$qry) { - $message = $this->db_onedev->error(); - $message['last_qry'] = $last_qry; - $this->sys_error($message); - exit; - } - $data = $qry->result_array(); - $result = [ - "records" => $data, - ]; - $this->sys_ok($result); - } catch (Exception $exc) { - $message = $exc->getMessage(); - $this->sys_error($message); - } - } + $qry = $this->db_onedev->query($sql, []); + $last_qry = $this->db_onedev->last_query(); + if (!$qry) { + $message = $this->db_onedev->error(); + $message['last_qry'] = $last_qry; + $this->sys_error($message); + exit; + } + $data = $qry->result_array(); + $result = [ + "records" => $data, + ]; + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } - function generate_code_string(){ - $length = 5; - $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $code = ''; - for ($i = 0; $i < $length; $i++) { - $code .= $characters[rand(0, strlen($characters) - 1)]; - } - return $code; - } + function generate_code_string() + { + $length = 5; + $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $code = ''; + for ($i = 0; $i < $length; $i++) { + $code .= $characters[rand(0, strlen($characters) - 1)]; + } + return $code; + } - function generate_uuid(){ - // Generate 16 bytes (128 bits) of random data - $data = random_bytes(16); - - // Set version to 0100 - $data[6] = chr(ord($data[6]) & 0x0f | 0x40); - // Set bits 6-7 to 10 - $data[8] = chr(ord($data[8]) & 0x3f | 0x80); + function generate_uuid() + { + // Generate 16 bytes (128 bits) of random data + $data = random_bytes(16); - // Output the 36 character UUID - return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); - } + // Set version to 0100 + $data[6] = chr(ord($data[6]) & 0x0f | 0x40); + // Set bits 6-7 to 10 + $data[8] = chr(ord($data[8]) & 0x3f | 0x80); - function generate_code_form(){ - try { - if (!$this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - $prm = $this->sys_input; - $mgm_mcu_id = $prm['id']; - $sql = "SELECT Mcu_PreregisterPatientsID - FROM mcu_preregister_patients - WHERE + // Output the 36 character UUID + return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); + } + + function generate_code_form() + { + try { + if (!$this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + $prm = $this->sys_input; + $mgm_mcu_id = $prm['id']; + $sql = "SELECT Mcu_PreregisterPatientsID + FROM mcu_preregister_patients + WHERE Mcu_PreregisterPatientsMgm_McuID = ? AND - ( - Mcu_PreregisterPatientsT_OrderHeaderID = 0 OR - Mcu_PreregisterPatientsIsRegistered = 'N' + ( + Mcu_PreregisterPatientsT_OrderHeaderID = 0 OR + Mcu_PreregisterPatientsIsRegistered = 'N' ) AND Mcu_PreregisterPatientsIsActive = 'Y' "; - $qry = $this->db_onedev->query($sql, [$mgm_mcu_id]); - $last_qry = $this->db_onedev->last_query(); - //echo $last_qry; - //exit; - if (!$qry) { - $message = $this->db_onedev->error(); - $message['last_qry'] = $last_qry; - $this->sys_error($message); - exit; - } - $data = $qry->result_array(); - if(count($data) > 0){ - foreach($data as $k => $v){ - - $sql = "SELECT COUNT(*) as total - FROM form_riwayat_pasien + $qry = $this->db_onedev->query($sql, [$mgm_mcu_id]); + $last_qry = $this->db_onedev->last_query(); + //echo $last_qry; + //exit; + if (!$qry) { + $message = $this->db_onedev->error(); + $message['last_qry'] = $last_qry; + $this->sys_error($message); + exit; + } + $data = $qry->result_array(); + if (count($data) > 0) { + foreach ($data as $k => $v) { + + $sql = "SELECT COUNT(*) as total + FROM form_riwayat_pasien WHERE FormRiwayatPasienPreregisterID = ? AND - FormRiwayatPasienIsActive = 'Y' + FormRiwayatPasienIsActive = 'Y' "; - $qry = $this->db_onedev->query($sql, [$v['Mcu_PreregisterPatientsID']]); - //echo $this->db_onedev->last_query(); - //exit; - if($qry){ - $total = $qry->result_array()[0]['total']; - if($total == 0){ - $code = $this->generate_code_string(); - $uuid = $this->generate_uuid(); + $qry = $this->db_onedev->query($sql, [$v['Mcu_PreregisterPatientsID']]); + //echo $this->db_onedev->last_query(); + //exit; + if ($qry) { + $total = $qry->result_array()[0]['total']; + if ($total == 0) { + $code = $this->generate_code_string(); + $uuid = $this->generate_uuid(); - $sql = "INSERT INTO form_riwayat_pasien ( - FormRiwayatPasienPreregisterID, - FormRiwayatPasienCode, + $sql = "INSERT INTO form_riwayat_pasien ( + FormRiwayatPasienPreregisterID, + FormRiwayatPasienCode, FormRiwayatPasienUUID, - FormRiwayatPasienCreated) + FormRiwayatPasienCreated) VALUES (?, ?, ?, NOW())"; - $qry = $this->db_onedev->query($sql, [$v['Mcu_PreregisterPatientsID'], $code, $uuid]); - - } - } - } - - - } - $result = [ - "records" => $data, - ]; - $this->sys_ok($result); - } catch (Exception $exc) { - $message = $exc->getMessage(); - $this->sys_error($message); - } - } + $qry = $this->db_onedev->query($sql, [$v['Mcu_PreregisterPatientsID'], $code, $uuid]); + } + } + } + } + $result = [ + "records" => $data, + ]; + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } - function search_patient_listing() - { - $prm = $this->sys_input; - if (!$this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } + function search_patient_listing() + { + $prm = $this->sys_input; + if (!$this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } - $search = $prm["search"]; - $setup = $prm["setup"]; - $status = $prm["status"]; - $sqlStatus = ""; - if ($status == 'Y') { - $sqlStatus = "AND Mcu_PreregisterPatientsIsRegistered = 'Y'"; - } else if ($status == 'N') { - $sqlStatus = "AND Mcu_PreregisterPatientsIsRegistered = 'N'"; - } - $q = [ - 'name' => '', - 'hp' => '', - 'dob' => '', - 'address' => '' - ]; + $search = $prm["search"]; + $setup = $prm["setup"]; + $status = $prm["status"]; + $sqlStatus = ""; + if ($status == 'Y') { + $sqlStatus = "AND Mcu_PreregisterPatientsIsRegistered = 'Y'"; + } else if ($status == 'N') { + $sqlStatus = "AND Mcu_PreregisterPatientsIsRegistered = 'N'"; + } + $q = [ + 'name' => '', + 'hp' => '', + 'dob' => '', + 'address' => '' + ]; - $sql_where = ""; - if ($prm['search'] != '') { - $e = explode('+', $prm['search']); - if (count($e) == 1) { - $sql_where .= "AND Mcu_PreregisterPatientsPatientName like CONCAT('%','{$e[0]}','%')"; - } - if (count($e) == 2) { - $sql_where .= "AND ( Mcu_PreregisterPatientsPatientName like CONCAT('%','{$e[0]}','%') AND Mcu_PreregisterPatientsNIP like CONCAT('%','{$e[1]}','%')) "; - } - } - // if ($search != "") { - // } + $sql_where = ""; + if ($prm['search'] != '') { + $e = explode('+', $prm['search']); + if (count($e) == 1) { + $sql_where .= "AND Mcu_PreregisterPatientsPatientName like CONCAT('%','{$e[0]}','%')"; + } + if (count($e) == 2) { + $sql_where .= "AND ( Mcu_PreregisterPatientsPatientName like CONCAT('%','{$e[0]}','%') AND Mcu_PreregisterPatientsNIP like CONCAT('%','{$e[1]}','%')) "; + } + } - $number_limit = 10; - $number_offset = ($prm['current_page'] - 1) * $number_limit; + if (!empty($prm['mcudate'])) { + $sql_where .= " AND Mcu_PreregisterDateCheckinSchedule = DATE({$prm['mcudate']}) "; + } - // if($setup['Mgm_McuM_BranchID']== '100'){ + $number_limit = 10; + $number_offset = ($prm['current_page'] - 1) * $number_limit; - // } + // if($setup['Mgm_McuM_BranchID']== '100'){ - $sql = " SELECT count(*) as total + // } + + $sql = " SELECT count(*) as total FROM mcu_preregister_patients JOIN m_patient ON Mcu_PreregisterPatientsM_PatientID = M_PatientID LEFT join terminology on attribute_path = 'Address.country' AND code = M_PatientAddressCountry LEFT JOIN m_title ON Mcu_PreregisterPatientsM_TitleID = M_TitleID LEFT JOIN t_orderheader ON Mcu_PreregisterPatientsT_OrderHeaderID = T_OrderHeaderID + LEFT JOIN mcu_preregister_date ON Mcu_PreregisterDateMcu_PreregisterPatientsID = Mcu_PreregisterPatientsID WHERE - Mcu_PreregisterPatientsIsActive = 'Y' AND Mcu_PreregisterPatientsMgm_McuID = {$setup['Mgm_McuID']} + Mcu_PreregisterPatientsIsActive = 'Y' AND Mcu_PreregisterPatientsMgm_McuID = {$setup['Mgm_McuID']} $sql_where $sqlStatus - - "; - //echo $sql; - $query = $this->db_onedev->query($sql); - $tot_count = 0; - $tot_page = 0; - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - $tot_page = ceil($tot_count / $number_limit); - } else { - $this->sys_error_db("m_doctor count", $this->db_onedev); - exit; - } + //echo $sql; + $query = $this->db_onedev->query($sql); + $tot_count = 0; + $tot_page = 0; + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + $tot_page = ceil($tot_count / $number_limit); + } else { + $this->sys_error_db("m_doctor count", $this->db_onedev); + exit; + } - $sql = " SELECT * + $sql = " SELECT * , '' as agreement, '' as packets, '' as tests, @@ -230,7 +231,8 @@ class Preregisterappcponev5 extends MY_Controller M_PatientReligionCode, CorporateEmail, IFNULL(FormRiwayatPasienCode, 'Belum digenerate') as code_form, - IFNULL(FormRiwayatPasienUUID, '') as uuid_form + IFNULL(FormRiwayatPasienUUID, '') as uuid_form, + Mcu_PreregisterDateCheckinSchedule FROM mcu_preregister_patients JOIN m_patient ON Mcu_PreregisterPatientsM_PatientID = M_PatientID JOIN mgm_mcu ON Mcu_PreregisterPatientsMgm_McuID = Mgm_McuID @@ -239,160 +241,161 @@ class Preregisterappcponev5 extends MY_Controller LEFT JOIN m_title ON Mcu_PreregisterPatientsM_TitleID = M_TitleID LEFT JOIN t_orderheader ON Mcu_PreregisterPatientsT_OrderHeaderID = T_OrderHeaderID LEFT JOIN form_riwayat_pasien ON Mcu_PreregisterPatientsID = FormRiwayatPasienPreregisterID AND FormRiwayatPasienIsActive = 'Y' + LEFT JOIN mcu_preregister_date ON Mcu_PreregisterDateMcu_PreregisterPatientsID = Mcu_PreregisterPatientsID WHERE - Mcu_PreregisterPatientsIsActive = 'Y' AND Mcu_PreregisterPatientsMgm_McuID = {$setup['Mgm_McuID']} + Mcu_PreregisterPatientsIsActive = 'Y' AND Mcu_PreregisterPatientsMgm_McuID = {$setup['Mgm_McuID']} $sql_where $sqlStatus ORDER BY T_OrderHeaderDate DESC, Mcu_PreregisterPatientsIsRegistered ASC, Mcu_PreregisterPatientsPatientName ASC limit $number_limit offset $number_offset"; - $query = $this->db_onedev->query($sql); - //echo $sql; - if (!$query) { - $message = $this->db_onedev->error(); - $message['last_qry'] = - $this->db_onedev->last_query(); - $this->sys_error($message); - exit; - }; - $lastQuerySearch = - $this->db_onedev->last_query(); - $rows = $query->result_array(); - if ($rows) { - foreach ($rows as $k => $v) { - $rows[$k]['packets'] = array(); - $rows[$k]['tests'] = array(); - $join_test = ''; - $filter_paket = "AND T_PacketSasCode IN ('')"; - $filter_test = "AND T_TestSasCode IN ('')"; + $query = $this->db_onedev->query($sql); + //echo $sql; + if (!$query) { + $message = $this->db_onedev->error(); + $message['last_qry'] = + $this->db_onedev->last_query(); + $this->sys_error($message); + exit; + }; + $lastQuerySearch = + $this->db_onedev->last_query(); + $rows = $query->result_array(); + if ($rows) { + foreach ($rows as $k => $v) { + $rows[$k]['packets'] = array(); + $rows[$k]['tests'] = array(); + $join_test = ''; + $filter_paket = "AND T_PacketSasCode IN ('')"; + $filter_test = "AND T_TestSasCode IN ('')"; - $testFromOptional = array(); - if ($v['Mcu_PreregisterPatientsOrders'] != '') { - $xjoin_tests = explode(',', $v['Mcu_PreregisterPatientsOrders']); - $unique_tests = array(); // array untuk menyimpan nilai unik - - if ($xjoin_tests) { - foreach ($xjoin_tests as $kjt => $vjt) { - $vjt = trim($vjt); + $testFromOptional = array(); + if ($v['Mcu_PreregisterPatientsOrders'] != '') { + $xjoin_tests = explode(',', $v['Mcu_PreregisterPatientsOrders']); + $unique_tests = array(); // array untuk menyimpan nilai unik - $opt = ""; - if (substr($vjt, -4) === '-opt') { - $opt = trim(explode("_", $vjt)[1]); - $vjt = trim(explode("_", $vjt)[0]); - // "10610200_163-opt" - } + if ($xjoin_tests) { + foreach ($xjoin_tests as $kjt => $vjt) { + $vjt = trim($vjt); - if (!in_array($vjt, $unique_tests)) { - $packet = trim(explode("-", $opt)[0]); - $testFromOptional[$vjt] = $packet; + $opt = ""; + if (substr($vjt, -4) === '-opt') { + $opt = trim(explode("_", $vjt)[1]); + $vjt = trim(explode("_", $vjt)[0]); + // "10610200_163-opt" + } - $unique_tests[] = $vjt; - if ($join_test != '') - $join_test .= ","; - $join_test .= "'{$vjt}'"; - } - } - } - //print_r($unique_tests)."
"; - //echo $join_test; - $filter_paket = "AND T_PacketSasCode IN ({$join_test})"; - $filter_test = "AND T_TestSasCode IN ({$join_test}) "; - } - $sql = "SELECT DISTINCT T_PacketID as id, T_PacketName as name, T_PacketSasCode as code, nat_test + if (!in_array($vjt, $unique_tests)) { + $packet = trim(explode("-", $opt)[0]); + $testFromOptional[$vjt] = $packet; + + $unique_tests[] = $vjt; + if ($join_test != '') + $join_test .= ","; + $join_test .= "'{$vjt}'"; + } + } + } + //print_r($unique_tests)."
"; + //echo $join_test; + $filter_paket = "AND T_PacketSasCode IN ({$join_test})"; + $filter_test = "AND T_TestSasCode IN ({$join_test}) "; + } + $sql = "SELECT DISTINCT T_PacketID as id, T_PacketName as name, T_PacketSasCode as code, nat_test FROM ss_price_mou - JOIN t_packet ON T_TestID = T_PacketID AND T_PacketIsActive = 'Y' + JOIN t_packet ON T_TestID = T_PacketID AND T_PacketIsActive = 'Y' JOIN mgm_mcupacket ON T_PacketID = Mgm_McuPacketT_PacketID AND Mgm_McuPacketIsActive = 'Y' AND Mgm_McuPacketMgm_McuID = {$setup['Mgm_McuID']} WHERE T_PriceT_PriceHeaderID = {$setup['Mgm_McuT_PriceHeaderID']} AND is_packet = 'Y' $filter_paket"; - //echo $sql; - $rows[$k]['packets'] = $this->db_onedev->query($sql)->result_array(); - if ($rows[$k]['packets']) { - foreach ($rows[$k]['packets'] as $kp => $vp) { - $rows[$k]['packets'][$kp]['nat_test'] = json_decode($vp['nat_test']); - } - } + //echo $sql; + $rows[$k]['packets'] = $this->db_onedev->query($sql)->result_array(); + if ($rows[$k]['packets']) { + foreach ($rows[$k]['packets'] as $kp => $vp) { + $rows[$k]['packets'][$kp]['nat_test'] = json_decode($vp['nat_test']); + } + } - $sql = "SELECT test.T_TestID as id, test.T_TestName as name, test.T_TestSasCode as code, nat_test + $sql = "SELECT test.T_TestID as id, test.T_TestName as name, test.T_TestSasCode as code, nat_test FROM ss_price_mou - JOIN t_test test ON test.T_TestID = ss_price_mou.T_TestID AND T_TestIsActive = 'Y' + JOIN t_test test ON test.T_TestID = ss_price_mou.T_TestID AND T_TestIsActive = 'Y' WHERE T_PriceT_PriceHeaderID = {$setup['Mgm_McuT_PriceHeaderID']} AND is_packet = 'N' AND T_PriceIsCito = 'N' $filter_test"; - //echo $sql; - $rows[$k]['tests'] = $this->db_onedev->query($sql)->result_array(); - if ($rows[$k]['tests']) { - foreach ($rows[$k]['tests'] as $kp => $vp) { - $rows[$k]['tests'][$kp]['nat_test'] = json_decode($vp['nat_test']); - // if test from optional packet - if (isset($testFromOptional[$vp['code']])) { - $rows[$k]['tests'][$kp]['T_PacketDetailT_PacketID'] = $testFromOptional[$vp['code']]; - } - } - } - } - $pids = array(); - $sql = "SELECT Mcu_PreregisterPatientsM_PatientID as id + //echo $sql; + $rows[$k]['tests'] = $this->db_onedev->query($sql)->result_array(); + if ($rows[$k]['tests']) { + foreach ($rows[$k]['tests'] as $kp => $vp) { + $rows[$k]['tests'][$kp]['nat_test'] = json_decode($vp['nat_test']); + // if test from optional packet + if (isset($testFromOptional[$vp['code']])) { + $rows[$k]['tests'][$kp]['T_PacketDetailT_PacketID'] = $testFromOptional[$vp['code']]; + } + } + } + } + $pids = array(); + $sql = "SELECT Mcu_PreregisterPatientsM_PatientID as id FROM mcu_preregister_patients WHERE Mcu_PreregisterPatientsIsActive = 'Y' AND Mcu_PreregisterPatientsMgm_McuID = '{$setup['Mgm_McuID']}'"; - $rows_all = $this->db_onedev->query($sql)->result_array(); - //echo $sql; - if ($rows_all) { - foreach ($rows_all as $ka => $va) { - array_push($pids, $va['id']); - } - } - } - //$this->_add_address($rows); - $result = array( - "total" => $tot_page, - "total_data" => $tot_count, - "records" => $rows, - "pids" => $pids, - "sql" => $this->db_onedev->last_query(), - "sqlsrc" => $lastQuerySearch - ); - $this->sys_ok($result); - exit; - } + $rows_all = $this->db_onedev->query($sql)->result_array(); + //echo $sql; + if ($rows_all) { + foreach ($rows_all as $ka => $va) { + array_push($pids, $va['id']); + } + } + } + //$this->_add_address($rows); + $result = array( + "total" => $tot_page, + "total_data" => $tot_count, + "records" => $rows, + "pids" => $pids, + "sql" => $this->db_onedev->last_query(), + "sqlsrc" => $lastQuerySearch + ); + $this->sys_ok($result); + exit; + } - function search_patient_table() - { - $prm = $this->sys_input; - $setup = $prm['setup']; + function search_patient_table() + { + $prm = $this->sys_input; + $setup = $prm['setup']; - $max_rst = 100; - $tot_count = 0; - $number_limit = 10; - $number_offset = (!isset($prm['current_page']) ? 1 : $prm['current_page'] - 1) * $number_limit; - if (isset($prm['reload'])) { - $number_limit = intval($prm['current_page']) * 10; - $number_offset = 0; - } + $max_rst = 100; + $tot_count = 0; + $number_limit = 10; + $number_offset = (!isset($prm['current_page']) ? 1 : $prm['current_page'] - 1) * $number_limit; + if (isset($prm['reload'])) { + $number_limit = intval($prm['current_page']) * 10; + $number_offset = 0; + } - $q = [ - 'name' => '', - 'hp' => '', - 'dob' => '', - 'address' => '' - ]; + $q = [ + 'name' => '', + 'hp' => '', + 'dob' => '', + 'address' => '' + ]; - if ($prm['search'] != '') { - $e = explode('+', $prm['search']); - if (isset($e[0])) - $q['name'] = "AND M_PatientName LIKE '%{$e[0]}%'"; - if (isset($e[1])) - $q['dob'] = "AND ((DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE '%{$e[1]}%' and M_PatientDOB IS NOT NULL) OR (M_PatientDOB IS NULL AND '{$e[1]}' = ''))"; - if (isset($e[2])) - $q['nik'] = "AND M_PatientNIP LIKE '%{$e[2]}%'"; - } + if ($prm['search'] != '') { + $e = explode('+', $prm['search']); + if (isset($e[0])) + $q['name'] = "AND M_PatientName LIKE '%{$e[0]}%'"; + if (isset($e[1])) + $q['dob'] = "AND ((DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE '%{$e[1]}%' and M_PatientDOB IS NOT NULL) OR (M_PatientDOB IS NULL AND '{$e[1]}' = ''))"; + if (isset($e[2])) + $q['nik'] = "AND M_PatientNIP LIKE '%{$e[2]}%'"; + } - $sql = "SELECT m_patient.*, + $sql = "SELECT m_patient.*, 'N' divider, concat(IFNULL(M_TitleName,''),' ',IFNULL(M_PatientPrefix,''),' ',M_PatientName,' ',IFNULL(M_PatientSuffix,'')) M_PatientName, M_PatientName M_PatientRealName, M_TitleID, M_TitleName, M_PatientGender, @@ -412,85 +415,85 @@ class Preregisterappcponev5 extends MY_Controller M_PatientDivisi as Mcu_PreregisterPatientsDivisi, M_PatientJob as Mcu_PreregisterPatientsJob, M_PatientDepartement as Mcu_PreregisterPatientsDepartment - from - m_patient + from + m_patient LEFT join m_title on M_PatientM_TitleID = M_TitleID - where M_PatientIsActive = 'Y' + where M_PatientIsActive = 'Y' {$q['name']} {$q['dob']} {$q['nik']} group by M_PatientID limit $number_limit offset $number_offset"; - //echo $sql; - $query = $this->db_onedev->query($sql); - $qryListing = $this->db_onedev->last_query(); + //echo $sql; + $query = $this->db_onedev->query($sql); + $qryListing = $this->db_onedev->last_query(); - if ($query) { - $rows = $query->result_array(); - if ($rows) { - $per_divider = 1; - foreach ($rows as $k => $v) { - if ($per_divider == 10) { - $rows[$k]['divider'] = 'Y'; - } - $per_divider = $per_divider + 1; - if ($per_divider > 10) - $per_divider = 1; - } - } - $pids = array(); - $sql = "SELECT Mcu_PreregisterPatientsM_PatientID as id + if ($query) { + $rows = $query->result_array(); + if ($rows) { + $per_divider = 1; + foreach ($rows as $k => $v) { + if ($per_divider == 10) { + $rows[$k]['divider'] = 'Y'; + } + $per_divider = $per_divider + 1; + if ($per_divider > 10) + $per_divider = 1; + } + } + $pids = array(); + $sql = "SELECT Mcu_PreregisterPatientsM_PatientID as id FROM mcu_preregister_patients WHERE Mcu_PreregisterPatientsIsActive = 'Y' AND Mcu_PreregisterPatientsMgm_McuID = '{$setup['Mgm_McuID']}'"; - $rows_all = $this->db_onedev->query($sql)->result_array(); - //echo $sql; - if ($rows_all) { - foreach ($rows_all as $ka => $va) { - array_push($pids, $va['id']); - } - } + $rows_all = $this->db_onedev->query($sql)->result_array(); + //echo $sql; + if ($rows_all) { + foreach ($rows_all as $ka => $va) { + array_push($pids, $va['id']); + } + } - $result = array("total" => "", "records" => $rows, "pids" => $pids, "sql" => $this->db_onedev->last_query(), "qrylisting" => $qryListing); - $this->sys_ok($result); - } else { - $this->sys_error_db("m_patient rows", $this->db_onedev); - exit; - } - } - function savenewform() - { - // $this->db_onedev->trans_begin(); - $this->db_onedev->trans_begin(); - // $this->db_onedev->trans_rollback(); - // $this->db_onedev->trans_commit(); - if (!$this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - $userid = $this->sys_user["M_UserID"]; - $prm = $this->sys_input; - //print_r($prm); - $setup = $prm['setup']; - $sql = "SELECT CorporateCode FROM corporate WHERE CorporateID = '{$setup['Mgm_McuCorporateID']}'"; - $qry = $this->db_onedev->query($sql); - if (!$qry) { - $message = $this->db_onedev->error(); - $this->db_onedev->trans_rollback(); - $this->sys_error($message); - exit; - } - $corporateCode = $qry->row_array()['CorporateCode']; - $v = $prm; + $result = array("total" => "", "records" => $rows, "pids" => $pids, "sql" => $this->db_onedev->last_query(), "qrylisting" => $qryListing); + $this->sys_ok($result); + } else { + $this->sys_error_db("m_patient rows", $this->db_onedev); + exit; + } + } + function savenewform() + { + // $this->db_onedev->trans_begin(); + $this->db_onedev->trans_begin(); + // $this->db_onedev->trans_rollback(); + // $this->db_onedev->trans_commit(); + if (!$this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + $userid = $this->sys_user["M_UserID"]; + $prm = $this->sys_input; + //print_r($prm); + $setup = $prm['setup']; + $sql = "SELECT CorporateCode FROM corporate WHERE CorporateID = '{$setup['Mgm_McuCorporateID']}'"; + $qry = $this->db_onedev->query($sql); + if (!$qry) { + $message = $this->db_onedev->error(); + $this->db_onedev->trans_rollback(); + $this->sys_error($message); + exit; + } + $corporateCode = $qry->row_array()['CorporateCode']; + $v = $prm; - $name = str_replace("'", "\\'", $v['M_PatientRealName']); - $nameEscape = $this->db_onedev->escape($v['M_PatientRealName']); - // print_r($name); - $pdob = date('Y-m-d', strtotime($v['M_PatientDOB'])); + $name = str_replace("'", "\\'", $v['M_PatientRealName']); + $nameEscape = $this->db_onedev->escape($v['M_PatientRealName']); + // print_r($name); + $pdob = date('Y-m-d', strtotime($v['M_PatientDOB'])); - $query = "INSERT INTO mcu_preregister_patients ( + $query = "INSERT INTO mcu_preregister_patients ( Mcu_PreregisterPatientsMgm_McuID, Mcu_PreregisterPatientsPID, Mcu_PreregisterPatientsM_PatientID, @@ -532,58 +535,58 @@ class Preregisterappcponev5 extends MY_Controller ?, ? )"; - //echo $query; - $rows = $this->db_onedev->query($query, [ - $setup['Mgm_McuID'], - $v['Mcu_PreregisterPatientsPID'], - $v['M_PatientID'], - $v['Mcu_PreregisterPatientsKTP'], - $v['M_PatientPrefix'], - $v['M_PatientRealName'], - $v['M_PatientSuffix'], - $v['M_PatientGender'], - $pdob, - $v['M_PatientReligionCode'], - $v['M_PatientJob'], - $v['M_PatientEmail'], - $v['M_PatientHp'], - $v['M_PatientPosisi'], - $v['M_PatientDivisi'], - $v['M_PatientLocation'], - $userid, - $v['Mcu_PreregisterPatientsM_TitleID'], - $corporateCode, - $v['M_PatientDepartement'], - $v['M_PatientNIP'] - ]); - if (!$rows) { - $message = $this->db_onedev->error(); - $this->db_onedev->trans_rollback(); - $this->sys_error($message); - exit; - } - $last_id_x = $this->db_onedev->insert_id(); - if (intval($v['Mcu_PreregisterPatientsM_PatientID']) == 0) { + //echo $query; + $rows = $this->db_onedev->query($query, [ + $setup['Mgm_McuID'], + $v['Mcu_PreregisterPatientsPID'], + $v['M_PatientID'], + $v['Mcu_PreregisterPatientsKTP'], + $v['M_PatientPrefix'], + $v['M_PatientRealName'], + $v['M_PatientSuffix'], + $v['M_PatientGender'], + $pdob, + $v['M_PatientReligionCode'], + $v['M_PatientJob'], + $v['M_PatientEmail'], + $v['M_PatientHp'], + $v['M_PatientPosisi'], + $v['M_PatientDivisi'], + $v['M_PatientLocation'], + $userid, + $v['Mcu_PreregisterPatientsM_TitleID'], + $corporateCode, + $v['M_PatientDepartement'], + $v['M_PatientNIP'] + ]); + if (!$rows) { + $message = $this->db_onedev->error(); + $this->db_onedev->trans_rollback(); + $this->sys_error($message); + exit; + } + $last_id_x = $this->db_onedev->insert_id(); + if (intval($v['Mcu_PreregisterPatientsM_PatientID']) == 0) { - $sql = "SELECT fn_numbering_cpone('P') as number"; - $rows = $this->db_onedev->query($sql); - if (!$rows) { - $message = $this->db_onedev->error(); - $this->db_onedev->trans_rollback(); - $this->sys_error($message); - exit; - } - $number = $rows->result_array()[0]['number']; + $sql = "SELECT fn_numbering_cpone('P') as number"; + $rows = $this->db_onedev->query($sql); + if (!$rows) { + $message = $this->db_onedev->error(); + $this->db_onedev->trans_rollback(); + $this->sys_error($message); + exit; + } + $number = $rows->result_array()[0]['number']; - $title_id = $v['Mcu_PreregisterPatientsM_TitleID']; - // $religion_id = $v['Mcu_PreregisterDetailsM_ReligionID']; - $religion_id = ''; - $nameNewP = $this->db_onedev->escape($v["Mcu_PreregisterPatientsPatientName"]); - $nameNewPn = str_replace("'", "\\'", $v['Mcu_PreregisterPatientsPatientName']); + $title_id = $v['Mcu_PreregisterPatientsM_TitleID']; + // $religion_id = $v['Mcu_PreregisterDetailsM_ReligionID']; + $religion_id = ''; + $nameNewP = $this->db_onedev->escape($v["Mcu_PreregisterPatientsPatientName"]); + $nameNewPn = str_replace("'", "\\'", $v['Mcu_PreregisterPatientsPatientName']); - $sql = "INSERT INTO m_patient ( + $sql = "INSERT INTO m_patient ( M_PatientPrefix, M_PatientName, M_PatientSuffix, @@ -645,151 +648,151 @@ class Preregisterappcponev5 extends MY_Controller '{$v['inp_CorporateAddressState']}', '{$v['country']}' )"; - //echo $sql; - $rows = $this->db_onedev->query($sql); - if (!$rows) { - $message = $this->db_onedev->error(); - $message['qry'] = $this->db_onedev->last_query(); - $this->db_onedev->trans_rollback(); - $this->sys_error($message); - exit; - } - $patient_id = $this->db_onedev->insert_id(); - $sql = "UPDATE mcu_preregister_patients SET Mcu_PreregisterPatientsM_PatientID = {$patient_id}, Mcu_PreregisterPatientsPID ='{$number}' WHERE Mcu_PreregisterPatientsID = {$last_id_x}"; - $rows = $this->db_onedev->query($sql); - if (!$rows) { - $message = $this->db_onedev->error(); - $this->db_onedev->trans_rollback(); - $this->sys_error($message); - exit; - } - } + //echo $sql; + $rows = $this->db_onedev->query($sql); + if (!$rows) { + $message = $this->db_onedev->error(); + $message['qry'] = $this->db_onedev->last_query(); + $this->db_onedev->trans_rollback(); + $this->sys_error($message); + exit; + } + $patient_id = $this->db_onedev->insert_id(); + $sql = "UPDATE mcu_preregister_patients SET Mcu_PreregisterPatientsM_PatientID = {$patient_id}, Mcu_PreregisterPatientsPID ='{$number}' WHERE Mcu_PreregisterPatientsID = {$last_id_x}"; + $rows = $this->db_onedev->query($sql); + if (!$rows) { + $message = $this->db_onedev->error(); + $this->db_onedev->trans_rollback(); + $this->sys_error($message); + exit; + } + } - $result = array( - "total" => 1, - "records" => array('status' => 'OK') - ); - $this->db_onedev->trans_commit(); - $this->sys_ok($result); - exit; - } - function getsexreg() - { - if (!$this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - $rows = []; - $query = " SELECT * + $result = array( + "total" => 1, + "records" => array('status' => 'OK') + ); + $this->db_onedev->trans_commit(); + $this->sys_ok($result); + exit; + } + function getsexreg() + { + if (!$this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + $rows = []; + $query = " SELECT * FROM m_title WHERE M_TitleIsActive = 'Y' "; - $gender = [ - [ - "M_SexID" => "MALE", - "M_SexCode" => "MALE", - "m_sexname" => "Laki Laki" - ], - [ - "M_SexID" => "FEMALE", - "M_SexCode" => "FEMALE", - "m_sexname" => "Perempuan" - ], - [ - "M_SexID" => "OTHER", - "M_SexCode" => "OTHER", - "m_sexname" => "Lainnya" - ] - ]; - //echo $query; - $rows['titles'] = $this->db_onedev->query($query)->result_array(); + $gender = [ + [ + "M_SexID" => "MALE", + "M_SexCode" => "MALE", + "m_sexname" => "Laki Laki" + ], + [ + "M_SexID" => "FEMALE", + "M_SexCode" => "FEMALE", + "m_sexname" => "Perempuan" + ], + [ + "M_SexID" => "OTHER", + "M_SexCode" => "OTHER", + "m_sexname" => "Lainnya" + ] + ]; + //echo $query; + $rows['titles'] = $this->db_onedev->query($query)->result_array(); - $rows['sexes'] = $gender; - $query = " SELECT * FROM terminology + $rows['sexes'] = $gender; + $query = " SELECT * FROM terminology WHERE attribute_path = 'Person.religion.code' AND code_system = 'xcpone.code.religion' AND status_cd = 'normal' ORDER BY order_no "; - //echo $query; - $rows['religions'] = $this->db_onedev->query($query)->result_array(); + //echo $query; + $rows['religions'] = $this->db_onedev->query($query)->result_array(); - $query = " SELECT * FROM terminology + $query = " SELECT * FROM terminology WHERE attribute_path = 'Person.identifier.type' AND code_system = 'http://terminology.hl7.org/CodeSystem/v2-0203' AND status_cd = 'normal' ORDER BY order_no "; - //echo $query; - $rows['kartuidentitass'] = $this->db_onedev->query($query)->result_array(); + //echo $query; + $rows['kartuidentitass'] = $this->db_onedev->query($query)->result_array(); - $result = array( - "total" => count($rows), - "records" => $rows, - ); - $this->sys_ok($result); - exit; - } - function removepatient() - { - if (!$this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - $userid = $this->sys_user["M_UserID"]; - $prm = $this->sys_input; + $result = array( + "total" => count($rows), + "records" => $rows, + ); + $this->sys_ok($result); + exit; + } + function removepatient() + { + if (!$this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + $userid = $this->sys_user["M_UserID"]; + $prm = $this->sys_input; - $query = " UPDATE mcu_preregister_patients SET + $query = " UPDATE mcu_preregister_patients SET Mcu_PreregisterPatientsIsActive = 'N', Mcu_PreregisterPatientsUserID = {$userid} WHERE Mcu_PreregisterPatientsID = {$prm['Mcu_PreregisterPatientsID']}"; - $this->db_onedev->query($query); - $result = array( - "total" => 1, - "records" => array('status' => 'OK') - ); + $this->db_onedev->query($query); + $result = array( + "total" => 1, + "records" => array('status' => 'OK') + ); - $this->sys_ok($result); - exit; - } - function getdatapackets() - { - if (!$this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - $prm = $this->sys_input; - $search = $prm["search"]; - $setup = $prm["setup"]; + $this->sys_ok($result); + exit; + } + function getdatapackets() + { + if (!$this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + $prm = $this->sys_input; + $search = $prm["search"]; + $setup = $prm["setup"]; - $number_limit = 10; - $number_offset = ($prm['current_page'] - 1) * $number_limit; + $number_limit = 10; + $number_offset = ($prm['current_page'] - 1) * $number_limit; - $sql = "SELECT DISTINCT - T_PacketID as id, - T_PacketName as name, - T_PacketSasCode as code, - T_PacketIsOptional, - nat_test, + $sql = "SELECT DISTINCT + T_PacketID as id, + T_PacketName as name, + T_PacketSasCode as code, + T_PacketIsOptional, + nat_test, ss_price_mou.T_PriceTotal as price FROM ss_price_mou - JOIN t_packet ON T_TestID = T_PacketID AND T_PacketIsActive = 'Y' + JOIN t_packet ON T_TestID = T_PacketID AND T_PacketIsActive = 'Y' JOIN mgm_mcupacket ON T_PacketID = Mgm_McuPacketT_PacketID AND Mgm_McuPacketIsActive = 'Y' AND Mgm_McuPacketMgm_McuID = {$setup['Mgm_McuID']} WHERE Ss_PriceMouMgm_McuID = {$setup['Mgm_McuID']} AND is_packet = 'Y' AND ( T_TestName LIKE CONCAT('%','{$search}','%') )"; - $sql = "SELECT count(*) as total + $sql = "SELECT count(*) as total FROM ( SELECT distinct T_PacketID as id, T_PacketName as name, T_PacketSasCode as code, nat_test FROM ss_price_mou - JOIN t_packet ON T_TestID = T_PacketID AND T_PacketIsActive = 'Y' + JOIN t_packet ON T_TestID = T_PacketID AND T_PacketIsActive = 'Y' JOIN mgm_mcupacket ON T_PacketID = Mgm_McuPacketT_PacketID AND Mgm_McuPacketIsActive = 'Y' AND Mgm_McuPacketMgm_McuID = {$setup['Mgm_McuID']} WHERE @@ -797,24 +800,24 @@ class Preregisterappcponev5 extends MY_Controller ( T_TestName LIKE CONCAT('%','{$search}','%') ) ) x "; - //echo $sql; - $query = $this->db_onedev->query($sql, []); - $tot_count = 0; - $tot_page = 0; - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - $tot_page = ceil($tot_count / $number_limit); - } else { - $this->sys_error_db("m_doctor count", $this->db_onedev); - exit; - } + //echo $sql; + $query = $this->db_onedev->query($sql, []); + $tot_count = 0; + $tot_page = 0; + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + $tot_page = ceil($tot_count / $number_limit); + } else { + $this->sys_error_db("m_doctor count", $this->db_onedev); + exit; + } - $query = "SELECT DISTINCT - T_PacketID as id, - T_PacketName as name, - T_PacketSasCode as code, - nat_test, - T_PacketIsOptional, + $query = "SELECT DISTINCT + T_PacketID as id, + T_PacketName as name, + T_PacketSasCode as code, + nat_test, + T_PacketIsOptional, ss_price_mou.T_PriceTotal as price FROM ss_price_mou JOIN t_packet ON T_TestID = T_PacketID AND T_PacketIsActive = 'Y' AND T_PacketIsGenerated = 'Y' @@ -825,38 +828,38 @@ class Preregisterappcponev5 extends MY_Controller ( T_TestName LIKE CONCAT('%','{$search}','%') ) ORDER BY T_PacketSasCode ASC limit $number_limit offset $number_offset"; - //echo $query; - $rows = $this->db_onedev->query($query)->result_array(); - if ($rows) { - foreach ($rows as $kp => $vp) { - $rows[$kp]['nat_test'] = json_decode($vp['nat_test']); - } - } + //echo $query; + $rows = $this->db_onedev->query($query)->result_array(); + if ($rows) { + foreach ($rows as $kp => $vp) { + $rows[$kp]['nat_test'] = json_decode($vp['nat_test']); + } + } - $result = array( - "total" => $tot_page, - "records" => $rows, - 'qry' => $this->db_onedev->last_query(), - ); - $this->sys_ok($result); - exit; - } + $result = array( + "total" => $tot_page, + "records" => $rows, + 'qry' => $this->db_onedev->last_query(), + ); + $this->sys_ok($result); + exit; + } - function getdatatests() - { - if (!$this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - $prm = $this->sys_input; - $search = $prm["search"]; - $setup = $prm["setup"]; - $number_limit = 10; - $number_offset = ($prm['current_page'] - 1) * $number_limit; + function getdatatests() + { + if (!$this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + $prm = $this->sys_input; + $search = $prm["search"]; + $setup = $prm["setup"]; + $number_limit = 10; + $number_offset = ($prm['current_page'] - 1) * $number_limit; - $sql = "SELECT test.T_TestID as id, test.T_TestName as name, test.T_TestSasCode as code, nat_test + $sql = "SELECT test.T_TestID as id, test.T_TestName as name, test.T_TestSasCode as code, nat_test FROM ss_price_mou - JOIN t_test test ON test.T_TestID = ss_price_mou.T_TestID AND T_TestIsActive = 'Y' + JOIN t_test test ON test.T_TestID = ss_price_mou.T_TestID AND T_TestIsActive = 'Y' JOIN t_price price ON test.T_TestID = price.T_PriceT_TestID AND T_PriceIsActive = 'Y' AND T_PriceT_PriceHeaderID = {$setup['Mgm_McuT_PriceHeaderID']} AND (test.T_TestName LIKE CONCAT('%','{$search}','%') OR test.T_TestSasCode LIKE CONCAT('%','{$search}','%')) @@ -864,112 +867,112 @@ class Preregisterappcponev5 extends MY_Controller Ss_PriceMouMgm_McuID = {$setup['Mgm_McuID']} AND is_packet = 'N' AND price.T_PriceIsCito = 'N'"; - $sql = "SELECT count(*) as total + $sql = "SELECT count(*) as total FROM ( SELECT test.T_TestID as id, test.T_TestName as name, test.T_TestSasCode as code, nat_test FROM ss_price_mou - JOIN t_test test ON test.T_TestID = ss_price_mou.T_TestID AND T_TestIsActive = 'Y' + JOIN t_test test ON test.T_TestID = ss_price_mou.T_TestID AND T_TestIsActive = 'Y' JOIN t_price price ON test.T_TestID = price.T_PriceT_TestID AND T_PriceIsActive = 'Y' AND price.T_PriceT_PriceHeaderID = {$setup['Mgm_McuT_PriceHeaderID']} AND (test.T_TestName LIKE CONCAT('%','{$search}','%') OR test.T_TestSasCode LIKE CONCAT('%','{$search}','%')) WHERE ss_price_mou.T_PriceT_PriceHeaderID = {$setup['Mgm_McuT_PriceHeaderID']} - AND is_packet = 'N' + AND is_packet = 'N' AND price.T_PriceIsCito = 'N' ) x "; - //echo $sql; - $query = $this->db_onedev->query($sql, []); - $tot_count = 0; - $tot_page = 0; - if ($query) { - $tot_count = $query->result_array()[0]["total"]; - $tot_page = ceil($tot_count / $number_limit); - } else { - $this->sys_error_db("m_doctor count", $this->db_onedev); - exit; - } - $query = "SELECT test.T_TestID as id, test.T_TestName as name, test.T_TestSasCode as code, nat_test,ss_price_mou.T_PriceTotal as price + //echo $sql; + $query = $this->db_onedev->query($sql, []); + $tot_count = 0; + $tot_page = 0; + if ($query) { + $tot_count = $query->result_array()[0]["total"]; + $tot_page = ceil($tot_count / $number_limit); + } else { + $this->sys_error_db("m_doctor count", $this->db_onedev); + exit; + } + $query = "SELECT test.T_TestID as id, test.T_TestName as name, test.T_TestSasCode as code, nat_test,ss_price_mou.T_PriceTotal as price FROM ss_price_mou - JOIN t_test test ON test.T_TestID = ss_price_mou.T_TestID AND T_TestIsActive = 'Y' + JOIN t_test test ON test.T_TestID = ss_price_mou.T_TestID AND T_TestIsActive = 'Y' JOIN t_price price ON test.T_TestID = price.T_PriceT_TestID AND T_PriceIsActive = 'Y' AND price.T_PriceT_PriceHeaderID = {$setup['Mgm_McuT_PriceHeaderID']} AND (test.T_TestName LIKE CONCAT('%','{$search}','%') OR test.T_TestSasCode LIKE CONCAT('%','{$search}','%')) WHERE ss_price_mou.T_PriceT_PriceHeaderID = {$setup['Mgm_McuT_PriceHeaderID']} - AND is_packet = 'N' + AND is_packet = 'N' AND price.T_PriceIsCito = 'N' ORDER BY T_TestSasCode ASC limit $number_limit offset $number_offset "; - //echo $query; - $rows = $this->db_onedev->query($query)->result_array(); - if ($rows) { - foreach ($rows as $kp => $vp) { - $rows[$kp]['nat_test'] = json_decode($vp['nat_test']); - } - } - $result = array( - "total" => $tot_page, - "records" => $rows, - ); - $this->sys_ok($result); - exit; - } + //echo $query; + $rows = $this->db_onedev->query($query)->result_array(); + if ($rows) { + foreach ($rows as $kp => $vp) { + $rows[$kp]['nat_test'] = json_decode($vp['nat_test']); + } + } + $result = array( + "total" => $tot_page, + "records" => $rows, + ); + $this->sys_ok($result); + exit; + } - function savepreregisterpatient() - { - $prm = $this->sys_input; - $userid = $this->sys_user["M_UserID"]; - if (!$this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - $v = $prm['selected_patient']; - $religion = $v['selected_religion']; + function savepreregisterpatient() + { + $prm = $this->sys_input; + $userid = $this->sys_user["M_UserID"]; + if (!$this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + $v = $prm['selected_patient']; + $religion = $v['selected_religion']; - $religionCode = $religion['code']; - $religionSystem = $religion['code_system']; - $setup = $prm['setup']; - $antrian = $prm['antrian'] ? $prm['antrian'] : ''; + $religionCode = $religion['code']; + $religionSystem = $religion['code_system']; + $setup = $prm['setup']; + $antrian = $prm['antrian'] ? $prm['antrian'] : ''; - $pdob = date('Y-m-d', strtotime($v['Mcu_PreregisterPatientsDOB'])); + $pdob = date('Y-m-d', strtotime($v['Mcu_PreregisterPatientsDOB'])); - $Mcu_PreregisterPatientsTests = ''; - $packettests = array(); - if (count($prm['selected_packets']) > 0) { - foreach ($prm['selected_packets'] as $kp => $vp) { - array_push($packettests, $vp['code']); - } - } - if (count($prm['selected_tests']) > 0) { - foreach ($prm['selected_tests'] as $kt => $vt) { - - // jika test diambil dari dalam paket opsional - if (!empty($vt['T_PacketDetailT_PacketID'])) { - $code = $vt['code'] . "_" . $vt['T_PacketDetailT_PacketID'] . "-opt"; - array_push($packettests, $code); - } else { - array_push($packettests, $vt['code']); - } - } - } - if (count($packettests) > 0) { - $Mcu_PreregisterPatientsTests = join(',', $packettests); - } + $Mcu_PreregisterPatientsTests = ''; + $packettests = array(); + if (count($prm['selected_packets']) > 0) { + foreach ($prm['selected_packets'] as $kp => $vp) { + array_push($packettests, $vp['code']); + } + } + if (count($prm['selected_tests']) > 0) { + foreach ($prm['selected_tests'] as $kt => $vt) { - $sql = "SELECT * FROM m_patient WHERE M_PatientID = ?"; - $rows = $this->db_onedev->query($sql, [$v['Mcu_PreregisterPatientsM_PatientID']]); - if (!$rows) { - $message = $this->db_onedev->error(); - $message['qry'] = $this->db_onedev->last_query(); - $this->sys_error($message); - exit; - } - $dataPatientBefore = $rows->row_array(); + // jika test diambil dari dalam paket opsional + if (!empty($vt['T_PacketDetailT_PacketID'])) { + $code = $vt['code'] . "_" . $vt['T_PacketDetailT_PacketID'] . "-opt"; + array_push($packettests, $code); + } else { + array_push($packettests, $vt['code']); + } + } + } + if (count($packettests) > 0) { + $Mcu_PreregisterPatientsTests = join(',', $packettests); + } - /*ada permintaan tdk bisa update nama pasien dari menu preregister 210525 (diki)*/ - $query = " UPDATE mcu_preregister_patients SET + $sql = "SELECT * FROM m_patient WHERE M_PatientID = ?"; + $rows = $this->db_onedev->query($sql, [$v['Mcu_PreregisterPatientsM_PatientID']]); + if (!$rows) { + $message = $this->db_onedev->error(); + $message['qry'] = $this->db_onedev->last_query(); + $this->sys_error($message); + exit; + } + $dataPatientBefore = $rows->row_array(); + + /*ada permintaan tdk bisa update nama pasien dari menu preregister 210525 (diki)*/ + $query = " UPDATE mcu_preregister_patients SET Mcu_PreregisterPatientsM_PatientID = ?, Mcu_PreregisterPatientsKTP = ?, Mcu_PreregisterPatientsNIP = ?, @@ -992,44 +995,44 @@ class Preregisterappcponev5 extends MY_Controller Mcu_PreregisterPatientsLastUpdated = NOW() WHERE Mcu_PreregisterPatientsID = ?"; - //echo $query; - $rows = $this->db_onedev->query($query, [ - $v['Mcu_PreregisterPatientsM_PatientID'], - $v['Mcu_PreregisterPatientsKTP'], - $v['Mcu_PreregisterPatientsNIP'], - $v['Mcu_PreregisterPatientsPatientPrefix'], - $v['Mcu_PreregisterPatientsPatientSuffix'], - $v['Mcu_PreregisterPatientsEmail'], - $v['Mcu_PreregisterPatientsHp'], - $pdob, - $v['Mcu_PreregisterPatientsPosisi'], - $v['Mcu_PreregisterPatientsDivisi'], - $v['Mcu_PreregisterPatientsJob'], - $v['Mcu_PreregisterPatientsLocation'], - $v['Mcu_PreregisterPatientsGender'], - $v['Mcu_PreregisterPatientsM_TitleID'], - $v['Mcu_PreregisterPatientsCorporateCode'], - $v['Mcu_PreregisterPatientsDepartment'], - $religionCode, - $Mcu_PreregisterPatientsTests, - $userid, - $v['Mcu_PreregisterPatientsID'] - ]); - if (!$rows) { - $message = $this->db_onedev->error(); - $message['qry'] = $this->db_onedev->last_query(); - $this->sys_error($message); - exit; - } + //echo $query; + $rows = $this->db_onedev->query($query, [ + $v['Mcu_PreregisterPatientsM_PatientID'], + $v['Mcu_PreregisterPatientsKTP'], + $v['Mcu_PreregisterPatientsNIP'], + $v['Mcu_PreregisterPatientsPatientPrefix'], + $v['Mcu_PreregisterPatientsPatientSuffix'], + $v['Mcu_PreregisterPatientsEmail'], + $v['Mcu_PreregisterPatientsHp'], + $pdob, + $v['Mcu_PreregisterPatientsPosisi'], + $v['Mcu_PreregisterPatientsDivisi'], + $v['Mcu_PreregisterPatientsJob'], + $v['Mcu_PreregisterPatientsLocation'], + $v['Mcu_PreregisterPatientsGender'], + $v['Mcu_PreregisterPatientsM_TitleID'], + $v['Mcu_PreregisterPatientsCorporateCode'], + $v['Mcu_PreregisterPatientsDepartment'], + $religionCode, + $Mcu_PreregisterPatientsTests, + $userid, + $v['Mcu_PreregisterPatientsID'] + ]); + if (!$rows) { + $message = $this->db_onedev->error(); + $message['qry'] = $this->db_onedev->last_query(); + $this->sys_error($message); + exit; + } - $sql_ktp = ''; - if (isset($v['Mcu_PreregisterPatientsKTP']) && $v['Mcu_PreregisterPatientsKTP'] != '') { - $sql_ktp = "M_PatientIdentifierCode = 'NNIDN', M_PatientIdentifierSystem='http://terminology.hl7.org/CodeSystem/v2-0203', M_PatientIdentifierValue = '{$v['Mcu_PreregisterPatientsKTP']}',"; - //echo $sql_ktp; - } else { - $sql_ktp = "M_PatientIdentifierCode = '', M_PatientIdentifierSystem='', M_PatientIdentifierValue = '',"; - } - $sql = "UPDATE m_patient SET + $sql_ktp = ''; + if (isset($v['Mcu_PreregisterPatientsKTP']) && $v['Mcu_PreregisterPatientsKTP'] != '') { + $sql_ktp = "M_PatientIdentifierCode = 'NNIDN', M_PatientIdentifierSystem='http://terminology.hl7.org/CodeSystem/v2-0203', M_PatientIdentifierValue = '{$v['Mcu_PreregisterPatientsKTP']}',"; + //echo $sql_ktp; + } else { + $sql_ktp = "M_PatientIdentifierCode = '', M_PatientIdentifierSystem='', M_PatientIdentifierValue = '',"; + } + $sql = "UPDATE m_patient SET $sql_ktp M_PatientDOB = ?, M_PatientM_TitleID = ?, @@ -1058,43 +1061,43 @@ class Preregisterappcponev5 extends MY_Controller WHERE M_PatientID = ? "; - //echo $sql; - $qry = $this->db_onedev->query($sql, [ - $pdob, - $v['Mcu_PreregisterPatientsM_TitleID'], - $v['Mcu_PreregisterPatientsNIP'], - $v['Mcu_PreregisterPatientsGender'], - $v['Mcu_PreregisterPatientsPatientPrefix'], - $v['Mcu_PreregisterPatientsPatientName'], - $v['Mcu_PreregisterPatientsPatientSuffix'], - $v['Mcu_PreregisterPatientsEmail'], - $v['Mcu_PreregisterPatientsHp'], - $v['Mcu_PreregisterPatientsDivisi'], - $v['Mcu_PreregisterPatientsPosisi'], - $v['Mcu_PreregisterPatientsLocation'], - $v['Mcu_PreregisterPatientsJob'], - $v['Mcu_PreregisterPatientsDepartment'], - $religionCode, - $religionSystem, - $prm['M_PatientAddressRegionalCd'], - $prm['M_PatientAddressState'], - $prm['M_PatientAddressCity'], - $prm['M_PatientAddressDistrict'], - $prm['M_PatientAddressVillage'], - $prm['M_PatientAddress'], - $userid, - $v['Mcu_PreregisterPatientsM_PatientID'] - ]); - if (!$qry) { - $message = $this->db_onedev->error(); - $message['qry'] = $this->db_onedev->last_query(); - $this->sys_error($message); - exit; - } - //echo $this->db_onedev->last_query(); + //echo $sql; + $qry = $this->db_onedev->query($sql, [ + $pdob, + $v['Mcu_PreregisterPatientsM_TitleID'], + $v['Mcu_PreregisterPatientsNIP'], + $v['Mcu_PreregisterPatientsGender'], + $v['Mcu_PreregisterPatientsPatientPrefix'], + $v['Mcu_PreregisterPatientsPatientName'], + $v['Mcu_PreregisterPatientsPatientSuffix'], + $v['Mcu_PreregisterPatientsEmail'], + $v['Mcu_PreregisterPatientsHp'], + $v['Mcu_PreregisterPatientsDivisi'], + $v['Mcu_PreregisterPatientsPosisi'], + $v['Mcu_PreregisterPatientsLocation'], + $v['Mcu_PreregisterPatientsJob'], + $v['Mcu_PreregisterPatientsDepartment'], + $religionCode, + $religionSystem, + $prm['M_PatientAddressRegionalCd'], + $prm['M_PatientAddressState'], + $prm['M_PatientAddressCity'], + $prm['M_PatientAddressDistrict'], + $prm['M_PatientAddressVillage'], + $prm['M_PatientAddress'], + $userid, + $v['Mcu_PreregisterPatientsM_PatientID'] + ]); + if (!$qry) { + $message = $this->db_onedev->error(); + $message['qry'] = $this->db_onedev->last_query(); + $this->sys_error($message); + exit; + } + //echo $this->db_onedev->last_query(); - if ($antrian != '' && $antrian != null) { - $sql = "INSERT INTO preregister_antrian( + if ($antrian != '' && $antrian != null) { + $sql = "INSERT INTO preregister_antrian( PreregisterAntrianMcu_PreregisterPatientsID, PreregisterAntrianMgm_McuID, PreregisterAntrianM_PatientID, @@ -1102,30 +1105,30 @@ class Preregisterappcponev5 extends MY_Controller PreregisterAntrianUserID, PreregisterAntrianCreated ) VALUES(?,?,?,?,?,NOW())"; - $qry = $this->db_onedev->query($sql, [ - $v['Mcu_PreregisterPatientsID'], - $v['Mcu_PreregisterPatientsMgm_McuID'], - $v['Mcu_PreregisterPatientsM_PatientID'], - $antrian, - $userid - ]); - if (!$qry) { - $message = $this->db_onedev->error(); - $message['qry'] = $this->db_onedev->last_query(); - $this->sys_error($message); - exit; - } - } - $sql = "SELECT * FROM m_patient WHERE M_PatientID = ?"; - $rows = $this->db_onedev->query($sql, [$v['Mcu_PreregisterPatientsM_PatientID']]); - if (!$rows) { - $message = $this->db_onedev->error(); - $message['qry'] = $this->db_onedev->last_query(); - $this->sys_error($message); - exit; - } - $dataPatientAfter = $rows->row_array(); - $sql = "INSERT INTO cpone_log.log_patient( + $qry = $this->db_onedev->query($sql, [ + $v['Mcu_PreregisterPatientsID'], + $v['Mcu_PreregisterPatientsMgm_McuID'], + $v['Mcu_PreregisterPatientsM_PatientID'], + $antrian, + $userid + ]); + if (!$qry) { + $message = $this->db_onedev->error(); + $message['qry'] = $this->db_onedev->last_query(); + $this->sys_error($message); + exit; + } + } + $sql = "SELECT * FROM m_patient WHERE M_PatientID = ?"; + $rows = $this->db_onedev->query($sql, [$v['Mcu_PreregisterPatientsM_PatientID']]); + if (!$rows) { + $message = $this->db_onedev->error(); + $message['qry'] = $this->db_onedev->last_query(); + $this->sys_error($message); + exit; + } + $dataPatientAfter = $rows->row_array(); + $sql = "INSERT INTO cpone_log.log_patient( Log_PatientM_PatientID, Log_PatientDate, Log_PatientCode, @@ -1133,159 +1136,159 @@ class Preregisterappcponev5 extends MY_Controller Log_PatientJsonAfter, Log_PatientUserID) VALUES (?, NOW(), 'EDIT', ?, ?, ?)"; - $rows = $this->db_onedev->query($sql, [ - $v['Mcu_PreregisterPatientsM_PatientID'], - json_encode($dataPatientBefore), - json_encode($dataPatientAfter), - $userid - ]); - if (!$rows) { - $message = $this->db_onedev->error(); - $message['qry'] = $this->db_onedev->last_query(); - $this->sys_error($message); - exit; - } + $rows = $this->db_onedev->query($sql, [ + $v['Mcu_PreregisterPatientsM_PatientID'], + json_encode($dataPatientBefore), + json_encode($dataPatientAfter), + $userid + ]); + if (!$rows) { + $message = $this->db_onedev->error(); + $message['qry'] = $this->db_onedev->last_query(); + $this->sys_error($message); + exit; + } - $result = array( - "msg" => "ok", - "total" => 1, - "records" => $prm - ); + $result = array( + "msg" => "ok", + "total" => 1, + "records" => $prm + ); - $this->sys_ok($result); - exit; - } + $this->sys_ok($result); + exit; + } - function checkpatientbynoid($noKtp, $pid, $corporateid) - { - // $prm = $this->sys_input; - // $userid = $this->sys_user["M_UserID"]; - // if (!$this->isLogin) { - // $this->sys_error("Invalid Token"); - // exit; - // } - // $noKtp = $prm['nik']; - // $pid = $prm['pid']; - // $corporateid = $prm['corporateid']; - $sql = "SELECT * FROM m_patient + function checkpatientbynoid($noKtp, $pid, $corporateid) + { + // $prm = $this->sys_input; + // $userid = $this->sys_user["M_UserID"]; + // if (!$this->isLogin) { + // $this->sys_error("Invalid Token"); + // exit; + // } + // $noKtp = $prm['nik']; + // $pid = $prm['pid']; + // $corporateid = $prm['corporateid']; + $sql = "SELECT * FROM m_patient WHERE M_PatientIdentifierCode = 'NNIDN' AND M_PatientIdentifierValue = $noKtp AND M_PatientIsActive = 'Y' AND M_PatientID <> $pid AND M_PatientRegisteredByCorporateID = $corporateid"; - $qry = $this->db_onedev->query($sql); - if (!$qry) { - $message = $this->db_onedev->error(); - $this->sys_error($message); - $message['qry'] = $this->db_onedev->last_query(); - exit; - } - $data = $qry->result_array(); - if (count($data) > 0) { - $rst = [ + $qry = $this->db_onedev->query($sql); + if (!$qry) { + $message = $this->db_onedev->error(); + $this->sys_error($message); + $message['qry'] = $this->db_onedev->last_query(); + exit; + } + $data = $qry->result_array(); + if (count($data) > 0) { + $rst = [ - "msg" => "errpatient", - "msg_dialog" => "Pasien memiliki NIK sama dengan pasien berikut", - "data" => $data, - "total" => count($data) - ]; - $this->sys_ok($rst); - exit; - } - } + "msg" => "errpatient", + "msg_dialog" => "Pasien memiliki NIK sama dengan pasien berikut", + "data" => $data, + "total" => count($data) + ]; + $this->sys_ok($rst); + exit; + } + } - function checkpatientbynamedob($name, $dob, $pid, $corporateid) - { - // $prm = $this->sys_input; - // $userid = $this->sys_user["M_UserID"]; - // if (!$this->isLogin) { - // $this->sys_error("Invalid Token"); - // exit; - // } - // $name = $prm['name']; - // $dob = $prm['dob']; - // $pid = $prm['pid']; - // $corporateid = $prm['corporateid']; - $sql = "SELECT * FROM m_patient + function checkpatientbynamedob($name, $dob, $pid, $corporateid) + { + // $prm = $this->sys_input; + // $userid = $this->sys_user["M_UserID"]; + // if (!$this->isLogin) { + // $this->sys_error("Invalid Token"); + // exit; + // } + // $name = $prm['name']; + // $dob = $prm['dob']; + // $pid = $prm['pid']; + // $corporateid = $prm['corporateid']; + $sql = "SELECT * FROM m_patient WHERE LOWER(M_PatientName)=LOWER(?) AND M_PatientDOB= '{$dob}' AND M_PatientIsActive = 'Y' AND M_PatientID <> $pid AND M_PatientRegisteredByCorporateID = $corporateid"; - $qry = $this->db_onedev->query($sql, [$name]); - if (!$qry) { - $message = $this->db_onedev->error(); - $message['qry'] = $this->db_onedev->last_query(); - $this->sys_error($message); - exit; - } - // echo $sql; - $data = $qry->result_array(); - if (count($data) > 0) { - $rst = [ - "msg" => "errpatient", - "msg_dialog" => "Pasien memiliki Nama dan Tanggal Lahir sama dengan pasien berikut", + $qry = $this->db_onedev->query($sql, [$name]); + if (!$qry) { + $message = $this->db_onedev->error(); + $message['qry'] = $this->db_onedev->last_query(); + $this->sys_error($message); + exit; + } + // echo $sql; + $data = $qry->result_array(); + if (count($data) > 0) { + $rst = [ + "msg" => "errpatient", + "msg_dialog" => "Pasien memiliki Nama dan Tanggal Lahir sama dengan pasien berikut", - "data" => $data, - "total" => count($data) - ]; - $this->sys_ok($rst); - exit; - } - } + "data" => $data, + "total" => count($data) + ]; + $this->sys_ok($rst); + exit; + } + } - function checkpatientbynip($nip, $pid, $corporateid) - { - // $prm = $this->sys_input; - // $userid = $this->sys_user["M_UserID"]; - // if (!$this->isLogin) { - // $this->sys_error("Invalid Token"); - // exit; - // } - // $name = $prm['name']; - // $dob = $prm['dob']; - // $pid = $prm['pid']; - // $corporateid = $prm['corporateid']; - $sql = "SELECT * FROM m_patient + function checkpatientbynip($nip, $pid, $corporateid) + { + // $prm = $this->sys_input; + // $userid = $this->sys_user["M_UserID"]; + // if (!$this->isLogin) { + // $this->sys_error("Invalid Token"); + // exit; + // } + // $name = $prm['name']; + // $dob = $prm['dob']; + // $pid = $prm['pid']; + // $corporateid = $prm['corporateid']; + $sql = "SELECT * FROM m_patient WHERE M_PatientNIP= '{$nip}' AND M_PatientIsActive = 'Y' AND M_PatientID <> $pid AND M_PatientRegisteredByCorporateID = $corporateid"; - $qry = $this->db_onedev->query($sql, []); - if (!$qry) { - $message = $this->db_onedev->error(); - $this->sys_error($message); - exit; - } - // echo $sql; - $data = $qry->result_array(); - if (count($data) > 0) { - $rst = [ - "msg" => "errpatient", - "msg_dialog" => "Pasien memiliki NIP sama dengan pasien berikut", + $qry = $this->db_onedev->query($sql, []); + if (!$qry) { + $message = $this->db_onedev->error(); + $this->sys_error($message); + exit; + } + // echo $sql; + $data = $qry->result_array(); + if (count($data) > 0) { + $rst = [ + "msg" => "errpatient", + "msg_dialog" => "Pasien memiliki NIP sama dengan pasien berikut", - "data" => $data, - "total" => count($data) - ]; - $this->sys_ok($rst); - exit; - } - } + "data" => $data, + "total" => count($data) + ]; + $this->sys_ok($rst); + exit; + } + } - function getDetailPacketByID() - { - if (!$this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } + function getDetailPacketByID() + { + if (!$this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } - $userid = $this->sys_user["M_UserID"]; - $prm = $this->sys_input; + $userid = $this->sys_user["M_UserID"]; + $prm = $this->sys_input; - $T_PacketID = $prm['T_PacketID']; + $T_PacketID = $prm['T_PacketID']; - // SELECT test.T_TestID as id, test.T_TestName as name, test.T_TestSasCode as code, nat_test,ss_price_mou.T_PriceTotal as price - $sql = "SELECT + // SELECT test.T_TestID as id, test.T_TestName as name, test.T_TestSasCode as code, nat_test,ss_price_mou.T_PriceTotal as price + $sql = "SELECT T_PacketName, T_PacketSasCode, pd.T_PacketDetailID, @@ -1307,17 +1310,17 @@ class Preregisterappcponev5 extends MY_Controller AND pd.T_PacketDetailIsActive = 'Y' AND pd.T_PacketDetailT_PacketID = $T_PacketID"; - $qry = $this->db_onedev->query($sql); - if (!$qry) { - $this->sys_error_db("list packet", $this->db_onedev); - exit; - } + $qry = $this->db_onedev->query($sql); + if (!$qry) { + $this->sys_error_db("list packet", $this->db_onedev); + exit; + } - $rows = $qry->result_array(); + $rows = $qry->result_array(); - foreach ($rows as $key => $obj) { - $sql_nattest = "WITH RECURSIVE TestNatTest AS ( - SELECT + foreach ($rows as $key => $obj) { + $sql_nattest = "WITH RECURSIVE TestNatTest AS ( + SELECT T_TestID, T_TestCode, T_TestSasCode, @@ -1337,209 +1340,209 @@ class Preregisterappcponev5 extends MY_Controller WHERE T_TestIsActive = 'Y' ) - SELECT + SELECT T_TestID, T_TestNat_TestID FROM TestNatTest ORDER BY T_TestNat_TestID"; - $que_nattest = $this->db_onedev->query($sql_nattest, [$obj['T_TestID']]); - if (!$que_nattest) { - $this->sys_error_db("[Error] get nat_test per pemeriksaan"); - exit; - } - $data = $que_nattest->result_array(); - $nattest = array_column($data, 'T_TestNat_TestID'); - array_unshift($nattest, $obj['T_TestNat_TestID']); + $que_nattest = $this->db_onedev->query($sql_nattest, [$obj['T_TestID']]); + if (!$que_nattest) { + $this->sys_error_db("[Error] get nat_test per pemeriksaan"); + exit; + } + $data = $que_nattest->result_array(); + $nattest = array_column($data, 'T_TestNat_TestID'); + array_unshift($nattest, $obj['T_TestNat_TestID']); - $rows[$key]['nat_test'] = $nattest; - } + $rows[$key]['nat_test'] = $nattest; + } - $result = array( - // "total" => $tot_page, - "records" => $rows, - ); - $this->sys_ok($result); - exit; - } - function getpreregistermenu() - { - if (!$this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } + $result = array( + // "total" => $tot_page, + "records" => $rows, + ); + $this->sys_ok($result); + exit; + } + function getpreregistermenu() + { + if (!$this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } - $sql = "SELECT S_MenuUrl as url FROM s_menu + $sql = "SELECT S_MenuUrl as url FROM s_menu WHERE S_MenuName = 'Registration (Preregister)' LIMIT 1"; - $qry = $this->db_onedev->query($sql); - if (!$qry) { - $message = $this->db_onedev->error(); - $this->sys_error($message); - exit; - } - $data = $qry->row(); + $qry = $this->db_onedev->query($sql); + if (!$qry) { + $message = $this->db_onedev->error(); + $this->sys_error($message); + exit; + } + $data = $qry->row(); - $this->sys_ok($data); - exit; - } - function lookup_barcodes() - { - try { - $prm = $this->sys_input; - //# cek token valid - if (!$this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - /*$sql = "SELECT T_BarcodeLabID as id, + $this->sys_ok($data); + exit; + } + function lookup_barcodes() + { + try { + $prm = $this->sys_input; + //# cek token valid + if (!$this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + /*$sql = "SELECT T_BarcodeLabID as id, 'barcode' as type, T_SampleTypeID, T_BarcodeLabID, - T_BarcodeLabBarcode, - T_BarcodeLabT_OrderHeaderID as orderid, - T_BarcodeLabCounter, - T_SampleTypeName, + T_BarcodeLabBarcode, + T_BarcodeLabT_OrderHeaderID as orderid, + T_BarcodeLabCounter, + T_SampleTypeName, 'N' as chex - FROM t_barcodelab + FROM t_barcodelab JOIN t_sampletype ON T_BarcodeLabT_SampleTypeID = T_SampleTypeID JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationIsNonLab = '' - WHERE + WHERE T_BarcodeLabT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_BarcodeLabIsActive = 'Y' UNION - SELECT T_TestID as id, - 'nonlab' as type, + SELECT T_TestID as id, + 'nonlab' as type, T_OrderDetailID as T_SampleTypeID, '' as T_BarcodeLabID, '-' as T_BarcodeLabBarcode, - T_OrderHeaderID as order_id, - 0 as T_BarcodeLabCounter, + T_OrderHeaderID as order_id, + 0 as T_BarcodeLabCounter, T_TestName as T_SampleTypeName, 'N' as chex FROM t_orderheader JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y' JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y' - JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID + JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultName <> 'lab' WHERE T_OrderHeaderID = {$prm['T_OrderHeaderID']} GROUP BY T_TestID - + ";*/ - $sql = "SELECT T_BarcodeLabID as id, + $sql = "SELECT T_BarcodeLabID as id, 'barcode' as type, T_SampleTypeID, T_BarcodeLabID, - T_BarcodeLabBarcode, - T_BarcodeLabT_OrderHeaderID as orderid, - T_BarcodeLabCounter, - T_SampleTypeName, + T_BarcodeLabBarcode, + T_BarcodeLabT_OrderHeaderID as orderid, + T_BarcodeLabCounter, + T_SampleTypeName, 'N' as chex - FROM t_barcodelab + FROM t_barcodelab JOIN t_sampletype ON T_BarcodeLabT_SampleTypeID = T_SampleTypeID JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationIsNonLab = '' - WHERE + WHERE T_BarcodeLabT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_BarcodeLabIsActive = 'Y' UNION - SELECT T_TestID as id, - 'nonlab' as type, + SELECT T_TestID as id, + 'nonlab' as type, T_OrderDetailID as T_SampleTypeID, '' as T_BarcodeLabID, '-' as T_BarcodeLabBarcode, - T_OrderHeaderID as order_id, - 0 as T_BarcodeLabCounter, + T_OrderHeaderID as order_id, + 0 as T_BarcodeLabCounter, T_TestName as T_SampleTypeName, 'N' as chex FROM t_orderheader JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y' JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y' - JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID - JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND - ( Group_ResultName <> 'lab' AND Group_ResultName <> 'Papsmear') AND + JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID + JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND + ( Group_ResultName <> 'lab' AND Group_ResultName <> 'Papsmear') AND Group_ResultFlagNonLab = 'Y' WHERE T_OrderHeaderID = {$prm['T_OrderHeaderID']} GROUP BY T_TestID UNION - SELECT T_TestID as id, - 'nonlab' as type, + SELECT T_TestID as id, + 'nonlab' as type, T_OrderDetailID as T_SampleTypeID, '' as T_BarcodeLabID, '-' as T_BarcodeLabBarcode, - T_OrderHeaderID as order_id, - 0 as T_BarcodeLabCounter, + T_OrderHeaderID as order_id, + 0 as T_BarcodeLabCounter, T_TestName as T_SampleTypeName, 'N' as chex FROM t_orderheader JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y' JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y' - JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID + JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND ( Group_ResultName = 'Papsmear') WHERE T_OrderHeaderID = {$prm['T_OrderHeaderID']} GROUP BY Group_ResultID - + "; - //echo $sql; - $query = $this->db_onedev->query($sql); - if (!$query) { - $message = $this->db_onedev->error(); - $message['qry'] = $this->db_onedev->last_query(); - $this->sys_error($message); - exit; - } - $rows = $query->result_array(); - $rst = []; - if ($rows) { - foreach ($rows as $k => $v) { - $v['chex'] = false; - // if ($v['chex'] == 'N') - // $rows[$k]['chex'] = false; - // else - // $rows[$k]['chex'] = true; - $v['count'] = 1; - $rst[] = $v; - // if ($v['type'] == 'barcode' && $v['T_SampleTypeID'] == 48) { - // $rst[] = $v; - // } - } - } - $result = array("total" => 0, "records" => $rst); - $this->sys_ok($result); - } catch (Exception $exc) { - $message = $exc->getMessage(); - $this->sys_error($message); - } - } - function getcorporate() - { - try { - $prm = $this->sys_input; - //# cek token valid - if (!$this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } - $code = $prm['code']; + //echo $sql; + $query = $this->db_onedev->query($sql); + if (!$query) { + $message = $this->db_onedev->error(); + $message['qry'] = $this->db_onedev->last_query(); + $this->sys_error($message); + exit; + } + $rows = $query->result_array(); + $rst = []; + if ($rows) { + foreach ($rows as $k => $v) { + $v['chex'] = false; + // if ($v['chex'] == 'N') + // $rows[$k]['chex'] = false; + // else + // $rows[$k]['chex'] = true; + $v['count'] = 1; + $rst[] = $v; + // if ($v['type'] == 'barcode' && $v['T_SampleTypeID'] == 48) { + // $rst[] = $v; + // } + } + } + $result = array("total" => 0, "records" => $rst); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + function getcorporate() + { + try { + $prm = $this->sys_input; + //# cek token valid + if (!$this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } + $code = $prm['code']; - $sql = "SELECT + $sql = "SELECT CorporateID, CorporateCode, CorporateName, 'Y' AS CorporateDefault - FROM corporate + FROM corporate WHERE (CorporateID = ?);"; - //echo $sql; - $query = $this->db_onedev->query($sql, [$code]); - if (!$query) { - $message = $this->db_onedev->error(); - $message['qry'] = $this->db_onedev->last_query(); - $this->sys_error($message); - exit; - } - $corporate = $query->row_array(); - $sql = "SELECT + //echo $sql; + $query = $this->db_onedev->query($sql, [$code]); + if (!$query) { + $message = $this->db_onedev->error(); + $message['qry'] = $this->db_onedev->last_query(); + $this->sys_error($message); + exit; + } + $corporate = $query->row_array(); + $sql = "SELECT CorporateID, CorporateCode, CorporateName, @@ -1548,77 +1551,77 @@ class Preregisterappcponev5 extends MY_Controller JOIN corporate ON CorporateRelationCorporateRelationID = CorporateID AND CorporateRelationIsActive = 'Y' AND CorporateRelationCorporateID = ?"; - //echo $sql; - $query = $this->db_onedev->query($sql, [$corporate['CorporateID']]); - if (!$query) { - $message = $this->db_onedev->error(); - $message['qry'] = $this->db_onedev->last_query(); - $this->sys_error($message); - exit; - } - $relation = $query->result_array(); - // $rows = [$corporate,...$relation] - $rows = [$corporate]; - for ($i = 0; $i < count($relation); $i++) { - array_push($rows, $relation[$i]); - } - $result = array("records" => $rows); - $this->sys_ok($result); - } catch (Exception $exc) { - $message = $exc->getMessage(); - $this->sys_error($message); - } - } - function search_patient_form() - { - $prm = $this->sys_input; - $name = $prm['name']; - $dob = $prm['dob']; - $nik = $prm['nik']; - $ktp = $prm['ktp']; - $add_where = ''; - // M_PatientIdentifierCode varchar(50) [NNIDN] - // M_PatientIdentifierSystem varchar(100) [http://terminology.hl7.org/CodeSystem/v2-0203] - // M_PatientIdentifierCode varchar(50) [NNIDN] - if ($nik != '') { - $add_where .= " AND M_PatientNIP = '{$nik}'"; - } - if ($ktp != '') { - $add_where .= " AND M_PatientIdentifierValue = '{$nik}' AND M_PatientIdentifierCode = 'NNIDN'"; - } - $setup = $prm['setup']; - $join_company = ""; - if (isset($prm['company']) && intval($prm['company']) > 0) { - $join_company = "JOIN t_orderheader ON T_OrderHeaderM_PatientID = M_PatientID AND - T_OrderHeaderIsActive = 'Y' AND + //echo $sql; + $query = $this->db_onedev->query($sql, [$corporate['CorporateID']]); + if (!$query) { + $message = $this->db_onedev->error(); + $message['qry'] = $this->db_onedev->last_query(); + $this->sys_error($message); + exit; + } + $relation = $query->result_array(); + // $rows = [$corporate,...$relation] + $rows = [$corporate]; + for ($i = 0; $i < count($relation); $i++) { + array_push($rows, $relation[$i]); + } + $result = array("records" => $rows); + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } + function search_patient_form() + { + $prm = $this->sys_input; + $name = $prm['name']; + $dob = $prm['dob']; + $nik = $prm['nik']; + $ktp = $prm['ktp']; + $add_where = ''; + // M_PatientIdentifierCode varchar(50) [NNIDN] + // M_PatientIdentifierSystem varchar(100) [http://terminology.hl7.org/CodeSystem/v2-0203] + // M_PatientIdentifierCode varchar(50) [NNIDN] + if ($nik != '') { + $add_where .= " AND M_PatientNIP = '{$nik}'"; + } + if ($ktp != '') { + $add_where .= " AND M_PatientIdentifierValue = '{$nik}' AND M_PatientIdentifierCode = 'NNIDN'"; + } + $setup = $prm['setup']; + $join_company = ""; + if (isset($prm['company']) && intval($prm['company']) > 0) { + $join_company = "JOIN t_orderheader ON T_OrderHeaderM_PatientID = M_PatientID AND + T_OrderHeaderIsActive = 'Y' AND T_OrderHeaderM_CompanyID = {$prm['company']}"; - } + } - $sql = "SELECT COUNT(*) as total + $sql = "SELECT COUNT(*) as total FROM ( SELECT * FROM m_patient $join_company LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID WHERE - M_PatientIsActive = 'Y' + M_PatientIsActive = 'Y' AND M_PatientRegisteredByCorporateID = {$setup['Mgm_McuCorporateID']} - AND M_PatientName LIKE CONCAT('%',?,'%') AND + AND M_PatientName LIKE CONCAT('%',?,'%') AND (DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE '%{$dob}%' and M_PatientDOB IS NOT NULL) {$add_where} GROUP BY M_PatientID ) x "; - //echo $sql; - $qry = $this->db_onedev->query($sql, [$name]); - if (!$qry) { - $message = $this->db_onedev->error(); - $message['qry'] = $this->db_onedev->last_query(); - $this->sys_error($message); - exit; - } - $countx = $qry->row()->total; - $sql = "SELECT *, DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') as dob_ina, + //echo $sql; + $qry = $this->db_onedev->query($sql, [$name]); + if (!$qry) { + $message = $this->db_onedev->error(); + $message['qry'] = $this->db_onedev->last_query(); + $this->sys_error($message); + exit; + } + $countx = $qry->row()->total; + $sql = "SELECT *, DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') as dob_ina, M_PatientNoReg as Mcu_PreregisterPatientsPID, M_PatientIdentifierValue as Mcu_PreregisterPatientsKTP, M_PatientID as Mcu_PreregisterPatientsM_PatientID, @@ -1641,130 +1644,130 @@ class Preregisterappcponev5 extends MY_Controller WHERE M_PatientRegisteredByCorporateID = {$setup['Mgm_McuCorporateID']} AND M_PatientIsActive = 'Y' AND - M_PatientName LIKE CONCAT('%',?,'%') AND + M_PatientName LIKE CONCAT('%',?,'%') AND (DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE '%{$dob}%' and M_PatientDOB IS NOT NULL) {$add_where} GROUP BY M_PatientID LIMIT 10 OFFSET 0 "; - //echo $sql; - $qry = $this->db_onedev->query($sql, [$name]); - if (!$qry) { - $message = $this->db_onedev->error(); - $message['qry'] = $this->db_onedev->last_query(); - $this->sys_error($message); - exit; - } - $rows = $qry->result_array(); - $result = array( - "total" => $countx, - "records" => $rows - ); - $this->sys_ok($result); - exit; - } + //echo $sql; + $qry = $this->db_onedev->query($sql, [$name]); + if (!$qry) { + $message = $this->db_onedev->error(); + $message['qry'] = $this->db_onedev->last_query(); + $this->sys_error($message); + exit; + } + $rows = $qry->result_array(); + $result = array( + "total" => $countx, + "records" => $rows + ); + $this->sys_ok($result); + exit; + } - function getdetailcorporate() - { - try { - if (!$this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } + function getdetailcorporate() + { + try { + if (!$this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } - $prm = $this->sys_input; + $prm = $this->sys_input; - $sql = "SELECT corporate.*, IFNULL(display, '') as countryName + $sql = "SELECT corporate.*, IFNULL(display, '') as countryName FROM corporate LEFT JOIN terminology ON attribute_path = 'Address.country' AND code = CorporateAddressCountry WHERE CorporateID = ?"; - $qry = $this->db_onedev->query($sql, array($prm['Mgm_McuCorporateID'])); + $qry = $this->db_onedev->query($sql, array($prm['Mgm_McuCorporateID'])); - if (!$qry) { - $this->sys_error_db("search corporate select error", $this->db_onedev); - exit; - } + if (!$qry) { + $this->sys_error_db("search corporate select error", $this->db_onedev); + exit; + } - $row = $qry->row_array(); - if (!$row) { - # code... - } - $result = array( - "records" => $row - ); + $row = $qry->row_array(); + if (!$row) { + # code... + } + $result = array( + "records" => $row + ); - $this->sys_ok($result); - } catch (Exception $exc) { - $message = $exc->getMessage(); - $this->sys_error($message); - } - } + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } - public function searchwilayah() - { - try { - if (!$this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } + public function searchwilayah() + { + try { + if (!$this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } - $prm = $this->sys_input; - $search = $prm['search']; + $prm = $this->sys_input; + $search = $prm['search']; - $sql = "SELECT - r.regional_cd, - r.regional_cd AS id, - r.regional_nm, + $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 + 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 + WHERE r.full_name LIKE CONCAT('%','{$search}','%') LIMIT 100 "; - $qry = $this->db_onedev->query($sql); + $qry = $this->db_onedev->query($sql); - if (!$qry) { - $this->sys_error_db("search wilayah select error", $this->db_onedev); - exit; - } + if (!$qry) { + $this->sys_error_db("search wilayah select error", $this->db_onedev); + exit; + } - $rows = $qry->result_array(); + $rows = $qry->result_array(); - $result = array( - "records" => $rows, - "sql" => $this->db_onedev->last_query() - ); + $result = array( + "records" => $rows, + "sql" => $this->db_onedev->last_query() + ); - $this->sys_ok($result); - } catch (Exception $exc) { - $message = $exc->getMessage(); - $this->sys_error($message); - } - } + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } - public function getCountryTerminology() - { - try { - if (!$this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } + public function getCountryTerminology() + { + try { + if (!$this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } - $prm = $this->sys_input; + $prm = $this->sys_input; - $sql = "SELECT + $sql = "SELECT code, display FROM @@ -1776,38 +1779,38 @@ class Preregisterappcponev5 extends MY_Controller AND code_system = 'urn:iso:std:iso:3166' "; - $qry = $this->db_onedev->query($sql); + $qry = $this->db_onedev->query($sql); - if (!$qry) { - $this->sys_error_db("terminology select error", $this->db_onedev); - exit; - } + if (!$qry) { + $this->sys_error_db("terminology select error", $this->db_onedev); + exit; + } - $rows = $qry->result_array(); + $rows = $qry->result_array(); - $result = array( - "records" => $rows, - "sql" => $this->db_onedev->last_query() - ); + $result = array( + "records" => $rows, + "sql" => $this->db_onedev->last_query() + ); - $this->sys_ok($result); - } catch (Exception $exc) { - $message = $exc->getMessage(); - $this->sys_error($message); - } - } + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } - public function getCountryTerminologySelected() - { - try { - if (!$this->isLogin) { - $this->sys_error("Invalid Token"); - exit; - } + public function getCountryTerminologySelected() + { + try { + if (!$this->isLogin) { + $this->sys_error("Invalid Token"); + exit; + } - $prm = $this->sys_input; + $prm = $this->sys_input; - $sql = "SELECT + $sql = "SELECT resource_type, attribute_path, code, @@ -1832,27 +1835,27 @@ class Preregisterappcponev5 extends MY_Controller AND attribute_path = 'Address.country' AND resource_type = 'Address' AND code_system = 'urn:iso:std:iso:3166' - AND + AND "; - $qry = $this->db_onedev->query($sql); + $qry = $this->db_onedev->query($sql); - if (!$qry) { - $this->sys_error_db("terminology select error", $this->db_onedev); - exit; - } + if (!$qry) { + $this->sys_error_db("terminology select error", $this->db_onedev); + exit; + } - $rows = $qry->result_array(); + $rows = $qry->result_array(); - $result = array( - "records" => $rows, - "sql" => $this->db_onedev->last_query() - ); + $result = array( + "records" => $rows, + "sql" => $this->db_onedev->last_query() + ); - $this->sys_ok($result); - } catch (Exception $exc) { - $message = $exc->getMessage(); - $this->sys_error($message); - } - } + $this->sys_ok($result); + } catch (Exception $exc) { + $message = $exc->getMessage(); + $this->sys_error($message); + } + } }