From 77a595eba434c0373eb91d02c4c203c9cfac8bf4 Mon Sep 17 00:00:00 2001 From: "sas.fajri" Date: Thu, 11 Jun 2026 14:37:39 +0700 Subject: [PATCH] FHM09062601IBL - refactor get_vaccines: autocomplete jenis vaksin by order MOU, pisahkan list_order_vaccines Co-Authored-By: Claude Sonnet 4.6 --- .../klinik/doctorv5/Anamnesedoctor.php | 62 ++++++++++++++----- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/application/controllers/klinik/doctorv5/Anamnesedoctor.php b/application/controllers/klinik/doctorv5/Anamnesedoctor.php index f3ce1736..c69cf616 100644 --- a/application/controllers/klinik/doctorv5/Anamnesedoctor.php +++ b/application/controllers/klinik/doctorv5/Anamnesedoctor.php @@ -3119,25 +3119,11 @@ function get_data_order_anamnesis($orderID){ // ─── Vaksin ──────────────────────────────────────────────────────────────── + // Master statis: injection_sites, routes, petugas (dipanggil sekali saat form dibuka) 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 @@ -3176,10 +3162,54 @@ function get_data_order_anamnesis($orderID){ exit; } + // Autocomplete jenis vaksin: filter by MOU order, param: orderid + search function get_vaccines() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } + $prm = $this->sys_input; + $orderid = intval($prm['orderid'] ?? 0); + $search = trim($prm['search'] ?? ''); + + if (!$orderid) { $this->sys_error("orderid required"); exit; } + + // Ambil MOU dari order + $order_row = $this->db_oneklinik->query( + "SELECT orderM_MouID FROM one_klinik.`order` WHERE orderID = ? LIMIT 1", + [$orderid] + )->row_array(); + + if (!$order_row || !$order_row['orderM_MouID']) { + $this->sys_ok(['records' => []]); + exit; + } + + $mou_id = intval($order_row['orderM_MouID']); + $search_esc = $this->db_onedev->escape_str($search); + + $sql = "SELECT DISTINCT + spm.T_TestID as id, + t.T_TestSasCode as code, + t.T_TestName as name + FROM one_lab.ss_price_mou spm + JOIN one_lab.t_test t ON spm.T_TestID = t.T_TestID AND t.T_TestIsActive = 'Y' + WHERE spm.Ss_PriceMouM_MouID = {$mou_id} + AND t.T_TestName LIKE CONCAT('%', '{$search_esc}', '%') + ORDER BY t.T_TestName + LIMIT 50"; + + $q = $this->db_onedev->query($sql); + if (!$q) { $this->sys_error_db("get jenis vaksin", $this->db_onedev); exit; } + + $this->sys_ok(['records' => $q->result_array()]); + exit; + } + + // List vaksin yang sudah tersimpan untuk satu order + function list_order_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; } @@ -3205,7 +3235,7 @@ function get_data_order_anamnesis($orderID){ 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; } + if (!$q) { $this->sys_error_db("list order_vaccine", $this->db_oneklinik); exit; } $this->sys_ok(['records' => $q->result_array()]); exit;