> Processing $b for $date \n";
$url = "http://$b/one-api/tools/thorax_etl/run/$date";
echo "\t$url \n";
$resp = $this->get($url);
if ($resp["status"] == "OK") {
foreach ($resp["data"] as $d) {
}
}
exit;
}
}
function get($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
$result = curl_exec($ch);
if (curl_errno($ch) > 0) {
return [
"status" => "ERR",
"message" => curl_error($ch),
];
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode != 200) {
return [
"status" => "ERR",
"message" => "Http Response : $httpCode",
];
}
$j_result = json_decode($result, true);
if (!$j_result) {
return [
"status" => "ERR",
"message" => "JSON invalid: $result",
];
}
return $j_result;
}
function post($url, $data)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/octet-stream",
"Content-Length: " . strlen($data),
]);
$result = curl_exec($ch);
if (curl_errno($ch) > 0) {
return [
"status" => "ERR",
"message" => curl_error($ch),
];
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode != 200) {
return [
"status" => "ERR",
"message" => "Http Response : $httpCode",
];
}
$j_result = json_decode($result, true);
if (!$j_result) {
return [
"status" => "ERR",
"message" => "JSON invalid: $result",
];
}
return $j_result;
}
function image()
{
$prm = $this->sys_input;
header("Content-Type: image/jpeg");
//echo "exists : " . file_exists($prm["image"]);
echo file_get_contents($prm["image"]);
}
function run($date = "", $edate = "")
{
if ($date == "") {
$date = date("Y-m-d 00:00:00");
$edate = date("Y-m-d 23:59:59");
} else {
$org_date = $date;
$date .= " 00:00:00";
if ($edate == "") {
$edate = $org_date . " 23:59:59";
} else {
$edate = $edate . " 23:59:59";
}
}
$sql = "select M_BranchCode, M_BranchName, M_BranchID,
T_OrderHeaderDate, T_OrderHeaderLabNumber,
T_OrderHeaderLabNumberExt,
T_OrderDetailT_TestName,
So_ResultEntrySo_TemplateName,
group_concat(So_ResultEntryCategoryResultValue) Result
from t_orderheader
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderHeaderDate >= ?
and T_OrderHeaderDate < ?
and T_OrderDetailIsActive = 'Y' and T_OrderHeaderIsActive = 'Y'
join t_test on T_OrderDetailT_TestID = T_TestID
and T_TestNat_GroupID = 3 and T_TestIsResult = 'Y' and T_TestName like '%Thorax%'
join so_resultentry on T_OrderDetailID = So_ResultEntryT_OrderDetailID
join so_resultentry_category_result on So_ResultEntryID = So_ResultEntryCategoryResultSo_ResultEntryID
join m_branch on M_Branc IsActive = 'Y' and M_BranchIsDefault = 'Y'
group by So_ResultEntryID
";
$qry = $this->db->query($sql, [$date, $edate]);
$this->check_error($qry, "get order");
$rows = $qry->result_array();
foreach ($rows as $idx => $r) {
$xday = date("Ymd", strtotime($r["T_OrderHeaderDate"]));
$ext = $r["T_OrderHeaderLabNumberExt"];
$a_file = [];
foreach (glob("/data-pacs/$xday/$ext-*.jpg") as $fname) {
$a_file[] = $fname;
}
$rows[$idx]["files"] = $a_file;
}
echo json_encode(["status" => "OK", "data" => $rows]);
}
function check_error($qry, $stage)
{
if (!$qry) {
echo json_encode([
"status" => "ERR",
"message" => $this->db->error(),
"sql" => $this->db->last_query()
]);
exit;
}
}
function print_table_style()
{
echo "
";
}
public function print_table_one_column($rows)
{
$rst = "
";
foreach ($rows as $r) {
$rst .= "";
$rst .= "| " . $r . " | ";
$rst .= "
";
}
$rst .= "
";
return $rst;
}
public function print_table($rows, $keys)
{
echo "";
echo "";
foreach ($keys as $k) {
echo "| $k | ";
}
echo "
\n";
foreach ($rows as $r) {
echo "";
foreach ($keys as $k) {
echo "| " . $r[$k] . " | ";
}
echo "
";
}
echo "
";
}
}