323 lines
14 KiB
PHP
323 lines
14 KiB
PHP
<?php
|
|
class Readytoinsert extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "Verify Doctor API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
}
|
|
|
|
public function getorder()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$date = $prm['date'];
|
|
$sql = "SELECT T_OrderHeaderID,
|
|
CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName,
|
|
JSON_UNQUOTE(JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID), '$.patient_fullname')) as M_PatientName,
|
|
T_OrderHeaderDate,
|
|
T_OrderHeaderLabNumber,
|
|
T_OrderHeaderLabNumberExt,
|
|
IF(T_EmailNonLabUrl IS NULL AND Group_ResultFlagNonLab = 'Y',' [Belum Pilih Format Hasil]','') temail,
|
|
IF(Group_ResultFlagPerTest = 'Y',T_OrderDetailT_TestID,Group_ResultID) as Group_ResultID,
|
|
GROUP_CONCAT(DISTINCT Group_ResultName SEPARATOR ' ,') as Group_ResultName,
|
|
IF(M_MouIsBill = 'Y','Sudah Lunas',if(ifnull(Last_StatusPaymentIsLunas,'N') = 'Y','Sudah Lunas','Belum Lunas')) as Last_StatusPaymentIsLunas,
|
|
IF(IF(Group_ResultFlagNonLab = 'Y','Y',T_OrderHeaderAddOnValidationDone) = 'N','Belum Selesai','Selesai') as validasi,
|
|
M_DeliveryID,
|
|
4 as M_DeliveryTypeID,
|
|
M_DeliveryName,
|
|
M_DeliverySource,
|
|
CASE
|
|
WHEN M_DeliverySource = 'PATIENT' THEN IF(T_OrderDeliveryDestination IS NULL OR T_OrderDeliveryDestination = '' OR T_OrderDeliveryDestination= 'null','-',T_OrderDeliveryDestination)
|
|
WHEN M_DeliverySource = 'DOCTOR' THEN IF(M_DoctorHP IS NULL OR M_DoctorHP = '' OR M_DoctorHP = 'null','-',M_DoctorHP)
|
|
END as
|
|
T_OrderDeliveryDestination,
|
|
CASE
|
|
WHEN M_DeliverySource = 'PATIENT' THEN IF(JSON_UNQUOTE(JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID), '$.M_PatientHP')) IS NULL OR JSON_UNQUOTE(JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID), '$.M_PatientHP')) = '' OR JSON_UNQUOTE(JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID), '$.M_PatientHP')) = 'null','---',JSON_UNQUOTE(JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID), '$.M_PatientHP')))
|
|
WHEN M_DeliverySource = 'DOCTOR' THEN IF(M_DoctorHP IS NULL OR M_DoctorHP = '' OR M_DoctorHP = 'null','---',M_DoctorHP)
|
|
END as hp,
|
|
IFNULL(Result_ProcessToOfficeStatus,'N') as Result_ProcessToOfficeStatus,
|
|
IF(IFNULL(Result_ProcessToOfficeStatus,'N') = 'N', 'Belum Serahkan Hasil','') as serahhasil,
|
|
T_OrderPromiseDateTime,
|
|
Result_ProcessToOfficeSendTime,
|
|
'' as urlreport
|
|
|
|
FROM t_orderheader
|
|
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
|
|
JOIN t_orderheaderaddon ON T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
|
|
join t_orderdelivery on T_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID and T_OrderDeliveryIsActive = 'Y' and T_OrderDeliveryM_DeliveryTypeID = 4
|
|
join m_delivery ON M_DeliveryID = T_OrderDeliveryM_DeliveryID
|
|
JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID
|
|
join last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailT_TestIsResult = 'Y'
|
|
join group_resultdetail on Group_ResultDetailT_TestID = T_OrderDetailT_TestID
|
|
and T_OrderDetailIsActive = 'Y' and Group_ResultDetailIsActive = 'Y'
|
|
and T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
|
join group_result on Group_ResultDetailGroup_ResultID = Group_ResultID
|
|
LEFT JOIN result_counter ON Result_CounterT_OrderHeaderID = T_OrderHeaderID AND Result_CounterGroup_ResultID = Group_ResultID AND Result_CounterM_DeliveryID = M_DeliveryID AND Result_CounterIsActive = 'Y'
|
|
LEFT JOIN t_email_nonlab ON T_EmailNonLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
|
T_EmailNonLabType LIKE CONCAT('%',REPLACE(Group_ResultName, 'Elektromedik', 'electromedis'),'%')
|
|
JOIN t_orderpromise ON T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN result_processtooffice ON Result_ProcessToOfficeT_OrderPromiseID = T_OrderPromiseID AND
|
|
T_OrderDeliveryID = Result_ProcessToOfficeT_OrderDeliveryID AND Result_ProcessToOfficeStatus = 'S'
|
|
AND
|
|
(( Result_ProcessToOfficeGroup_ResultID = T_OrderDetailT_TestID AND Group_ResultFlagPerTest = 'Y')
|
|
or (Result_ProcessToOfficeGroup_ResultID = Group_ResultID AND Group_ResultFlagPerTest = 'N' ))
|
|
|
|
WHERE Result_CounterID IS NULL AND T_OrderHeaderIsActive = 'Y' AND date(Result_ProcessToOfficeSendTime) = '{$date}'
|
|
-- AND T_OrderHeaderID = 132122
|
|
-- AND (JSON_UNQUOTE(JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID), '$.patient_fullname')) LIKE CONCAT('%','{$nama}','%') OR T_OrderHeaderLabNumber LIKE CONCAT('%','{$nama}','%'))
|
|
GROUP BY IF(Group_ResultFlagPerTest = 'Y',T_OrderDetailT_TestID,Group_ResultID),M_DeliveryID,T_OrderHeaderID
|
|
ORDER BY T_OrderHeaderID DESC";
|
|
|
|
|
|
|
|
$query = $this->db_onedev->query($sql, $sql_param);
|
|
//echo $this->db_onedev->last_query();
|
|
$rows = $query->result_array();
|
|
if($rows){
|
|
foreach($rows as $k => $v){
|
|
$xname = $v["M_PatientName"];
|
|
$xname = $this->escape_fname($xname);
|
|
$x_reports = $this->get_pdf(
|
|
$v["T_OrderHeaderID"],
|
|
$v["T_OrderHeaderLabNumberExt"],
|
|
$xname,
|
|
$v["Group_ResultID"],
|
|
$v["T_OrderHeaderDate"]
|
|
);
|
|
$reports = [];
|
|
foreach ($x_reports as $xr) {
|
|
$groupResultID = $xr["groupID"];
|
|
$wa_idx = "$headerID-$deliveryID-$groupResultID";
|
|
if ($xr["url"] == "") {
|
|
//echo "Blank URL : $wa_idx\n";
|
|
continue;
|
|
}
|
|
if ($xr["url"] == "-") {
|
|
//echo "Blank URL : $wa_idx\n";
|
|
continue;
|
|
}
|
|
|
|
$xr["Result_ProcessToOfficeStatus"] =
|
|
$r["Result_ProcessToOfficeStatus"];
|
|
$reports[] = $xr;
|
|
}
|
|
$rows[$k]['urlreport'] = $xr["url"];
|
|
$arr = [
|
|
"Result_CounterT_OrderHeaderID" => $v["T_OrderHeaderID"],
|
|
"Result_CounterGroup_ResultID" => $v["Group_ResultID"],
|
|
"Result_CounterM_DeliveryID" => $v["M_DeliveryID"],
|
|
"Result_CounterDestination" => $v["T_OrderDeliveryDestination"],
|
|
"Result_CounterUrlReport" => $xr["url"]
|
|
];
|
|
$qry = $this->db->insert("result_counter", $arr);
|
|
$query_msg .= $this->db->last_query() . "\n";
|
|
if (!$qry) {
|
|
$db_msg .=
|
|
"insert result_counter | " .
|
|
$this->db->error()["message"] .
|
|
"|" .
|
|
$this->db->last_query() .
|
|
"\n";
|
|
$this->db->trans_rollback();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//$this->_add_address($rows);
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function get_pdf($id, $noreg, $pname, $groupResultID, $orderDate)
|
|
{
|
|
$orderDate = substr($orderDate, 0, 10);
|
|
$pname = str_replace(" ", "-", $pname);
|
|
$pname = str_replace(".", "_", $pname);
|
|
$pname = str_replace("\\'", "", $pname);
|
|
$pname = str_replace("(", "", $pname);
|
|
$pname = str_replace(")", "", $pname);
|
|
|
|
$sql = "select distinct
|
|
Group_ResultID,Group_ResultName,
|
|
Group_ResultFlagNonLab,IFNULL(T_EmailNonLabUrl,'-') EmailNonLabUrl,
|
|
IF(T_EmailNonLabUrl IS NULL AND Group_ResultFlagNonLab = 'Y',' [Belum Pilih Format Hasil]','') temail
|
|
from
|
|
t_orderdetail
|
|
join group_resultdetail
|
|
on Group_ResultDetailT_TestID = T_OrderDetailT_TestID
|
|
and T_OrderDetailIsActive = 'Y' and Group_ResultDetailIsActive = 'Y'
|
|
and T_OrderDetailT_OrderHeaderID = ?
|
|
join group_result
|
|
on Group_ResultDetailGroup_ResultID = Group_ResultID
|
|
and Group_ResultIsActive = 'Y'
|
|
and Group_ResultID = ?
|
|
LEFT JOIN t_email_nonlab ON T_EmailNonLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
|
T_EmailNonLabType LIKE CONCAT('%',REPLACE(Group_ResultName, 'Elektromedik', 'electromedis'),'%')";
|
|
$query = $this->db->query($sql, [$id, $groupResultID]);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$ts = "&ts=" . date("Ymdhis");
|
|
foreach ($rows as $r) {
|
|
$xname = $r["Group_ResultName"];
|
|
$name = $this->escape_fname($xname);
|
|
$gid = $r["Group_ResultID"];
|
|
$temail = $r["temail"];
|
|
$isnonlab = $r["Group_ResultFlagNonLab"];
|
|
$emailnonlaburl = str_replace(" ", "", $r["EmailNonLabUrl"]);
|
|
if (strpos($emailnonlaburl, "fisik") > 0) {
|
|
continue;
|
|
}
|
|
|
|
$report = "";
|
|
switch ($gid) {
|
|
case 1:
|
|
$report =
|
|
"/birt/frameset?__report=report/one/lab/rpt_test_email.rptdesign&__format=pdf&username=admin&PID=" .
|
|
$id .
|
|
$ts;
|
|
break;
|
|
case 2:
|
|
$report =
|
|
"/birt/frameset?__report=report/one/lab/rpt_hasil_papsmear_email.rptdesign&__format=pdf&username=admin&PID=" .
|
|
$id .
|
|
$ts;
|
|
break;
|
|
case 3:
|
|
$report =
|
|
"/birt/frameset?__report=report/one/lab/rpt_hasil_fna_email.rptdesign&__format=pdf&username=admin&PID=" .
|
|
$id .
|
|
$ts;
|
|
break;
|
|
case 4:
|
|
$report = $emailnonlaburl;
|
|
break;
|
|
case 5:
|
|
$report = $emailnonlaburl;
|
|
break;
|
|
case 6:
|
|
$report = $emailnonlaburl;
|
|
break;
|
|
case 7:
|
|
$report = $emailnonlaburl;
|
|
break;
|
|
case 8:
|
|
$report = $emailnonlaburl;
|
|
break;
|
|
case 9:
|
|
$report = $emailnonlaburl;
|
|
break;
|
|
case 10:
|
|
$report = $emailnonlaburl;
|
|
break;
|
|
case 11:
|
|
$report = $emailnonlaburl;
|
|
break;
|
|
case 12:
|
|
$report =
|
|
"/birt/frameset?__report=report/one/lab/rpt_hasil_lcprep_email.rptdesign&__format=pdf&username=admin&PID=" .
|
|
$id .
|
|
$ts;
|
|
break;
|
|
case 13:
|
|
$report =
|
|
"/birt/frameset?__report=report/one/lab/rpt_test_mikro_email.rptdesign&__format=pdf&username=admin&PID=" .
|
|
$id .
|
|
$ts;
|
|
break;
|
|
case 14:
|
|
$report =
|
|
"/birt/frameset?__report=report/one/lab/rpt_hasil_cytologi_email.rptdesign&__format=pdf&username=admin&PID=" .
|
|
$id .
|
|
$ts;
|
|
break;
|
|
case 15:
|
|
$report = $emailnonlaburl;
|
|
break;
|
|
case 16:
|
|
$report = $emailnonlaburl;
|
|
break;
|
|
case 17:
|
|
$report = $emailnonlaburl;
|
|
break;
|
|
}
|
|
if ($report != "-") {
|
|
$result[] = [
|
|
"name" => $name,
|
|
"groupID" => $gid,
|
|
"fname" => $noreg . "-" . $pname . "-" . $name . ".pdf",
|
|
"url" => $this->encode_url_param($report),
|
|
];
|
|
} else {
|
|
$result[] = [
|
|
"name" => $name . "*" . $temail . "*",
|
|
"fname" => "File tidak ditemukan",
|
|
"url" => "",
|
|
];
|
|
}
|
|
}
|
|
}
|
|
if (
|
|
$groupResultID == 4 &&
|
|
count($result) > 0 &&
|
|
$result[0]["url"] != ""
|
|
) {
|
|
$files = $this->get_files($noreg, $orderDate);
|
|
foreach ($files as $f) {
|
|
$result[] = [
|
|
"name" => basename($f),
|
|
"groupID" => 4,
|
|
"fname" => basename($f),
|
|
"url" => $f,
|
|
];
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
function get_files($noreg, $orderDate)
|
|
{
|
|
$orderDate = str_replace("-", "", $orderDate);
|
|
$prm_glob = "/data-pacs/$orderDate/$noreg*jpg";
|
|
$result = [];
|
|
foreach (glob($prm_glob) as $filename) {
|
|
$result[] = $filename;
|
|
}
|
|
return $result;
|
|
}
|
|
function escape_fname($xname)
|
|
{
|
|
$find = [" ", "&", '\r\n', '\n', "+", ","];
|
|
$xname = str_replace($find, "-", $xname);
|
|
|
|
//delete and replace rest of special chars
|
|
$find = ["/[^a-zA-Z0-9\-<>]/", "/[\-]+/", "/<[^>]*>/"];
|
|
$repl = ["", "-", ""];
|
|
$xname = preg_replace($find, $repl, $xname);
|
|
return $xname;
|
|
}
|
|
function encode_url_param($data)
|
|
{
|
|
$path = parse_url($data, PHP_URL_PATH);
|
|
$query = parse_url($data, PHP_URL_QUERY);
|
|
parse_str($query, $args);
|
|
$result = "";
|
|
foreach ($args as $k => $v) {
|
|
if ($result != "") {
|
|
$result .= "&";
|
|
}
|
|
$result .= $k . "=" . urlencode($v);
|
|
}
|
|
$result = $path . "?$result";
|
|
return $result;
|
|
}
|
|
}
|