443 lines
20 KiB
PHP
443 lines
20 KiB
PHP
<?php
|
|
class Listrptpatienttahunaneng extends MY_Controller
|
|
{
|
|
var $db;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
echo "Listing Report Patient API";
|
|
}
|
|
|
|
function get_list_patient_rpt($orderHeaderID,$timestamp='',$tanpa_kesimpulan='N',$debug='N')
|
|
{
|
|
try {
|
|
|
|
$attachments = [];
|
|
|
|
$sql = "SELECT File_AttachmentID as fid, File_AttachmentFileName as fname
|
|
FROM file_attachment
|
|
JOIN t_orderheader ON T_OrderHeaderID = File_AttachmentT_OrderHeaderID
|
|
WHERE
|
|
File_AttachmentT_OrderHeaderID = ? AND File_AttachmentIsActive = 'Y' AND File_AttachmentIsFCI = 'Y'";
|
|
$qry = $this->db->query($sql, [$orderHeaderID]);
|
|
if ($qry) {
|
|
$attachments = $qry->result_array();
|
|
}
|
|
|
|
$lab_number = "";
|
|
$patient_name = "";
|
|
$lab = "";
|
|
$sql = "SELECT
|
|
toh.T_OrderHeaderID,
|
|
toh.T_OrderHeaderLabNumber,
|
|
mp.M_PatientID,
|
|
mp.M_PatientName,
|
|
DATE_FORMAT(NOW(), '%y%m%d%H%i%s') AS Datetime
|
|
from t_orderheader toh
|
|
JOIN m_patient mp ON toh.T_OrderHeaderM_PatientID = mp.M_PatientID AND mp.M_PatientIsActive = 'Y'
|
|
JOIN t_orderdetail ON toh.T_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID AND Group_ResultDetailIsActive = 'Y'
|
|
JOIN group_result ON Group_ResultID = Group_ResultDetailGroup_ResultID AND Group_ResultName = 'LAB'
|
|
WHERE toh.T_OrderHeaderID = ? AND toh.T_OrderHeaderIsActive = 'Y'
|
|
LIMIT 1";
|
|
$qry = $this->db->query($sql, [$orderHeaderID]);
|
|
if ($qry) {
|
|
$row = $qry->result_array();
|
|
if($row && count($row) > 0){
|
|
foreach ($row as $key => $value) {
|
|
$lab_number = $value["T_OrderHeaderLabNumber"];
|
|
$patient_name = $value["M_PatientName"];
|
|
$lab = "/birt/run?__report=report/one/lab/rpt_test_eng.rptdesign&__format=pdf&PID={$value["M_PatientID"]}&tm={$value["Datetime"]}&username=admin";
|
|
}
|
|
}
|
|
} else {
|
|
$this->sys_error_db("error get nomor lab dan nama pasien", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$lab_number = "";
|
|
$patient_name = "";
|
|
$lab = "";
|
|
foreach ($row as $key => $value) {
|
|
$lab_number = $value["T_OrderHeaderLabNumber"];
|
|
$patient_name = $value["M_PatientName"];
|
|
$lab = "/birt/run?__report=report/one/lab/rpt_test_eng.rptdesign&__format=pdf&PID={$value["T_OrderHeaderID"]}&tm={$value["Datetime"]}&username=admin";
|
|
}
|
|
|
|
## non-lab rpt
|
|
$sql_so = "SELECT
|
|
sre.So_ResultEntryID,
|
|
sre.So_ResultEntryT_OrderHeaderID,
|
|
sre.So_ResultEntryT_OrderDetailID,
|
|
sre.So_ResultEntryNonlab_TemplateID,
|
|
sre.So_ResultEntryNonlab_TemplateName,
|
|
DATE_FORMAT(NOW(), '%y%m%d%H%i%s') AS Datetime
|
|
FROM t_orderdetail tdet
|
|
JOIN t_test tt ON tdet.T_OrderDetailT_TestID = tt.T_TestID
|
|
AND tt.T_TestIsActive = 'Y'
|
|
JOIN so_resultentry sre ON sre.So_ResultEntryT_OrderDetailID = tdet.T_OrderDetailID
|
|
AND sre.So_ResultEntryIsActive = 'Y'
|
|
WHERE tdet.T_OrderDetailT_OrderHeaderID = ?
|
|
AND tdet.T_OrderDetailIsActive = 'Y'";
|
|
$qry_so = $this->db->query($sql_so, [$orderHeaderID]);
|
|
if ($qry_so) {
|
|
//$rows_so = $qry_so->result_array();
|
|
} else {
|
|
$this->sys_error_db("error get so result entry", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT DISTINCT group_resultName as rpt_name,
|
|
group_resultName as group_name,
|
|
IFNULL(So_ResultEntryID,0) as so_id,
|
|
T_OrderDetailT_OrderHeaderID as order_id,
|
|
DATE_FORMAT(NOW(), '%y%m%d%H%i%s') AS Datetime
|
|
FROM t_orderdetail
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID
|
|
JOIN group_result ON Group_ResultID = Group_ResultDetailGroup_ResultID AND
|
|
Group_ResultFlagPerTest = 'N' AND Group_ResultName <> 'LAB' AND Group_ResultFlagNonLab = 'N'
|
|
LEFT JOIN so_resultentry ON So_ResultEntryT_OrderDetailID = T_OrderDetailID AND So_ResultEntryIsActive = 'Y' AND
|
|
So_ResultEntryStatus = 'VAL1'
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = {$orderHeaderID} AND Group_ResultName <> 'Tanpa Hasil' AND T_OrderDetailIsActive = 'Y'
|
|
UNION
|
|
SELECT group_resultName as rpt_name,
|
|
group_resultName as group_name,
|
|
IFNULL(So_ResultEntryID,0) as so_id,
|
|
T_OrderDetailT_OrderHeaderID as order_id,
|
|
DATE_FORMAT(NOW(), '%y%m%d%H%i%s') AS Datetime
|
|
FROM t_orderdetail
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
|
T_SamplingSoT_TestID = T_TestID
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID
|
|
JOIN group_result ON Group_ResultID = Group_ResultDetailGroup_ResultID AND
|
|
Group_ResultFlagPerTest = 'N' AND Group_ResultName <> 'LAB' AND Group_ResultFlagNonLab = 'Y'
|
|
JOIN so_resultentry ON So_ResultEntryT_OrderDetailID = T_OrderDetailID AND So_ResultEntryIsActive = 'Y' AND
|
|
So_ResultEntryStatus = 'VAL1'
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = {$orderHeaderID} AND Group_ResultName <> 'Tanpa Hasil' AND T_OrderDetailIsActive = 'Y'
|
|
GROUP BY so_id
|
|
UNION
|
|
SELECT DISTINCT T_TestName as rpt_name,
|
|
group_resultName as group_name,
|
|
IFNULL(So_ResultEntryID,0) as so_id,
|
|
T_OrderDetailT_OrderHeaderID as order_id,
|
|
DATE_FORMAT(NOW(), '%y%m%d%H%i%s') AS Datetime
|
|
FROM t_orderdetail
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestName NOT IN ('Visus Mata','Buta Warna','Pemeriksaan Lapang Pandang')
|
|
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
|
T_SamplingSoT_TestID = T_TestID
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID
|
|
JOIN group_result ON Group_ResultID = Group_ResultDetailGroup_ResultID AND
|
|
Group_ResultFlagPerTest = 'Y' AND Group_ResultFlagNonLab = 'Y'
|
|
JOIN so_resultentry ON So_ResultEntryT_OrderDetailID = T_OrderDetailID AND So_ResultEntryIsActive = 'Y' AND
|
|
So_ResultEntryStatus = 'VAL1'
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = {$orderHeaderID} AND Group_ResultName <> 'Tanpa Hasil' AND T_OrderDetailIsActive = 'Y'";
|
|
$qry = $this->db->query($sql);
|
|
if ($qry) {
|
|
$rows_rpt = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db("error get rpts", $this->db);
|
|
exit;
|
|
}
|
|
|
|
## nonlab pid = so result id
|
|
$fisik = "";
|
|
$rontgen = [];
|
|
$ekg = "";
|
|
$audiometri = "";
|
|
$spirometri = "";
|
|
$treadmill = "";
|
|
$treadmill_attachment = array();
|
|
$papsmear = "";
|
|
$mikro = "";
|
|
$usg = array();
|
|
$sds = "";
|
|
$kebugaran = '';
|
|
|
|
|
|
foreach ($rows_rpt as $key => $value) {
|
|
if($value['rpt_name'] == 'Pemeriksaan Fisik')
|
|
$fisik = "/birt/run?__report=report/one/mcu/mcu_fisik_history_eng.rptdesign&__format=pdf&PType=fisik&PLang=1&PID={$value["so_id"]}&tm={$value["Datetime"]}&username=admin";
|
|
|
|
if($value['rpt_name'] == 'Rontgen')
|
|
$rontgen[] = "/birt/run?__report=report/one/lab/rpt_hasil_so_xray_eng.rptdesign&__format=pdf&PID={$value["so_id"]}&tm={$value["Datetime"]}&username=admin";
|
|
|
|
if($value['rpt_name'] == 'Audiometri')
|
|
$audiometri = "/birt/run?__report=report/one/lab/rpt_hasil_so_audiometri_eng.rptdesign&__format=pdf&PID={$value["so_id"]}&tm={$value["Datetime"]}&username=admin";
|
|
|
|
if($value['rpt_name'] == 'Spirometri')
|
|
$spirometri = "/birt/run?__report=report/one/lab/rpt_hasil_so_spirometri_eng.rptdesign&__format=pdf&PID={$value["so_id"]}&tm={$value["Datetime"]}&username=admin";
|
|
|
|
if($value['rpt_name'] == 'ECG')
|
|
$ekg = "/birt/run?__report=report/one/lab/rpt_hasil_so_ecg_eng.rptdesign&__format=pdf&PID={$value["so_id"]}&tm={$value["Datetime"]}&username=admin";
|
|
|
|
if($value['rpt_name'] == 'Treadmill'){
|
|
$treadmill = "/birt/run?__report=report/one/lab/rpt_hasil_so_treadmill_eng.rptdesign&__format=pdf&PID={$value["so_id"]}&tm={$value["Datetime"]}&username=admin";
|
|
$sql = "SELECT *
|
|
FROM t_nonlabdocument
|
|
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_NonlabDocumentT_OrderHeaderID AND
|
|
T_NonlabDocumentT_SamplingSoID = T_SamplingSoID AND T_SamplingSoIsActive = 'Y'
|
|
JOIN t_test ON T_SamplingSoT_TestID = T_TestID AND T_TestID in (1651)
|
|
WHERE T_NonlabDocumentT_OrderHeaderID = ? AND
|
|
T_NonlabDocumentIsActive = 'Y' ";
|
|
$qry = $this->db->query($sql, [$orderHeaderID]);
|
|
// echo $this->db->last_query();
|
|
if ($qry) {
|
|
$rows_attachment = $qry->result_array();
|
|
if(count($rows_attachment) > 0){
|
|
foreach ($rows_attachment as $key => $value) {
|
|
$treadmill_attachment[] = '/one-media/one-document-nonlab/'.$value['T_NonlabDocumentFile'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if($value['rpt_name'] == 'Papsmear')
|
|
$papsmear = "/birt/run?__report=report/one/lab/rpt_test_papsmear_eng.rptdesign&__format=pdf&PID={$value["order_id"]}&tm={$value["Datetime"]}&username=admin";
|
|
|
|
if($value['rpt_name'] == 'Mikro')
|
|
$mikro = "/birt/run?__report=report/one/lab/rpt_test_mikro_eng.rptdesign&__format=pdf&PID={$value["order_id"]}&tm={$value["Datetime"]}&username=admin";
|
|
|
|
if($value['group_name'] == 'USG')
|
|
$usg[] = "/birt/run?__report=report/one/lab/rpt_hasil_so_usg_eng.rptdesign&__format=pdf&PID={$value["so_id"]}&tm={$value["Datetime"]}&username=admin";
|
|
|
|
if($value['rpt_name'] == 'SDS' && intval($value["so_id"]) > 0){
|
|
$sql_type = "SELECT So_ResultEntrySDSTypeValue as xtype
|
|
FROM so_resultentrysds_type
|
|
WHERE So_ResultEntrySDSTypeSo_ResultEntryID = ?
|
|
AND So_ResultEntrySDSTypeIsActive = 'Y' LIMIT 1";
|
|
$qry_type = $this->db->query($sql_type, [$value["so_id"]]);
|
|
if ($qry_type) {
|
|
//https://devcpone.aplikasi.web.id/birt/run?__report=report/one/lab/rpt_hasil_so_sds.rptdesign&__format=pdf&username=hrdisuzu@gmail.com&PID=9196&PType=30&tm=240926151412
|
|
$type_rpt = $qry_type->row()->xtype;
|
|
$sds = "/birt/run?__report=report/one/lab/rpt_hasil_so_sds_eng.rptdesign&__format=pdf&PID={$value["so_id"]}&PType={$type_rpt}&tm={$value["Datetime"]}&username=admin";
|
|
}
|
|
}
|
|
|
|
if($value['rpt_name'] == 'Test Kebugaran')
|
|
$kebugaran = "/birt/run?__report=report/one/lab/rpt_hasil_so_layanan_eng.rptdesign&__format=pdf&PID={$value["so_id"]}&tm={$value["Datetime"]}&username=admin";
|
|
}
|
|
|
|
$sql_resume = "SELECT
|
|
Mcu_ResumeID,
|
|
DATE_FORMAT(NOW(), '%y%m%d%H%i%s') AS Datetime
|
|
FROM mcu_resume
|
|
WHERE Mcu_ResumeT_OrderHeaderID = ?
|
|
AND Mcu_ResumeIsActive = 'Y' AND Mcu_ResumeStatus = 'VAL'";
|
|
$qry_resume = $this->db->query($sql_resume, [$orderHeaderID]);
|
|
if ($qry_resume) {
|
|
$row_resume = $qry_resume->result_array();
|
|
} else {
|
|
$this->sys_error_db("error get resume id", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$kesimpulan_saran = "";
|
|
$cover_rpt = "";
|
|
|
|
$file_cover = "rpt_mcu_resume_cover_eng";
|
|
|
|
$sql = "SELECT M_CoverRpt as file_cover, M_CoverRptLogo as file_logo, M_CoverRptEng as file_eng
|
|
FROM t_orderheader
|
|
JOIN mgm_cover ON T_OrderHeaderMgm_McuID = Mgm_CoverMgm_McuID AND Mgm_CoverIsActive = 'Y'
|
|
JOIN m_cover ON Mgm_CoverM_CoverCode = M_CoverCode AND M_CoverIsActive = 'Y'
|
|
WHERE T_OrderHeaderID = ?
|
|
LIMIT 1";
|
|
$qry_cover = $this->db->query($sql, [$orderHeaderID]);
|
|
if ($qry_cover) {
|
|
$row_cover = $qry_cover->result_array();
|
|
if(count($row_cover) > 0){
|
|
$file_cover = $row_cover[0]['file_eng'];
|
|
}
|
|
}
|
|
|
|
|
|
## resume ID
|
|
foreach ($row_resume as $key => $value) {
|
|
$kesimpulan_saran = "/birt/run?__report=report/one/mcu/rpt_mcu_saran_kesimpulan_v2_eng.rptdesign&__format=pdf&username=admin&PID={$value["Mcu_ResumeID"]}&tm={$value["Datetime"]}";
|
|
$cover_rpt = "/birt/run?__report=report/one/mcu/".$file_cover.".rptdesign&__format=pdf&username=admin&PID={$value["Mcu_ResumeID"]}&tm={$value["Datetime"]}";
|
|
}
|
|
|
|
$additional = "";
|
|
if($fisik == ""){
|
|
$sql = "SELECT *
|
|
FROM t_orderdetail
|
|
JOIN so_resultentry ON So_ResultEntryT_OrderDetailID = T_OrderDetailID AND So_ResultEntryIsActive = 'Y'
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = ? AND T_OrderDetailIsActive = 'Y' AND T_OrderDetailT_TestID IN (2571,2573,2573,3450,2572)
|
|
LIMIT 1";
|
|
$qry_additional = $this->db->query($sql, [$orderHeaderID]);
|
|
if ($qry_additional) {
|
|
$rows_addtional = $qry_additional->result_array();
|
|
//print_r($rows_addtional);
|
|
if(count($rows_addtional) > 0){
|
|
$id_additional = $rows_addtional[0]['So_ResultEntryID'];
|
|
$additional = "/birt/run?__report=report/one/mcu/mcu_fisik_ttbbmata_portal.rptdesign&__format=pdf&username=admin&PType=fisik&PID={$id_additional}&PLang=1&tm={$value["Datetime"]}";
|
|
}
|
|
|
|
} else {
|
|
$this->sys_error_db("error get addtional", $this->db);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT *
|
|
FROM t_nonlabdocument
|
|
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_NonlabDocumentT_OrderHeaderID AND
|
|
T_NonlabDocumentT_SamplingSoID = T_SamplingSoID AND T_SamplingSoIsActive = 'Y'
|
|
JOIN t_test ON T_SamplingSoT_TestID = T_TestID AND T_TestID NOT IN (1651)
|
|
WHERE T_NonlabDocumentT_OrderHeaderID = ? AND T_NonlabDocumentIsActive = 'Y'
|
|
GROUP BY T_SamplingSoID";
|
|
$qry_nonlabdocument = $this->db->query($sql, [$orderHeaderID]);
|
|
if ($qry_nonlabdocument) {
|
|
$rows_nonlabdocument = $qry_nonlabdocument->result_array();
|
|
} else {
|
|
$this->sys_error_db("error get nonlabdocument", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$prefix = "http://localhost";
|
|
$prefix = "https://".$_SERVER['SERVER_NAME'];
|
|
$list_rpt = array();
|
|
|
|
if ($cover_rpt != "") {
|
|
$list_rpt[] = $prefix . $cover_rpt;
|
|
}
|
|
if(count($attachments) > 0){
|
|
foreach ($attachments as $key => $value) {
|
|
$list_rpt[] = $prefix."/one-media/one-files/".$value['fname'];
|
|
}
|
|
}
|
|
if ($fisik != "") {
|
|
$list_rpt[] = $prefix . $fisik;
|
|
}
|
|
if(count($rontgen) > 0){
|
|
foreach ($rontgen as $key => $value) {
|
|
$list_rpt[] = $prefix . $value;
|
|
}
|
|
}
|
|
/*if ($usg_abdomen != "") {
|
|
$list_rpt[] = $prefix . $usg_abdomen;
|
|
}*/
|
|
if(count($usg) > 0){
|
|
foreach ($usg as $key => $value) {
|
|
$list_rpt[] = $prefix . $value;
|
|
}
|
|
}
|
|
if ($ekg != "") {
|
|
$list_rpt[] = $prefix . $ekg;
|
|
}
|
|
if ($audiometri != "") {
|
|
$list_rpt[] = $prefix . $audiometri;
|
|
}
|
|
if ($spirometri != "") {
|
|
$list_rpt[] = $prefix . $spirometri;
|
|
}
|
|
if ($treadmill != "") {
|
|
$list_rpt[] = $prefix . $treadmill;
|
|
if(count($treadmill_attachment) > 0){
|
|
foreach ($treadmill_attachment as $key => $value) {
|
|
$list_rpt[] = $prefix . $value;
|
|
}
|
|
}
|
|
}
|
|
if ($sds != "") {
|
|
$list_rpt[] = $prefix . $sds;
|
|
}
|
|
if ($kebugaran != "") {
|
|
$list_rpt[] = $prefix . $kebugaran;
|
|
}
|
|
if ($kesimpulan_saran != "" && $tanpa_kesimpulan == "N") {
|
|
$list_rpt[] = $prefix . $kesimpulan_saran;
|
|
}
|
|
if ($lab != "") {
|
|
$list_rpt[] = $prefix . $lab;
|
|
}
|
|
if ($papsmear != "") {
|
|
$list_rpt[] = $prefix . $papsmear;
|
|
}
|
|
if ($mikro != "") {
|
|
$list_rpt[] = $prefix . $mikro;
|
|
}
|
|
|
|
if ($additional != "") {
|
|
$list_rpt[] = $prefix . $additional;
|
|
}
|
|
|
|
if(count($rows_nonlabdocument) > 0){
|
|
foreach ($rows_nonlabdocument as $key => $value) {
|
|
$list_rpt[] = $prefix . "/one-media/one-document-nonlab/".$value['T_NonlabDocumentFile'];
|
|
}
|
|
}
|
|
|
|
//echo json_encode($list_rpt);
|
|
//print_r($list_rpt);
|
|
//exit;
|
|
|
|
if($debug == 'Y'){
|
|
print_r($rows_nonlabdocument);
|
|
exit;
|
|
foreach ($list_rpt as $key => $value) {
|
|
echo "<a href='".$value."' target='_blank'>".$value."</a><br>";
|
|
}
|
|
exit;
|
|
}
|
|
|
|
|
|
$merge_input = array(
|
|
"output" => "test.pdf",
|
|
"input" => $list_rpt
|
|
);
|
|
$jsonData = json_encode($merge_input);
|
|
|
|
// Initialize cURL session
|
|
$target_pdf = "https://".$_SERVER['SERVER_NAME']."/one-api/tools/merge_pdf/merge";
|
|
//echo $target_pdf ;
|
|
$response = $this->post($target_pdf, $jsonData);
|
|
$output_file_name = $lab_number . "_" . str_replace(" ", "_", $patient_name) . ".pdf";
|
|
header("Content-type: application/pdf");
|
|
header(
|
|
'Content-Disposition: inline; filename="' .
|
|
$output_file_name .
|
|
'"'
|
|
);
|
|
echo ($response);
|
|
|
|
// $this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
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_VERBOSE, true);
|
|
curl_setopt(
|
|
$ch,
|
|
CURLOPT_HTTPHEADER,
|
|
array(
|
|
'Content-Type: application/json',
|
|
'Content-Length: ' . strlen($data)
|
|
)
|
|
);
|
|
$result = curl_exec($ch);
|
|
return $result;
|
|
}
|
|
}
|