206 lines
5.4 KiB
PHP
206 lines
5.4 KiB
PHP
<?php
|
|
class Thorax_etl extends MY_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
function devone()
|
|
{
|
|
$branches = [
|
|
"riau", "toha", "pajajaran", "cimahi",
|
|
"aditya", "ngagel", "jemur", "parkus", "mulyo",
|
|
"matraman", "bonjer", "ragunan", "samanhudi"
|
|
];
|
|
$date = "2024-03-01";
|
|
foreach ($branches as $b) {
|
|
echo ">> 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 "
|
|
<style>
|
|
th, td {
|
|
padding: 15px;
|
|
text-align: left;
|
|
}
|
|
tr:nth-child(even) {background-color: #f2f2f2;}
|
|
table {
|
|
border: solid 1px ;
|
|
min-width:600px;
|
|
margin-left:auto;
|
|
margin-right:auto;
|
|
}
|
|
</style>
|
|
";
|
|
}
|
|
public function print_table_one_column($rows)
|
|
{
|
|
$rst = "<table>";
|
|
foreach ($rows as $r) {
|
|
$rst .= "<tr>";
|
|
$rst .= "<td>" . $r . "</td>";
|
|
$rst .= "</tr>";
|
|
}
|
|
$rst .= "</table>";
|
|
return $rst;
|
|
}
|
|
public function print_table($rows, $keys)
|
|
{
|
|
echo "<table>";
|
|
echo "<tr>";
|
|
foreach ($keys as $k) {
|
|
echo "<td>$k</td>";
|
|
}
|
|
echo "</tr>\n";
|
|
foreach ($rows as $r) {
|
|
echo "<tr>";
|
|
foreach ($keys as $k) {
|
|
echo "<td>" . $r[$k] . "</td>";
|
|
}
|
|
echo "</tr>";
|
|
}
|
|
echo "</table>";
|
|
}
|
|
}
|