Files
BE_IBL/application/controllers/tools/regonline/xxx
2026-04-15 15:23:57 +07:00

154 lines
5.0 KiB
Plaintext

public function status_report_hs($debug = "N")
{
echo "{$this->now()} Start Report Status HS\n";
$sql = "select
M_BranchCode
from m_branch
where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
$qry = $this->db->query($sql);
if (!$qry) {
echo "{$this->now()} ERR : {$this->db->error()["message"]}\n";
exit();
}
$rows = $qry->result_array();
if (count($rows) == 0) {
echo "{$this->now()} ERR Update Status - Branch : {$this->db->error()["message"]}\n";
exit();
}
$branchCode = $rows[0]["M_BranchCode"];
$or_debug = "";
$sql = "select T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt, T_OrderHeaderID,
T_OrderOldID T_OnlineOrderT_OrderID,
T_OrderT_TransactionOldID T_OnlineTxOrgID,
max(Result_ProcessToOfficeLastUpdated) maxDate ,
max(T_OrderHeaderAddonReadyPrintDate) maxPrintDate,
T_OrderHeaderM_PatientID
from one_hs.t_order
join t_orderheader
on T_OrderT_OrderHeaderID = T_OrderHeaderID
and date(T_OrderHeaderDate) >= '2021-12-13'
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID
join pb_upload
on pbUploadCode = 'RESULT'
join result_processtooffice on
Result_ProcessToOfficeT_OrderHeaderID = T_OrderHeaderID
and Result_ProcessToOfficeIsActive = 'Y'
and (
Result_ProcessToOfficeLastUpdated > pbUploadExecuted
-- or
-- T_OrderHeaderAddonReadyPrintDate > pbUploadExecuted
)
group by T_OrderHeaderID
";
$qry = $this->db->query($sql);
if (!$qry) {
echo "{$this->now()} ERR Status Report : {$this->db->error()["message"]} | {$this->db->last_query()}\n";
exit();
}
$rows = $qry->result_array();
$tot_row = count($rows);
if ($tot_row == 0) {
echo "{$this->now()} No Status Report HS : $tot_row \n";
return;
}
$s_patientID = "0";
foreach ($rows as $r) {
$s_patientID .= "," . $r["T_OrderHeaderM_PatientID"];
}
//get patient
$sql = "
select M_PatientName,
M_PatientDOB,
M_PatientNoreg,
M_PatientM_SexID,
M_PatientJob,
M_PatientM_IdTypeID,
M_PatientIDNumber,
T_OnlineOrderT_OrderID
from m_patient
join t_onlineorder
on M_PatientID in ($s_patientID)
and T_OnlineOrderM_PatientID = M_PatientID
and T_OnlineOrderIsActive = 'Y'";
$qry = $this->db->query($sql);
if (!$qry) {
echo "{$this->now()} ERR Report : Patient HS : {$this->db->error()["message"]} | {$this->db->last_query()}\n";
exit();
}
$patients = $qry->result_array();
$status = [];
$counter = 0;
echo "{$this->now()} Upload Status Report HS : \n";
foreach ($rows as $r) {
$headerID = $r["T_OrderHeaderID"];
$reports = $this->get_report($headerID);
if ($reports == []) {
echo "\t\t" .
$r["T_OrderHeaderLabNumber"] .
" No Report Found\n";
continue;
}
$arr_reports = [];
$idx = 1;
foreach ($reports as $xr) {
if (trim($xr["url_rpt"]) == "-") {
echo "\t {$r['T_OrderHeaderLabNumber']} : {$xr['Group_ResultName']} => Kosong \n";
continue;
}
$rpt_url = "http://localhost/" . $xr["url_rpt"];
$fname =
$r["T_OnlineTxOrgID"] .
"_" .
$r["T_OnlineOrderT_OrderID"] .
"_" .
$xr["Group_ResultName"] .
"_" .
$r["T_OrderHeaderLabNumberExt"] .
".pdf";
$arr_reports[] = [
"name" => $xr["Group_ResultName"],
"branchCode" => $branchCode,
"fname" => $fname,
"content" => base64_encode(file_get_contents($rpt_url)),
];
$idx++;
echo "\t {$r['T_OrderHeaderLabNumber']} => $fname : $rpt_url\n";
}
$msg =
"Nomor Registrasi : " . $r["T_OrderHeaderLabNumberExt"] . "\n";
$msg .= "Sudah selesai.";
$status[] = [
"T_TxMessageT_TransactionID" => $r["T_OnlineTxOrgID"],
"T_TxMessageT_OrderID" => $r["T_OnlineOrderT_OrderID"],
"T_TxMessageNote" => $msg,
"reports" => $arr_reports,
"T_TxMessageCode" => "RESULT",
];
$counter++;
}
if (count($status) > 0) {
$url = $this->url . "status";
$param = ["status" => $status, "patients" => $patients];
$z_param = gzdeflate(json_encode($param), 9);
$resp = $this->post($url, $z_param);
if ($resp["status"] == "OK") {
echo "{$this->now()} Upload Status Report : $counter\n{$resp["message"]}\n";
foreach ($status["report"] as $r) {
echo "{$this->now()} => $fname \n";
}
} else {
echo "{$this->now()} ERR {$resp["message"]}\n";
}
} else {
echo "{$this->now()} Upload Status Report : $counter\n";
}
//update pb_upload
}