From b653f0e9871438b3ead36b0302f4176d0aad0461 Mon Sep 17 00:00:00 2001 From: "sas.fajri" Date: Fri, 12 Jun 2026 15:52:43 +0700 Subject: [PATCH] FHM09062601IBL - move anamnesis visit info to php --- .../klinik/doctorv5/Anamnesedoctor.php | 59 ++++++++++++++++--- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/application/controllers/klinik/doctorv5/Anamnesedoctor.php b/application/controllers/klinik/doctorv5/Anamnesedoctor.php index 082b21e0..27e8f289 100644 --- a/application/controllers/klinik/doctorv5/Anamnesedoctor.php +++ b/application/controllers/klinik/doctorv5/Anamnesedoctor.php @@ -127,20 +127,63 @@ class Anamnesedoctor extends MY_Controller $rows[$k]['M_PatientAddress'] = $rows[$k]['M_PatientAddressDescription']; } - $info = $this->db_onedev->query("SELECT fn_fo_patient_visit(?) info", [$v['M_PatientID']])->row(); - $rows[$k]['info'] = json_decode($info->info); - } + $rows[$k]['info'] = $this->build_patient_visit_info($v['M_PatientID'], $rows[$k]['M_PatientDOB']); + } $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() + } + } + + protected function build_patient_visit_info($patient_id, $patient_dob) + { + $visit = 1; + $birthday = 'N'; + + $visit_query = $this->db_onedev->query( + "SELECT COUNT(DISTINCT T_OrderHeaderID) AS n + FROM t_orderheader + JOIN t_orderdetail ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_OrderDetailIsActive = 'Y' + WHERE T_OrderHeaderIsActive = 'Y' + AND T_OrderHeaderM_PatientID = ?", + [$patient_id] + ); + + if ($visit_query) { + $visit_row = $visit_query->row_array(); + $visit += (int) ($visit_row['n'] ?? 0); + } + + $init_visit_query = $this->db_onedev->query( + "SELECT M_PatientInitialVisit + FROM m_patient + WHERE M_PatientID = ?", + [$patient_id] + ); + + if ($init_visit_query) { + $init_visit_row = $init_visit_query->row_array(); + if (!empty($init_visit_row['M_PatientInitialVisit'])) { + $visit += (int) $init_visit_row['M_PatientInitialVisit']; + } + } + + $dob_time = empty($patient_dob) ? false : strtotime($patient_dob); + if ($dob_time !== false) { + $birthday = date('m-d', $dob_time) === date('m-d') ? 'Y' : 'N'; + } + + return json_decode(json_encode([ + 'visit' => $visit, + 'birthday' => $birthday, + ])); + } + + + function get_data() { if (!$this->isLogin) { $this->sys_error("Invalid Token");