563 lines
17 KiB
PHP
563 lines
17 KiB
PHP
<?php
|
|
|
|
class Ucopy_v2 extends MY_Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function get_data($sql)
|
|
{
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
echo json_encode([
|
|
"status" => "ERR",
|
|
"message" =>
|
|
"Order ERR:" .
|
|
$this->db->error()["message"] .
|
|
"|" .
|
|
$this->db->last_query(),
|
|
]);
|
|
exit();
|
|
}
|
|
$result = $qry->result_array();
|
|
return $result;
|
|
}
|
|
|
|
public function db()
|
|
{
|
|
if (true) {
|
|
ini_set("display_errors", 1);
|
|
ini_set("display_startup_errors", 1);
|
|
error_reporting(E_ALL);
|
|
}
|
|
//M_BranchCode
|
|
$sql =
|
|
"select * from m_branch where M_BranchIsActive='Y' and M_BranchIsDefault='Y'";
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
echo json_encode([
|
|
"status" => "ERR",
|
|
"message" =>
|
|
"M Branch Code ERR:" . $this->db->error()["message"],
|
|
]);
|
|
exit();
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0) {
|
|
echo json_encode([
|
|
"status" => "ERR",
|
|
"message" => "M Branch Code ",
|
|
]);
|
|
exit();
|
|
}
|
|
$branch = $rows[0];
|
|
//mcu code
|
|
$sql = "select * from mcu_offline_prepare";
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
echo json_encode([
|
|
"status" => "ERR",
|
|
"message" => "MCU Code ERR:" . $this->db->error()["message"],
|
|
]);
|
|
exit();
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0) {
|
|
echo json_encode([
|
|
"status" => "ERR",
|
|
"message" => "MCU Code No Record ",
|
|
]);
|
|
exit();
|
|
}
|
|
$McuCode = $rows[0]["McuOfflinePrepareCode"];
|
|
$mcuOfflinePrepares = $rows[0];
|
|
|
|
//mcu screening
|
|
$sql = "select * from mcu_screening where Mcu_ScreeningIsActive='Y'";
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
echo json_encode([
|
|
"status" => "ERR",
|
|
"message" =>
|
|
"MCU Screening ERR:" . $this->db->error()["message"],
|
|
]);
|
|
exit();
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0) {
|
|
echo json_encode([
|
|
"status" => "ERR",
|
|
"message" => "MCU Screening No Record ",
|
|
]);
|
|
exit();
|
|
}
|
|
$mcuScreening = $rows;
|
|
|
|
//last master id
|
|
$sql = "select * from last_master_id";
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
echo json_encode([
|
|
"status" => "ERR",
|
|
"message" => "Last Master ERR:" . $this->db->error()["message"],
|
|
]);
|
|
exit();
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0) {
|
|
echo json_encode([
|
|
"status" => "ERR",
|
|
"message" => "Last Master No Record ",
|
|
]);
|
|
exit();
|
|
}
|
|
$TheLastMaster = $rows[0];
|
|
|
|
//ambil order_header
|
|
$sql = "select distinct t_orderheader.*
|
|
from t_orderheader
|
|
join mcu_screening
|
|
on T_OrderHeaderIsActive='Y'
|
|
and Mcu_ScreeningIsActive = 'Y'
|
|
and T_OrderHeaderID = Mcu_ScreeningT_OrderHeaderID
|
|
";
|
|
$orders = $this->get_data($sql);
|
|
|
|
$x_ids = "-1";
|
|
$x_patient_ids = "-1";
|
|
foreach ($orders as $r) {
|
|
$x_ids .= "," . $r["T_OrderHeaderID"];
|
|
$x_patient_ids .= "," . $r["T_OrderHeaderM_PatientID"];
|
|
}
|
|
|
|
$sql = "select * from t_orderheaderaddon
|
|
where T_OrderHeaderAddOnT_OrderHeaderID in ($x_ids)";
|
|
$header_addon = $this->get_data($sql);
|
|
|
|
//ambil order_detail
|
|
$sql = "select * from t_orderdetail
|
|
where T_OrderDetailIsActive = 'Y'
|
|
and T_OrderDetailT_OrderHeaderID in ( $x_ids ) ";
|
|
$details = $this->get_data($sql);
|
|
//order detail addon
|
|
|
|
$sql = "select t_orderdetailaddon.*
|
|
from t_orderdetailaddon
|
|
join t_orderdetail on T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID
|
|
and T_OrderDetailT_OrderHeaderID in ($x_ids)";
|
|
$detail_addon = $this->get_data($sql);
|
|
foreach ($details as $idx => $d) {
|
|
$orderDetailID = $d["T_OrderDetailID"];
|
|
foreach ($detail_addon as $addon) {
|
|
if (
|
|
$orderDetailID ==
|
|
$addon["T_OrderDetailAddOnT_OrderDetailID"]
|
|
) {
|
|
if (!isset($details["idx"]["addon"])) {
|
|
$details[$idx]["addon"] = [];
|
|
}
|
|
$details[$idx]["addon"][] = $addon;
|
|
}
|
|
}
|
|
}
|
|
|
|
//last_status_payment
|
|
$sql = "select * from last_statuspayment where Last_StatusPaymentT_OrderHeaderID
|
|
in ( $x_ids )";
|
|
$last_status_payment = $this->get_data($sql);
|
|
|
|
//fo status
|
|
$sql = "select * from fo_status where Fo_StatusT_OrderHeaderID
|
|
in ( $x_ids )";
|
|
$fo_status = $this->get_data($sql);
|
|
|
|
//t_orderdelivery
|
|
$sql = "select * from t_orderdelivery where T_OrderDeliveryT_OrderHeaderID
|
|
in ( $x_ids )";
|
|
$order_delivery = $this->get_data($sql);
|
|
$x_delivery_ids = "-1";
|
|
foreach ($order_delivery as $d) {
|
|
$x_delivery_ids .= ", " . $d["T_OrderDeliveryID"];
|
|
}
|
|
$sql = "select * from t_orderdeliverynote where T_OrderDeliveryNoteT_OrderDeliveryID
|
|
in ( $x_delivery_ids )";
|
|
$order_delivery_note = $this->get_data($sql);
|
|
|
|
//t_orderreq
|
|
$sql = "select * from t_orderreq where T_OrderReqT_OrderHeaderID
|
|
in ( $x_ids )";
|
|
$order_req = $this->get_data($sql);
|
|
|
|
//t_orderpromise
|
|
$sql = "select * from t_orderpromise where T_OrderPromiseT_OrderHeaderID
|
|
in ( $x_ids )";
|
|
$order_promise = $this->get_data($sql);
|
|
|
|
//order_log
|
|
$sql = "select * from order_log where OrderLogT_OrderHeaderID
|
|
in ( $x_ids )";
|
|
$order_log = $this->get_data($sql);
|
|
|
|
//order_attr
|
|
$sql = "select * from order_attr where OrderAttrT_OrderHeaderID
|
|
in ( $x_ids )";
|
|
$order_attr = $this->get_data($sql);
|
|
|
|
//order_px
|
|
$sql = "select * from order_px where OrderPxT_OrderHeaderID
|
|
in ( $x_ids )";
|
|
$order_px = $this->get_data($sql);
|
|
|
|
//last_status
|
|
$sql = "select * from last_status where Last_StatusT_OrderHeaderID
|
|
in ( $x_ids )";
|
|
$last_status = $this->get_data($sql);
|
|
|
|
foreach ($orders as $idx => $o) {
|
|
$headerID = $o["T_OrderHeaderID"];
|
|
$orders[$idx]["detail"] = $this->get_children(
|
|
$headerID,
|
|
"T_OrderDetailT_OrderHeaderID",
|
|
$details
|
|
);
|
|
$orders[$idx]["addon"] = $this->get_children(
|
|
$headerID,
|
|
"T_OrderHeaderAddOnT_OrderHeaderID",
|
|
$header_addon
|
|
);
|
|
$orders[$idx]["last_status_payment"] = $this->get_children(
|
|
$headerID,
|
|
"Last_StatusPaymentT_OrderHeaderID",
|
|
$last_status_payment
|
|
);
|
|
$orders[$idx]["fo_status"] = $this->get_children(
|
|
$headerID,
|
|
"Fo_StatusT_OrderHeaderID",
|
|
$fo_status
|
|
);
|
|
$orders[$idx]["t_orderdelivery"] = $this->get_children(
|
|
$headerID,
|
|
"T_OrderDeliveryT_OrderHeaderID",
|
|
$order_delivery
|
|
);
|
|
$delivery_notes = [];
|
|
foreach ($orders[$idx]["t_orderdelivery"] as $d) {
|
|
$x_notes = $this->get_children(
|
|
$d["T_OrderDeliveryID"],
|
|
"T_OrderDeliveryNoteT_OrderDeliveryID",
|
|
$order_delivery_note
|
|
);
|
|
$delivery_notes = array_merge($delivery_notes, $x_notes);
|
|
}
|
|
$orders[$idx]["t_orderdeliverynote"] = $delivery_notes;
|
|
|
|
$orders[$idx]["t_orderreq"] = $this->get_children(
|
|
$headerID,
|
|
"T_OrderReqT_OrderHeaderID",
|
|
$order_req
|
|
);
|
|
$orders[$idx]["t_orderpromise"] = $this->get_children(
|
|
$headerID,
|
|
"T_OrderPromiseT_OrderHeaderID",
|
|
$order_promise
|
|
);
|
|
$orders[$idx]["order_log"] = $this->get_children(
|
|
$headerID,
|
|
"OrderLogT_OrderHeaderID",
|
|
$order_log
|
|
);
|
|
$orders[$idx]["order_attr"] = $this->get_children(
|
|
$headerID,
|
|
"orderAttrT_OrderHeaderID",
|
|
$order_attr
|
|
);
|
|
$orders[$idx]["order_px"] = $this->get_children(
|
|
$headerID,
|
|
"OrderPxT_OrderHeaderID",
|
|
$order_px
|
|
);
|
|
|
|
$orders[$idx]["last_status"] = $this->get_children(
|
|
$headerID,
|
|
"Last_StatusT_OrderHeaderID",
|
|
$last_status
|
|
);
|
|
}
|
|
|
|
//ambil patient
|
|
$sql = "select * from m_patient where M_PatientID in ($x_patient_ids)";
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
echo json_encode([
|
|
"status" => "ERR",
|
|
"message" => "Patient ERR:" . $this->db->error()["message"],
|
|
]);
|
|
exit();
|
|
}
|
|
$patients = $qry->result_array();
|
|
$sql = "select * from m_patientaddress where M_PatientAddressM_PatientID in ($x_patient_ids)";
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
echo json_encode([
|
|
"status" => "ERR",
|
|
"message" =>
|
|
"Patient Detail ERR:" . $this->db->error()["message"],
|
|
]);
|
|
exit();
|
|
}
|
|
$address = $qry->result_array();
|
|
foreach ($patients as $idx => $p) {
|
|
$patientID = $p["M_PatientID"];
|
|
foreach ($address as $addr) {
|
|
if ($addr["M_PatientAddressM_PatientID"] == $patientID) {
|
|
if (!isset($patients[$idx]["address"])) {
|
|
$patients[$idx]["address"] = [];
|
|
}
|
|
$patients[$idx]["address"][] = $addr;
|
|
}
|
|
}
|
|
}
|
|
|
|
//payment
|
|
|
|
$log_tables = ["log_patient", "log_fostatus", "log_fo"];
|
|
|
|
$log_data = $this->get_log($log_tables);
|
|
|
|
$result = [
|
|
"branch" => $branch,
|
|
"mcuCode" => $McuCode,
|
|
"mcu_offline_prepare" => $mcuOfflinePrepares,
|
|
"mcu_screening" => $mcuScreening,
|
|
"last_master" => $TheLastMaster,
|
|
"order" => $orders,
|
|
"patient" => $patients,
|
|
"logs" => $log_data,
|
|
"payment" => $this->get_payment(),
|
|
"fo_verif" => $this->get_fo_verif(),
|
|
"spec_col" => $this->get_spec_col(),
|
|
"spec_ver" => $this->get_spec_ver(),
|
|
"sample_handling" => $this->get_sample_handling(),
|
|
"rad_pasien_handling" => $this->get_rad_pasien_handling(),
|
|
"rad_image_verif" => $this->get_rad_image_verif(),
|
|
"rad_image_handling" => $this->get_rad_image_handling(),
|
|
"rad_dok_hasil" => $this->get_rad_dok_hasil(),
|
|
"rad_verif_hasil" => $this->get_rad_verif_hasil(),
|
|
// elektromedis idem radiologi
|
|
"worklist" => $this->get_worklist(),
|
|
"result" => $this->get_result(),
|
|
];
|
|
|
|
$content = json_encode($result);
|
|
//$z_content = gzcompress($content,9);
|
|
$z_content = gzencode($content, 9);
|
|
$fname = $McuCode . "_" . date("Y-m-d-H") . ".json.gz";
|
|
|
|
header("Content-Description: File Transfer");
|
|
header("Content-Type: application/octet-stream");
|
|
header('Content-Disposition: attachment; filename="' . $fname . '"');
|
|
header("Expires: 0");
|
|
header("Cache-Control: must-revalidate");
|
|
header("Pragma: public");
|
|
header("Content-Length: " . strlen($z_content));
|
|
echo $z_content;
|
|
}
|
|
|
|
public function get_result()
|
|
{
|
|
$tables = ["pre_analytic", "t_worklist_confirm"];
|
|
$result = [];
|
|
$result["data"] = $this->get_table($tables);
|
|
|
|
$logs = ["log_process"];
|
|
$result["log"] = $this->get_log($logs);
|
|
return $result;
|
|
}
|
|
|
|
public function get_worklist()
|
|
{
|
|
$tables = ["pre_analytic", "t_worklist_confirm"];
|
|
$result = [];
|
|
$result["data"] = $this->get_table($tables);
|
|
|
|
$logs = ["log_worklist"];
|
|
$result["log"] = $this->get_log($logs);
|
|
return $result;
|
|
}
|
|
|
|
public function get_rad_verif_hasil()
|
|
{
|
|
$tables = ["result_verifications_value", "result_verification_by_step"];
|
|
$result = [];
|
|
$result["data"] = $this->get_table($tables);
|
|
|
|
$logs = ["log_result_verifications_value"];
|
|
$result["log"] = $this->get_log($logs);
|
|
return $result;
|
|
}
|
|
|
|
public function get_rad_dok_hasil()
|
|
{
|
|
$tables = [""];
|
|
$result = [];
|
|
$result["data"] = $this->get_table($tables);
|
|
|
|
$logs = ["log_resultentry_so"];
|
|
$result["log"] = $this->get_log($logs);
|
|
return $result;
|
|
}
|
|
|
|
public function get_rad_image_handling()
|
|
{
|
|
$tables = ["snap_doctor_fee"];
|
|
$result = [];
|
|
$result["data"] = $this->get_table($tables);
|
|
|
|
$logs = [];
|
|
$result["log"] = $this->get_log($logs);
|
|
return $result;
|
|
}
|
|
|
|
public function get_rad_image_verif()
|
|
{
|
|
$tables = ["t_samplingso_film"];
|
|
$result = [];
|
|
$result["data"] = $this->get_table($tables);
|
|
|
|
$logs = [];
|
|
$result["log"] = $this->get_log($logs);
|
|
return $result;
|
|
}
|
|
public function get_rad_pasien_handling()
|
|
{
|
|
$tables = [
|
|
"t_samplingso",
|
|
"sample_so_by_step",
|
|
"so_resultentry",
|
|
"so_resultentrydetail",
|
|
"t_samplingso_requirement",
|
|
"t_samplingso_form",
|
|
"so_resultentrydetail_other",
|
|
"so_resultentry_fisik_umum"
|
|
];
|
|
$result = [];
|
|
$result["data"] = $this->get_table($tables);
|
|
|
|
$logs = ["log_sampling_queue_so", "log_sampling_so_form"];
|
|
$result["log"] = $this->get_log($logs);
|
|
return $result;
|
|
}
|
|
public function get_sample_handling()
|
|
{
|
|
$tables = [];
|
|
$result = [];
|
|
$result["data"] = $this->get_table($tables);
|
|
|
|
$logs = [];
|
|
$result["log"] = $this->get_log($logs);
|
|
return $result;
|
|
}
|
|
|
|
public function get_spec_ver()
|
|
{
|
|
$tables = [];
|
|
$result = [];
|
|
$result["data"] = $this->get_table($tables);
|
|
|
|
$logs = ["log_sample_req"];
|
|
$result["log"] = $this->get_log($logs);
|
|
return $result;
|
|
}
|
|
|
|
public function get_spec_col()
|
|
{
|
|
$tables = [
|
|
"t_sampling_queue_last_status",
|
|
"t_sampling_queue_by_action",
|
|
"helper_bahan",
|
|
"t_ordersamplereq",
|
|
];
|
|
$result = [];
|
|
$result["data"] = $this->get_table($tables);
|
|
$logs = ["log_sampling_queue"];
|
|
$result["log"] = $this->get_log($logs);
|
|
return $result;
|
|
}
|
|
|
|
public function get_fo_verif()
|
|
{
|
|
$tables = [
|
|
"fo_verificationsvalue",
|
|
"t_ordermessage",
|
|
"cr_order",
|
|
"t_barcodelab",
|
|
"t_ordersample",
|
|
"last_statussample",
|
|
"sample_by_step",
|
|
"helper_sst",
|
|
];
|
|
$result = [];
|
|
$result["data"] = $this->get_table($tables);
|
|
$logs = ["log_sample", "log_sample_order"];
|
|
$result["log"] = $this->get_log($logs);
|
|
return $result;
|
|
}
|
|
public function get_payment()
|
|
{
|
|
// f_payment
|
|
$tables = [
|
|
"f_payment",
|
|
"f_payment_test",
|
|
"f_payment_orderheader",
|
|
"f_payment_detail",
|
|
];
|
|
$result = [];
|
|
$result["data"] = $this->get_table($tables);
|
|
$logs = ["log_payment"];
|
|
$result["log"] = $this->get_log($logs);
|
|
return $result;
|
|
}
|
|
public function get_log($logs)
|
|
{
|
|
$result = [];
|
|
foreach ($logs as $log) {
|
|
$sql = "select * from one_log.{$log}";
|
|
$qry = $this->db->query($sql);
|
|
if ($qry) {
|
|
$result[$log] = $qry->result_array();
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
public function get_table($tables)
|
|
{
|
|
$result = [];
|
|
foreach ($tables as $tb) {
|
|
$sql = "select * from {$tb}";
|
|
$qry = $this->db->query($sql);
|
|
if ($qry) {
|
|
$result[$tb] = $qry->result_array();
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
public function get_children($parent_id, $child_field, $child)
|
|
{
|
|
$result = [];
|
|
foreach ($child as $d) {
|
|
if (isset($d[$child_field])) {
|
|
if ($parent_id == $d[$child_field]) {
|
|
$result[] = $d;
|
|
}
|
|
} else {
|
|
echo "Debug Err : Exit $child_field ";
|
|
print_r($d);
|
|
exit();
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
}
|