ss_gw.php: add encounter-v2, clinic-encounter, clinic-encounter-v2 cmds

Adds the encounter-v2 / clinic-encounter / clinic-encounter-v2 endpoints and
get_clinic_encounter() helper that were deployed to all branches but never
committed.
This commit is contained in:
2026-08-14 12:31:06 +07:00
parent d62954ab50
commit a07a704394

155
ss_gw.php
View File

@@ -64,6 +64,114 @@ if ($p["cmd"] == "service_req") {
$dbh->jsonReply($resp, $dbh->info());
exit;
}
if ($p["cmd"] == "clinic-encounter") {
$resp = $dbh->connect();
$dbh->exit_if_error($resp[0], $resp[1]);
$sql = "select
order.orderID, order.orderCreated orderDate,
order.orderM_DoctorID, order.orderM_PatientID,
order.orderNumbering,
m_patient.M_PatientNIK, m_patient.M_PatientName,
a_doctor.A_DoctorName, a_doctor.A_DoctorID, NIK A_DoctorNIK
from one_clinic.order
join m_patient on
order.orderDate >=? and
order.orderDate < ?
and order.orderM_PatientID = m_patient.M_PatientID
and order.orderIsActive = 'Y'
left join a_doctor on orderM_DoctorID = a_doctor.A_DoctorID";
$date = $p["date"];
if ($date == "") {
$date = date("Y-m-d");
}
$sdate = $date . " 00:00:00";
if ($p["edate"] != "") {
$edate = $p["edate"] . " 23:59:59";
} else {
$edate = $date . " 23:59:59";
}
$resp = $dbh->query($sql, [$sdate, $edate]);
$dbh->exit_if_error($resp[0], $resp[1]);
if (isset($p["sum"]) && $p["sum"] != "") {
$first = true;
$a_doctor = [];
foreach ($resp[1] as $d) {
if ($first) {
$edate = substr($edate, 0, 10);
echo "\nFrom $date to {$edate} :\n";
$first = false;
}
$name = $d["A_DoctorName"];
if (!isset($a_doctor[$name])) {
$a_doctor[$name] = 1;
} else {
$a_doctor[$name] += 1;
}
}
foreach ($a_doctor as $d => $count) {
echo "\t{$d} \t\t: $count\n";
}
exit;
}
$dbh->jsonReply($resp);
exit;
}
function get_clinic_encounter($sdate, $edate)
{
global $dbh;
$resp = $dbh->connect();
$dbh->exit_if_error($resp[0], $resp[1]);
$sql = "select distinct m_branch.M_BranchID, m_branch.M_BranchCode,
t_orderheader.T_OrderHeaderID orderID,
t_orderheader.T_OrderHeaderDate orderDate,
t_orderheader.T_OrderHeaderM_DoctorPJID orderM_DoctorID,
t_orderheader.T_OrderHeaderM_PatientID orderM_PatientID,
t_orderheader.T_OrderHeaderLabNumber orderNumbering,
m_patient.M_PatientNIK,
m_patient.M_PatientName,
m_doctor.M_DoctorID A_DoctorID,
m_doctor.M_DoctorName A_DoctorName,
t_orderheader.T_OrderHeaderReceivedSample ,
T_OrderHeaderUserID, M_UserUsername
from t_orderheader
join m_patient on
t_orderheader.T_OrderHeaderDate > ? and
t_orderheader.T_OrderHeaderDate < ?
and t_orderheader.T_OrderHeaderM_PatientID = m_patient.M_PatientID
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderHeaderIsActive = 'Y' and T_OrderDetailIsActive = 'Y'
join t_test on T_OrderDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testgroup on T_TestT_TestGroupID = T_TestGroupID
and T_TestGroupT_ServiceID <> 1
left join m_doctor on T_OrderHeaderM_DoctorPJID = m_doctor.M_DoctorID
left join m_user on T_OrderHeaderUserID = M_UserID
left join m_branch on m_branch.M_BranchIsDefault = 'Y' and m_branch.M_BranchIsActive = 'Y' ";
$resp = $dbh->query($sql, [$sdate, $edate]);
$dbh->exit_if_error($resp[0], $resp[1]);
return $resp;
}
if ($p["cmd"] == "clinic-encounter-v2") {
$date = $p["date"];
$edate = $p["edate"];
if ($date == "") {
$date = date("Y-m-d");
}
if ($edate == "") {
$edate = $date;
}
$sdate = $date . " 00:00:01";
$edate = $edate . " 23:59:59";
$resp = get_clinic_encounter($sdate, $edate);
$dbh->exit_if_error($resp[0], $resp[1]);
$dbh->jsonReply($resp);
exit;
}
if ($p["cmd"] == "encounter") {
$resp = $dbh->connect();
$dbh->exit_if_error($resp[0], $resp[1]);
@@ -72,13 +180,15 @@ if ($p["cmd"] == "encounter") {
t_orderheader.T_OrderHeaderM_DoctorPJID, t_orderheader.T_OrderHeaderM_PatientID,
t_orderheader.T_OrderHeaderLabNumber,
m_patient.M_PatientNIK, m_patient.M_PatientName,
m_doctor.M_DoctorName
m_doctor.M_DoctorName, t_orderheader.T_OrderHeaderReceivedSample,
T_OrderHeaderUserID, M_UserUsername
from t_orderheader
join m_patient on
t_orderheader.T_OrderHeaderDate > ? and
t_orderheader.T_OrderHeaderDate < ?
and t_orderheader.T_OrderHeaderM_PatientID = m_patient.M_PatientID
left join m_doctor on T_OrderHeaderM_DoctorPJID = m_doctor.M_DoctorID
left join m_user on T_OrderHeaderUserID = M_UserID
left join m_branch on m_branch.M_BranchIsDefault = 'Y' and m_branch.M_BranchIsActive = 'Y' ";
$date = $p["date"];
if ($date == "") {
@@ -91,6 +201,49 @@ if ($p["cmd"] == "encounter") {
$dbh->jsonReply($resp);
exit;
}
if ($p["cmd"] == "encounter-v2") {
$resp = $dbh->connect();
$dbh->exit_if_error($resp[0], $resp[1]);
$date = $p["date"];
if ($date == "") {
$date = date("Y-m-d");
}
$sdate = $date . " 00:00:01";
$edate = $date . " 23:59:59";
$cl_resp = get_clinic_encounter($sdate, $edate);
$dbh->exit_if_error($cl_resp[0], $cl_resp[1]);
$cl_arr = array_map(function ($r) {
return $r["orderID"];
}, $cl_resp[1]);
$cl_ids = implode(",", $cl_arr);
if ($cl_ids == "") {
$cl_ids = "0";
}
$sql = "select m_branch.M_BranchID, m_branch.M_BranchCode,
t_orderheader.T_OrderHeaderID, t_orderheader.T_OrderHeaderDate,
t_orderheader.T_OrderHeaderM_DoctorPJID, t_orderheader.T_OrderHeaderM_PatientID,
t_orderheader.T_OrderHeaderLabNumber,
m_patient.M_PatientNIK, m_patient.M_PatientName,
m_doctor.M_DoctorName, t_orderheader.T_OrderHeaderReceivedSample,
T_OrderHeaderUserID, M_UserUsername
from t_orderheader
join m_patient on
t_orderheader.T_OrderHeaderDate > ? and
t_orderheader.T_OrderHeaderDate < ?
and t_orderheader.T_OrderHeaderID not in ($cl_ids)
and t_orderheader.T_OrderHeaderM_PatientID = m_patient.M_PatientID
left join m_doctor on T_OrderHeaderM_DoctorPJID = m_doctor.M_DoctorID
left join m_user on T_OrderHeaderUserID = M_UserID
left join m_branch on m_branch.M_BranchIsDefault = 'Y' and m_branch.M_BranchIsActive = 'Y' ";
$resp = $dbh->query($sql, [$sdate, $edate]);
$dbh->exit_if_error($resp[0], $resp[1]);
$dbh->jsonReply($resp);
exit;
}
echo json_encode(["status" => "ERR", "message" => "[sys] cmd not found"]);