db_onedev = $this->load->database("onedev", true); } public function search() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $nama = $prm["name"]; $date = $prm['date']; $status = $prm["status"]; /* $e = explode('+', $prm['name']); if (isset($e[0])) $nama = "%{$e[0]}%"; if (isset($e[1])) $nohp = "%{$e[1]}%"; // echo $norm; $sql_where = ""; $sql_param = array(); if ($nama != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " M_PatientName like ?"; $sql_param[] = "$nama"; //$prm['current_page'] = 1; } if ($sql_where != "") $sql_where .= " and "; */ // Order masih dalam status registrasi $sql_where .= " T_WorklistRefConfirmDetailIsDeliveryOrder = 'N' AND T_WorklistRefConfirmDetailIsActive = 'Y' AND (JSON_UNQUOTE(JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID), '$.patient_fullname')) LIKE CONCAT('%','{$nama}','%') OR T_OrderHeaderLabNumber LIKE CONCAT('%','{$nama}','%') OR T_WorklistName LIKE CONCAT('%','{$nama}','%')) AND (date(T_WorklistRefConfirmDate) BETWEEN date(now()) - INTERVAL 7 DAY AND date(now()))"; if ($sql_where != "") { $sql_where = " where $sql_where"; //$prm['current_page'] = 1; } $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit ; $sql = "SELECT count(*) as total from t_worklist_ref_confirmdetail join t_worklist_ref_confirm ON T_WorklistRefConfirmDetailT_WorklistRefConfirmID = T_WorklistRefConfirmID AND T_WorklistRefConfirmIsActive = 'Y' join t_orderheader ON T_WorklistRefConfirmDetailT_OrderHeaderID = T_OrderHeaderID join t_worklist ON T_WorklistRefConfirmDetailT_WorklistID = T_WorklistID $sql_where"; $query = $this->db_onedev->query($sql, $sql_param); $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("t_orderheader count", $this->db_onedev); exit; } $sql = "SELECT T_OrderHeaderID, T_WorklistRefConfirmDetailID, JSON_UNQUOTE(JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID), '$.patient_fullname')) as M_PatientName, T_OrderHeaderLabNumber, T_TestName, T_WorklistName from t_worklist_ref_confirmdetail join t_worklist_ref_confirm ON T_WorklistRefConfirmDetailT_WorklistRefConfirmID = T_WorklistRefConfirmID AND T_WorklistRefConfirmIsActive = 'Y' join t_orderheader ON T_WorklistRefConfirmDetailT_OrderHeaderID = T_OrderHeaderID join t_worklist ON T_WorklistRefConfirmDetailT_WorklistID = T_WorklistID join t_test ON T_WorklistRefConfirmDetailT_TestID = T_TestID $sql_where ORDER BY T_OrderHeaderID ASC, T_TestSasCode ASC limit $number_limit offset $number_offset"; $query = $this->db_onedev->query($sql, $sql_param); //echo $this->db_onedev->last_query(); $rows = $query->result_array(); if($rows){ foreach($rows as $k => $v){ //$rows[$k]['verification_px'] = $this->add_verification_test($v['M_PatientID']); } } //$this->_add_address($rows); $result = array("total" => $tot_page,"total_filter" => $tot_page2,"records" => $rows, "sql"=> $this->db_onedev->last_query()); $this->sys_ok($result); exit; } public function searchtrace() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $deliveryorder = $prm['deliveryorder']; $deliveryorderdetail = $prm['name']; $sql = $this->db_onedev->query("SELECT M_BranchID, M_BranchName FROM m_branch WHERE M_BranchIsActive = 'Y' AND M_BranchIsDefault = 'Y' ORDER BY M_BranchID DESC LIMIT 1")->row(); $branchid = $sql->M_BranchID; $branchname = $sql->M_BranchName; $sql = $this->db_onedev->query("SELECT COUNT(T_RefDeliveryOrderDetailID) as totalorder FROM t_ref_deliveryorder JOIN t_ref_deliveryorder_detail ON T_RefDeliveryOrderID = T_RefDeliveryOrderDetailT_RefDeliveryOrderID AND T_RefDeliveryOrderDetailIsActive = 'Y' WHERE T_RefDeliveryOrderIsActive = 'Y' AND T_RefDeliveryOrderDate = '{$deliveryorder}'")->row(); $totalorder = $sql->totalorder; $sql = $this->db_onedev->query("SELECT COUNT(T_RefDeliveryOrderDetailID) as totalconfirm FROM t_ref_deliveryorder JOIN t_ref_deliveryorder_detail ON T_RefDeliveryOrderID = T_RefDeliveryOrderDetailT_RefDeliveryOrderID AND T_RefDeliveryOrderDetailIsActive = 'Y' AND T_RefDeliveryOrderDetailIsConfirm <> 'N' WHERE T_RefDeliveryOrderIsActive = 'Y' AND T_RefDeliveryOrderIsConfirm <> 'N' AND T_RefDeliveryOrderDate = '{$deliveryorder}'")->row(); $totalconfirm = $sql->totalconfirm; $sql = $this->db_onedev->query("SELECT COUNT(T_RefDeliveryOrderDetailID) as totalverif FROM t_ref_deliveryorder JOIN t_ref_deliveryorder_detail ON T_RefDeliveryOrderID = T_RefDeliveryOrderDetailT_RefDeliveryOrderID AND T_RefDeliveryOrderDetailIsActive = 'Y' WHERE T_RefDeliveryOrderIsActive = 'Y' AND T_RefDeliveryOrderDate = '{$deliveryorder}' AND (T_RefDeliveryOrderDetailStage = 'VERIFICATION' OR T_RefDeliveryOrderDetailStage = 'VALIDATION')")->row(); $totalverif = $sql->totalverif; $sql = $this->db_onedev->query("SELECT COUNT(T_RefDeliveryOrderDetailID) as totalvalid FROM t_ref_deliveryorder JOIN t_ref_deliveryorder_detail ON T_RefDeliveryOrderID = T_RefDeliveryOrderDetailT_RefDeliveryOrderID AND T_RefDeliveryOrderDetailIsActive = 'Y' WHERE T_RefDeliveryOrderIsActive = 'Y' AND T_RefDeliveryOrderDate = '{$deliveryorder}' AND T_RefDeliveryOrderDetailStage = 'VALIDATION'")->row(); $totalvalid = $sql->totalvalid; $limit = ''; if($all == 'N'){ $limit = ' LIMIT 10'; } $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit ; $sql = "select COUNT(*) as total FROM(SELECT * from t_ref_deliveryorder LEFT JOIN t_ref_deliveryorder_detail ON T_RefDeliveryOrderID = T_RefDeliveryOrderDetailT_RefDeliveryOrderID AND T_RefDeliveryOrderDetailIsActive = 'Y' JOIN t_orderheader ON T_RefDeliveryOrderDetailT_OrderHeaderID = T_OrderHeaderID JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID JOIN m_title ON M_PatientM_TitleID = M_TitleID JOIN t_test ON T_RefDeliveryOrderDetailT_TestID = T_TestID where (T_RefDeliveryOrderNumber LIKE CONCAT('%','{$deliveryorderdetail}','%') OR T_OrderHeaderLabNumber LIKE CONCAT('%','{$deliveryorderdetail}','%') OR M_PatientName LIKE CONCAT('%','{$deliveryorderdetail}','%')) AND T_RefDeliveryOrderIsActive = 'Y'AND '{$deliveryorderdetail}' <> '' GROUP BY T_RefDeliveryOrderDetailID) a"; $sql_param = array($search); // $total = $this->db_onedev->query($sql,$sql_param)->row()->total; $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("t_ref_deliveryorder count", $this->db_onedev); exit; } $sql = "SELECT * FROM( SELECT t_ref_deliveryorder.*, T_RefDeliveryOrderDetailID as id, date_format(T_OrderHeaderDate,'%d-%m-%Y') as tanggal_order, date_format(T_RefDeliveryOrderDate,'%d-%m-%Y') as tanggal_suratjalan, 'Internal' as isexternal, b.M_BranchID as M_BranchID, b.M_BranchName as M_BranchName, b.M_BranchAddress as M_BranchAddress, d.M_BranchID as M_DestinationID, d.M_BranchName as M_DestinationName, T_RefDeliveryOrderAddress as M_DestinationAddress, T_RefDeliveryOrderUp as M_DestinationUp, d.M_BranchName as destination, M_CityID, M_CityName, M_DistrictID, M_DistrictName, M_KelurahanID, M_KelurahanName, M_CourierID, M_StaffName, T_WorklistID, T_WorklistName, CASE WHEN T_RefDeliveryOrderIsConfirm = 'N' THEN CONCAT('Surat Jalan Baru','\r\n',DATE_FORMAT(T_RefDeliveryOrderLastUpdated,'%T')) WHEN T_RefDeliveryOrderIsConfirm = 'Y' THEN CONCAT('Serah Terima Kurir','\r\n',DATE_FORMAT(T_RefDeliveryOrderLastUpdated,'%T')) WHEN T_RefDeliveryOrderIsConfirm = 'S' THEN CONCAT('Data Terkirim ke Tujuan','\r\n',DATE_FORMAT(T_RefDeliveryOrderLastUpdated,'%T')) ELSE '' END as status, DATE_FORMAT(T_RefDeliveryOrderDate,'%d%m%Y') as startdate, DATE_FORMAT(T_RefDeliveryOrderDate,'%d-%m-%Y') as T_RefDeliveryOrderDatex, T_RefDeliveryOrderDetailID, T_OrderHeaderLabNumber, CONCAT(M_TitleName, ' ', M_PatientName) as M_PatientName, T_TestName, T_RefDeliveryOrderDetailResult, T_RefDeliveryOrderDetailStatus, T_RefDeliveryOrderDetailStage, T_RefDeliveryOrderDetailNote, IF(T_RefDeliveryOrderIsConfirm <> 'N' AND T_RefDeliveryOrderDetailIsConfirm = 'N','N','Y') as iskonfirmasi, T_RefDeliveryOrderDetailT_OrderHeaderID, T_RefDeliveryOrderDetailT_TestID FROM t_ref_deliveryorder JOIN t_ref_deliveryorder_detail ON T_RefDeliveryOrderID = T_RefDeliveryOrderDetailT_RefDeliveryOrderID AND T_RefDeliveryOrderDetailIsActive = 'Y' LEFT JOIN m_branch b ON T_RefDeliveryOrderM_BranchID = b.M_BranchID LEFT JOIN t_worklist ON T_RefDeliveryOrderT_WorklistID = T_WorklistID LEFT JOIN m_branch d ON T_RefDeliveryOrderM_DestinationID = d.M_BranchID LEFT JOIN m_city ON d.M_BranchM_CityID = M_CityID LEFT JOIN m_district ON d.M_BranchM_DistrictID = M_DistrictID LEFT JOIN m_kelurahan ON d.M_BranchM_KelurahanID = M_KelurahanID LEFT JOIN m_courier ON T_RefDeliveryOrderM_CourierID = M_CourierID LEFT JOIN m_staff ON M_CourierM_StaffID = M_StaffID JOIN t_orderheader ON T_RefDeliveryOrderDetailT_OrderHeaderID = T_OrderHeaderID JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID JOIN m_title ON M_PatientM_TitleID = M_TitleID JOIN t_test ON T_RefDeliveryOrderDetailT_TestID = T_TestID where (T_RefDeliveryOrderNumber LIKE CONCAT('%','{$deliveryorderdetail}','%') OR T_OrderHeaderLabNumber LIKE CONCAT('%','{$deliveryorderdetail}','%') OR M_PatientName LIKE CONCAT('%','{$deliveryorderdetail}','%')) AND T_RefDeliveryOrderIsActive = 'Y' AND T_RefDeliveryOrderIsExternal = 'N' AND '{$deliveryorderdetail}' <> '' UNION SELECT t_ref_deliveryorder.*, T_RefDeliveryOrderDetailID as id, date_format(T_OrderHeaderDate,'%d-%m-%Y') as tanggal_order, date_format(T_RefDeliveryOrderDate,'%d-%m-%Y') as tanggal_suratjalan, 'External' as isexternal, M_BranchID, M_BranchName, M_BranchAddress, M_LabReferenceID as M_DestinationID, M_LabReferenceName as M_DestinationName, T_RefDeliveryOrderAddress as M_DestinationAddress, T_RefDeliveryOrderUp as M_DestinationUp, M_LabReferenceName as destination, M_CityID, M_CityName, M_DistrictID, M_DistrictName, M_KelurahanID, M_KelurahanName, M_CourierID, M_StaffName, T_WorklistID, T_WorklistName, CASE WHEN T_RefDeliveryOrderIsConfirm = 'N' THEN CONCAT('Surat Jalan Baru','\r\n',DATE_FORMAT(T_RefDeliveryOrderLastUpdated,'%T')) WHEN T_RefDeliveryOrderIsConfirm = 'Y' THEN CONCAT('Serah Terima Kurir','\r\n',DATE_FORMAT(T_RefDeliveryOrderLastUpdated,'%T')) WHEN T_RefDeliveryOrderIsConfirm = 'S' THEN CONCAT('Data Terkirim ke Tujuan','\r\n',DATE_FORMAT(T_RefDeliveryOrderLastUpdated,'%T')) ELSE '' END as status, DATE_FORMAT(T_RefDeliveryOrderDate,'%d%m%Y') as startdate, DATE_FORMAT(T_RefDeliveryOrderDate,'%d-%m-%Y') as T_RefDeliveryOrderDatex, T_RefDeliveryOrderDetailID, T_OrderHeaderLabNumber, CONCAT(M_TitleName, ' ', M_PatientName) as M_PatientName, T_TestName, T_RefDeliveryOrderDetailResult, T_RefDeliveryOrderDetailStatus, T_RefDeliveryOrderDetailStage, T_RefDeliveryOrderDetailNote, IF(T_RefDeliveryOrderIsConfirm <> 'N' AND T_RefDeliveryOrderDetailIsConfirm = 'N','N','Y') as iskonfirmasi, T_RefDeliveryOrderDetailT_OrderHeaderID, T_RefDeliveryOrderDetailT_TestID FROM t_ref_deliveryorder JOIN t_ref_deliveryorder_detail ON T_RefDeliveryOrderID = T_RefDeliveryOrderDetailT_RefDeliveryOrderID AND T_RefDeliveryOrderDetailIsActive = 'Y' LEFT JOIN m_branch ON T_RefDeliveryOrderM_BranchID = M_BranchID LEFT JOIN t_worklist ON T_RefDeliveryOrderT_WorklistID = T_WorklistID LEFT JOIN m_labreference d ON T_RefDeliveryOrderM_DestinationID = M_LabReferenceID LEFT JOIN m_city ON M_LabReferenceM_CityID = M_CityID LEFT JOIN m_district ON M_LabReferenceM_DistrictID = M_DistrictID LEFT JOIN m_kelurahan ON M_LabReferenceM_KelurahanID = M_KelurahanID LEFT JOIN m_courier ON T_RefDeliveryOrderM_CourierID = M_CourierID LEFT JOIN m_staff ON M_CourierM_StaffID = M_StaffID JOIN t_orderheader ON T_RefDeliveryOrderDetailT_OrderHeaderID = T_OrderHeaderID JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID JOIN m_title ON M_PatientM_TitleID = M_TitleID JOIN t_test ON T_RefDeliveryOrderDetailT_TestID = T_TestID where (T_RefDeliveryOrderNumber LIKE CONCAT('%','{$deliveryorderdetail}','%') OR T_OrderHeaderLabNumber LIKE CONCAT('%','{$deliveryorderdetail}','%') OR M_PatientName LIKE CONCAT('%','{$deliveryorderdetail}','%')) AND T_RefDeliveryOrderIsActive = 'Y' AND T_RefDeliveryOrderIsExternal = 'Y' AND '{$deliveryorderdetail}' <> '' ) a GROUP BY T_RefDeliveryOrderDetailID ORDER BY T_RefDeliveryOrderID DESC, T_RefDeliveryOrderDetailT_OrderHeaderID ASC, T_RefDeliveryOrderDetailT_TestID ASC limit $number_limit offset $number_offset"; $sql_param = array($search); $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("t_ref_deliveryorder select"); exit; } $result = array ("total" => $tot_page,"totalorder" => $totalorder,"totalconfirm" => $totalconfirm,"totalverif" => $totalverif,"totalvalid" => $totalvalid, "total_filter"=>count($rows),"records" => $rows, "branchid" => $branchid, "branchname" => $branchname); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function lookupresultbyid(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $all = $prm['all']; $limit = ''; if($all == 'N'){ $limit = ' LIMIT 10'; } $number_limit = 10; $number_offset = (1 - 1) * $number_limit ; $sql = "select COUNT(*) as total FROM(SELECT * from t_ref_deliveryorder_child JOIN t_ref_deliveryorder_detail ON T_RefDeliveryOrderChildT_RefDeliveryOrderDetailID = T_RefDeliveryOrderDetailID JOIN t_ref_deliveryorder ON T_RefDeliveryOrderDetailT_RefDeliveryOrderID = T_RefDeliveryOrderID AND T_RefDeliveryOrderIsActive = 'Y' JOIN t_orderheader ON T_RefDeliveryOrderDetailT_OrderHeaderID = T_OrderHeaderID JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID JOIN m_title ON M_PatientM_TitleID = M_TitleID JOIN t_test ON T_RefDeliveryOrderChildT_TestID = T_TestID WHERE T_RefDeliveryOrderChildT_RefDeliveryOrderDetailID = '{$id}' GROUP BY T_RefDeliveryOrderChildID ORDER BY T_TestSasCode ASC) a"; // $total = $this->db_onedev->query($sql,$sql_param)->row()->total; $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); $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("t_ref_deliveryorder_child count", $this->db_onedev); exit; } $sql = "select t_ref_deliveryorder_detail.*, t_ref_deliveryorder_child.*, T_RefDeliveryOrderChildID as id, T_OrderHeaderLabNumber, CONCAT(M_TitleName, ' ', M_PatientName) as M_PatientName, T_TestName, 'Y' as ischoose, 'N' as isnew, IF(T_RefDeliveryOrderChildNote LIKE CONCAT('%','valid','%') ,'VALIDATION','') as T_RefDeliveryOrderChildStage from t_ref_deliveryorder_child JOIN t_ref_deliveryorder_detail ON T_RefDeliveryOrderChildT_RefDeliveryOrderDetailID = T_RefDeliveryOrderDetailID JOIN t_ref_deliveryorder ON T_RefDeliveryOrderDetailT_RefDeliveryOrderID = T_RefDeliveryOrderID AND T_RefDeliveryOrderIsActive = 'Y' JOIN t_orderheader ON T_RefDeliveryOrderDetailT_OrderHeaderID = T_OrderHeaderID JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID JOIN m_title ON M_PatientM_TitleID = M_TitleID JOIN t_test ON T_RefDeliveryOrderChildT_TestID = T_TestID WHERE T_RefDeliveryOrderChildT_RefDeliveryOrderDetailID = '{$id}' GROUP BY T_RefDeliveryOrderChildID ORDER BY T_RefDeliveryOrderChildID ASC"; $sql_param = array($search); $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("t_ref_deliveryorder_child select"); exit; } $result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function searchconfirm() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $code = $prm["code"]; $nama = $prm["name"]; $date = $prm['date']; $e = explode('+', $prm['name']); if (isset($e[0])) $nama = "%{$e[0]}%"; if (isset($e[1])) $alamat = "%{$e[1]}%"; if (isset($e[2])) $nohp = "%{$e[2]}%"; // echo $norm; $sql_where = ""; $sql_param = array(); if ($code != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " M_DoctorOldCode like ?"; $sql_param[] = "$code"; //$prm['current_page'] = 1; } if ($nama != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " M_DoctorName like ?"; $sql_param[] = "$nama"; //$prm['current_page'] = 1; } if ($alamat != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " CONCAT(M_DoctorAddressNote, ': ',M_DoctorAddressDescription) like ?"; $sql_param[] = "$alamat"; //$prm['current_page'] = 1; } if ($nohp != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " M_DoctorHP like ?"; $sql_param[] = "$nohp"; //$prm['current_page'] = 1; } if ($sql_where != "") $sql_where .= " and "; // Order masih dalam status registrasi $sql_where .= " M_DoctorIsMarketingConfirm = 'Y' AND M_DoctorIsActive = 'Y'"; if ($sql_where != "") { $sql_where = " where $sql_where"; //$prm['current_page'] = 1; } $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit ; $sql = " SELECT count(*) as total, CONCAT(M_DoctorAddressNote, ': ',M_DoctorAddressDescription) as doctor_address FROM m_doctor JOIN m_sex ON M_DoctorM_SexID = M_SexID LEFT JOIN m_religion ON M_DoctorM_ReligionID = M_ReligionID LEFT JOIN m_staff ON M_DoctorM_StaffID = M_StaffID left join m_doctoraddress ON M_DoctorOldCode = M_DoctorAddressM_DoctorOldCode AND M_DoctorAddressIsActive = 'Y' $sql_where "; $query = $this->db_onedev->query($sql, $sql_param); $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; } $doctor_field = " M_DoctorID, M_DoctorOldCode, M_DoctorCode , M_DoctorPrefix , M_DoctorPrefix2 , M_DoctorName , M_DoctorSufix , M_DoctorSufix2 , M_DoctorSufix3 , M_DoctorM_SexID , M_DoctorM_ReligionID, M_DoctorM_StaffID, IFNULL(M_DoctorEmail,'') as M_DoctorEmail, M_DoctorHP , M_DoctorNote, M_DoctorPhone , M_DoctorIsMarketingConfirm, ifnull(M_DoctorPjIsPJ,'N') M_DoctorIsPJ, ifnull(M_DoctorPjIsDefaultPJ,'N') M_DoctorIsDefaultPJ , M_DoctorM_SpecialID , ifnull(M_DoctorPjIsClinic,'N') M_DoctorIsClinic , ifnull(M_DoctorPjIsDefault,'N') M_DoctorIsDefault , M_DoctorEmailIsDefault, M_DoctorIsDefaultMcu, M_DoctorCreated , M_DoctorLastUpdated, M_DoctorIsActive, M_DoctorReportCode , M_DoctorPrivateRequest, M_DoctorM_UserID , M_DoctorCreated, "; $sql = "SELECT $doctor_field CONCAT(IFNULL(M_DoctorPrefix,''),IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as doctor_fullname, M_SexName, M_ReligionName, M_StaffName, GROUP_CONCAT(CONCAT(M_DoctorAddressNote, ': ',M_DoctorAddressDescription) SEPARATOR '\r\n') as M_DoctorAddressNote, GROUP_CONCAT(CONCAT(M_DoctorAddressNote, ': ',M_DoctorAddressDescription) SEPARATOR '\r\n') as doctor_address, 'Telah dikonfirmasi marketing' as status FROM m_doctor JOIN m_sex ON M_DoctorM_SexID = M_SexID left join m_doctorpj on M_DoctorID = M_DoctorPjM_DoctorID left JOIN m_religion ON M_DoctorM_ReligionID = M_ReligionID left JOIN m_staff ON M_DoctorM_StaffID = M_StaffID left join m_doctoraddress ON M_DoctorOldCode = M_DoctorAddressM_DoctorOldCode AND M_DoctorAddressIsActive = 'Y' $sql_where GROUP BY M_DoctorID ORDER BY M_DoctorName ASC limit $number_limit offset $number_offset"; $query = $this->db_onedev->query($sql, $sql_param); // echo $this->db_onedev->last_query(); $rows = $query->result_array(); if($rows){ foreach($rows as $k => $v){ //$rows[$k]['verification_px'] = $this->add_verification_test($v['M_PatientID']); } } //$this->_add_address($rows); $result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query()); $this->sys_ok($result); exit; } function getsexreg(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query =" SELECT * FROM m_sex WHERE M_SexIsActive = 'Y' "; //echo $query; $rows['sexes'] = $this->db_onedev->query($query)->result_array(); $query =" SELECT * FROM m_religion WHERE M_ReligionIsActive = 'Y' "; //echo $query; $rows['religions'] = $this->db_onedev->query($query)->result_array(); $query =" SELECT 0 as M_StaffID, 'Semua' as M_StaffName UNION SELECT M_StaffID, M_StaffName FROM m_staff WHERE M_StaffIsActive = 'Y' and M_StaffM_PositionID = '2' "; //echo $query; $rows['staffs'] = $this->db_onedev->query($query)->result_array(); $query =" SELECT '' as M_BranchCode, 'Semua' as M_BranchName UNION SELECT M_BranchCode, M_BranchName FROM m_branch WHERE M_BranchIsActive = 'Y' "; //echo $query; $rows['branchs'] = $this->db_onedev->query($query)->result_array(); $query =" SELECT * FROM nat_jpa WHERE Nat_JpaIsActive = 'Y' "; //echo $query; $rows['jpas'] = $this->db_onedev->query($query)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getnewcode(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $sql = $this->db_onedev->query("SELECT `fn_numbering`('DOCTOR') as code")->row(); $newcode = $sql->code; $rows = []; $query ="SELECT `fn_numbering`('DOCTOR') as code "; //echo $query; $rows['code'] = $this->db_onedev->query($query)->result_array(); $result = array( "total" => 1, "records" => $rows, "newcode" => $newcode ); $this->sys_ok($result); exit; } function searchcity(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM m_city WHERE M_CityName like ? AND M_CityIsActive = 'Y'"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_city count",$this->db_onedev); exit; } $sql = " SELECT * FROM m_city WHERE M_CityName like ? AND M_CityIsActive = 'Y' ORDER BY M_CityName DESC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_city rows",$this->db_onedev); exit; } } function getdistrict(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query =" SELECT * FROM m_district WHERE M_DistrictIsActive = 'Y' AND M_DistrictM_CityID = ? "; //echo $query; $rows = $this->db_onedev->query($query,array($prm['id']))->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getkelurahan(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query =" SELECT * FROM m_kelurahan WHERE M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ? "; //echo $query; $rows = $this->db_onedev->query($query,array($prm['id']))->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getjpa(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query =" SELECT * FROM nat_jpa WHERE Nat_JpaIsActive = 'Y' "; //echo $query; $rows = $this->db_onedev->query($query)->result_array(); // $rows['jpas'] = $this->db_onedev->query($query)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function save(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; // ambil data lama $sql = "select * from tx_whatsapp where Tx_WhatsappID = ?"; $qry = $this->db_onedev->query($sql,array($prm["id"])); $rows = $qry->result_array(); $old_doctor = array(); if (count($rows) > 0 ) $old_doctor = $rows[0]; $query ="UPDATE tx_whatsapp SET Tx_WhatsappUpdated = now(), Tx_WhatsappUserID = '{$userid}', Tx_WhatsappIsSent = 'Y' WHERE Tx_WhatsappID = '{$prm['id']}' "; //echo $query; $rows = $this->db_onedev->query($query); $this->sys_ok($result); exit; } function newdoctor(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $prm = $this->sys_input; $ispj = $prm['M_DoctorIsPJ']; $isdefaultpj = $prm['M_DoctorIsDefaultPJ']; $isdefault = $prm['M_DoctorIsDefault']; $isclinic = $prm['M_DoctorIsClinic']; $query ="INSERT INTO m_doctor ( M_DoctorPrefix, M_DoctorPrefix2, M_DoctorName, M_DoctorSufix, M_DoctorSufix2, M_DoctorSufix3, M_DoctorM_SexID, M_DoctorM_ReligionID, M_DoctorM_StaffID, M_DoctorEmail, M_DoctorHP, M_DoctorNote, M_DoctorPhone, M_DoctorIsMarketingConfirm, M_DoctorIsPJ, M_DoctorIsDefaultPJ, M_DoctorIsClinic, M_DoctorIsDefault, M_DoctorEmailIsDefault, M_DoctorM_UserID ) VALUES( '{$prm['M_DoctorPrefix']}', '{$prm['M_DoctorPrefix2']}', '{$prm['M_DoctorName']}', '{$prm['M_DoctorSufix']}', '{$prm['M_DoctorSufix2']}', '{$prm['M_DoctorSufix3']}', '{$prm['M_DoctorM_SexID']}', '{$prm['M_DoctorM_ReligionID']}', '{$prm['M_DoctorM_StaffID']}', '{$prm['M_DoctorEmail']}', '{$prm['M_DoctorHP']}', '{$prm['M_DoctorNote']}', '{$prm['M_DoctorPhone']}', '{$prm['M_DoctorIsMarketingConfirm']}', '{$prm['M_DoctorIsPJ']}', '{$prm['M_DoctorIsDefaultPJ']}', '{$prm['M_DoctorIsClinic']}', '{$prm['M_DoctorIsDefault']}', '{$prm['M_DoctorEmailIsDefault']}', $userid ) "; //echo $query; $rows = $this->db_onedev->query($query); $last_id = $this->db_onedev->insert_id(); if($rows){ if($isdefault == 'Y'){ $querydefault ="UPDATE m_doctorpj SET M_DoctorPjIsDefault = 'N' WHERE M_DoctorPjIsDefault = 'Y' "; $rows = $this->db_onedev->query($querydefault); } if($isdefaultpj == 'Y'){ $querydefault ="UPDATE m_doctorpj SET M_DoctorPjIsDefaultPJ = 'N' WHERE M_DoctorPjIsDefaultPJ = 'Y' "; $rows = $this->db_onedev->query($querydefault); } if($ispj == 'Y' || $isdefaultpj == 'Y' || $isdefault == 'Y' || $isclinic === 'Y'){ $querypj ="INSERT INTO m_doctorpj ( M_DoctorPjM_DoctorID, M_DoctorPjIsPJ, M_DoctorPjIsDefaultPJ, M_DoctorPjIsClinic, M_DoctorPjIsDefault, M_DoctorPjCreated ) VALUES( '{$last_id}', '{$prm['M_DoctorIsPJ']}', '{$prm['M_DoctorIsDefaultPJ']}', '{$prm['M_DoctorIsClinic']}', '{$prm['M_DoctorIsDefault']}', NOW() ) "; $rows = $this->db_onedev->query($querypj); } } $result = array( "total" => 1 , "records" => array('status'=>'OK'), "id" => $last_id ); //sipe tambah log doctor $prm["M_DoctorID"] = $last_id; $prm["M_DoctorM_UserID"] = $userid; $d_doctor = json_encode($prm); $this->db_onedev->query("call one_log.log_me('DOCTOR','DOCTOR_ADD','{$d_doctor}',$userid)"); $this->sys_ok($result); exit; } function deletedoctor(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; // sipe nambah ambil userid $userid = $this->sys_user["M_UserID"]; $query ="UPDATE m_doctor SET M_DoctorIsActive = 'N' WHERE M_DoctorID = '{$prm['M_DoctorID']}' "; //echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); //adi tambah log doctor $prm["M_DoctorM_UserID"] = $userid; $d_doctor = json_encode($prm); $this->db_onedev->query("call one_log.log_me('DOCTOR','DOCTOR_DELETE','{$d_doctor}',$userid)"); $this->sys_ok($result); exit; } function getaddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query =" SELECT m_doctoraddress.*, M_KelurahanName, M_DistrictID, M_DistrictName, M_CityID, M_CityName,Nat_JpaName, '' as action FROM m_doctoraddress JOIN m_kelurahan ON M_DoctorAddressM_KelurahanID = M_KelurahanID JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID JOIN m_city ON M_DistrictM_CityID = M_CityID left join nat_jpa on M_DoctorAddressNat_JpaID = Nat_JpaID WHERE M_DoctorAddressIsActive = 'Y' AND M_DoctorAddressM_DoctorID = ? "; //echo $query; $rows = $this->db_onedev->query($query,array($prm['id']))->result_array(); if($rows){ foreach($rows as $k => $v){ $rows[$k]['action'] = 'delete'; $rows[$k]['action'] .= 'edit'; } } $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function savenewaddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $prm = $this->sys_input; $count_addrs = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = '{$prm['M_DoctorAddressM_DoctorID']}' AND M_DoctorAddressIsActive = 'Y'")->row()->countx; //echo $this->db_onedev->last_query(); if($count_addrs == 0){ $prm['M_DoctorAddressNote'] = 'Utama'; } else{ $count_addrs_utama = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = '{$prm['M_DoctorAddressM_DoctorID']}' AND M_DoctorAddressNote = 'Utama' AND M_DoctorAddressIsActive = 'Y'")->row()->countx; if($count_addrs_utama > 0 && strtolower($prm['M_DoctorAddressNote']) == 'utama'){ $rx = date('YmdHis'); $prm['M_DoctorAddressNote'] = 'Utama_'.$rx; } } $query ="INSERT INTO m_doctoraddress ( M_DoctorAddressM_DoctorID, M_DoctorAddressNote, M_DoctorAddressDescription, M_DoctorAddressM_KelurahanID, M_DoctorAddressNat_JpaID, M_DoctorAddressCreated ) VALUES( '{$prm['M_DoctorAddressM_DoctorID']}', '{$prm['M_DoctorAddressNote']}', '{$prm['M_DoctorAddressDescription']}', '{$prm['M_DoctorAddressM_KelurahanID']}', '{$prm['M_DoctorAddressNat_JpaID']}', NOW() ) "; //echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); //adi tambah log doctor $prm["M_DoctorM_UserID"] = $userid; $d_doctor = json_encode($prm); $this->db_onedev->query("call one_log.log_me('DOCTOR','DOCTOR_ADDR','{$d_doctor}',$userid)"); $this->sys_ok($result); exit; } function saveeditaddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $prm = $this->sys_input; $query ="UPDATE m_doctoraddress SET M_DoctorAddressM_DoctorID = '{$prm['M_DoctorAddressM_DoctorID']}', M_DoctorAddressNote = '{$prm['M_DoctorAddressNote']}', M_DoctorAddressDescription = '{$prm['M_DoctorAddressDescription']}', M_DoctorAddressM_KelurahanID = '{$prm['M_DoctorAddressM_KelurahanID']}', M_DoctorAddressNat_JpaID = '{$prm['M_DoctorAddressNat_JpaID']}' WHERE M_DoctorAddressID = '{$prm['M_DoctorAddressID']}' "; // echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); //adi tambah log doctor $prm["M_DoctorM_UserID"] = $userid; $d_doctor = json_encode($prm); $this->db_onedev->query("call one_log.log_me('DOCTOR','DOCTOR_ADDR_EDIT','{$d_doctor}',$userid)"); $this->sys_ok($result); exit; } function deleteaddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $prm = $this->sys_input; $query ="UPDATE m_doctoraddress SET M_DoctorAddressIsActive = 'N' WHERE M_DoctorAddressID = '{$prm['M_DoctorAddressID']}' "; //echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); //adi tambah log doctor $prm["M_DoctorM_UserID"] = $userid; $d_doctor = json_encode($prm); $this->db_onedev->query("call one_log.log_me('DOCTOR','DOCTOR_ADDR_DELETE','{$d_doctor}',$userid)"); $this->sys_ok($result); exit; } }