From 8cb59caa8e9b0315234c04eaee1159b9a9297770 Mon Sep 17 00:00:00 2001 From: padmanto Date: Mon, 17 Aug 2026 05:25:31 +0700 Subject: [PATCH] ss_gw.php: add clinic-diagnose cmd (T_OrderHeaderNote per clinic order) - start_date/end_date default to today, ids optional intersect - service <> 1 filter via EXISTS on t_orderdetail/t_testgroup --- ss_gw.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/ss_gw.php b/ss_gw.php index bc862b9..27bfbdc 100644 --- a/ss_gw.php +++ b/ss_gw.php @@ -118,6 +118,44 @@ if ($p["cmd"] == "clinic-service_req") { $dbh->jsonReply($resp, $dbh->info()); exit; } +if ($p["cmd"] == "clinic-diagnose") { + $resp = $dbh->connect(); + $dbh->exit_if_error($resp[0], $resp[1]); + $ids = isset($p["ids"]) ? implode(",", $p["ids"]) : ""; + $start_date = isset($p["start_date"]) ? $p["start_date"] : ""; + $end_date = isset($p["end_date"]) ? $p["end_date"] : ""; + if ($start_date == "") { + $start_date = date("Y-m-d"); + } + if ($end_date == "") { + $end_date = $start_date; + } + $params = [$start_date . " 00:00:00", $end_date . " 23:59:59"]; + $where_ids = ""; + if ($ids != "") { + $where_ids = " and T_OrderHeaderID in ($ids) "; + } + $sql = "select + T_OrderHeaderID, + T_OrderHeaderNote, + T_OrderHeaderDate + from t_orderheader + where T_OrderHeaderIsActive = 'Y' + and T_OrderHeaderDate >= ? and T_OrderHeaderDate <= ? + $where_ids + and exists (select 1 + from t_orderdetail d + join t_test tt on d.T_OrderDetailT_TestID = tt.T_TestID + and tt.T_TestIsActive = 'Y' + join t_testgroup g on tt.T_TestT_TestGroupID = g.T_TestGroupID + and g.T_TestGroupT_ServiceID <> 1 and g.T_TestGroupIsActive = 'Y' + where d.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID + and d.T_OrderDetailIsActive = 'Y')"; + $resp = $dbh->query($sql, $params); + $dbh->exit_if_error($resp[0], $resp[1]); + $dbh->jsonReply($resp, $dbh->info()); + exit; +} if ($p["cmd"] == "clinic-encounter") { $resp = $dbh->connect();