db->query($sql, $prm); } else { $qry = $this->db->query($sql); } if (!$qry) { $msg = "Error Query : {$this->db->error()["message"]} | {$this->db->last_query()}\n"; return [false, $msg]; } $rows = $qry->result_array(); return [true, $rows]; } function get_one_row($sql, $prm) { list($status, $msg) = $this->get_rows($sql, $prm); if ($status !== true) { return [$status, $msg]; } if (count($msg) == 0) { return [false, "Record not found. | " . $msg]; } return [true, $msg[0]]; } public function print_table_style() { echo " "; } public function print_table($rows, $keys) { echo ""; echo ""; foreach ($keys as $k) { echo ""; } echo "\n"; foreach ($rows as $r) { echo ""; foreach ($keys as $k) { echo ""; } echo ""; } echo "
$k
" . $r[$k] . "
"; } function __construct() { parent::__construct(); $this->resp = ["status" => "ERR", "message" => "Unknown error"]; $this->branchID = 0; $this->branchCode = ""; $this->host = "http://localhost"; $this->debug = false; } 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 check($nolab) { $sql = "select T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,T_OrderHeaderLabNumberExt,T_OrderHeaderIsActive from t_orderheader where T_OrderHeaderLabNumber = ? or T_OrderHeaderLabNumberExt=?"; $resp = $this->get_rows($sql, [$nolab, $nolab]); $this->print_table_style(); if (!$resp[0]) { echo "ERR : " . $resp[1]; exit(); } $rows = $resp[1]; $this->print_table($rows, array_keys($rows[0])); echo "
"; if (count($rows) == 0) { echo "$nolab not found"; exit; } $id= $rows[0]["T_OrderHeaderID"]; $noreg= $rows[0]["T_OrderHeaderLabNumberExt"]; $orderDate= $rows[0]["T_OrderHeaderDate"]; $rows = $this->get_group_result($rows[0]["T_OrderHeaderID"]); $this->print_table($rows, array_keys($rows[0])); $gids = []; echo "
"; foreach($rows as $r) { $groupResultID = $r["Group_ResultID"]; $pname = $r["patient"]; if(in_array($groupResultID,$gids)) continue; $gids[] = $groupResultID; $res_pdf = $this->get_pdf($id, $noreg, $pname, $groupResultID, $orderDate); foreach($res_pdf as $idx => $rp) { $fname = $rp["url"]; if (substr($fname,-3) == "jpg") { if (! file_exists($fname)) { $res_pdf[$idx]["Info"] = "File Not Exists"; continue; } $fsize = filesize(($fname)) / (1024 * 1024); $res_pdf[$idx]["Info"] = "Size : " . round($fsize,2) . " mb"; } else { $url = $rp["url"]; $res_pdf[$idx]["Info"] = "View"; } } $this->print_table($res_pdf,array_keys($res_pdf[0])); echo "
"; } } function get_group_result($orderID) { $sql = "select distinct Group_ResultFlagPerTest, if(Group_ResultFlagPerTest = 'Y', T_OrderDetailT_TestID, Group_ResultDetailGroup_ResultID) Group_ResultID, M_DeliverySource, M_DeliveryName, T_OrderDeliveryDestination, fn_get_patient_atribute(T_OrderHeaderM_PatientID) patientAttribute, fn_global_doctor_name(T_OrderHeaderSenderM_DoctorID) DoctorName, IF(M_MouIsBill = 'Y','Y',ifnull(Last_StatusPaymentIsLunas,'N')) IsLunas, M_DoctorHP from t_orderheader join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID and T_OrderDetailIsActive = 'Y' and T_OrderHeaderID = ? join group_resultdetail on Group_ResultDetailT_TestID = T_OrderDetailT_TestID and Group_ResultDetailIsActive = 'Y' join group_result on Group_ResultIsActive = 'Y' and Group_ResultID = Group_ResultDetailGroup_ResultID 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 = 4 or T_OrderDeliveryM_DeliveryTypeID = 3 ) join m_delivery on T_OrderDeliveryM_DeliveryID = M_DeliveryID left join last_statuspayment ON T_OrderHeaderID = Last_StatusPaymentT_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y' where ( M_MouIsBill = 'Y' or Last_StatusPaymentIsLunas = 'Y' ) group by T_OrderHeaderID, Group_ResultID, M_DeliverySource order by IsLunas desc, T_OrderHeaderID"; $resp = $this->get_rows($sql, [$orderID]); if (!$resp[0]) { echo "ERR : " . $resp[1]; exit(); } $rows = $resp[1]; foreach($rows as $idx => $r) { $jp = json_decode($r["patientAttribute"],true); unset($rows[$idx]["patientAttribute"]); $pname = $jp["patient_fullname"]; $rows[$idx]["Patient"] = $pname; } return $rows; } function list($date = "") { if ($date == "") { $date = date("Y-m-d"); } // $sql = "select group_concat(distinct T_OrderHeaderID) xids from t_orderheader join result_processtooffice on Result_ProcessToOfficeT_OrderHeaderID= T_OrderHeaderID and T_OrderHeaderIsActive = 'Y' join t_orderdelivery on T_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID 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_OrderDeliveryIsActive = 'Y' and T_OrderDeliveryIsDone = 'N' and T_OrderDeliveryM_DeliveryTypeID in ( 4 ) "; $qry = $this->db->query($sql, [$date, $date, $date, $date, $date]); if (!$qry) { $this->resp["message"] = "Err select orderheaderid | " . $this->db->error()["message"] . "|" . $this->db->last_query(); $this->reply(); } $rows = $qry->result_array(); if (count($rows) == 0) { $this->resp["message"] = "No Pending Request"; $this->reply(); } $order_ids = $rows[0]["xids"]; if ($order_ids == "") { $order_ids = "-1"; } //tambahan order ids partial all $sql = "select group_concat(distinct T_OrderHeaderID) xids from t_orderheader join result_processtooffice on Result_ProcessToOfficeT_OrderHeaderID= T_OrderHeaderID and T_OrderHeaderIsActive = 'Y' join t_orderdelivery on T_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID 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_OrderDeliveryIsActive = 'Y' and T_OrderDeliveryM_DeliveryTypeID in ( 4 ) "; $qry = $this->db->query($sql, [$date, $date, $date, $date, $date]); if (!$qry) { $this->resp["message"] = "Err select orderheaderid | " . $this->db->error()["message"] . "|" . $this->db->last_query(); $this->reply(); } $rows = $qry->result_array(); if (count($rows) == 0) { $this->resp["message"] = "No Pending Request"; $this->reply(); } $order_ids_all = $rows[0]["xids"]; if ($order_ids_all == "") { $order_ids_all = "-1"; } // populate tx_whatsapp status $sql = "select * from tx_whatsapp where Tx_WhatsappT_OrderHeaderID in ( $order_ids ) and Tx_WhatsappIsActive = 'Y' and Tx_WhatsappIsSent = 'Y'"; $qry = $this->db->query($sql); if (!$qry) { $this->resp["message"] = "Err Populate Tx Whatsapp | " . $this->db->error()["message"] . "|" . $this->db->last_query(); $this->reply(); } $tx_whatsapp = []; $rows = $qry->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"; $tx_whatsapp[$idx] = "Y"; } // populate tx_whatsapp_partial $sql = "select * from tx_whatsapp_partial where Tx_WhatsappPartialT_OrderHeaderID in ( $order_ids_all ) and Tx_WhatsappPartialIsActive = 'Y' and Tx_WhatsappPartialIsSent = 'N'"; $qry = $this->db->query($sql); if (!$qry) { $this->resp["message"] = "Err Populate Tx Whatsapp | " . $this->db->error()["message"] . "|" . $this->db->last_query(); $this->reply(); } $tx_whatsapp_partial = []; $rows = $qry->result_array(); foreach ($rows as $r) { $headerID = $r["Tx_WhatsappPartialT_OrderHeaderID"]; $groupResultID = $r["Tx_WhatsappPartialGroup_ResultID"]; $deliveryID = $r["Tx_WhatsappPartialM_DeliveryID"]; $idx = "$headerID-$deliveryID-$groupResultID"; $tx_whatsapp_partial[$idx] = "Y"; } // populate tx_whatsapp_partial_sent $sql = "select * from tx_whatsapp_partial where Tx_WhatsappPartialT_OrderHeaderID in ( $order_ids_all ) and Tx_WhatsappPartialIsActive = 'Y' and Tx_WhatsappPartialIsSent = 'Y'"; $qry = $this->db->query($sql); if (!$qry) { $this->resp["message"] = "Err Populate Tx Whatsapp Partial Sent | " . $this->db->error()["message"] . "|" . $this->db->last_query(); $this->reply(); } $tx_whatsapp_partial_sent = []; $rows = $qry->result_array(); foreach ($rows as $r) { $headerID = $r["Tx_WhatsappPartialT_OrderHeaderID"]; $groupResultID = $r["Tx_WhatsappPartialGroup_ResultID"]; $deliveryID = $r["Tx_WhatsappPartialM_DeliveryID"]; $idx = "$headerID-$deliveryID-$groupResultID"; $tx_whatsapp_partial_sent[$idx] = "Y"; } $sql = "select distinct T_OrderHeaderID, T_OrderHeaderLabNumber, T_OrderHeaderLabNumberExt, if(Group_ResultFlagPerTest = 'Y', T_OrderDetailT_TestID, Group_ResultDetailGroup_ResultID) Group_ResultID, M_DeliverySource, ifnull(Result_ProcessToOfficeStatus,'N') Result_ProcessToOfficeStatus, M_DeliveryID, M_DeliveryName, T_OrderDeliveryDestination, T_OrderHeaderDate, fn_get_patient_atribute(T_OrderHeaderM_PatientID) patientAttribute, fn_global_doctor_name(T_OrderHeaderSenderM_DoctorID) DoctorName, IF(M_MouIsBill = 'Y','Y',ifnull(Last_StatusPaymentIsLunas,'N')) IsLunas, T_OrderHeaderDate, fn_global_doctor_name(T_OrderHeaderSenderM_DoctorID) DoctorName, M_DoctorHP, T_OrderHeaderAddOnReadyPrint, T_OrderHeaderSenderM_DoctorID, T_OrderHeaderM_PatientID, T_OrderHeaderM_MouID, T_OrderHeaderM_CompanyID, T_OrderDeliveryID from t_orderheader join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID and T_OrderDetailIsActive = 'Y' join group_resultdetail on Group_ResultDetailT_TestID = T_OrderDetailT_TestID and Group_ResultDetailIsActive = 'Y' join group_result on Group_ResultIsActive = 'Y' and Group_ResultID = Group_ResultDetailGroup_ResultID 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 = 4 join m_delivery on T_OrderDeliveryM_DeliveryID = M_DeliveryID left join result_processtooffice on Result_ProcessToOfficeT_OrderHeaderID= T_OrderHeaderID and Result_ProcessToOfficeT_OrderDeliveryID = T_OrderDeliveryID AND ( ( Result_ProcessToOfficeGroup_ResultID = T_OrderDetailT_TestID AND Group_ResultFlagPerTest = 'Y' ) or ( Result_ProcessToOfficeGroup_ResultID = Group_ResultID AND Group_ResultFlagPerTest = 'N' ) ) and Result_ProcessToOfficeIsActive ='Y' left join last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y' where T_OrderHeaderID in ( $order_ids ) and ( M_MouIsBill = 'Y' or Last_StatusPaymentIsLunas = 'Y' ) group by T_OrderHeaderID, Group_ResultID, M_DeliverySource order by IsLunas desc, T_OrderHeaderID limit 0,1000"; $qry = $this->db->query($sql); if (!$qry) { $this->resp["message"] = "Err Populate List | " . $this->db->error()["message"] . "|" . $this->db->last_query(); $this->reply(); } $rows = $qry->result_array(); $arr_partial = []; foreach ($rows as $r) { $headerID = $r["T_OrderHeaderID"]; $Result_ProcessToOfficeStatus = $r["Result_ProcessToOfficeStatus"]; if ($Result_ProcessToOfficeStatus == "N") { $arr_partial[] = $headerID; } } $list_result = []; $group_result = []; $counter_list = 0; foreach ($rows as $idx => $r) { $headerID = $r["T_OrderHeaderID"]; if (in_array($headerID, $arr_partial)) { if ($r["Result_ProcessToOfficeStatus"] == "S") { $rows_partial_only[] = $r; } continue; } $deliveryID = $r["M_DeliveryID"]; $groupResultID = $r["Group_ResultID"]; if ($r["M_DeliverySource"] == "DOCTOR") { $rows[$idx]["template"] = "02"; if ( $r["M_DoctorHP"] == "" || strlen(trim($r["M_DoctorHP"])) < 6 ) { continue; } $rows[$idx]["T_OrderDeliveryDestination"] = $r["M_DoctorHP"]; } else { if ( $r["T_OrderDeliveryDestination"] == "" || strlen(trim($r["T_OrderDeliveryDestination"])) < 6 ) { continue; } $rows[$idx]["template"] = "01"; } $group_idx = $headerID . "-" . $r["M_DeliverySource"]; $j_pasien = json_decode($r["patientAttribute"], true); $xname = $j_pasien["patient_fullname"]; $xname = $this->escape_fname($xname); $x_reports = $this->get_pdf( $r["T_OrderHeaderID"], $r["T_OrderHeaderLabNumberExt"], $xname, $groupResultID, $r["T_OrderHeaderDate"] ); $reports = []; foreach ($x_reports as $xr) { $groupResultID = $xr["groupID"]; $wa_idx = "$headerID-$deliveryID-$groupResultID"; if (isset($tx_whatsapp[$wa_idx])) { //echo "In Tx Whatsapp \n"; continue; } if ($xr["url"] == "") { //echo "Empty Report\n"; continue; } if ($xr["url"] == "-") { //echo "Empty Report\n"; continue; } $xr["Result_ProcessToOfficeStatus"] = $r["Result_ProcessToOfficeStatus"]; $reports[] = $xr; } if (count($reports) == 0) { //echo "No Report =| {$r['T_OrderHeaderLabNumber']} \n"; unset($rows[$idx]); continue; } $rows[$idx]["reports"] = $reports; $list_result[] = $rows[$idx]; if (isset($group_result[$group_idx])) { $group_result[$group_idx]["reports"][] = $xr; } else { $group_result[$group_idx] = $rows[$idx]; } $counter_list++; if ($counter_list > 5) { break; } } $list_result = []; foreach ($group_result as $gr) { $list_result[] = $gr; } //partial only if (true) { foreach ($rows_partial_only as $idx => $r) { $headerID = $r["T_OrderHeaderID"]; $deliveryID = $r["M_DeliveryID"]; $groupResultID = $r["Group_ResultID"]; $partial_idx = "$headerID-$deliveryID-$groupResultID"; if (!isset($tx_whatsapp_partial[$partial_idx])) { continue; } if ($r["M_DeliverySource"] == "DOCTOR") { $rows[$idx]["template"] = "02"; if ( $r["M_DoctorHP"] == "" || strlen(trim($r["M_DoctorHP"])) < 6 ) { continue; } $rows[$idx]["T_OrderDeliveryDestination"] = $r["M_DoctorHP"]; } else { if ( $r["T_OrderDeliveryDestination"] == "" || strlen(trim($r["T_OrderDeliveryDestination"])) < 6 ) { continue; } $rows[$idx]["template"] = "01"; } $j_pasien = json_decode($r["patientAttribute"], true); $xname = $j_pasien["patient_fullname"]; $xname = $this->escape_fname($xname); $x_reports = $this->get_pdf( $r["T_OrderHeaderID"], $r["T_OrderHeaderLabNumberExt"], $xname, $groupResultID, $r["T_OrderHeaderDate"] ); $reports = []; foreach ($x_reports as $xr) { $groupResultID = $xr["groupID"]; $wa_idx = "$headerID-$deliveryID-$groupResultID"; if (isset($tx_whatsapp[$wa_idx])) { //echo "In Tx Whatsapp \n"; continue; } if ($xr["url"] == "") { //echo "Empty Report\n"; continue; } if ($xr["url"] == "-") { //echo "Empty Report\n"; continue; } $xr["Result_ProcessToOfficeStatus"] = $r["Result_ProcessToOfficeStatus"]; $reports[] = $xr; } if (count($reports) == 0) { //echo "No Report =| {$r['T_OrderHeaderLabNumber']} \n"; unset($rows_partial_only[$idx]); continue; } $rows_partial_only[$idx]["reports"] = $reports; $list_result[] = $rows_partial_only[$idx]; $counter_list++; if ($counter_list > 10) { break; } } } //sisa dari partial $sql = "select distinct T_OrderHeaderID, if(Tx_WhatsappID is NULL,'N','Y') IsWhatsappSent, Group_ResultDetailGroup_ResultID Group_ResultID, T_OrderDeliveryM_DeliveryID, max(ifnull(Result_ProcessToOfficeStatus,'N')) Result_ProcessToOfficeStatus from t_orderheader join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID and T_OrderDetailIsActive = 'Y' join group_resultdetail on Group_ResultDetailT_TestID = T_OrderDetailT_TestID and Group_ResultDetailIsActive = 'Y' join group_result on Group_ResultIsActive = 'Y' and Group_ResultID = Group_ResultDetailGroup_ResultID 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 = 4 join tx_whatsapp_partial on Tx_WhatsappPartialT_OrderHeaderID = T_OrderHeaderID and date(Tx_WhatsappPartialCreated) = date(now()) left join tx_whatsapp on T_OrderHeaderID = Tx_WhatsappT_OrderHeaderID and Group_ResultDetailGroup_ResultID = Tx_WhatsappGroup_ResultID join m_delivery on T_OrderDeliveryM_DeliveryID = M_DeliveryID left join result_processtooffice on Result_ProcessToOfficeT_OrderHeaderID= T_OrderHeaderID and Result_ProcessToOfficeT_OrderDeliveryID = T_OrderDeliveryID AND ( ( Result_ProcessToOfficeGroup_ResultID = T_OrderDetailT_TestID AND Group_ResultFlagPerTest = 'Y' ) or ( Result_ProcessToOfficeGroup_ResultID = Group_ResultID AND Group_ResultFlagPerTest = 'N' ) ) and Result_ProcessToOfficeIsActive ='Y' left join last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y' where ( M_MouIsBill = 'Y' or Last_StatusPaymentIsLunas = 'Y' ) group by T_OrderHeaderID, Group_ResultID having IsWhatsappSent = 'N' and Result_ProcessToOfficeStatus = 'S' order by T_OrderHeaderID limit 0,1000"; $qry = $this->db->query($sql); $x_ids = "-1"; $x_group_ids = "-1"; $x_mdelivery_ids = "-1"; if ($qry) { $rows = $qry->result_array(); if (count($rows) > 0) { foreach ($rows as $r) { $x_ids .= ", " . $r["T_OrderHeaderID"]; $x_group_ids .= "," . $r["Group_ResultID"]; $x_mdelivery_ids .= "," . $r["T_OrderDeliveryM_DeliveryID"]; } } } // echo $sql . "\n\n"; // Listing sisa dari partial yg sudah ready $sql = "select distinct T_OrderHeaderID, T_OrderHeaderLabNumber, T_OrderHeaderLabNumberExt, Group_ResultDetailGroup_ResultID Group_ResultID, M_DeliverySource, ifnull(Result_ProcessToOfficeStatus,'N') Result_ProcessToOfficeStatus, M_DeliveryID, M_DeliveryName, T_OrderDeliveryDestination, T_OrderHeaderDate, fn_get_patient_atribute(T_OrderHeaderM_PatientID) patientAttribute, fn_global_doctor_name(T_OrderHeaderSenderM_DoctorID) DoctorName, IF(M_MouIsBill = 'Y','Y',ifnull(Last_StatusPaymentIsLunas,'N')) IsLunas, T_OrderHeaderDate, fn_global_doctor_name(T_OrderHeaderSenderM_DoctorID) DoctorName, M_DoctorHP, T_OrderHeaderAddOnReadyPrint, T_OrderHeaderSenderM_DoctorID, T_OrderHeaderM_PatientID, T_OrderHeaderM_MouID, T_OrderHeaderM_CompanyID, T_OrderDeliveryID from t_orderheader join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID and T_OrderDetailIsActive = 'Y' and T_OrderDetailT_TestIsResult = 'Y' join group_resultdetail on Group_ResultDetailT_TestID = T_OrderDetailT_TestID and Group_ResultDetailIsActive = 'Y' join group_result on Group_ResultIsActive = 'Y' and Group_ResultID = Group_ResultDetailGroup_ResultID 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 = 4 join m_delivery on T_OrderDeliveryM_DeliveryID = M_DeliveryID left join result_processtooffice on Result_ProcessToOfficeT_OrderHeaderID= T_OrderHeaderID and Result_ProcessToOfficeT_OrderDeliveryID = T_OrderDeliveryID AND ( ( Result_ProcessToOfficeGroup_ResultID = T_OrderDetailT_TestID AND Group_ResultFlagPerTest = 'Y' ) or ( Result_ProcessToOfficeGroup_ResultID = Group_ResultID AND Group_ResultFlagPerTest = 'N' ) ) and Result_ProcessToOfficeIsActive ='Y' left join last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y' where T_OrderHeaderID in ( $x_ids ) and Group_ResultDetailGroup_ResultID in ( $x_group_ids ) and T_OrderDeliveryM_DeliveryID in ( $x_mdelivery_ids ) and ( M_MouIsBill = 'Y' or Last_StatusPaymentIsLunas = 'Y' ) group by T_OrderHeaderID, Group_ResultID, M_DeliverySource order by IsLunas desc, T_OrderHeaderID limit 0,1000"; $qry = $this->db->query($sql); if (!$qry) { $this->resp["message"] = "Err Populate List tx partial | " . $this->db->error()["message"] . "|" . $this->db->last_query(); $this->reply(); } $rows = $qry->result_array(); //echo $sql . "\n"; $z_group_result = []; foreach ($rows as $idx => $r) { $headerID = $r["T_OrderHeaderID"]; $deliveryID = $r["M_DeliveryID"]; $groupResultID = $r["Group_ResultID"]; //ditambahkan check ke tx_whatsapp_partial $partial_idx = "$headerID-$deliveryID-$groupResultID"; if (isset($tx_whatsapp[$partial_idx])) { // echo $r["T_OrderHeaderID"] . " in wa sent \n"; continue; } if (isset($tx_whatsapp_partial_sent[$partial_idx])) { // echo $r["T_OrderHeaderID"] . " $partial_idx in wa partial sent \n"; continue; } if ($r["Result_ProcessToOfficeStatus"] == "N") { // echo $r["T_OrderHeaderID"] . " $partial_idx Result_ProcessToOffice N \n"; continue; } if ($r["M_DeliverySource"] == "DOCTOR") { $rows[$idx]["template"] = "02"; if ( $r["M_DoctorHP"] == "" || strlen(trim($r["M_DoctorHP"])) < 6 ) { continue; } $rows[$idx]["T_OrderDeliveryDestination"] = $r["M_DoctorHP"]; } else { if ( $r["T_OrderDeliveryDestination"] == "" || strlen(trim($r["T_OrderDeliveryDestination"])) < 6 ) { continue; } $rows[$idx]["template"] = "01"; } $group_idx = $headerID . "-" . $r["M_DeliverySource"]; $j_pasien = json_decode($r["patientAttribute"], true); $xname = $j_pasien["patient_fullname"]; /* echo "Get PDF " . $r["T_OrderHeaderID"] . "," . $r["T_OrderHeaderLabNumberExt"] . "," . $xname . "," . $groupResultID . "," . $r["T_OrderHeaderDate"] . "\n\n"; */ $xname = $this->escape_fname($xname); $x_reports = $this->get_pdf( $r["T_OrderHeaderID"], $r["T_OrderHeaderLabNumberExt"], $xname, $groupResultID, $r["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; } if (count($reports) == 0) { unset($rows[$idx]); continue; } $rows[$idx]["reports"] = $reports; if (isset($z_group_result[$group_idx])) { $z_group_result[$group_idx]["reports"][] = $xr; } else { $z_group_result[$group_idx] = $rows[$idx]; } $counter_list++; if ($counter_list > 15) { break; } } foreach ($z_group_result as $gr) { $list_result[] = $gr; } $params = []; $this->get_branch(); foreach ($list_result as $result) { $param = $this->populate_param($result); if ($param["phone"] == "Invalid") { continue; } if ( isset($param["doctor"]["M_DoctorHP"]) && strlen($param["doctor"]["M_DoctorHP"]) > 3 ) { if (substr($param["doctor"]["M_DoctorHP"], 0, 1) != "0") { $param["doctor"]["M_DoctorHP"] = "0" . $param["doctor"]["M_DoctorHP"]; } } $params[] = $param; } $this->resp["status"] = "OK"; $this->resp["params"] = $params; $this->reply(); } function get_branch() { $sql = "select M_BranchID,M_BranchCode from m_branch where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'"; $qry = $this->db->query($sql); if (!$qry) { echo "ERR Branch : " . $this->db->error()["message"] . "|" . $this->db->last_query() . "\n"; return; } $rows = $qry->result_array(); if (count($rows) == 0) { echo "ERR Branch No result\n"; return; } $this->branchID = $rows[0]["M_BranchID"]; $this->branchCode = $rows[0]["M_BranchCode"]; } function get_doctor($id) { $this->db->where("M_DoctorID", $id); $qry = $this->db->get("m_doctor"); if (!$qry) { echo "ERR Doctor : " . $this->db->error()["message"] . "|" . $this->db->last_query() . "\n"; return; } $rows = $qry->result_array(); if (count($rows) > 0) { return $rows[0]; } return []; } function get_patient($id) { $this->db->where("M_PatientID", $id); $qry = $this->db->get("m_patient"); if (!$qry) { echo "ERR Patient : " . $this->db->error()["message"] . "|" . $this->db->last_query() . "\n"; return; } $rows = $qry->result_array(); if (count($rows) > 0) { return $rows[0]; } return []; } function get_mou($id) { $this->db->where("M_MouID", $id); $qry = $this->db->get("m_mou"); if (!$qry) { echo "ERR MOU : " . $this->db->error()["message"] . "|" . $this->db->last_query() . "\n"; return; } $rows = $qry->result_array(); if (count($rows) > 0) { return $rows[0]; } return []; } function get_company($id) { $this->db->where("M_CompanyID", $id); $qry = $this->db->get("m_company"); if (!$qry) { echo "ERR Company : " . $this->db->error()["message"] . "|" . $this->db->last_query() . "\n"; return; } $rows = $qry->result_array(); if (count($rows) > 0) { return $rows[0]; } return []; } function get_order($id) { $this->db->where("T_OrderHeaderID", $id); $qry = $this->db->get("t_orderheader"); if (!$qry) { echo "ERR OrderHeader : " . $this->db->error()["message"] . "|" . $this->db->last_query() . "\n"; return; } $rows = $qry->result_array(); if (count($rows) > 0) { return $rows[0]; } return []; } function populate_param($r, $debug = false) { $pasien = json_decode($r["patientAttribute"], true); $tgl_lab = date("Ymd", strtotime($r["T_OrderHeaderDate"])); $dob = date("Ymd", strtotime($pasien["M_PatientDOB"])); $files = []; $groupID = []; foreach ($r["reports"] as $xr) { $groupID[] = $xr["groupID"]; if ($this->debug || $debug) { $file = [ "name" => $xr["fname"], "data" => "content-skipped", ]; } else { if (strpos($xr["url"], "jpg")) { $file = [ "name" => $xr["fname"], "data" => base64_encode(file_get_contents($xr["url"])), ]; } else { $file = [ "name" => $xr["fname"], "data" => base64_encode( file_get_contents($this->host . $xr["url"]) ), ]; } } if ($this->debug) { $file["url"] = $this->host . $xr["url"]; } $files[] = $file; } $param = [ "phone" => $this->sanitize_hp($r["T_OrderDeliveryDestination"]), "sapaan" => $pasien["M_TitleName"], "nama" => substr( $this->sanitize_string($pasien["M_PatientName"]), 0, 250 ), "dokter" => substr( $this->sanitize_string($r["DoctorName"]), 0, 250 ), "tgl_lab" => $tgl_lab, "tgl_lahir" => $dob, "branchID" => $this->branchID, "branchCode" => $this->branchCode, "files" => $files, "groupID" => $groupID, "template" => $r["template"], "noreg" => $r["T_OrderHeaderLabNumberExt"], "M_DoctorID" => $r["T_OrderHeaderSenderM_DoctorID"], "M_PatientID" => $r["T_OrderHeaderM_PatientID"], "orderID" => $r["T_OrderHeaderID"], "deliveryID" => $r["T_OrderDeliveryID"], "M_DeliveryID" => $r["M_DeliveryID"], "doctor" => $this->get_doctor($r["T_OrderHeaderSenderM_DoctorID"]), "patient" => $this->get_patient($r["T_OrderHeaderM_PatientID"]), "mou" => $this->get_mou($r["T_OrderHeaderM_MouID"]), "company" => $this->get_company($r["T_OrderHeaderM_CompanyID"]), "order" => $this->get_order($r["T_OrderHeaderID"]), ]; return $param; } 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_ResultID = ? LEFT JOIN t_email_nonlab ON T_EmailNonLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_EmailNonLabType LIKE CONCAT('%',REPLACE(Group_ResultName, 'Elektromedik', 'electromedis'),'%') union select distinct T_OrderDetailT_TestID 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 = ? and T_OrderDetailT_TestID = ? join group_result on Group_ResultDetailGroup_ResultID = Group_ResultID and Group_ResultFlagPerTest = '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, [ $id, $groupResultID, $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"]); $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; default: $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 get_param() { $z_raw = file_get_contents("php://input"); $raw = gzinflate($z_raw); $j_param = json_decode($raw, true); if ($j_param) { return [true, "", $j_param]; } else { return [false, "Invalid JSON : " . $raw, []]; } } function update() { list($p_status, $message, $param) = $this->get_param(); if (!$p_status) { $this->resp["message"] = $param; } $db_msg = ""; $query_msg = ""; foreach ($param as $p) { $this->db->trans_begin(); $headerID = $p["headerID"]; $deliveryID = $p["deliveryID"]; $outboundID = $p["outboundID"]; $status = $p["status"]; $groupID = $p["groupID"]; $M_DeliveryID = $p["M_DeliveryID"]; $destination = $p["phone"]; $note = $p["note"]; foreach ($groupID as $gid) { $this->db->where("Tx_WhatsappT_OrderHeaderID", $headerID); $this->db->where("Tx_WhatsappGroup_ResultID", $gid); $this->db->where("Tx_WhatsappM_DeliveryID", $M_DeliveryID); $this->db->where("Tx_WhatsappIsActive", "Y"); $qry = $this->db->get("tx_whatsapp"); $query_msg .= $this->db->last_query() . "\n"; if (!$qry) { $db_msg .= "$headerID | " . $this->db->error()["message"] . "|" . $this->db->last_query() . "\n"; $this->db->trans_rollback(); $rows = $qry->result_array(); $Tx_WhatsappID = 0; $this->resp["message"] = $rows; $this->db->trans_rollback(); $this->reply(); break; } $rows = $qry->result_array(); $Tx_WhatsappID = 0; if (count($rows) == 0) { $arr = [ "Tx_WhatsappT_OrderHeaderID" => $headerID, "Tx_WhatsappGroup_ResultID" => $gid, "Tx_WhatsappOutboundID" => $outboundID, "Tx_WhatsappM_DeliveryID" => $M_DeliveryID, "Tx_WhatsappDestination" => $destination, ]; if ($status == "01") { $arr["Tx_WhatsappIsSent"] = "Y"; $arr["Tx_WhatsappSentDate"] = date("Y-m-d H:i:s"); } $qry = $this->db->insert("tx_whatsapp", $arr); $query_msg .= $this->db->last_query() . "\n"; if (!$qry) { $db_msg .= "insert tx_whatsapp $headerID | " . $this->db->error()["message"] . "|" . $this->db->last_query() . "\n"; $this->db->trans_rollback(); } $Tx_WhatsappID = $this->db->insert_id(); } else { $Tx_WhatsappID = $rows[0]["Tx_WhatsappID"]; } //update tx_whatsapp_partial $arr_partial_update = [ "Tx_WhatsappPartialIsSent" => "Y", "Tx_WhatsappPartialLastUpadated" => date("Y-m-d H:i:s"), ]; $this->db->where( "Tx_WhatsappPartialT_OrderHeaderID", $headerID ); $this->db->where("Tx_WhatsappPartialGroup_ResultID", $gid); $this->db->where( "Tx_WhatsappPartialM_DeliveryID", $M_DeliveryID ); $qry = $this->db->update( "tx_whatsapp_partial", $arr_partial_update ); $query_msg .= $this->db->last_query() . "\n"; if (!$qry) { $db_msg .= "whatsappDetail $Tx_WhatsappID | " . $this->db->error()["message"] . "|" . $this->db->last_query() . "\n"; $this->db->trans_rollback(); break; } $this->db->where( "Tx_WhatsappDetailTx_WhatsappID", $Tx_WhatsappID ); $qry = $this->db->get("tx_whatsappdetail"); $query_msg .= $this->db->last_query() . "\n"; if (!$qry) { $db_msg .= "whatsappDetail $Tx_WhatsappID | " . $this->db->error()["message"] . "|" . $this->db->last_query() . "\n"; $this->db->trans_rollback(); break; } $rows = $qry->result_array(); $Tx_WhatsappDetailID = 0; if (count($rows) == 0) { $arr = [ "Tx_WhatsappDetailTx_WhatsappID" => $Tx_WhatsappID, "Tx_WhatsappDetailUuid" => $outboundID, "Tx_WhatsappDetailIsSend" => "Y", "Tx_WhatsappDetailSend" => date("Y-m-d H:i:s"), "Tx_WhatsappDetailCreated" => date("Y-m-d H:i:s"), "Tx_WhatsappDetailMessage" => $note, ]; $qry = $this->db->insert("tx_whatsappdetail", $arr); $query_msg .= $this->db->last_query() . "\n"; if (!$qry) { $db_msg .= "whatsappDetail $Tx_WhatsappID | " . $this->db->error()["message"] . "|" . $this->db->last_query() . "\n"; $this->db->trans_rollback(); } } else { $Tx_WhatsappDetailID = $rows[0]["Tx_WhatsappDetailID"]; } if ($status == "01") { $arr = [ "Tx_WhatsappDetailIsSend" => "Y", "Tx_WhatsappDetailSend" => date("Y-m-d H:i:s"), ]; } elseif ($status == "02") { $arr = [ "Tx_WhatsappDetailIsReceive" => "Y", "Tx_WhatsappDetailReceive" => date("Y-m-d H:i:s"), ]; } elseif ($status == "03") { $arr = [ "Tx_WhatsappDetailIsRead" => "Y", "Tx_WhatsappDetailRead" => date("Y-m-d H:i:s"), ]; } if ($status == "01" || $status == "02" || $status == "03") { $this->db->where( "Tx_WhatsappDetailID", $Tx_WhatsappDetailID ); $qry = $this->db->update("tx_whatsappdetail", $arr); $query_msg .= $this->db->last_query() . "\n"; if (!$qry) { $db_msg .= "whatsappDetail $Tx_WhatsappID | " . $this->db->error()["message"] . "|" . $this->db->last_query() . "\n"; $this->db->trans_rollback(); } $arr = ["T_OrderDeliveryIsDone" => "Y"]; $this->db->where("T_OrderDeliveryID", $deliveryID); $qry = $this->db->update("t_orderdelivery", $arr); $query_msg .= $this->db->last_query() . "\n"; if (!$qry) { $db_msg .= "update order delivery $headerID | " . $this->db->error()["message"] . "|" . $this->db->last_query() . "\n"; $this->db->trans_rollback(); break; } } } if ($this->db->trans_status === false) { $this->db->tans_rollback(); $db_msg .= "Transaction Error : " . $this->db->error()["message"] . "\n"; } else { $this->db->trans_commit(); $query_msg .= "__|Commit|__\n"; } } if ($db_msg == "") { $this->resp["status"] = "OK"; $this->resp["message"] = $query_msg; $this->reply(); } else { $this->resp["message"] = $db_msg; $this->reply(); } } function api_get_branch() { $this->get_branch(); $this->resp["branchID"] = $this->branchID; $this->resp["branchCode"] = $this->branchCode; $this->resp["status"] = "OK"; $this->reply(); } 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; } function update_progress($debug = 0) { list($p_status, $message, $param) = $this->get_param(); if (!$p_status) { $this->resp["message"] = $param; } $db_msg = ""; $query_msg = ""; foreach ($param as $p) { $this->db->trans_begin(); $headerID = $p["T_OrderHeaderID"]; $deliveryID = $p["deliveryID"]; $outboundID = $p["outboundID"]; $status = $p["status"]; $time_stamp = $p["time_stamp"]; if ($status == "02") { $arr = [ "Tx_WhatsappDetailIsReceive" => "Y", "Tx_WhatsappDetailReceive" => $time_stamp, ]; $this->db->where("Tx_WhatsappDetailUuid", $outboundID); $qry = $this->db->update("tx_whatsappdetail", $arr); if ($qry) { //update send if N $arr = [ "Tx_WhatsappDetailIsSend" => "Y", "Tx_WhatsappDetailSend" => $time_stamp, ]; $this->db->where("Tx_WhatsappDetailUuid", $outboundID); $this->db->where("Tx_WhatsappDetailIsSend", "N"); $qry = $this->db->update("tx_whatsappdetail", $arr); } } elseif ($status == "03") { $arr = [ "Tx_WhatsappDetailIsRead" => "Y", "Tx_WhatsappDetailRead" => $time_stamp, ]; $this->db->where("Tx_WhatsappDetailUuid", $outboundID); $qry = $this->db->update("tx_whatsappdetail", $arr); } elseif ($status == "04") { $arr = [ "Tx_WhatsappDetailIsTimeout" => "Y", ]; $this->db->where("Tx_WhatsappDetailUuid", $outboundID); $qry = $this->db->update("tx_whatsappdetail", $arr); } if ($debug > 0) { echo $this->db->last_query(); echo "\n"; } if ($this->db->trans_status === false) { $this->db->tans_rollback(); $db_msg .= "Transaction Error : " . $this->db->error()["message"] . "\n"; if ($debug > 0) { echo "Transaction Error : " . $this->db->error()["message"] . "\n"; } } else { $this->db->trans_commit(); $query_msg .= "__|Commit|__\n"; if ($debug > 0) { echo "__|Commit|__\n"; } } if ($debug > 0) { echo $this->db->last_query() . "\n"; } } if ($db_msg == "") { $this->resp["status"] = "OK"; $this->resp["message"] = $query_msg; $this->reply(!$debug); } else { $this->resp["message"] = $db_msg; $this->reply(!$debug); } } function sanitize_string($data) { $hasil = ""; $hasil = preg_replace("/[^0-9a-zA-Z ()|:.,?!+@_-]/", " ", $data); $hasil = filter_var( $hasil, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW ); $hasil = filter_var( $hasil, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH ); $hasil = str_replace("'", "", $hasil); if (str_replace(" ", "", $hasil) == "") { return ""; } else { return $hasil; } } function sanitize_hp($inp_hp) { $nohp = str_replace(" ", "", $inp_hp); // kadang ada penulisan no hp 0811 239 345 $nohp = str_replace("(", "", $nohp); // kadang ada penulisan no hp (0274) 778787 $nohp = str_replace(")", "", $nohp); // kadang ada penulisan no hp (0274) 778787 $nohp = str_replace(".", "", $nohp); // kadang ada penulisan no hp 0811.239.345 if (!preg_match("/[^+0-9]/", trim($nohp))) { // cek apakah no hp mengandung karakter + dan 0-9 if (substr(trim($nohp), 0, 3) == "+62") { // cek apakah no hp karakter 1-3 adalah +62 $nohp = substr(trim($nohp), 1); } if (substr(trim($nohp), 0, 2) == "62") { // cek apakah no hp karakter 1-2 adalah 62 $nohp = trim($nohp); } elseif (substr(trim($nohp), 0, 1) == "0") { // cek apakah no hp karakter 1 adalah 0 $nohp = "62" . substr(trim($nohp), 1); } elseif (substr(trim($nohp), 0, 1) == "8") { // cek apakah no hp karakter 1 adalah 8 $nohp = "62" . trim($nohp); } // fungsi trim() untuk menghilangan // spasi yang ada didepan/belakang } else { $nohp = "Invalid"; } return $nohp; } }