diff --git a/application/controllers/klinik/doctorv5/Anamnesedoctor.php b/application/controllers/klinik/doctorv5/Anamnesedoctor.php index 5ba1633b..f3ce1736 100644 --- a/application/controllers/klinik/doctorv5/Anamnesedoctor.php +++ b/application/controllers/klinik/doctorv5/Anamnesedoctor.php @@ -3117,5 +3117,195 @@ function get_data_order_anamnesis($orderID){ return array('text'=>$doctor_text,'form'=>$doctor_form); } + // ─── Vaksin ──────────────────────────────────────────────────────────────── + + function get_vaccine_masters() + { + if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } + + $prm = $this->sys_input; + $search = trim($prm['search'] ?? ''); + + // Jenis vaksin dari one_lab.t_test + $search_esc = $this->db_onedev->escape_str($search); + $sql = "SELECT T_TestID as id, T_TestSasCode as code, T_TestName as name + FROM one_lab.t_test + WHERE T_TestIsActive = 'Y' + AND T_TestName LIKE CONCAT('%', '{$search_esc}', '%') + ORDER BY T_TestName + LIMIT 100"; + $q = $this->db_onedev->query($sql); + if (!$q) { $this->sys_error_db("get t_test vaccine", $this->db_onedev); exit; } + $result['jenis_vaksin'] = $q->result_array(); + + // Lokasi suntik + $q = $this->db_oneklinik->query( + "SELECT M_InjectionSiteCode as code, M_InjectionSiteName as name + FROM one_klinik.m_injection_site + WHERE M_InjectionSiteIsActive = 'Y' + ORDER BY M_InjectionSiteID" + ); + if (!$q) { $this->sys_error_db("get m_injection_site", $this->db_oneklinik); exit; } + $result['injection_sites'] = $q->result_array(); + + // Rute vaksin + $q = $this->db_oneklinik->query( + "SELECT M_RouteVaccineCode as code, M_RouteVaccineName as name + FROM one_klinik.m_route_vaccine + WHERE M_RouteVaccineIsActive = 'Y' + ORDER BY M_RouteVaccineID" + ); + if (!$q) { $this->sys_error_db("get m_route_vaccine", $this->db_oneklinik); exit; } + $result['routes'] = $q->result_array(); + + // Petugas penyuntik + $q = $this->db_onedev->query( + "SELECT M_DoctorID as id, + 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' + ORDER BY M_DoctorName" + ); + if (!$q) { $this->sys_error_db("get doctors", $this->db_onedev); exit; } + $result['petugas'] = $q->result_array(); + + $this->sys_ok($result); + exit; + } + + function get_vaccines() + { + if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } + + $prm = $this->sys_input; + $orderid = intval($prm['orderid'] ?? 0); + if (!$orderid) { $this->sys_error("orderid required"); exit; } + + $sql = "SELECT + ov.*, + t.T_TestName as jenis_vaksin_name, + t.T_TestSasCode as jenis_vaksin_code, + ins.M_InjectionSiteName as injection_site_name, + rv.M_RouteVaccineName as route_name, + CONCAT(IFNULL(d.M_DoctorPrefix,''), IFNULL(d.M_DoctorPrefix2,''), ' ', + d.M_DoctorName, ' ', + IFNULL(d.M_DoctorSufix,''), IFNULL(d.M_DoctorSufix2,''), IFNULL(d.M_DoctorSufix3,'')) as petugas_name + FROM one_klinik.order_vaccine ov + LEFT JOIN one_lab.t_test t ON ov.orderVaccineT_TestID = t.T_TestID + LEFT JOIN one_klinik.m_injection_site ins + ON ov.orderVaccineInjectionSiteCode = ins.M_InjectionSiteCode + LEFT JOIN one_klinik.m_route_vaccine rv + ON ov.orderVaccineRouteCode = rv.M_RouteVaccineCode + LEFT JOIN m_doctor d ON ov.orderVaccinePetugasM_DoctorID = d.M_DoctorID + WHERE ov.orderVaccineOrderID = ? + AND ov.orderVaccineIsActive = 'Y' + ORDER BY ov.orderVaccineCreated ASC"; + + $q = $this->db_oneklinik->query($sql, [$orderid]); + if (!$q) { $this->sys_error_db("get order_vaccine", $this->db_oneklinik); exit; } + + $this->sys_ok(['records' => $q->result_array()]); + exit; + } + + function save_vaccine() + { + if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } + + $prm = $this->sys_input; + $userID = $this->sys_user['M_UserID']; + + $orderid = intval($prm['orderid'] ?? 0); + $vaccine_id = intval($prm['vaccine_id'] ?? 0); // orderVaccineID; 0 = insert baru + $t_test_id = intval($prm['t_test_id'] ?? 0); + + if (!$orderid || !$t_test_id) { + $this->sys_error("orderid dan t_test_id wajib diisi"); + exit; + } + + $batch = trim($prm['batch_number'] ?? ''); + $expired = trim($prm['expired_date'] ?? ''); + $dosis = max(1, intval($prm['dosis'] ?? 1)); + $site_code = trim($prm['injection_site_code'] ?? ''); + $route_code = trim($prm['route_code'] ?? ''); + $petugas_id = isset($prm['petugas_id']) && $prm['petugas_id'] ? intval($prm['petugas_id']) : null; + $given_at = trim($prm['given_at'] ?? ''); + $next_date = trim($prm['next_date'] ?? ''); + $catatan = trim($prm['catatan'] ?? ''); + + $given_at_sql = ($given_at && strtotime($given_at)) ? date('Y-m-d H:i:s', strtotime($given_at)) : date('Y-m-d H:i:s'); + $expired_val = ($expired && strtotime($expired)) ? date('Y-m-d', strtotime($expired)) : null; + $next_date_val = ($next_date && strtotime($next_date)) ? date('Y-m-d', strtotime($next_date)) : null; + + if ($vaccine_id > 0) { + $ok = $this->db_oneklinik->query( + "UPDATE one_klinik.order_vaccine SET + orderVaccineT_TestID = ?, + orderVaccineBatchNumber = ?, + orderVaccineExpiredDate = ?, + orderVaccineDosis = ?, + orderVaccineInjectionSiteCode = ?, + orderVaccineRouteCode = ?, + orderVaccinePetugasM_DoctorID = ?, + orderVaccineGivenAt = ?, + orderVaccineNextDate = ?, + orderVaccineCatatan = ?, + orderVaccineUserID = ? + WHERE orderVaccineID = ? AND orderVaccineOrderID = ?", + [ + $t_test_id, $batch ?: null, $expired_val, $dosis, + $site_code ?: null, $route_code ?: null, $petugas_id, + $given_at_sql, $next_date_val, $catatan ?: null, + $userID, $vaccine_id, $orderid + ] + ); + } else { + $ok = $this->db_oneklinik->query( + "INSERT INTO one_klinik.order_vaccine + (orderVaccineOrderID, orderVaccineT_TestID, orderVaccineBatchNumber, + orderVaccineExpiredDate, orderVaccineDosis, orderVaccineInjectionSiteCode, + orderVaccineRouteCode, orderVaccinePetugasM_DoctorID, orderVaccineGivenAt, + orderVaccineNextDate, orderVaccineCatatan, orderVaccineUserID) + VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", + [ + $orderid, $t_test_id, $batch ?: null, $expired_val, $dosis, + $site_code ?: null, $route_code ?: null, $petugas_id, + $given_at_sql, $next_date_val, $catatan ?: null, $userID + ] + ); + $vaccine_id = $this->db_oneklinik->insert_id(); + } + + if (!$ok) { $this->sys_error_db("save order_vaccine", $this->db_oneklinik); exit; } + + $this->sys_ok(['orderVaccineID' => $vaccine_id]); + exit; + } + + function delete_vaccine() + { + if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } + + $prm = $this->sys_input; + $vaccine_id = intval($prm['orderVaccineID'] ?? 0); + $userID = $this->sys_user['M_UserID']; + + if (!$vaccine_id) { $this->sys_error("orderVaccineID required"); exit; } + + $ok = $this->db_oneklinik->query( + "UPDATE one_klinik.order_vaccine SET orderVaccineIsActive = 'N', orderVaccineUserID = ? + WHERE orderVaccineID = ?", + [$userID, $vaccine_id] + ); + if (!$ok) { $this->sys_error_db("delete order_vaccine", $this->db_oneklinik); exit; } + + $this->sys_ok(['msg' => 'deleted']); + exit; + } + } diff --git a/sql/manual_changes/2026-06-11-create-order-vaccine.sql b/sql/manual_changes/2026-06-11-create-order-vaccine.sql new file mode 100644 index 00000000..ab352bb2 --- /dev/null +++ b/sql/manual_changes/2026-06-11-create-order-vaccine.sql @@ -0,0 +1,22 @@ +-- Tabel pencatatan pemberian vaksin per kunjungan +CREATE TABLE `one_klinik`.`order_vaccine` ( + `orderVaccineID` int(11) NOT NULL AUTO_INCREMENT, + `orderVaccineOrderID` int(11) NOT NULL DEFAULT 0, + `orderVaccineT_TestID` int(11) NOT NULL DEFAULT 0 COMMENT 'FK one_lab.t_test - jenis vaksin', + `orderVaccineBatchNumber` varchar(50) DEFAULT NULL, + `orderVaccineExpiredDate` date DEFAULT NULL, + `orderVaccineDosis` tinyint(3) NOT NULL DEFAULT 1 COMMENT 'dosis ke-', + `orderVaccineInjectionSiteCode` varchar(30) DEFAULT NULL COMMENT 'FK m_injection_site.M_InjectionSiteCode', + `orderVaccineRouteCode` varchar(30) DEFAULT NULL COMMENT 'FK m_route_vaccine.M_RouteVaccineCode', + `orderVaccinePetugasM_DoctorID` int(11) DEFAULT NULL COMMENT 'petugas penyuntik', + `orderVaccineGivenAt` datetime NOT NULL DEFAULT current_timestamp() COMMENT 'tanggal & jam pemberian', + `orderVaccineNextDate` date DEFAULT NULL COMMENT 'tanggal vaksin selanjutnya', + `orderVaccineCatatan` text DEFAULT NULL, + `orderVaccineIsActive` char(1) NOT NULL DEFAULT 'Y', + `orderVaccineUserID` int(11) DEFAULT NULL, + `orderVaccineCreated` datetime NOT NULL DEFAULT current_timestamp(), + `orderVaccineLastUpdated` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`orderVaccineID`), + KEY `orderVaccineOrderID` (`orderVaccineOrderID`), + KEY `orderVaccineIsActive` (`orderVaccineIsActive`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;