db_onedev = $this->load->database("onedev", true); $this->db_oneklinik = $this->load->database("onedev", true); $this->IP_SOCKET_IO = "localhost"; } public function search() { $prm = $this->sys_input; $id = $prm['id']; $sql = "SELECT orderID, orderDate, orderNumber, orderIsAnamnese, orderIsCheck, orderAge as patient_age, DATE_FORMAT(orderDate,'%d-%m-%Y') as order_date, 'N' divider, M_PatientID, M_PatientNoReg, M_PatientPrefix, M_PatientName, M_PatientSuffix, M_PatientHP, M_PatientEmail, M_PatientPOB, M_PatientPhone, M_PatientIDNumber, DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as M_PatientDOB, M_PatientNote, M_PatientNIK, M_PatientJabatan, M_PatientKedudukan, M_PatientPJ, M_PatientLocation, M_PatientJob, M_PatientM_SexID, M_SexName, M_PatientM_TitleID, M_TitleName, M_PatientM_ReligionID, M_ReligionName, M_PatientM_IdTypeID, M_IdTypeName, M_PatientIDNumber, IF(ISNULL(M_PatientSuspendID),'active','suspend' ) as status, M_PatientAddressM_KelurahanID M_KelurahanID, 0 M_DistrictID, 0 M_CityID, 0 M_ProvinceID FROM one_klinik.order JOIN m_patient ON M_PatientID = orderM_PatientID AND M_PatientIsActive = 'Y' JOIN m_title ON M_PatientM_TitleID = M_TitleID JOIN m_sex ON M_PatientM_SexID = M_SexID JOIN m_branch ON M_BranchIsActive = 'Y' AND M_BranchIsDefault = 'Y' JOIN m_patientaddress ON M_PatientAddressM_PatientID = M_PatientID AND M_PatientAddressIsActive = 'Y' LEFT JOIN m_idtype ON M_IdTypeID = M_PatientM_IdTypeID AND M_IdTypeIsActive = 'Y' LEFT JOIN m_religion ON m_patientm_religionid = m_religionid LEFT JOIN m_patientsuspend ON M_PatientSuspendM_PatientID = M_PatientID AND M_PatientSuspendIsActive = 'Y' WHERE orderNumber = '{$id}' AND M_PatientSuspendID IS NULL GROUP BY M_PatientID"; //echo $sql; $query = $this->db_onedev->query($sql); if ($query) { $rows = $query->result_array(); foreach ($rows as $k => $v) { $rows[$k]['M_PatientName'] = stripslashes($rows[$k]['M_PatientName']); $rows[$k]['M_PatientAddressDescription'] = stripslashes($v['M_PatientAddressDescription']); $patient_name = str_replace("'", "\\'", $prm['M_PatientName']); $sql = "SELECT *, concat('{$rows[$k]['M_PatientAddressDescription']}', '\n\n', m_kelurahanname, ', ', m_districtname,'\n', m_cityname, ', ', m_provincename) as xaddress FROM m_kelurahan JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID JOIN m_city ON M_DistrictM_CityID = M_CityID JOIN m_province ON M_CityM_ProvinceID = M_ProvinceID WHERE M_KelurahanID = {$v['M_KelurahanID']} "; //echo $sql; $row_address = $this->db_onedev->query($sql)->row_array(); $rows[$k]['M_PatientAddress'] = stripslashes($row_address['xaddress']); $rows[$k]['M_DistrictID'] = $row_address['M_DistrictID']; $rows[$k]['M_CityID'] = $row_address['M_CityID']; $rows[$k]['M_ProvinceID'] = $row_address['M_ProvinceID']; $info = $this->db_onedev->query("SELECT fn_fo_patient_visit(?) info", [$v['M_PatientID']])->row(); $rows[$k]['info'] = json_decode($info->info); } $result = array("total" => 1, "records" => $rows, "sql" => $this->db_onedev->last_query()); $this->sys_ok($result); } else { $this->sys_error_db("m_patient rows", $this->db_onedev); exit; } } function get_data() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $result = array('data' => ''); if ($prm['type_field'] == 'TEXT') { if ($prm['selected_doctor_tab']['id'] == 'VITAL' && $prm['type_field'] == 'TEXT') { $sql = "SELECT IFNULL(orderDoctorVitalSign,'') as value FROM one_klinik.order_doctor WHERE orderDoctorOrderID = ? AND orderDoctorType = 'TEXT' AND orderDoctorIsActive = 'Y' LIMIT 1"; $query = $this->db_oneklinik->query($sql, array($prm['orderid'])); } if ($prm['selected_doctor_tab']['id'] == 'RECEIPT') { $sql = "SELECT IFNULL(orderDoctorReceipt,'') as value FROM one_klinik.order_doctor WHERE orderDoctorOrderID = ? AND orderDoctorType = 'TEXT' AND orderDoctorIsActive = 'Y' LIMIT 1"; $query = $this->db_oneklinik->query($sql, array($prm['orderid'])); } if ($prm['selected_doctor_tab']['id'] == 'DIAGPRIMER') { $sql = "SELECT IFNULL(orderDoctorDiagnosePrimer,'') as value FROM one_klinik.order_doctor WHERE orderDoctorOrderID = ? AND orderDoctorType = 'TEXT' AND orderDoctorIsActive = 'Y' LIMIT 1"; $query = $this->db_oneklinik->query($sql, array($prm['orderid'])); } if ($prm['selected_doctor_tab']['id'] == 'DIAGSEKUNDER') { $sql = "SELECT IFNULL(orderDoctorDiagnoseSekunder,'') as value FROM one_klinik.order_doctor WHERE orderDoctorOrderID = ? AND orderDoctorType = 'TEXT' AND orderDoctorIsActive = 'Y' LIMIT 1"; $query = $this->db_oneklinik->query($sql, array($prm['orderid'])); } if ($prm['selected_doctor_tab']['id'] == 'MEDIC' && $prm['type_field'] == 'TEXT') { $sql = "SELECT IFNULL(orderDoctorMedic,'') as value FROM one_klinik.order_doctor WHERE orderDoctorOrderID = ? AND orderDoctorType = 'TEXT' AND orderDoctorIsActive = 'Y' LIMIT 1"; $query = $this->db_oneklinik->query($sql, array($prm['orderid'])); } if ($prm['selected_doctor_tab']['id'] == 'SARAN') { $sql = "SELECT IFNULL(orderDoctorSaran,'') as value FROM one_klinik.order_doctor WHERE orderDoctorOrderID = ? AND orderDoctorType = 'TEXT' AND orderDoctorIsActive = 'Y' LIMIT 1"; $query = $this->db_oneklinik->query($sql, array($prm['orderid'])); } if ($prm['selected_doctor_tab']['id'] == 'ADDITIONAL') { $sql = "SELECT Nat_GroupID as id, Nat_GroupName as name FROM nat_group WHERE Nat_GroupIsActive = 'Y'"; $query = $this->db_onedev->query($sql); } //echo $this->db_onedev->last_query(); if (!$query) { $this->sys_error("Invalid get nat_group"); exit; } if ($prm['selected_doctor_tab']['id'] != 'ADDITIONAL') { $rst = $query->row_array(); if ($rst) { $result['data'] = $rst['value']; } else { $result['data'] = ''; } } if ($prm['selected_doctor_tab']['id'] === 'ADDITIONAL') { $group_tests = $query->result_array(); if ($group_tests) { $result['group_tests'] = $group_tests; $group_id = $group_tests[0]['id']; $result['subgroups'] = $this->get_subgroup($group_id); $result['tests'] = $this->get_tests($group_id, [], ''); //$mouID = $this->getMouID(); $sql = "SELECT settingM_MouID as id FROM one_klinik.setting WHERE settingIsActive = 'Y'"; $query = $this->db_oneklinik->query($sql); if (!$query) { $this->sys_error("error get setting"); return 0; } $mouID = $query->row()->id; $result['selected_test'] = $this->getSelectedTest($prm['orderid'], $mouID); } else { $result['data'] = ''; } } } if ($prm['selected_doctor_tab']['id'] == 'VITAL' && $prm['type_field'] == 'FORM') { $sql = "SELECT IFNULL(orderDoctorVitalSign,'') as value FROM one_klinik.order_doctor WHERE orderDoctorOrderID = ? AND orderDoctorType = 'FORM' AND orderDoctorIsActive = 'Y' LIMIT 1"; $query = $this->db_oneklinik->query($sql, array($prm['orderid'])); if (!$query) { $this->sys_error("Invalid get orderDoctorVitalSign FORM"); exit; } $data_vital = $query->row_array(); if ($data_vital) { $jsonData = stripslashes(html_entity_decode($data_vital['value'])); $vital_sign = json_decode($jsonData, true); $result['data'] = $vital_sign; } else { $result['data'] = $this->get_form_vital($prm['orderid']); } } if ($prm['selected_doctor_tab']['id'] == 'DIAGPRIMER') { $result['icd10'] = array(); $xcount = $this->check_exist_icd10_row($prm['orderid']); //echo $xcount; if ($xcount > 0) { $sql = "SELECT terminology.*, CONCAT(code,' | ', display) as display_name FROM one_klinik.order_diagnose_icd10 JOIN one_terminology.terminology ON code = orderDiagnoseIcd10Primary AND attribute_path = 'icd10' WHERE orderDiagnoseIcd10OrderID = ? AND orderDiagnoseIcd10IsActive = 'Y' LIMIT 1"; $query = $this->db_oneklinik->query($sql, array($prm['orderid'])); if (!$query) { $this->sys_error("Invalid get order_diagnose_icd10"); exit; } $result['icd10'] = $query->row_array(); } } if ($prm['selected_doctor_tab']['id'] == 'DIAGSEKUNDER') { $result['icd10'] = array(); $xcount = $this->check_exist_icd10_row($prm['orderid']); if ($xcount > 0) { $sql = "SELECT terminology.*, CONCAT(code,' | ', display) as display_name FROM one_klinik.order_diagnose_icd10 JOIN one_terminology.terminology ON code = orderDiagnoseIcd10Sekunder AND attribute_path = 'icd10' WHERE orderDiagnoseIcd10OrderID = ? AND orderDiagnoseIcd10IsActive = 'Y' LIMIT 1"; $query = $this->db_oneklinik->query($sql, array($prm['orderid'])); if (!$query) { $this->sys_error("Invalid get order_diagnose_icd10"); exit; } $result['icd10'] = $query->row_array(); } } $sql = "SELECT M_DoctorID as id, M_DoctorMcuDefaultKlinik as isDefault, CONCAT(IFNULL(M_DoctorPrefix,''),IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as name FROM m_doctormcu JOIN m_doctor ON M_DoctorMcuM_DoctorID = M_DoctorID WHERE M_DoctorMcuIsActive = 'Y'"; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error("error get doctors"); echo $this->db_onedev->last_query(); exit; } $result['doctors'] = $query->result_array(); $sql = "SELECT IFNULL(M_DoctorID,0) as id, IFNULL(M_DoctorMcuDefaultKlinik,'N') as isDefault, CONCAT(IFNULL(M_DoctorPrefix,''),IFNULL(M_DoctorPrefix2,''),' ',IFNULL(M_DoctorName,''),' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as name FROM one_klinik.order LEFT JOIN m_doctor ON orderM_DoctorID = M_DoctorID LEFT JOIN m_doctormcu ON M_DoctorMcuM_DoctorID = M_DoctorID WHERE orderID = ?"; $query = $this->db_onedev->query($sql, array($prm['orderid'])); if (!$query) { $this->sys_error("error get doctor order"); echo $this->db_onedev->last_query(); exit; } $selected_doctor = $query->row_array(); if ($selected_doctor['id'] == 0) { $selected_doctor = array(); foreach ($result['doctors'] as $key => $value) { if ($value['isDefault'] == 'Y') { $selected_doctor = $value; } } } $result['selected_doctor'] = $selected_doctor; $this->sys_ok($result); exit; } function get_data_anamnese() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $result = array('data' => ''); if ($prm['type_field'] == 'TEXT') { if ($prm['selected_anamnese_tab']['id'] == 'SYMPTOM' && $prm['type_field'] == 'TEXT') { $sql = "SELECT IFNULL(orderAnamnesisKeluhanUtama,'') as value FROM one_klinik.order_anamnesis WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = 'TEXT' AND orderAnamnesisIsActive = 'Y' LIMIT 1"; } if ($prm['selected_anamnese_tab']['id'] == 'HYSOLD' && $prm['type_field'] == 'TEXT') { $sql = "SELECT IFNULL(orderAnamnesisRiwayatPenyakitDanAlergiDahulu,'') as value FROM one_klinik.order_anamnesis WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = 'TEXT' AND orderAnamnesisIsActive = 'Y' LIMIT 1"; } if ($prm['selected_anamnese_tab']['id'] == 'HYSNOW' && $prm['type_field'] == 'TEXT') { $sql = "SELECT IFNULL(orderAnamnesisRiwayatPenyakitDanAlergiSekarang,'') as value FROM one_klinik.order_anamnesis WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = 'TEXT' AND orderAnamnesisIsActive = 'Y' LIMIT 1"; } if ($prm['selected_anamnese_tab']['id'] == 'FAMILY' && $prm['type_field'] == 'TEXT') { $sql = "SELECT IFNULL(orderAnamnesisRiwayatPenyakitKeluarga,'') as value FROM one_klinik.order_anamnesis WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = 'TEXT' AND orderAnamnesisIsActive = 'Y' LIMIT 1"; } if ($prm['selected_anamnese_tab']['id'] == 'MEDICINE' && $prm['type_field'] == 'TEXT') { $sql = "SELECT IFNULL(orderAnamnesisRiwayatPengobatan,'') as value FROM one_klinik.order_anamnesis WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = 'TEXT' AND orderAnamnesisIsActive = 'Y' LIMIT 1"; } if ($prm['selected_anamnese_tab']['id'] == 'SOSIAL' && $prm['type_field'] == 'TEXT') { $sql = "SELECT IFNULL(orderAnamnesisRiwayatSosial,'') as value FROM one_klinik.order_anamnesis WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = 'TEXT' AND orderAnamnesisIsActive = 'Y' LIMIT 1"; } if ($prm['selected_anamnese_tab']['id'] == 'OPERATING' && $prm['type_field'] == 'TEXT') { $sql = "SELECT IFNULL(orderAnamnesisRiwayatOperasi,'') as value FROM one_klinik.order_anamnesis WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = 'TEXT' AND orderAnamnesisIsActive = 'Y' LIMIT 1"; } if ($prm['selected_anamnese_tab']['id'] == 'VAKSIN' && $prm['type_field'] == 'TEXT') { $sql = "SELECT IFNULL(orderAnamnesisRiwayatImunisasi,'') as value FROM one_klinik.order_anamnesis WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = 'TEXT' AND orderAnamnesisIsActive = 'Y' LIMIT 1"; } $query = $this->db_oneklinik->query($sql, array($prm['orderid'])); //echo $this->db_onedev->last_query(); if (!$query) { $this->sys_error("Invalid get data"); exit; } $rst = $query->row_array(); if ($rst) { $result['data'] = $rst['value']; } else { $result['data'] = ''; } } if ($prm['type_field'] == 'FORM') { $formName = ''; if ($prm['selected_anamnese_tab']['id'] == 'SYMPTOM') { $formName = 'KELUHAN SAAT INI'; $sql = "SELECT IFNULL(orderAnamnesisKeluhanUtama,'') as value FROM one_klinik.order_anamnesis WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = 'FORM' AND orderAnamnesisIsActive = 'Y' LIMIT 1"; } if ($prm['selected_anamnese_tab']['id'] == 'HYSOLD') { $formName = 'RIWAYAT PENYAKIT'; $sql = "SELECT IFNULL(orderAnamnesisRiwayatPenyakitDanAlergiDahulu,'') as value FROM one_klinik.order_anamnesis WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = 'FORM' AND orderAnamnesisIsActive = 'Y' LIMIT 1"; } if ($prm['selected_anamnese_tab']['id'] == 'HYSNOW') { $formName = 'RIWAYAT PENYAKIT'; $sql = "SELECT IFNULL(orderAnamnesisRiwayatPenyakitDanAlergiSekarang,'') as value FROM one_klinik.order_anamnesis WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = 'FORM' AND orderAnamnesisIsActive = 'Y' LIMIT 1"; } if ($prm['selected_anamnese_tab']['id'] == 'FAMILY') { $formName = 'RIWAYAT PENYAKIT KELUARGA'; $sql = "SELECT IFNULL(orderAnamnesisRiwayatPenyakitKeluarga,'') as value FROM one_klinik.order_anamnesis WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = 'FORM' AND orderAnamnesisIsActive = 'Y' LIMIT 1"; } if ($prm['selected_anamnese_tab']['id'] == 'MEDICINE') { $formName = 'RIWAYAT KONSUMSI OBAT TERATUR'; $sql = "SELECT IFNULL(orderAnamnesisRiwayatPengobatan,'') as value FROM one_klinik.order_anamnesis WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = 'FORM' AND orderAnamnesisIsActive = 'Y' LIMIT 1"; } if ($prm['selected_anamnese_tab']['id'] == 'SOSIAL') { $formName = 'RIWAYAT KEBIASAAN HIDUP'; $sql = "SELECT IFNULL(orderAnamnesisRiwayatSosial,'') as value FROM one_klinik.order_anamnesis WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = 'FORM' AND orderAnamnesisIsActive = 'Y' LIMIT 1"; } if ($prm['selected_anamnese_tab']['id'] == 'VAKSIN') { $formName = 'RIWAYAT IMUNISASI'; $sql = "SELECT IFNULL(orderAnamnesisRiwayatImunisasi,'') as value FROM one_klinik.order_anamnesis WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = 'FORM' AND orderAnamnesisIsActive = 'Y' LIMIT 1"; } $query = $this->db_oneklinik->query($sql, array($prm['orderid'])); if (!$query) { $this->sys_error("Invalid get FORM"); exit; } //echo $this->db_oneklinik->last_query(); $data_vital = $query->row_array(); if ($data_vital && $data_vital['value'] != '') { //echo 'in'; $jsonData = stripslashes(html_entity_decode($data_vital['value'])); $vital_sign = json_decode($jsonData, true); $result['data'] = $vital_sign; } else { //echo 'dasdas'; $result['data'] = $this->get_form_anamnese($prm['orderid'], $formName); } } $sql = "SELECT M_DoctorID as id, M_DoctorMcuDefaultKlinik as isDefault, CONCAT(IFNULL(M_DoctorPrefix,''),IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as name FROM m_doctormcu JOIN m_doctor ON M_DoctorMcuM_DoctorID = M_DoctorID WHERE M_DoctorMcuIsActive = 'Y'"; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error("error get doctors"); echo $this->db_onedev->last_query(); exit; } $result['doctors'] = $query->result_array(); $sql = "SELECT IFNULL(M_DoctorID,0) as id, IFNULL(M_DoctorMcuDefaultKlinik,'N') as isDefault, CONCAT(IFNULL(M_DoctorPrefix,''),IFNULL(M_DoctorPrefix2,''),' ',IFNULL(M_DoctorName,''),' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as name FROM one_klinik.order LEFT JOIN m_doctor ON orderM_DoctorID = M_DoctorID LEFT JOIN m_doctormcu ON M_DoctorMcuM_DoctorID = M_DoctorID WHERE orderID = ?"; $query = $this->db_onedev->query($sql, array($prm['orderid'])); if (!$query) { $this->sys_error("error get doctor order"); echo $this->db_onedev->last_query(); exit; } $selected_doctor = $query->row_array(); if ($selected_doctor['id'] == 0) { $selected_doctor = array(); foreach ($result['doctors'] as $key => $value) { if ($value['isDefault'] == 'Y') { $selected_doctor = $value; } } } $result['selected_doctor'] = $selected_doctor; $this->sys_ok($result); exit; } function getSelectedTest($orderID, $mouID) { $sql = "SELECT ss_price_mou.*, 'N' as selected FROM ss_price_mou JOIN t_test xtest ON xtest.T_TestID = ss_price_mou.T_TestID AND xtest.T_TestIsActive = 'Y' JOIN one_klinik.`order_penunjang` ON orderPenunjangOrderID = ? AND orderPenunjangT_TestID = xtest.T_TestID AND orderPenunjangIsActive = 'Y' WHERE T_PriceM_MouID = ? AND is_packet = 'N' GROUP BY ss_price_mou.T_TestID "; $query = $this->db_onedev->query($sql, array($orderID, $mouID)); if (!$query) { $this->sys_error("error get ss_price_mou"); echo $this->db_onedev->last_query(); exit; } $rst = $query->result_array(); foreach ($rst as $k => $v) { if ($v['selected'] == 'N') $rst[$k]['selected'] = false; $rst[$k]['nat_test'] = json_decode($v['nat_test']); $child_test = json_decode($v['child_test']); if ($v['px_type'] == 'PR' || $v['px_type'] == 'PXR') { foreach ($child_test as $key => $value) { //print_r($child_test[$key]); $child_test[$key] = $this->objToArray($value); $child_test[$key]['Ss_PriceMouID'] = $v['Ss_PriceMouID']; } } $rst[$k]['child_test'] = $child_test; } return $rst; } function get_subgroup($group_id) { $sql = "SELECT Nat_SubGroupID as id, Nat_SubGroupName as name FROM nat_subgroup WHERE Nat_SubGroupIsActive = 'Y' AND Nat_SubGroupNat_GroupID = ?"; $query = $this->db_onedev->query($sql, array($group_id)); if (!$query) { $this->sys_error("error get nat_subgroup"); exit; } $subgroups = $query->result_array(); return $subgroups; } function getMouID() { $sql = "SELECT settingM_MouID as id FROM one_klinik.setting WHERE settingIsActive = 'Y'"; $query = $this->db_oneklinik->query($sql); if (!$query) { $this->sys_error("error get setting"); return 0; } return $query->row()->id; } function get_tests($group_id, $filter_subgroup, $search_test) { //$mouID = $this->getMouID(); $sql = "SELECT settingM_MouID as id FROM one_klinik.setting WHERE settingIsActive = 'Y'"; $query = $this->db_oneklinik->query($sql); if (!$query) { $this->sys_error("error get setting"); return 0; } $mouID = $query->row()->id; //echo $mouID; $query_filter_subgroup = ""; if (count($filter_subgroup) > 0) { //echo count($filter_subgroup) ; $query_filter_subgroup = " AND ( "; foreach ($filter_subgroup as $key => $value) { if ($key > 0) $query_filter_subgroup .= " OR "; $query_filter_subgroup .= " Nat_TestNat_SubGroupID = {$value['id']}"; } $query_filter_subgroup .= " ) "; } $query_search_test = ""; if ($search_test != '') { $query_search_test = "WHERE xtest.T_TestName LIKE CONCAT('%','{$search_test}','%')"; } $sql = "SELECT ss_price_mou.*, 'N' as selected FROM t_test xtest JOIN nat_test ON Nat_TestNat_GroupID = ? AND nat_test.Nat_TestID = xtest.T_TestNat_TestID AND Nat_TestIsActive = 'Y' AND xtest.T_TestIsActive = 'Y' {$query_filter_subgroup} JOIN ss_price_mou ON T_PriceM_MouID = ? AND xtest.T_TestID = ss_price_mou.T_TestID AND is_packet = 'N' {$query_search_test} GROUP BY ss_price_mou.T_TestID LIMIT 50"; $query = $this->db_onedev->query($sql, array($group_id, $mouID)); //echo $this->db_onedev->last_query(); if (!$query) { $this->sys_error("error get ss_price_mou"); echo $this->db_onedev->last_query(); exit; } //echo $this->db_onedev->last_query(); $tests = $query->result_array(); foreach ($tests as $k => $v) { if ($v['selected'] == 'N') $tests[$k]['selected'] = false; $tests[$k]['nat_test'] = json_decode($v['nat_test']); $child_test = json_decode($v['child_test']); if ($v['px_type'] == 'PR' || $v['px_type'] == 'PXR') { foreach ($child_test as $key => $value) { //print_r($child_test[$key]); $child_test[$key] = $this->objToArray($value); $child_test[$key]['Ss_PriceMouID'] = $v['Ss_PriceMouID']; } } $tests[$k]['child_test'] = $child_test; } return $tests; } protected function objToArray($obj) { // Not an object or array if (!is_object($obj) && !is_array($obj)) { return $obj; } // Parse array foreach ($obj as $key => $value) { $arr[$key] = $this->objToArray($value); } // Return parsed array return $arr; } function do_gettests() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; //print_r($prm['subgroup']); $result['tests'] = $this->get_tests($prm['group_id']['id'], $prm['subgroup'], $prm['search']); $result['subgroups'] = $this->get_subgroup($prm['group_id']['id']); $this->sys_ok($result); exit; } function get_doctorpj() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $result = array(); /*$sql = "SELECT M_DoctorID as doctor_id, CONCAT(IFNULL(M_DoctorPrefix,''),IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as doctor_name FROM m_doctor_schedule JOIN one_aditya.m_doctor ON M_DoctorScheduleM_DoctorID = M_DoctorID WHERE M_DoctorScheduleM_RegDayID = DAYOFWEEK(DATE(NOW())) AND M_DoctorScheduleIsActive = 'Y'"; */ $sql = " SELECT M_DoctorID as doctor_id, CONCAT(IFNULL(M_DoctorPrefix,''),IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as doctor_name FROM one_klinik.`order` JOIN m_doctor ON orderM_DoctorID = M_DoctorID WHERE orderNumber = ?"; $query = $this->db_oneklinik->query($sql, array($prm['orderNumber'])); //echo $this->db_oneklinik->last_query(); if (!$query) { $this->sys_error("Invalid Query m_doctor_schedule"); exit; } $rst = $query->row_array(); if ($rst) { $result['doctor_pj'] = $rst; } else { $result['doctor_pj'] = []; } $this->sys_ok($result); exit; } function get_doctors() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $sql = "SELECT M_DoctorID as id, M_DoctorMcuDefaultKlinik as isDefault, CONCAT(IFNULL(M_DoctorPrefix,''),IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as name FROM m_doctormcu JOIN m_doctor ON M_DoctorMcuM_DoctorID = M_DoctorID WHERE M_DoctorMcuIsActive = 'Y'"; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error("error get doctors"); echo $this->db_onedev->last_query(); exit; } $result['doctors'] = $query->result_array(); $sql = "SELECT IFNULL(M_DoctorID,0) as id, IFNULL(M_DoctorMcuDefaultKlinik,'N') as isDefault, CONCAT(IFNULL(M_DoctorPrefix,''),IFNULL(M_DoctorPrefix2,''),' ',IFNULL(M_DoctorName,''),' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as name FROM one_klinik.order LEFT JOIN m_doctor ON orderM_DoctorID = M_DoctorID LEFT JOIN m_doctormcu ON M_DoctorMcuM_DoctorID = M_DoctorID WHERE orderNumber = ?"; $query = $this->db_onedev->query($sql, array($prm['orderNumber'])); if (!$query) { $this->sys_error("error get doctor order"); echo $this->db_onedev->last_query(); exit; } $selected_doctor = $query->row_array(); if ($selected_doctor['id'] == 0) { $selected_doctor = array(); foreach ($result['doctors'] as $key => $value) { if ($value['isDefault'] == 'Y') { $selected_doctor = $value; } } } $result['selected_doctor'] = $selected_doctor; $this->sys_ok($result); exit; } function save_text() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userID = $this->sys_user['M_UserID']; $result = array(); $sql = "UPDATE one_klinik.`order` SET orderM_DoctorID = ?, orderUserID = ? WHERE orderID = ?"; $query = $this->db_oneklinik->query($sql, array($prm['doctor']['id'], $userID, $prm['orderid'])); if (!$query) { echo $this->db_oneklinik->last_query(); $this->sys_error("Invalid update doctor"); exit; } $sql = "SELECT COUNT(*) as xcount FROM one_klinik.order_doctor WHERE orderDoctorOrderID = ? AND orderDoctorType = ? AND orderDoctorIsActive = 'Y'"; $query = $this->db_oneklinik->query($sql, array($prm['orderid'], $prm['type'])); if (!$query) { $this->sys_error("Invalid Query XCOUNT"); exit; } //echo $this->db_oneklinik->last_query(); $xcount_exist = $query->row()->xcount; if ($xcount_exist == 0) { $sql = "INSERT INTO one_klinik.order_doctor ( orderDoctorType, orderDoctorOrderID, orderDoctorVitalSign, orderDoctorReceipt, orderDoctorDiagnosePrimer, orderDoctorDiagnoseSekunder, orderDoctorSaran, orderDoctorUserID, orderDoctorCreated ) VALUES( ?,?,'','','','','',?,NOW() )"; $query = $this->db_oneklinik->query($sql, array( $prm['type'], $prm['orderid'], $userID )); //echo $this->db_oneklinik->last_query(); if (!$query) { $this->sys_error("Invalid INSERT NEW VITAL SIGN"); exit; } } if ($prm['selected_doctor_tab']['id'] == 'VITAL') { $sql = "UPDATE one_klinik.order_doctor SET orderDoctorVitalSign = ?, orderDoctorUserID = ? WHERE orderDoctorOrderID = ? AND orderDoctorType = ? AND orderDoctorIsActive = 'Y'"; } if ($prm['selected_doctor_tab']['id'] == 'RECEIPT') { $sql = "UPDATE one_klinik.order_doctor SET orderDoctorReceipt = ?, orderDoctorUserID = ? WHERE orderDoctorOrderID = ? AND orderDoctorType = ? AND orderDoctorIsActive = 'Y'"; } if ($prm['selected_doctor_tab']['id'] == 'MEDIC') { $sql = "UPDATE one_klinik.order_doctor SET orderDoctorMedic = ?, orderDoctorUserID = ? WHERE orderDoctorOrderID = ? AND orderDoctorType = ? AND orderDoctorIsActive = 'Y'"; } if ($prm['selected_doctor_tab']['id'] == 'DIAGPRIMER') { $sql = "UPDATE one_klinik.order_doctor SET orderDoctorDiagnosePrimer = ?, orderDoctorUserID = ? WHERE orderDoctorOrderID = ? AND orderDoctorType = ? AND orderDoctorIsActive = 'Y'"; } if ($prm['selected_doctor_tab']['id'] == 'DIAGSEKUNDER') { $sql = "UPDATE one_klinik.order_doctor SET orderDoctorDiagnoseSekunder = ?, orderDoctorUserID = ? WHERE orderDoctorOrderID = ? AND orderDoctorType = ? AND orderDoctorIsActive = 'Y'"; //echo $sql; } if ($prm['selected_doctor_tab']['id'] == 'SARAN') { $sql = "UPDATE one_klinik.order_doctor SET orderDoctorSaran = ?, orderDoctorUserID = ? WHERE orderDoctorOrderID = ? AND orderDoctorType = ? AND orderDoctorIsActive = 'Y'"; } $value = $prm['note']; if ($prm['type'] == 'FORM') { $vital_sign = str_replace('\'', '\\\'', json_encode($prm["vital_sign"], JSON_UNESCAPED_UNICODE | JSON_HEX_APOS | JSON_HEX_QUOT)); //$value = addslashes(str_replace('\"', '\\\"',$vital_sign)); $value = $vital_sign; } $query = $this->db_oneklinik->query($sql, array($value, $userID, $prm['orderid'], $prm['type'])); //echo $this->db_oneklinik->last_query(); if (!$query) { $this->sys_error("Invalid Query update " . $prm['selected_doctor_tab']['id']); exit; } if ($prm['icd10_primer']) $save_icd10 = $this->save_icd10_primer($prm['orderid'], $prm['icd10_primer']['code'], $prm['icd10_primer']['display']); if ($prm['icd10_sekunder']) $save_icd10 = $this->save_icd10_sekunder($prm['orderid'], $prm['icd10_sekunder']['code'], $prm['icd10_sekunder']['display']); $this->sys_ok($result); exit; } function save_text_anamnese() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userID = $this->sys_user['M_UserID']; $result = array(); $sql = "UPDATE one_klinik.`order` SET orderM_DoctorID = ?, orderUserID = ? WHERE orderID = ?"; $query = $this->db_oneklinik->query($sql, array($prm['doctor']['id'], $userID, $prm['orderid'])); if (!$query) { echo $this->db_oneklinik->last_query(); $this->sys_error("Invalid update doctor"); exit; } $sql = "SELECT COUNT(*) as xcount FROM one_klinik.order_anamnesis WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = ? AND orderAnamnesisIsActive = 'Y'"; $query = $this->db_oneklinik->query($sql, array($prm['orderid'], $prm['type'])); if (!$query) { $this->sys_error("Invalid Query XCOUNT"); exit; } //echo $this->db_oneklinik->last_query(); $xcount_exist = $query->row()->xcount; if ($xcount_exist == 0) { $sql = "INSERT INTO one_klinik.order_anamnesis ( orderAnamnesisTypeForm, orderAnamnesisOrderID, orderAnamnesisKeluhanUtama, orderAnamnesisRiwayatPenyakitDanAlergiDahulu, orderAnamnesisRiwayatPenyakitDanAlergiSekarang, orderAnamnesisRiwayatPenyakitKeluarga, orderAnamnesisRiwayatPengobatan, orderAnamnesisRiwayatSosial, orderAnamnesisRiwayatOperasi, orderAnamnesisRiwayatAlergi, orderAnamnesisRiwayatImunisasi, orderAnamnesisCreated, orderAnamnesisUserID ) VALUES( ?,?,'','','','','','','','','',NOW(),? )"; $query = $this->db_oneklinik->query($sql, array( $prm['type'], $prm['orderid'], $userID )); //echo $this->db_oneklinik->last_query(); if (!$query) { $this->sys_error("Invalid INSERT ANAMNESE"); exit; } } if ($prm['selected_anamnese_tab']['id'] == 'SYMPTOM') { $sql = "UPDATE one_klinik.order_anamnesis SET orderAnamnesisKeluhanUtama = ?, orderAnamnesisUserID = ? WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = ? AND orderAnamnesisIsActive = 'Y'"; } if ($prm['selected_anamnese_tab']['id'] == 'HYSOLD') { $sql = "UPDATE one_klinik.order_anamnesis SET orderAnamnesisRiwayatPenyakitDanAlergiDahulu = ?, orderAnamnesisUserID = ? WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = ? AND orderAnamnesisIsActive = 'Y'"; } if ($prm['selected_anamnese_tab']['id'] == 'HYSNOW') { $sql = "UPDATE one_klinik.order_anamnesis SET orderAnamnesisRiwayatPenyakitDanAlergiSekarang = ?, orderAnamnesisUserID = ? WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = ? AND orderAnamnesisIsActive = 'Y'"; } if ($prm['selected_anamnese_tab']['id'] == 'FAMILY') { $sql = "UPDATE one_klinik.order_anamnesis SET orderAnamnesisRiwayatPenyakitKeluarga = ?, orderAnamnesisUserID = ? WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = ? AND orderAnamnesisIsActive = 'Y'"; } if ($prm['selected_anamnese_tab']['id'] == 'MEDICINE') { $sql = "UPDATE one_klinik.order_anamnesis SET orderAnamnesisRiwayatPengobatan = ?, orderAnamnesisUserID = ? WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = ? AND orderAnamnesisIsActive = 'Y'"; } if ($prm['selected_anamnese_tab']['id'] == 'SOSIAL') { $sql = "UPDATE one_klinik.order_anamnesis SET orderAnamnesisRiwayatSosial = ?, orderAnamnesisUserID = ? WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = ? AND orderAnamnesisIsActive = 'Y'"; } if ($prm['selected_anamnese_tab']['id'] == 'OPERATING') { $sql = "UPDATE one_klinik.order_anamnesis SET orderAnamnesisRiwayatOperasi = ?, orderAnamnesisUserID = ? WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = ? AND orderAnamnesisIsActive = 'Y'"; } if ($prm['selected_anamnese_tab']['id'] == 'VAKSIN') { $sql = "UPDATE one_klinik.order_anamnesis SET orderAnamnesisRiwayatImunisasi = ?, orderAnamnesisUserID = ? WHERE orderAnamnesisOrderID = ? AND orderAnamnesisTypeForm = ? AND orderAnamnesisIsActive = 'Y'"; } $value = $prm['note']; if ($prm['type'] == 'FORM') { $value = str_replace('\'', '\\\'', json_encode($prm["json_form"], JSON_UNESCAPED_UNICODE | JSON_HEX_APOS | JSON_HEX_QUOT)); } $query = $this->db_oneklinik->query($sql, array($value, $userID, $prm['orderid'], $prm['type'])); //echo $this->db_oneklinik->last_query(); if (!$query) { $this->sys_error("Invalid Query update " . $prm['selected_anamnese_tab']['id']); exit; } $this->sys_ok($result); exit; } function change_doctor() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userID = $this->sys_user['M_UserID']; $sql = "UPDATE one_klinik.`order` SET orderM_DoctorID = ?, orderUserID = ? WHERE orderID = ?"; $query = $this->db_oneklinik->query($sql, array($prm['doctor']['id'], $userID, $prm['orderid'])); if (!$query) { $this->sys_error("Invalid update doctor"); exit; } $result = array('status' => 'saved'); $this->sys_ok($result); exit; } function save_px() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userID = $this->sys_user['M_UserID']; $sql = "UPDATE one_klinik.`order` SET orderM_DoctorID = ?, orderUserID = ? WHERE orderID = ?"; $query = $this->db_oneklinik->query($sql, array($prm['doctor']['id'], $userID, $prm['orderid'])); if (!$query) { $this->sys_error("Invalid update doctor"); exit; } if (count($prm['selected_test']) > 0) { $sql = "UPDATE one_klinik.order_penunjang SET orderPenunjangIsActive = 'N' WHERE orderPenunjangOrderID = ? AND orderPenunjangIsActive = 'Y'"; $query = $this->db_oneklinik->query($sql, array($prm['orderid'])); //echo $this->db_oneklinik->last_query(); if (!$query) { $this->sys_error("Invalid Query Is Active N"); exit; } foreach ($prm['selected_test'] as $key => $value) { $sql = "INSERT INTO one_klinik.order_penunjang( orderPenunjangOrderID, orderPenunjangT_TestID, orderPenunjangCreated ) VALUES( ?,?,NOW() )"; $query = $this->db_oneklinik->query($sql, array($prm['orderid'], $value['T_TestID'])); //echo $this->db_oneklinik->last_query(); if (!$query) { $this->sys_error("Invalid Query Insert " . $value['T_TestName']); exit; } } } //$mouID = $this->getMouID(); $sql = "SELECT settingM_MouID as id FROM one_klinik.setting WHERE settingIsActive = 'Y'"; $query = $this->db_oneklinik->query($sql); if (!$query) { $this->sys_error("error get setting"); return 0; } $mouID = $query->row()->id; $result['selected_test'] = $this->getSelectedTest($prm['orderid'], $mouID); $this->sys_ok($result); exit; } function get_form_vital($orderID) { /*$sql = "SELECT * FROM one_klinik.`order` WHERE orderID = ? "; $query = $this->db_oneklinik->query($sql,$orderID); if(!$query){ $this->sys_error("error get language"); echo $this->db_oneklinik->last_query(); return array("data" => 'error languange'); } $langID = $query->row()->orderM_LanguageID;*/ $sql = "SELECT * FROM fisik_templateresult WHERE Fisik_TemplateResultM_LangID = 1 AND Fisik_TemplateResultType = 'fisik' AND Fisik_TemplateResultIsActive = 'Y' LIMIT 1 "; $query = $this->db_onedev->query($sql, array($langID)); if (!$query) { $this->sys_error("error get fisik template"); //echo $this->db_onedev->last_query(); return array("data" => 'error'); } $fisik = json_decode($query->row()->Fisik_TemplateResultText); $tanda_vital = []; foreach ($fisik as $key => $value) { if ($value->title == 'TANDA VITAL' || $value->title == 'STATUS GIZI') $tanda_vital[] = $value; } return $tanda_vital; } function get_form_anamnese($orderID, $formName) { /*$sql = "SELECT * FROM one_klinik.`order` WHERE orderID = ? "; $query = $this->db_oneklinik->query($sql,$orderID); if(!$query){ $this->sys_error("error get language"); echo $this->db_oneklinik->last_query(); return array("data" => 'error languange'); } $langID = $query->row()->orderM_LanguageID;*/ $sql = "SELECT * FROM fisik_templateresult WHERE Fisik_TemplateResultM_LangID = 1 AND Fisik_TemplateResultType = 'riwayat' AND Fisik_TemplateResultIsActive = 'Y' LIMIT 1 "; $query = $this->db_onedev->query($sql, array($langID)); if (!$query) { $this->sys_error("error get riwayat template"); //echo $this->db_onedev->last_query(); return array("data" => 'error'); } $riwayat = json_decode($query->row()->Fisik_TemplateResultText); $json_form = []; foreach ($riwayat as $key => $value) { if ($value->title == $formName) $json_form[] = $value; } return $json_form; } public function list_patient() { $prm = $this->sys_input; $max_rst = 20; $tot_count = 0; $number_limit = 20; $number_offset = (!isset($prm['current_page']) ? 1 : $prm['current_page'] - 1) * $number_limit; $xdate = $prm['date']; $status = $prm['status']; $sql = "SELECT 'N' divider, CONCAT(M_TitleName,' ',IF(M_PatientPrefix = NULL,'',CONCAT(M_PatientPrefix,' ')),M_PatientName,IF(M_PatientPrefix = NULL,'',CONCAT(M_PatientSuffix,' '))) as patient_name, `order`.*,DATE_FORMAT(orderDate,'%d-%m-%Y') as date_order, '' as kode_status, '' as status FROM one_klinik.`order` JOIN m_patient ON orderM_PatientID = M_PatientID JOIN m_title ON M_PatientM_TitleID = M_TitleID LEFT JOIN s_menu ON ( S_MenuUrl LIKE CONCAT('%test/vuex/one-klinik-fo-registration-v') OR S_MenuName = 'Periksa dokter') WHERE orderIsActive = 'Y' AND DATE(orderDate) = ? AND orderIsCheck = ? LIMIT $number_limit offset $number_offset"; //echo $sql; $query = $this->db_oneklinik->query($sql, array($xdate, $status)); //echo $this->db_oneklinik->last_query(); if ($query) { $rows = $query->result_array(); foreach ($rows as $key => $value) { $sql = "SELECT FROM one_klinik.order_status WHERE orderStatusOrderID = ? ORDER BY "; } $result = array("total" => $tot_page, "records" => $rows, "sql" => $this->db_onedev->last_query()); $this->sys_ok($result); } else { $this->sys_error_db("m_patient rows", $this->db_onedev); exit; } } function process_now() { 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 orderID, orderQueueNumber AS queueNumber, orderM_LocationID AS locationID, M_LocationName AS locationName, M_LocationT_SampleStationID FROM one_klinik.order JOIN m_location ON orderM_LocationID = M_LocationID WHERE orderID = {$prm['orderID']}"; $qry = $this->db_onedev->query($sql); if (!$qry) { $this->sys_error("Gagal cek data"); exit; } $location = $qry->row_array(); $locationID = $location['locationID']; $stationID = $location['M_LocationT_SampleStationID']; $locationName = $location['locationName']; $sql = "INSERT INTO one_klinik.order_status ( orderStatusOrderID, orderStatusCode, orderStatusValue, orderStatusUserID ) VALUES( ?,?,?,? )"; $query = $this->db_oneklinik->query($sql, array($prm['orderID'], 'C', 'Y', $userID)); if (!$query) { $this->sys_error("Gagal Process"); } $sql = "UPDATE one_klinik.`order` SET orderIsCheck = 'Y', orderUserID = ? WHERE orderID = ?"; $query = $this->db_oneklinik->query($sql, array($userID, $prm['orderID'])); if (!$query) { $this->sys_error("Gagal Update"); } $query = "INSERT INTO t_sampling_clinic_queue_last_status ( T_SamplingQueueLastStatusT_SampleStationID, T_SamplingQueueLastStatusT_OrderHeaderID, T_SamplingQueueLastStatusT_SamplingQueueStatusID, T_SamplingQueueLastStatusUserID) VALUES( {$stationID}, {$prm['orderID']}, 3, {$userID}) ON DUPLICATE KEY UPDATE T_SamplingQueueLastStatusT_SamplingQueueStatusID = 3"; //echo $query; $rows = $this->db_onedev->query($query); if (!$rows) { $this->sys_error("Gagal insert / update t_sampling_queue_last_status"); exit; } file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/serve.sm.{$locationID}"); $result = array('process' => 'OK'); $this->sys_ok($result); exit; } function cancel_now() { 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 orderID, orderQueueNumber AS queueNumber, orderM_LocationID AS locationID, M_LocationName AS locationName, M_LocationT_SampleStationID FROM one_klinik.order JOIN m_location ON orderM_LocationID = M_LocationID WHERE orderID = {$prm['orderID']}"; $qry = $this->db_onedev->query($sql); if (!$qry) { $this->sys_error("Gagal cek data"); exit; } $location = $qry->row_array(); $locationID = $location['locationID']; $stationID = $location['M_LocationT_SampleStationID']; $locationName = $location['locationName']; $sql = "INSERT INTO one_klinik.order_status ( orderStatusOrderID, orderStatusCode, orderStatusValue, orderStatusUserID ) VALUES( ?,?,?,? )"; $query = $this->db_oneklinik->query($sql, array($prm['orderID'], 'C', 'N', $userID)); if (!$query) { $this->sys_error("Gagal Process"); } $sql = "UPDATE one_klinik.`order` SET orderIsCheck = 'N', orderUserID = ? WHERE orderID = ?"; $query = $this->db_oneklinik->query($sql, array($userID, $prm['orderID'])); if (!$query) { $this->sys_error("Gagal Process"); } $query = "INSERT INTO t_sampling_clinic_queue_last_status ( T_SamplingQueueLastStatusT_SampleStationID, T_SamplingQueueLastStatusT_OrderHeaderID, T_SamplingQueueLastStatusT_SamplingQueueStatusID, T_SamplingQueueLastStatusUserID) VALUES( {$stationID}, {$prm['orderID']}, 2, {$userID}) ON DUPLICATE KEY UPDATE T_SamplingQueueLastStatusT_SamplingQueueStatusID = 2"; //echo $query; $rows = $this->db_onedev->query($query); if (!$rows) { $this->sys_error("Gagal insert / update t_sampling_queue_last_status"); exit; } file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/skip.sm.{$locationID}"); $result = array('process' => 'OK'); $this->sys_ok($result); exit; } function end_session() { 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 orderID, orderQueueNumber AS queueNumber, orderM_LocationID AS locationID, M_LocationName AS locationName, M_LocationT_SampleStationID FROM one_klinik.order JOIN m_location ON orderM_LocationID = M_LocationID WHERE orderID = {$prm['orderID']}"; $qry = $this->db_onedev->query($sql); if (!$qry) { $this->sys_error("Gagal cek data"); exit; } $location = $qry->row_array(); $locationID = $location['locationID']; $stationID = $location['M_LocationT_SampleStationID']; $locationName = $location['locationName']; $sql = "INSERT INTO one_klinik.order_status ( orderStatusOrderID, orderStatusCode, orderStatusValue, orderStatusUserID ) VALUES( ?,?,?,? )"; $query = $this->db_oneklinik->query($sql, array($prm['orderID'], 'C', 'D', $userID)); if (!$query) { $this->sys_error("Gagal End"); } $sql = "UPDATE one_klinik.`order` SET orderIsCheck = 'D', orderUserID = ? WHERE orderID = ?"; $query = $this->db_oneklinik->query($sql, array($userID, $prm['orderID'])); if (!$query) { $this->sys_error("Gagal ENd"); } $query = "INSERT INTO t_sampling_clinic_queue_last_status ( T_SamplingQueueLastStatusT_SampleStationID, T_SamplingQueueLastStatusT_OrderHeaderID, T_SamplingQueueLastStatusT_SamplingQueueStatusID, T_SamplingQueueLastStatusUserID) VALUES( {$stationID}, {$prm['orderID']}, 5, {$userID}) ON DUPLICATE KEY UPDATE T_SamplingQueueLastStatusT_SamplingQueueStatusID = 5"; //echo $query; $rows = $this->db_onedev->query($query); if (!$rows) { $this->sys_error("Gagal insert / update t_sampling_queue_last_status"); exit; } file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/done.sm.{$locationID}"); $result = array('process' => 'OK'); $this->sys_ok($result); 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; } function save_icd10_primer($orderID, $icd10_code, $icd10_display) { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //$prm = $this->sys_input; $prm['orderID'] = $orderID; $prm['icd10']['code'] = $icd10_code; $userID = $this->sys_user['M_UserID']; //print_r($prm['subgroup']); $sql = "SELECT COUNT(*) as xcount FROM one_klinik.order_diagnose_icd10 WHERE orderDiagnoseIcd10OrderID = ? AND orderDiagnoseIcd10IsActive = 'Y' LIMIT 1"; $query = $this->db_oneklinik->query($sql, array($prm['orderID'])); if (!$query) { $this->sys_error("Gagal hitung"); } $xcount = $query->row()->xcount; if ($xcount == 0) { $sql = "INSERT INTO one_klinik.order_diagnose_icd10 ( orderDiagnoseIcd10OrderID, orderDiagnoseIcd10Created, orderDiagnoseIcd10UserID ) VALUES( ?,NOW(),? )"; $query = $this->db_oneklinik->query($sql, array($prm['orderID'], $userID)); if (!$query) { $this->sys_error("Gagal insert"); } } $sql = "UPDATE one_klinik.order_diagnose_icd10 SET orderDiagnoseIcd10Primary = ?, orderDiagnoseIcd10PrimaryText = ?, orderDiagnoseIcd10UserID = ? WHERE orderDiagnoseIcd10OrderID = ? "; $query = $this->db_oneklinik->query($sql, array($prm['icd10']['code'], $icd10_display, $userID, $prm['orderID'])); if (!$query) { $this->sys_error("Gagal update"); } $this->sys_ok($result); exit; } function check_exist_icd10_row($orderID) { $sql = "SELECT COUNT(*) as xcount FROM one_klinik.order_diagnose_icd10 WHERE orderDiagnoseIcd10OrderID = ? AND orderDiagnoseIcd10IsActive = 'Y' LIMIT 1"; $query = $this->db_oneklinik->query($sql, array($orderID)); if (!$query) { $this->sys_error("Gagal hitung"); } return $query->row()->xcount; } function save_icd10_sekunder($orderID, $icd10_code, $icd10_display) { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } //$prm = $this->sys_input; $prm['orderID'] = $orderID; $prm['icd10']['code'] = $icd10_code; $userID = $this->sys_user['M_UserID']; //print_r($prm['subgroup']); $xcount = $this->check_exist_icd10_row($prm['orderID']); if ($xcount == 0) { $sql = "INSERT INTO one_klinik.order_diagnose_icd10 ( orderDiagnoseIcd10OrderID, orderDiagnoseIcd10Created, orderDiagnoseIcd10UserID ) VALUES( ?,NOW(),? )"; $query = $this->db_oneklinik->query($sql, array($prm['orderID'], $userID)); if (!$query) { $this->sys_error("Gagal insert"); } } $sql = "UPDATE one_klinik.order_diagnose_icd10 SET orderDiagnoseIcd10Sekunder = ?, orderDiagnoseIcd10SekunderText = ?, orderDiagnoseIcd10UserID = ? WHERE orderDiagnoseIcd10OrderID = ? "; $query = $this->db_oneklinik->query($sql, array($prm['icd10']['code'], $icd10_display, $userID, $prm['orderID'])); if (!$query) { $this->sys_error("Gagal update"); } $this->sys_ok($result); exit; } }