313 lines
12 KiB
PHP
313 lines
12 KiB
PHP
<?php
|
|
class Wa extends MY_Controller
|
|
{
|
|
function __construct() {
|
|
parent::__construct();
|
|
$this->db = $this->load->database("onedev", true);
|
|
}
|
|
function index() {
|
|
$this->cek(true);
|
|
}
|
|
function get_pdf($id,$noreg,$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'
|
|
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,array($id));
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$ts = "&ts=" . date("Ymdhis");
|
|
foreach($rows as $r) {
|
|
$name = $r["Group_ResultName"];
|
|
$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[] = array(
|
|
"name" => $name,
|
|
"groupID" => $gid,
|
|
"fname" => $noreg . "-" . $pname . "-" . $name . ".pdf",
|
|
"url" => $report);
|
|
}else{
|
|
$result[] = array(
|
|
"name" => $name . "*". $temail ."*",
|
|
"fname" => "File tidak ditemukan",
|
|
"url" => "");
|
|
}
|
|
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
function clean_up_message($msg) {
|
|
$msg = str_replace("=","\=",$msg);
|
|
$msg = str_replace("-","\-",$msg);
|
|
$msg = str_replace("(","\(",$msg);
|
|
$msg = str_replace(")","\)",$msg);
|
|
$msg = str_replace(".","\.",$msg);
|
|
$msg = str_replace("[","\[",$msg);
|
|
$msg = str_replace("]","\]",$msg);
|
|
$msg = str_replace("|","\|",$msg);
|
|
$msg = str_replace("_","\_",$msg);
|
|
return $msg;
|
|
}
|
|
function cek_terkirim($d) {
|
|
foreach($d as $x ) {
|
|
$json = json_decode($x["Tx_WhatsappJson"],true);
|
|
$rst = array();
|
|
foreach($json as $j) {
|
|
$doc = $j["data"]["message"];
|
|
$ext = pathinfo($doc, PATHINFO_EXTENSION);
|
|
if ($ext == "pdf" ) {
|
|
$status = "";
|
|
if($x["Tx_WhatsappDetailIsSend"] == "Y" ) $status = "K";
|
|
if($x["Tx_WhatsappDetailIsReceive"] == "Y" ) $status .= "T";
|
|
if($x["Tx_WhatsappDetailIsRead"] == "Y" ) $status = "B";
|
|
$rst[$doc] = array("status" => $status, "message" => $j["message"] );
|
|
}
|
|
}
|
|
}
|
|
return $rst;
|
|
}
|
|
function cek($debug=false) {
|
|
echo "<pre>";
|
|
$sql = "select * from m_branch where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
|
$branchName = "No Branch";
|
|
$qry = $this->db->query($sql);
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
$branchName = $rows[0]["M_BranchName"];
|
|
} else {
|
|
print_r($this->db->error());
|
|
}
|
|
$date = $this->sys_input["date"];
|
|
if ($date == "" ) $date = date("Y-m-d");
|
|
|
|
$sql = "select group_concat(distinct T_OrderHeaderID) xids
|
|
from
|
|
t_orderheader
|
|
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID and T_OrderHeaderAddOnIsActive = 'Y'
|
|
join result_processtooffice on Result_ProcessToOfficeT_OrderHeaderID= T_OrderHeaderID
|
|
join t_orderdelivery on T_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID
|
|
and T_OrderHeaderIsActive = 'Y'
|
|
and (
|
|
date(T_OrderHeaderDate) = ?
|
|
or date(T_OrderHeaderDate + interval 1 day ) = ?
|
|
or date(T_OrderDeliveryCreated) = ?
|
|
or date(T_OrderDeliveryCreated + interval 1 day ) = ?
|
|
or date(Result_ProcessToOfficeCreated) = ?
|
|
)
|
|
and T_OrderHeaderDate > '2020-09-27'
|
|
and T_OrderDeliveryIsActive = 'Y'
|
|
and T_OrderDeliveryM_DeliveryTypeID in ( 4 )
|
|
";
|
|
$ids = "";
|
|
$query = $this->db->query($sql,array($date,$date,$date,$date,$date));
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
if (count($rows) > 0 ) $ids = $rows[0]["xids"];
|
|
} else {
|
|
print_r($this->db->error());
|
|
}
|
|
if ($ids == "") {
|
|
echo "Zero";
|
|
exit;
|
|
}
|
|
// populate tx_whatsapp status
|
|
$sql = "select *
|
|
from tx_whatsapp
|
|
join tx_whatsappdetail on Tx_WhatsappID = Tx_WhatsappDetailTx_WhatsappID
|
|
where Tx_WhatsappT_OrderHeaderID in ( $ids )
|
|
and Tx_WhatsappIsSent = 'Y'";
|
|
$query = $this->db->query($sql);
|
|
$tx_whatsapp = array();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
foreach($rows as $r) {
|
|
$headerID = $r["Tx_WhatsappT_OrderHeaderID"];
|
|
$groupResultID = $r["Tx_WhatsappGroup_ResultID"];
|
|
$deliveryID = $r["Tx_WhatsappM_DeliveryID"];
|
|
$idx = "$headerID-$deliveryID-$groupResultID";
|
|
if (! isset($tx_whatsapp[$idx]) ) $tx_whatsapp[$idx] = array();
|
|
$tx_whatsapp[$idx][] = $r;
|
|
}
|
|
|
|
} else {
|
|
echo json_encode( array("status"=> "ERR" ,
|
|
"message" => print_r($this->db->error(),true)
|
|
));
|
|
}
|
|
$sql = "select distinct T_OrderHeaderID, T_OrderHeaderLabNumber, T_OrderHeaderLabNumberExt,
|
|
M_DeliveryID, M_DeliveryName, M_DeliverySource, T_OrderDeliveryDestination,
|
|
T_OrderHeaderDate, fn_get_patient_atribute(T_OrderHeaderM_PatientID) PatientName,
|
|
fn_global_doctor_name(T_OrderHeaderSenderM_DoctorID) DoctorName,
|
|
IF(M_MouIsBill = 'Y','Y',ifnull(Last_StatusPaymentIsLunas,'N')) IsLunas,
|
|
date_format(T_OrderHeaderDate,'%d %M %Y') xdate,
|
|
fn_global_doctor_name(T_OrderHeaderSenderM_DoctorID) DoctorName,
|
|
M_DoctorHP,
|
|
T_OrderHeaderAddOnReadyPrint, Result_ProcessToOfficeStatus
|
|
from t_orderheader
|
|
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID
|
|
join m_doctor on T_OrderHeaderSenderM_DoctorID = M_DoctorID
|
|
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
|
|
join t_orderdelivery on T_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID and T_OrderDeliveryIsActive = 'Y'
|
|
and T_OrderDeliveryM_DeliveryTypeID in ( 4 )
|
|
join result_processtooffice on Result_ProcessToOfficeT_OrderHeaderID= T_OrderHeaderID
|
|
and Result_ProcessToOfficeT_OrderDeliveryID = T_OrderDeliveryID
|
|
and Result_ProcessToOfficeStatus = 'S' and Result_ProcessToOfficeIsActive ='Y'
|
|
join m_delivery on T_OrderDeliveryM_DeliveryID = M_DeliveryID
|
|
left join last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
|
|
where T_OrderHeaderID in ( $ids )
|
|
order by IsLunas desc, T_OrderHeaderID
|
|
limit 0,2000";
|
|
$query = $this->db->query($sql);
|
|
$ready_print =0;
|
|
$ready_report=0;
|
|
$queue = 0;
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$list_result = array();
|
|
$counter_list = 0;
|
|
$terkirim = array();
|
|
foreach($rows as $idx => $r) {
|
|
$headerID = $r["T_OrderHeaderID"];
|
|
$deliveryID = $r["M_DeliveryID"];
|
|
$j_pasien = json_decode($r["PatientName"],true);
|
|
$xname = $j_pasien["patient_fullname"];
|
|
$x_reports = $this->get_pdf($r["T_OrderHeaderID"], $r["T_OrderHeaderLabNumber"], $xname);
|
|
$reports = array();
|
|
foreach($x_reports as $xr) {
|
|
$groupResultID = $xr["groupID"];
|
|
$wa_idx = "$headerID-$deliveryID-$groupResultID";
|
|
if (isset($tx_whatsapp[$wa_idx])) {
|
|
$terkirim[$headerID] = array(
|
|
"nolab" => $r["T_OrderHeaderLabNumber"],
|
|
"date" => substr($r["T_OrderHeaderDate"],0,10),
|
|
"hp" => $r["T_OrderDeliveryDestination"],
|
|
"pasien" => $xname,
|
|
"status" => $this->cek_terkirim($tx_whatsapp[$wa_idx])
|
|
);
|
|
continue;
|
|
}
|
|
if ($groupResultID == 1 && $r["T_OrderHeaderAddOnReadyPrint"] == "N" ) {
|
|
$ready_print++;
|
|
continue;
|
|
}
|
|
$xr["Result_ProcessToOfficeStatus"] = $r["Result_ProcessToOfficeStatus"];
|
|
$reports[] = $xr;
|
|
}
|
|
if ( count($reports) == 0 ) {
|
|
unset($rows[$idx]);
|
|
$ready_report++;
|
|
continue;
|
|
}
|
|
$queue++;
|
|
}
|
|
$total_issue = 0;
|
|
foreach($terkirim as $k) {
|
|
$is_false = false;
|
|
foreach($k["status"] as $doc => $s) {
|
|
if ($s["status"] == "" ) $is_false = true;
|
|
}
|
|
if ($is_false) {
|
|
$total_issue++;
|
|
echo "{$k['date']} {$k['nolab']} : [{$k['hp']}] : {$k['pasien']} => ";
|
|
foreach($k["status"] as $doc => $s) {
|
|
echo "{$doc} : {$s['status']}, ";
|
|
}
|
|
echo "\n";
|
|
}
|
|
}
|
|
echo "\nTotal terkirim ke Provider , belum terima notifikasi KTB : $total_issue\n";
|
|
exit;
|
|
} else {
|
|
echo "Err: " . print_r($this->db->error(),true);
|
|
}
|
|
}
|
|
function print_chr($inp) {
|
|
for($i=0;$i<strlen($inp);$i++) {
|
|
$chr = substr($inp,$i,1);
|
|
echo "$i\t$chr => " . ord($chr) . "\n";
|
|
}
|
|
}
|
|
function sasone($msg) {
|
|
$url = "http://bandungraya.aplikasi.web.id/one-api/tgram/xone/sasone";
|
|
$data = json_encode( array("text" => $msg ));
|
|
$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_HTTPHEADER, array(
|
|
'Content-Type: application/json',
|
|
'Content-Length: ' . strlen($data))
|
|
);
|
|
$result = curl_exec($ch);
|
|
echo $result;
|
|
}
|
|
}
|