db->query($sql, [$companyID]); if (!$qry) { $this->reply_gz( json_encode([ "status" => "ERR", "message" => $this->db->error()["message"], ]) ); } $rows = $qry->result_array(); $this->reply_gz( json_encode([ "status" => "OK", "data" => $rows, ]) ); } function update_upload_mou() { $param = $this->get_param(); $uploadID = $param["uploadID"]; $status = $param["status"]; $sql = "update corp_upload set Corp_UploadStatus = ? , Corp_UploadRetry = Corp_UploadRetry+1 , Corp_UploadSentDate = now() where Corp_UploadID = ? "; $qry = $this->db->query($sql, [$status, $uploadID]); if (!$qry) { $this->reply_gz( json_encode([ "status" => "ERR", "message" => $this->db->error()["message"], ]) ); } $this->reply_gz( json_encode([ "status" => "OK", "message" => "", ]) ); } function get_upload_mou() { //Hardcode 1st //2277,2278,2279,2613 list($branchID, $branchCode) = $this->get_branch(); $sql = "select Corp_UploadID, Corp_UploadM_MouID M_MouID, M_MouM_CompanyID from corp_upload join m_mou on Corp_UploadM_MouID = M_MouID where Corp_UploadStatus <> 'Y' and Corp_UploadIsActive = 'Y' and Corp_UploadRetry < 5 limit 0,10 "; $resp = $this->get_rows($sql); if ($resp["status"] == -1) { $this->error_reply_gz($resp["message"]); } $result = []; foreach ($resp["data"] as $idx => $r) { $result[] = $r; } $data = json_encode(["status" => "OK", "data" => $result]); $this->reply_gz($data); } function mou_order($mouID) { list($branchID, $branchCode) = $this->get_branch(); // get order | pasien $sql = "select T_OrderHeaderID,T_OrderHeaderDate,T_OrderHeaderLabNumber,T_OrderHeaderLabNumberExt, T_OrderHeaderLastUpdated, max(ifnull(T_OrderDetailValDate,'1971-01-01 00:01:01')) LastValidationDate, max(ifnull(T_OrderDetailVerDate,'1971-01-01 00:01:01')) LastVerifDate, $branchID M_BranchID, '$branchCode' M_BranchCode, T_OrderHeaderM_PatientID, JSON_UNQUOTE( JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID),'$.patient_fullname')) FullName, JSON_UNQUOTE( JSON_EXTRACT(fn_get_patient_atribute(T_OrderHeaderM_PatientID),'$.M_PatientName')) M_PatientName, T_OrderHeaderM_CompanyID M_CompanyID, M_CompanyNumber, T_OrderHeaderM_MouID M_MouID, M_PatientNIK, M_PatientJabatan, M_PatientKedudukan, M_PatientLocation, M_PatientJob from t_orderheader join t_orderheaderaddon on T_OrderHeaderM_MouID = ? and T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID and T_OrderHeaderIsActive = 'Y' -- and T_OrderHeaderAddOnValidationDone = 'Y' join m_company on M_CompanyID = T_OrderHeaderM_CompanyID join m_patient on T_OrderHeaderM_PatientID = M_PatientID join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID group by T_OrderHeaderID"; $resp = $this->get_rows($sql, [$mouID]); if ($resp["status"] == -1) { $this->error_reply_gz( "Err Get Order for MOU ID : $mouID | " . $resp["message"] ); exit(); } $orders = $resp["data"]; echo $this->reply_gz( json_encode(["status" => "OK", "data" => $orders]) ); } //Get Detail Mou function mou_detail($mouID) { list($branchID, $branchCode) = $this->get_branch(); $sql = "select $branchID Corp_M_BranchID , '$branchCode' Corp_M_BranchCode, M_MouID, M_MouName, M_MouNote , M_CompanyNumber M_MouM_CompanyNumber, M_MouM_CompanyID , M_MouRefNumber , M_MouNumber , M_MouStartDate , M_MouEndDate , M_MouBase, M_MouM_OmzetTypeID , M_MouIsReleased , M_MouReleaseDate , M_MouReleaseUserID , M_MouCreated , M_MouLastUpdated , M_MouIsActive, M_MouUserID from m_mou join m_company on M_MouM_CompanyID = M_CompanyID where M_MouID = ?"; $resp = $this->get_row($sql, [$mouID]); if ($resp["status"] == -1) { $this->error_reply_gz($resp["message"]); } if ($resp["status"] == 0) { $this->error_reply_gz("Mou ID $mouID not found."); } $result = $resp["data"]; $this->reply_gz( json_encode(["status" => "OK", "data" => $resp["data"]]) ); } function reply_gz($resp) { echo gzcompress($resp); exit(); } function get_branch() { $sql = "select M_BranchID,M_BranchCode from m_branch where M_BranchIsActive='Y' and M_BranchIsDefault ='Y'"; $resp = $this->get_row($sql); if ($resp["status"] != 1) { echo json_encode($resp); exit(); } return [$resp["data"]["M_BranchID"], $resp["data"]["M_BranchCode"]]; } function log($msg) { $dt = date("Y-m-d H:i:s"); echo "$dt $msg\n"; } function error_reply_gz($msg) { echo gzcompress(json_encode(["status" => "ERR", "message" => $msg])); } function reply($resp, $type = 1) { echo json_encode($resp); } function error_reply($msg) { echo json_encode(["status" => "ERR", "message" => $msg]); } function get_mou_param($mouID) { $sql = "select M_MouM_CompanyID, M_MouStartDate, M_MouEndDate from m_mou where M_MouID = ?"; $resp = $this->get_row($sql, [$mouID]); if ($resp["status"] == -1) { $this->error_reply( "Err Get Mou Param from $mouID : " . $resp["message"] ); exit(); } if ($resp["status"] == 0) { return [0, "1971-01-01", "1971-01-01"]; } $r = $resp["data"]; return [ $r["M_MouM_CompanyID"], $r["M_MouStartDate"], $r["M_MouEndDate"], ]; } function getCompanyNumber($companyID) { $sql = "select M_CompanyNumber from m_company where M_CompanyID = ?"; $resp = $this->get_row($sql, [$companyID]); if ($resp["status"] == -1) { $this->error_reply( "Err Get Company from $companyID: " . $resp["message"] ); exit(); } if ($resp["status"] == 0) { return ""; } $r = $resp["data"]; return $r["M_CompanyNumber"]; } // function do_global($mouID) { list($branchID, $branchCode) = $this->get_branch(); $arr_sp = ["sp_rpt_nl_001_v2", "sp_rpt_nl_002_v2", "sp_rpt_nl_003_v2"]; list($companyID, $startDate, $endDate) = $this->get_mou_param($mouID); $companyNumber = $this->getCompanyNumber($companyID); $result = []; for ($idx = 0; $idx < 3; $idx++) { $sp = $arr_sp[$idx]; $key = str_replace("sp_", "", $sp); $key = str_replace("_v2", "", $key); $sql = "call {$sp}(?,?,?,?,'admin')"; $resp = $this->get_sp($sql, [ $startDate, $endDate, $companyID, $mouID, ]); if ($resp["status"] == -1) { $this->error_reply_gz("Err $sp : " . $resp["message"]); exit(); } $xresult = []; foreach ($resp["data"] as $r) { $r["M_CompanyNumber"] = $companyNumber; $r["M_BranchID"] = $branchID; $r["M_BranchCode"] = $branchCode; $xresult[] = $r; } $result[$key] = $xresult; } echo $this->reply_gz( json_encode([ "status" => "OK", "branchID" => $branchID, "branchCode" => $branchCode, "companyID" => $companyID, "result" => $result, ]) ); } function get_resume_id($headerID) { $sql = "select Mcu_ResumeID from mcu_resume where Mcu_ResumeT_OrderHeaderID = ? and Mcu_ResumeIsActive = 'Y' order by Mcu_ResumeID desc limit 0,1"; $resp = $this->get_row($sql, [$headerID]); if ($resp["status"] == -1) { $this->error_reply( "Err Get ResumeID from T_OrderHeaderID $headerID : " . $resp["message"] ); exit(); } if ($resp["status"] == 0) { return 0; } return $resp["data"]["Mcu_ResumeID"]; } function json_get_so_id($headerID, $so = "") { echo json_encode($this->get_so_result_entry_id($headerID, $so)); } function get_so_result_entry_id($headerID, $so = "", $debug = "") { $sql = "select So_ResultEntryID from so_resultentry join t_orderdetail on T_OrderDetailID = So_ResultEntryT_OrderDetailID join t_test on T_OrderDetailT_TestID = T_TestID and T_TestNat_GroupID = 4 and T_TestIsNonLab = 'FISIK UMUM' where So_ResultEntryT_OrderHeaderID = ? and So_ResultentryIsActive = 'Y' order by So_ResultEntryID desc limit 0,1"; if ($so == "audio") { $sql = "select So_ResultEntryID from so_resultentry join t_orderdetail on T_OrderDetailID = So_ResultEntryT_OrderDetailID join t_test on T_OrderDetailT_TestID = T_TestID and T_TestNat_GroupID = 2 and T_TestIsNonLab = 'AUDIOMETRY' where So_ResultEntryT_OrderHeaderID = ? and So_ResultentryIsActive = 'Y' order by So_ResultEntryID desc limit 0,1"; } elseif ($so == "ecg") { $sql = "select So_ResultEntryID from so_resultentry join t_orderdetail on T_OrderDetailID = So_ResultEntryT_OrderDetailID join t_test on T_OrderDetailT_TestID = T_TestID and T_TestNat_GroupID = 2 and T_TestIsNonLab = 'ELECTROMEDIS' where So_ResultEntryT_OrderHeaderID = ? and So_ResultentryIsActive = 'Y' order by So_ResultEntryID desc limit 0,1"; } elseif ($so == "treadmill") { $sql = "select So_ResultEntryID from so_resultentry join t_orderdetail on T_OrderDetailID = So_ResultEntryT_OrderDetailID join t_test on T_OrderDetailT_TestID = T_TestID and T_TestNat_GroupID = 2 and T_TestIsNonLab = 'TREADMILL' where So_ResultEntryT_OrderHeaderID = ? and So_ResultentryIsActive = 'Y' order by So_ResultEntryID desc limit 0,1"; } elseif ($so == "elmd") { $sql = "select So_ResultEntryID from so_resultentry join t_orderdetail on T_OrderDetailID = So_ResultEntryT_OrderDetailID join t_test on T_OrderDetailT_TestID = T_TestID and T_TestNat_GroupID = 2 where So_ResultEntryT_OrderHeaderID = ? and So_ResultentryIsActive = 'Y' order by So_ResultEntryID desc limit 0,1"; } elseif ($so == "usg") { $sql = "select So_ResultEntryID from so_resultentry join t_orderdetail on T_OrderDetailID = So_ResultEntryT_OrderDetailID join t_test on T_OrderDetailT_TestID = T_TestID and T_TestNat_GroupID = 3 and T_TestNat_SubGroupID = 22 where So_ResultEntryT_OrderHeaderID = ? and So_ResultentryIsActive = 'Y' order by So_ResultEntryID desc limit 0,1"; } elseif ($so == "manthoux") { $sql = "select So_ResultEntryID from so_resultentry join t_orderdetail on T_OrderDetailID = So_ResultEntryT_OrderDetailID join t_test on T_OrderDetailT_TestID = T_TestID and T_TestNat_GroupID = 1 and T_TestNat_SubGroupID = 10 where So_ResultEntryT_OrderHeaderID = ? and So_ResultentryIsActive = 'Y' order by So_ResultEntryID desc limit 0,1"; } elseif ($so == "pajanan") { $sql = "select So_ResultEntryID from so_resultentry join t_orderdetail on T_OrderDetailID = So_ResultEntryT_OrderDetailID join t_test on T_OrderDetailT_TestID = T_TestID and T_TestNat_GroupID = 4 where So_ResultEntryT_OrderHeaderID = ? and So_ResultentryIsActive = 'Y' and So_ResultEntrySo_TemplateName = 'FISIK UMUM K3' order by So_ResultEntryID desc limit 0,1"; } elseif ($so == "fisik") { $sql = "select So_ResultEntryID from so_resultentry join t_orderdetail on T_OrderDetailID = So_ResultEntryT_OrderDetailID join t_test on T_OrderDetailT_TestID = T_TestID and T_TestNat_GroupID = 4 where So_ResultEntryT_OrderHeaderID = ? and So_ResultentryIsActive = 'Y' and So_ResultEntrySo_TemplateName in ('FISIK UMUM', 'FISIK UMUM KONSUL' ) order by So_ResultEntryID desc limit 0,1"; } $resp = $this->get_row($sql, [$headerID]); if ($debug != "") { echo $this->db->last_query(); } if ($resp["status"] == -1) { $this->error_reply( "Err Get ResumeID from T_OrderHeaderID $headerID : " . $resp["message"] ); exit(); } if ($resp["status"] == 0) { return 0; } if ($debug != "") { echo json_encode($resp); } return $resp["data"]["So_ResultEntryID"]; } // Hasil lab per individu // Hasil Non Lab per individu // Hasil Resume Individu // by T_OrderHeaderID function get_report($uploadID = "", $debug = "") { // $sql = "select Corp_ReportCode // from // corp_report // join corp_uploaderdetail on // Corp_UploaderDetailCorp_ReportID = Corp_ReportID // and Corp_UploaderDetailCorp_UploadID = ?"; // $qry = $this->db->query($sql, [$uploadID]); // if (!$qry) { // $this->reply_gz( // json_encode([ // "status" => "ERR", // "message" => // "Error get Reports : " . $this->db->error()["message"], // ]) // ); // } // $rows = $qry->result_array(); $result = []; //pasti ikut $result[] = "sp_rpt_t_hasil_sampling"; $result[] = "sp_rpt_t_hasil_sampling_eng"; $result[] = "sp_rpt_t_hasil_so"; $result[] = "sp_rpt_t_hasil2"; $result[] = "sp_rpt_t_hasil_eng"; $result[] = "sp_rpt_t_hasil_so_xray"; $result[] = "sp_rpt_t_hasil_so_elmd"; $result[] = "sp_rpt_mcu_resume_cp_r"; $result[] = "sp_rpt_mcu_resume_cp_r_eng"; $result[] = "sp_dummy_fisik"; $result[] = "sp_rpt_t_hasil_so_elmd-audio"; $result[] = "sp_rpt_t_hasil_so_elmd-ecg"; $result[] = "sp_rpt_t_hasil_so_elmd-treadmill"; $result[] = "sp_dummy_pajanan"; // foreach ($rows as $r) { // $rpt_code = $r["Corp_ReportCode"]; // switch ($rpt_code) { // case "001": // if (!in_array("sp_rpt_t_hasil2", $result)) { // $result[] = "sp_rpt_t_hasil2"; // } // break; // case "002": // if (!in_array("sp_rpt_t_hasil_eng", $result)) { // $result[] = "sp_rpt_t_hasil_eng"; // } // break; // case "003": // if (!in_array("sp_rpt_t_hasil_so", $result)) { // $result[] = "sp_rpt_t_hasil_so"; // } // if (!in_array("sp_rpt_t_hasil_so_xray", $result)) { // $result[] = "sp_rpt_t_hasil_so_xray"; // } // break; // case "004": // if (!in_array("sp_rpt_t_hasil_so", $result)) { // $result[] = "sp_rpt_t_hasil_so"; // } // if (!in_array("sp_rpt_t_hasil_so_elmd", $result)) { // $result[] = "sp_rpt_t_hasil_so_elmd"; // } // break; // case "005": // if (!in_array("sp_rpt_t_hasil_so", $result)) { // $result[] = "sp_rpt_t_hasil_so"; // } // if (!in_array("sp_rpt_mcu_resume_cp_r", $result)) { // $result[] = "sp_rpt_mcu_resume_cp_r"; // } // if (!in_array("sp_rpt_mcu_resume_cp_r_eng", $result)) { // $result[] = "sp_rpt_mcu_resume_cp_r_eng"; // } // break; // case "006": // if (!in_array("sp_rpt_t_hasil_so", $result)) { // $result[] = "sp_rpt_t_hasil_so"; // } // if (!in_array("sp_rpt_mcu_resume_cp_r", $result)) { // $result[] = "sp_rpt_mcu_resume_cp_r"; // } // if (!in_array("sp_rpt_mcu_resume_cp_r_eng", $result)) { // $result[] = "sp_rpt_mcu_resume_cp_r_eng"; // } // break; // case "007": // if (!in_array("sp_rpt_t_hasil_so", $result)) { // $result[] = "sp_rpt_t_hasil_so"; // } // if (!in_array("sp_rpt_mcu_resume_cp_r", $result)) { // $result[] = "sp_rpt_mcu_resume_cp_r"; // } // if (!in_array("sp_rpt_mcu_resume_cp_r_eng", $result)) { // $result[] = "sp_rpt_mcu_resume_cp_r_eng"; // } // break; // case "008": // case "009": // if (!in_array("riw", $result)) { // $result[] = "sp_dummy_fisik"; // } // break; // case "010": //audio // if (!in_array("sp_rpt_t_hasil_so", $result)) { // $result[] = "sp_rpt_t_hasil_so"; // } // if (!in_array("sp_rpt_t_hasil_so_elmd-audio", $result)) { // $result[] = "sp_rpt_t_hasil_so_elmd-audio"; // } // break; // case "011": //ecg // if (!in_array("sp_rpt_t_hasil_so", $result)) { // $result[] = "sp_rpt_t_hasil_so"; // } // if (!in_array("sp_rpt_t_hasil_so_elmd-ecg", $result)) { // $result[] = "sp_rpt_t_hasil_so_elmd-ecg"; // } // break; // case "012": //treadmill // if (!in_array("sp_rpt_t_hasil_so", $result)) { // $result[] = "sp_rpt_t_hasil_so"; // } // if ( // !in_array("sp_rpt_t_hasil_so_elmd-treadmill", $result) // ) { // $result[] = "sp_rpt_t_hasil_so_elmd-treadmill"; // } // break; // case "013": //pajanan // if (!in_array("sp_dummy_pajanan", $result)) { // $result[] = "sp_dummy_pajanan"; // } // break; // } // } if ($debug != "") { print_r($result); } return $result; } function individu($headerID, $uploadID = "", $debug = "") { // $arr_sp = $this->get_report($uploadID); $arr_sp = $this->get_report(); $result = []; foreach ($arr_sp as $sp) { $key = str_replace("sp_", "", $sp); $sql = "call {$sp}(?,'admin')"; if ($sp == "sp_rpt_mcu_resume_cp_r") { $sql = "call {$sp}(?,1,'admin')"; $resumeID = $this->get_resume_id($headerID); $resp = $this->get_sp($sql, [$resumeID]); } elseif ($sp == "sp_rpt_mcu_resume_cp_r_eng") { $sql = "call {$sp}(?,2,'admin')"; $resumeID = $this->get_resume_id($headerID); $resp = $this->get_sp($sql, [$resumeID]); } elseif ($sp == "sp_rpt_t_hasil_so") { $sql = "call {$sp}(?,2,'admin')"; $resultEntryID = $this->get_so_result_entry_id($headerID); $resp = $this->get_sp($sql, [$resultEntryID]); $new_data = []; foreach ($resp["data"] as $d) { $d["M_LangID"] = 2; $new_data[] = $d; } $sql = "call {$sp}(?,1,'admin')"; $resp = $this->get_sp($sql, [$resultEntryID]); foreach ($resp["data"] as $d) { $d["M_LangID"] = 1; $new_data[] = $d; } $resp["data"] = $new_data; } elseif ($sp == "sp_rpt_t_hasil_bdm") { $sql = "call {$sp}(?,2,'admin')"; $resp = $this->get_sp($sql, [$headerID]); $new_data = []; foreach ($resp["data"] as $d) { $d["M_LangID"] = 2; $new_data[] = $d; } $sql = "call {$sp}(?,1,'admin')"; $resp = $this->get_sp($sql, [$headerID]); foreach ($resp["data"] as $d) { $d["M_LangID"] = 1; $new_data[] = $d; } $resp["data"] = $new_data; } elseif ($sp == "sp_rpt_t_hasil_so_elmd") { $sql = "call {$sp}(?,2,'admin')"; $resultEntryID = $this->get_so_result_entry_id( $headerID, "elmd" ); $resp = $this->get_sp($sql, [$resultEntryID]); $new_data = []; foreach ($resp["data"] as $d) { $d["M_LangID"] = 2; $new_data[] = $d; } $sql = "call {$sp}(?,1,'admin')"; $resp = $this->get_sp($sql, [$resultEntryID]); foreach ($resp["data"] as $d) { $d["M_LangID"] = 1; $new_data[] = $d; } $resp["data"] = $new_data; } elseif ($sp == "sp_rpt_t_hasil_so_elmd-audio") { $xsp = "sp_rpt_t_hasil_so_elmd"; $sql = "call {$xsp}(?,2,'admin')"; $resultEntryID = $this->get_so_result_entry_id( $headerID, "audio" ); $resp = $this->get_sp($sql, [$resultEntryID]); $new_data = []; foreach ($resp["data"] as $d) { $d["M_LangID"] = 2; $new_data[] = $d; } $sql = "call {$xsp}(?,1,'admin')"; $resp = $this->get_sp($sql, [$resultEntryID]); foreach ($resp["data"] as $d) { $d["M_LangID"] = 1; $new_data[] = $d; } $resp["data"] = $new_data; } elseif ($sp == "sp_rpt_t_hasil_so_elmd-ecg") { $xsp = "sp_rpt_t_hasil_so_elmd"; $sql = "call {$xsp}(?,2,'admin')"; $resultEntryID = $this->get_so_result_entry_id( $headerID, "ecg" ); $resp = $this->get_sp($sql, [$resultEntryID]); $new_data = []; foreach ($resp["data"] as $d) { $d["M_LangID"] = 2; $new_data[] = $d; } $sql = "call {$xsp}(?,1,'admin')"; $resp = $this->get_sp($sql, [$resultEntryID]); foreach ($resp["data"] as $d) { $d["M_LangID"] = 1; $new_data[] = $d; } $resp["data"] = $new_data; } elseif ($sp == "sp_rpt_t_hasil_so_elmd-treadmill") { $xsp = "sp_rpt_t_hasil_so_elmd"; $sql = "call {$xsp}(?,2,'admin')"; $resultEntryID = $this->get_so_result_entry_id( $headerID, "treadmill" ); $resp = $this->get_sp($sql, [$resultEntryID]); $new_data = []; foreach ($resp["data"] as $d) { $d["M_LangID"] = 2; $new_data[] = $d; } $sql = "call {$xsp}(?,1,'admin')"; $resp = $this->get_sp($sql, [$resultEntryID]); foreach ($resp["data"] as $d) { $d["M_LangID"] = 1; $new_data[] = $d; } $resp["data"] = $new_data; } elseif ($sp == "sp_dummy_pajanan") { $arr_sub_url = [ "pribadi", "faktor_ergonomi", "faktor_biologi", "faktor_fisik", "faktor_kimia", "faktor_psikologi", ]; $resultEntryID = $this->get_so_result_entry_id( $headerID, "pajanan" ); $new_data = ["pajanan" => []]; if ($resultEntryID > 0) { foreach ($arr_sub_url as $s_url) { $new_data["pajanan"][$s_url] = $this->get_fisik_pajanan( $s_url, $resultEntryID, "k3" ); } } $arr_sub_url = [ "pribadi", "keluhan_saat_ini_new", "riwayat_phobia", "riwayat_obat", "riwayat_penyakit", "riwayat_hidup", "riwayat_keluarga", "tanda_vital", "status_gizi", "keadaan_umum", "mulut", "gigi", "visus", "kepala_wajah", "mata", "telinga", "thorax", "paru", "jantung", "integumen", "sistem", "anggota", "genitourinaria", "perut", "leher", "hidung", "persepsi_warna", ]; $new_data["fisik"] = []; $new_data["riwayat"] = []; if ($resultEntryID > 0) { foreach ($arr_sub_url as $s_url) { $new_data["fisik"][$s_url] = $this->get_fisik( $s_url, $resultEntryID, "fisik" ); $new_data["riwayat"][$s_url] = $this->get_fisik( $s_url, $resultEntryID, "riwayat" ); } } $resp = ["data" => $new_data, "status" => 0]; } elseif ($sp == "sp_rpt_t_hasil_so_layanan") { $sql = "call {$sp}(?,2,'admin')"; $resultEntryID = $this->get_so_result_entry_id( $headerID, "layanan" ); $resp = $this->get_sp($sql, [$resultEntryID]); $new_data = []; foreach ($resp["data"] as $d) { $d["M_LangID"] = 2; $new_data[] = $d; } $sql = "call {$sp}(?,1,'admin')"; $resp = $this->get_sp($sql, [$resultEntryID]); foreach ($resp["data"] as $d) { $d["M_LangID"] = 1; $new_data[] = $d; } $resp["data"] = $new_data; } elseif ($sp == "sp_rpt_t_hasil_so_manthoux") { $sql = "call {$sp}(?,2,'admin')"; $resultEntryID = $this->get_so_result_entry_id( $headerID, "manthoux" ); $resp = $this->get_sp($sql, [$resultEntryID]); $new_data = []; foreach ($resp["data"] as $d) { $d["M_LangID"] = 2; $new_data[] = $d; } $sql = "call {$sp}(?,1,'admin')"; $resp = $this->get_sp($sql, [$resultEntryID]); foreach ($resp["data"] as $d) { $d["M_LangID"] = 1; $new_data[] = $d; } $resp["data"] = $new_data; } elseif ($sp == "sp_rpt_t_hasil_so_manthoux_sampling") { $sql = "call {$sp}(?,2,'admin')"; $resultEntryID = $this->get_so_result_entry_id( $headerID, "manthoux" ); $resp = $this->get_sp($sql, [$resultEntryID]); $new_data = []; foreach ($resp["data"] as $d) { $d["M_LangID"] = 2; $new_data[] = $d; } $sql = "call {$sp}(?,1,'admin')"; $resp = $this->get_sp($sql, [$resultEntryID]); foreach ($resp["data"] as $d) { $d["M_LangID"] = 1; $new_data[] = $d; } $resp["data"] = $new_data; } elseif ($sp == "sp_rpt_t_hasil_so_usg") { $sql = "call {$sp}(?,2,'admin')"; $resultEntryID = $this->get_so_result_entry_id( $headerID, "usg" ); $resp = $this->get_sp($sql, [$resultEntryID]); $new_data = []; foreach ($resp["data"] as $d) { $d["M_LangID"] = 2; $new_data[] = $d; } $sql = "call {$sp}(?,1,'admin')"; $resp = $this->get_sp($sql, [$resultEntryID]); foreach ($resp["data"] as $d) { $d["M_LangID"] = 1; $new_data[] = $d; } $resp["data"] = $new_data; } elseif ($sp == "sp_rpt_t_hasil_so_xray") { $sql = "call {$sp}(?,2,'admin')"; $resp = $this->get_sp($sql, [$headerID]); $new_data = []; foreach ($resp["data"] as $d) { $d["M_LangID"] = 2; $new_data[] = $d; } $sql = "call {$sp}(?,1,'admin')"; $resp = $this->get_sp($sql, [$headerID]); foreach ($resp["data"] as $d) { $d["M_LangID"] = 1; $new_data[] = $d; } $resp["data"] = $new_data; } elseif ($sp == "sp_dummy_fisik") { $arr_sub_url = [ "pribadi", "keluhan_saat_ini_new", "riwayat_phobia", "riwayat_obat", "riwayat_penyakit", "riwayat_hidup", "riwayat_keluarga", "tanda_vital", "status_gizi", "keadaan_umum", "mulut", "gigi", "visus", "kepala_wajah", "mata", "telinga", "thorax", "paru", "jantung", "integumen", "sistem", "anggota", "genitourinaria", "perut", "leher", "hidung", "persepsi_warna", ]; $resultEntryID = $this->get_so_result_entry_id( $headerID, "fisik" ); $new_data = ["fisik" => [], "riwayat" => []]; if ($resultEntryID > 0) { foreach ($arr_sub_url as $s_url) { $new_data["fisik"][$s_url] = $this->get_fisik( $s_url, $resultEntryID, "fisik" ); $new_data["riwayat"][$s_url] = $this->get_fisik( $s_url, $resultEntryID, "riwayat" ); } } $resp = ["data" => $new_data, "status" => 0]; } else { $resp = $this->get_sp($sql, [$headerID]); } if ($resp["status"] == -1) { $this->error_reply_gz("Err $sp : " . $resp["message"]); exit(); } $result[$key] = $resp["data"]; if ($key == "dummy_pajanan") { $result["dummy_fisik"] = $resp["data"]; } } if ($debug != "") { echo json_encode(["status" => "OK", "result" => $result]); exit(); } // cek data $sql_cek_data = " select OneResultConfirmT_OrderHeaderID from one_result_confirm where OneResultConfirmStatus IN ('C','R','E') AND OneResultConfirmRetry <= 5 AND OneResultConfirmIsActive = 'Y' AND OneResultConfirmT_OrderHeaderID = ? "; $qry_cek_data = $this->db->query($sql_cek_data,[ $headerID ]); if(!$qry_cek_data){ $this->db->trans_rollback(); $this->sys_error_db("select cek data one_result_confirm by orderId", $this->db); exit; } $row_cek_data = $qry_cek_data->result_array(); if (count($row_cek_data) > 0) { // resume_id $sql = "call sp_rpt_mcu_resume_cp_r(?,1,'admin')"; $resumeID = $this->get_resume_id($headerID); $resume_mcu = $this->get_sp($sql, [$resumeID]); if($resume_mcu['status'] == 0){ $resume_mcu = $resume_mcu['data']; }else{ $resume_mcu = []; } // resume eng $sql = "call sp_rpt_mcu_resume_cp_r(?,2,'admin')"; $resumeID = $this->get_resume_id($headerID); $resume_mcu_eng = $this->get_sp($sql, [$resumeID]); if($resume_mcu_eng['status'] == 0){ $resume_mcu_eng = $resume_mcu_eng['data']; }else{ $resume_mcu_eng = []; } // field t_orderheader by order id $fields_object = $this->get_field_by_order_id($headerID); // field t_orderheader all $t_orderheader_all = $this->get_field_t_order_header_by_order_id($headerID); // field patient and address $M_PatientID = $fields_object['M_PatientID']; $m_patient_all = $this->get_field_m_patient_by_m_patient_id($M_PatientID); // field m_company $M_CompanyID = $fields_object['M_CompanyID']; $m_company_all = $this->get_field_m_company_by_m_company_id($M_CompanyID); // field t_orderdetail $t_orderdetail_all = $this->get_field_t_orderdetail_by_order_id($headerID); // field m_doctor dan m_doctoraddress $m_doctor_all = $this->get_field_m_doctor_by_order_id($headerID); // field m_mou $T_OrderHeaderM_MouID = $fields_object['T_OrderHeaderM_MouID']; $m_mou_all = $this->get_field_m_mou_by_order_id($T_OrderHeaderM_MouID); // field so_resultentry $so_entry_all = $this->get_field_so_resultentry_by_order_id($headerID); echo json_encode( [ "status" => "OK", "message" => "Data Ditemukan", "OneResultConfirmT_OrderHeaderID" => $fields_object['OneResultConfirmT_OrderHeaderID'], "T_OrderHeaderID" => $fields_object['T_OrderHeaderID'], 'branch_id' => $fields_object['branch_id'], 'branch_code' => $fields_object['branch_code'], "NIK" => $fields_object['NIK'], "NO_REG" => $fields_object['NO_REG'], "PID" => $fields_object['PID'], "NO_HP" => $fields_object['NO_HP'], "T_OrderHeaderDate" => $fields_object['T_OrderHeaderDate'], "M_CompanyID" => $fields_object['M_CompanyID'], "T_OrderHeaderM_MouID" => $fields_object['T_OrderHeaderM_MouID'], "M_PatientID" => $fields_object['M_PatientID'], "t_orderheader_json" => ($t_orderheader_all), "patient" => ($m_patient_all), "m_company_json" => ($m_company_all), "t_orderdetail_json" => ($t_orderdetail_all), "doctor" => ($m_doctor_all), "m_mou_json" => ($m_mou_all), // "report" => $result, "so_resultentry" => $so_entry_all, // resume mcu "resume_mcu" => $resume_mcu, "resume_mcu_eng" => $resume_mcu_eng ] ); }else{ echo json_encode( [ "status"=>"ERR", "message"=>"Data Tidak Ditemukan order ID $headerID" ] ); } // echo $this->reply_gz( // json_encode( // [ // "status" => "OK", // "header" => $header_patient, // "result" => $result // ] // ) // ); } function get_fisik_pajanan($param, $result_entry_id, $type, $lang_id = 1) { $url = "http://localhost/one-api/v1/report/fisik/$param/$result_entry_id/$lang_id/$type/k3"; $resp = $this->get($url); return json_decode($resp, true); } function get_fisik($param, $result_entry_id, $type, $lang_id = 1) { $url = "http://localhost/one-api/v1/report/fisik/$param/$result_entry_id/$lang_id/$type"; $resp = $this->get($url); return json_decode($resp, true); } function get($url, $timeout = 60, $c_timeout = 5) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); $err_msg = curl_error($ch); if ($err_msg != "") { return json_encode(["status" => "ERR", "message" => $err_msg]); } return $result; } function get_sp($sql, $param = false) { $resp = $this->get_rows($sql, $param); $this->clean_mysqli_connection($this->db->conn_id); return $resp; } function get_mou($companyID) { $sql = "select M_MouID,M_MouName, M_MouNumber from m_mou where M_MouIsActive = 'Y' and M_MouM_CompanyID = ?"; $resp = $this->get_rows($sql, [$companyID]); if ($resp["status"] == -1) { $this->error_reply("Error Get MOU by Company $companyID"); exit(); } echo json_encode([ "status" => "OK", "data" => $resp["data"], ]); } function step_debug($rows) { print_r($rows); exit(); } function get_rows($sql, $param = false) { if ($param) { $qry = $this->db->query($sql, $param); } else { $qry = $this->db->query($sql); } if (!$qry) { return [ "status" => -1, "message" => $this->db->last_query() . "|" . $this->db->error()["message"], ]; } return ["status" => 0, "data" => $qry->result_array()]; } function get_row($sql, $param = false) { $resp = $this->get_rows($sql, $param); if ($resp["status"] == -1) { return $resp; } if (count($resp["data"]) == 0) { return ["status" => 0, "message" => "Not found."]; } return ["status" => 1, "data" => $resp["data"][0]]; } // get field by order_id function get_field_by_order_id($order_id) { // branch $sql_get_branch = " select IFNULL(M_BranchID,'') as M_BranchID, IFNULL(M_BranchCode,'') as M_BranchCode from m_branch WHERE M_BranchIsDefault='Y' AND M_BranchIsActive ='Y' "; $query_m_branch = $this->db->query($sql_get_branch); if (!$query_m_branch) { $this->db->trans_rollback(); $message = $this->db->error(); $this->sys_error($message); exit; } $rows_branch = $query_m_branch->result_array(); if (count($rows_branch) == 0) { $this->db->trans_rollback(); $this->sys_error('Cabang Tidak Ketemu'); exit; } $branch_id = $rows_branch[0]['M_BranchID']; $branch_code = $rows_branch[0]['M_BranchCode']; // kolom fields $sql_kolom_fields = "SELECT OneResultConfirmT_OrderHeaderID, T_OrderHeaderID, '{$branch_id}' as branch_id, '{$branch_code}' as branch_code, M_PatientIDNumber as NIK, T_OrderHeaderLabNumber as NO_REG, M_PatientNoReg as PID, M_PatientHP as NO_HP, T_OrderHeaderDate, M_CompanyID, T_OrderHeaderM_MouID, M_PatientID from one_result_confirm join t_orderheader ON OneResultConfirmT_OrderHeaderID = T_OrderHeaderID AND OneResultConfirmT_OrderHeaderID = ? AND OneResultConfirmStatus IN ('C','R','E') AND OneResultConfirmRetry <= 5 AND OneResultConfirmIsActive = 'Y' AND T_OrderHeaderIsActive = 'Y' JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive = 'Y' join m_title on M_PatientM_TitleID = M_TitleID AND M_TitleIsActive = 'Y' left join m_patientaddress ON M_PatientID = M_PatientAddressM_PatientID AND M_PatientIsActive = 'Y' join m_company on T_OrderHeaderM_CompanyID = M_CompanyID"; $qry = $this->db->query($sql_kolom_fields, [$order_id]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("select one_result_confirm by order_id", $this->db); exit; } $rows_fields = $qry->result_array(); if (count($rows_fields) > 0) { return $rows_fields[0]; } return $rows_fields[0]; } // get_field_t_order_header_by_order_id function get_field_t_order_header_by_order_id($order_id) { // kolom fields $sql_t_orderheader_field = "SELECT * from t_orderheader WHERE T_OrderHeaderIsActive = 'Y' AND T_OrderHeaderID = ?"; $qry = $this->db->query($sql_t_orderheader_field, [$order_id]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("select t_orderheader by order_id", $this->db); exit; } $rows_t_order_header = $qry->result_array(); // echo json_encode($result_header); if (count($rows_t_order_header) > 0) { return $rows_t_order_header[0]; } return $rows_t_order_header; } // get_field_m_patient_address_by_m_patient_id function get_field_m_patient_address_by_m_patient_id($M_PatientID) { // kolom fields $sql_m_patient_address_field = "SELECT * from m_patientaddress WHERE M_PatientAddressM_PatientID = ?"; $qry = $this->db->query($sql_m_patient_address_field, [$M_PatientID]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("select m_patientaddress by patientId", $this->db); exit; } $rows_m_patient_address = $qry->result_array(); // echo json_encode($result_header); if (count($rows_m_patient_address) > 0) { return $rows_m_patient_address; } return $rows_m_patient_address; } // get_field_m_patient_by_m_patient_id function get_field_m_patient_by_m_patient_id($M_PatientID) { // kolom fields $sql_m_patient_field = "SELECT * from m_patient WHERE M_PatientIsActive = 'Y' AND M_PatientID = ?"; $qry = $this->db->query($sql_m_patient_field, [$M_PatientID]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("select m_patient by patientId", $this->db); exit; } $rows_m_patient = $qry->result_array(); $result = []; if (count($rows_m_patient) > 0) { foreach ($rows_m_patient as $key => $value) { $result = $value; } $data_address = $this->get_field_m_patient_address_by_m_patient_id($M_PatientID); $result['m_address_json'] = $data_address; } return $result; } // get_field_m_company_by_m_company_id function get_field_m_company_by_m_company_id($M_CompanyID) { // kolom fields $sql_m_company_field = "SELECT * from m_company WHERE M_CompanyID = ? AND M_CompanyIsActive = 'Y'"; $qry = $this->db->query($sql_m_company_field, [$M_CompanyID]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("select m_company by companyId", $this->db); exit; } $rows_m_company = $qry->result_array(); if (count($rows_m_company) > 0) { return $rows_m_company[0]; } return $rows_m_company; } // get_field_t_orderdetail_by_order_id function get_field_t_orderdetail_by_order_id($order_id) { // kolom fields $sql_t_orderdetail_field = "SELECT * from t_orderdetail WHERE T_OrderDetailT_OrderHeaderID = ? AND T_OrderDetailIsActive = 'Y'"; $qry = $this->db->query($sql_t_orderdetail_field, [$order_id]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("select t_orderdetail by orderId", $this->db); exit; } $rows_t_orderdetail = $qry->result_array(); if (count($rows_t_orderdetail) > 0) { return $rows_t_orderdetail; } return $rows_t_orderdetail; } // get_field_m_doctor_by_order_id function get_field_m_doctor_by_order_id($order_id) { $sql_t_orderheader = "SELECT T_OrderHeaderID, T_OrderHeaderSenderM_DoctorID, T_OrderHeaderPjM_DoctorID, IF(T_OrderHeaderSenderM_DoctorID = T_OrderHeaderPjM_DoctorID,'sama','beda') as status_doctor_id FROM t_orderheader WHERE T_OrderHeaderID = ?"; $qry_t_orderheader = $this->db->query($sql_t_orderheader, [$order_id]); if (!$qry_t_orderheader) { $this->db->trans_rollback(); $this->sys_error_db("select t_orderheader by orderId", $this->db); exit; } $rows_data = $qry_t_orderheader->result_array(); $T_OrderHeaderSenderM_DoctorID = ""; $T_OrderHeaderPjM_DoctorID = ""; $result = []; $sql_doctor_sender = ""; // sender dgn pjm beda // sender start $T_OrderHeaderSenderM_DoctorID = $rows_data[0]['T_OrderHeaderSenderM_DoctorID']; $sql_doctor_sender = "select * from m_doctor where M_DoctorID = ?"; $qry_doctor_sender = $this->db->query($sql_doctor_sender, $T_OrderHeaderSenderM_DoctorID); if (!$qry_doctor_sender) { $this->db->trans_rollback(); $this->sys_error_db("select m_doctor sender by M_DoctorID", $this->db); exit; } $rows_doctor_sender = $qry_doctor_sender->result_array(); $sql_address_doctor_sender = "select * from m_doctoraddress where M_DoctorAddressM_DoctorID = ?"; $qry_address_doctor_sender = $this->db->query($sql_address_doctor_sender, $T_OrderHeaderSenderM_DoctorID); if (!$qry_address_doctor_sender) { $this->db->trans_rollback(); $this->sys_error_db("select m_doctoraddress sender by M_DoctorAddressM_DoctorID", $this->db); exit; } $rows_address_doctor_sender = $qry_address_doctor_sender->result_array(); if (count($rows_doctor_sender) > 0) { foreach ($rows_doctor_sender as $key => $value) { $result['sender'][$key] = $value; } $result['sender'][] = [ "doctor_address" => $rows_address_doctor_sender ]; } // sender end // pjm start $T_OrderHeaderPjM_DoctorID = $rows_data[0]['T_OrderHeaderPjM_DoctorID']; $sql_doctor_pjm = "select * from m_doctor where M_DoctorID = ?"; $qry_doctor_pjm = $this->db->query($sql_doctor_pjm, $T_OrderHeaderPjM_DoctorID); if (!$qry_doctor_pjm) { $this->db->trans_rollback(); $this->sys_error_db("select m_doctor pjm by M_DoctorID", $this->db); exit; } $sql_address_doctor_pjm = "select * from m_doctoraddress where M_DoctorAddressM_DoctorID = ?"; $qry_address_doctor_pjm = $this->db->query($sql_address_doctor_pjm, $T_OrderHeaderPjM_DoctorID); if (!$qry_address_doctor_pjm) { $this->db->trans_rollback(); $this->sys_error_db("select m_doctoraddress pjm by M_DoctorAddressM_DoctorID", $this->db); exit; } $rows_address_doctor_pjm = $qry_address_doctor_pjm->result_array(); $rows_doctor_pjm = $qry_doctor_pjm->result_array(); if (count($rows_doctor_pjm) > 0) { foreach ($rows_doctor_pjm as $key => $value) { $result['pj'][$key] = $value; } $result['pj'][] = [ "doctor_address" => $rows_address_doctor_pjm ]; } return $result; } // get_field_m_mou_by_order_id function get_field_m_mou_by_order_id($T_OrderHeaderM_MouID) { // kolom fields $sql_m_mou_field = "SELECT * from m_mou WHERE M_MouIsActive = 'Y' AND M_MouID = ?"; $qry = $this->db->query($sql_m_mou_field, [$T_OrderHeaderM_MouID]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("select m_mou by mou_id", $this->db); exit; } $rows_m_mou = $qry->result_array(); if (count($rows_m_mou) > 0) { return $rows_m_mou[0]; } return $rows_m_mou; } // get_field_so_resultentrydetail_by_so_resultid function get_field_so_resultentrydetail_by_so_resultid($so_resultid) { // kolom fields $sql_so_resultentrydetail = "SELECT * from so_resultentrydetail WHERE So_ResultEntryDetailIsActive = 'Y' AND So_ResultEntryDetailSo_ResultEntryID = ?"; $qry = $this->db->query($sql_so_resultentrydetail, [$so_resultid]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("select so_resultentrydetail by so_resultid", $this->db); exit; } $rows_so_resultentry_detail = $qry->result_array(); if (count($rows_so_resultentry_detail) > 0) { return $rows_so_resultentry_detail; } return $rows_so_resultentry_detail; } // get_field_so_resultentrydetailother_by_so_resultid function get_field_so_resultentrydetailother_by_so_resultid($so_resultid) { // kolom fields $sql_so_resultentrydetailother = "SELECT * from so_resultentrydetail_other WHERE So_ResultEntryDetailOtherIsActive = 'Y' AND So_ResultEntryDetailOtherSo_ResultEntryID = ?"; $qry = $this->db->query($sql_so_resultentrydetailother, [$so_resultid]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("select so_resultentrydetailother by so_resultid", $this->db); exit; } $rows_so_resultentry_detailother = $qry->result_array(); if (count($rows_so_resultentry_detailother) > 0) { return $rows_so_resultentry_detailother; } return $rows_so_resultentry_detailother; } // get_field_so_resultentrycategoryresult_by_so_resultid function get_field_so_resultentrycategoryresult_by_so_resultid($so_resultid) { // kolom fields $sql_so_resultentrydetailcategory = "SELECT * from so_resultentry_category_result WHERE So_ResultEntryCategoryResultIsActive = 'Y' AND So_ResultEntryCategoryResultSo_ResultEntryID = ?"; $qry = $this->db->query($sql_so_resultentrydetailcategory, [$so_resultid]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("select so_resultentry_category_result by so_resultid", $this->db); exit; } $data_so_resultentrydetailcategory = $qry->result_array(); if (count($data_so_resultentrydetailcategory) > 0) { return $data_so_resultentrydetailcategory; } return $data_so_resultentrydetailcategory; } // get_field_so_resultentryfisikumum_by_so_resultid function get_field_so_resultentryfisikumum_by_so_resultid($so_resultid) { // kolom fields $sql_so_resultentryfisikumum = "SELECT * from so_resultentry_fisik_umum WHERE So_ResultEntryFisikUmumIsActive = 'Y' AND So_ResultEntryFisikUmumSo_ResultEntryID = ?"; $qry = $this->db->query($sql_so_resultentryfisikumum, [$so_resultid]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("select so_resultentry_fisik_umum by so_resultid", $this->db); exit; } $data_so_resultentryfisikumum = $qry->result_array(); if (count($data_so_resultentryfisikumum) > 0) { return $data_so_resultentryfisikumum; } return $data_so_resultentryfisikumum; } // get_field_so_resultentryother_by_so_resultid function get_field_so_resultentryother_by_so_resultid($so_resultid) { // kolom fields $sql_so_resultentryother = "SELECT * from so_resultentry_other WHERE So_ResultEntryOtherIsActive = 'Y' AND So_ResultEntryOtherSo_ResultEntryID = ?"; $qry = $this->db->query($sql_so_resultentryother, [$so_resultid]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("select so_resultentry_other by so_resultid", $this->db); exit; } $data_so_resultentryother = $qry->result_array(); if (count($data_so_resultentryother) > 0) { return $data_so_resultentryother; } return $data_so_resultentryother; } // get_field_so_resultentrysmwtdetails_by_smwt_id function get_field_so_resultentrysmwtdetails_by_smwt_id($smwt_id) { // kolom fields $sql_so_resultentrysmwtdetails = "SELECT * from so_resultentry_smwt_details WHERE So_ResultentrySmwtDetailsIsActive = 'Y' AND So_ResultentrySmwtDetailsSo_ResultentrySmwtID = ?"; $qry = $this->db->query($sql_so_resultentrysmwtdetails, [$smwt_id]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("select so_resultentry_smwt_details by smwt_id", $this->db); exit; } $data_so_resultentrysmwt_detail = $qry->result_array(); if (count($data_so_resultentrysmwt_detail) > 0) { return $data_so_resultentrysmwt_detail; } return $data_so_resultentrysmwt_detail; } // get_field_so_resultentrysmwt_by_so_resultid function get_field_so_resultentrysmwt_by_so_resultid($so_resultid) { // kolom fields $sql_so_resultentrysmwt = "SELECT * from so_resultentry_smwt WHERE So_ResultentrySmwtIsActive = 'Y' AND So_ResultentrySmwtSo_ResultentryID = ?"; $qry = $this->db->query($sql_so_resultentrysmwt, [$so_resultid]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("select so_resultentry_smwt by so_resultid", $this->db); exit; } $data_so_resultentrysmwt = $qry->result_array(); if (count($data_so_resultentrysmwt) > 0) { return $data_so_resultentrysmwt; } return $data_so_resultentrysmwt; } // get_field_so_resultentry_by_order_id function get_field_so_resultentry_by_order_id($order_id) { // kolom fields $sql_so_resultentry = "SELECT * from so_resultentry WHERE So_ResultEntryIsActive = 'Y' AND So_ResultEntryT_OrderHeaderID = ?"; $qry = $this->db->query($sql_so_resultentry, [$order_id]); if (!$qry) { $this->db->trans_rollback(); $this->sys_error_db("select so_resultentry by order_id", $this->db); exit; } $result = []; $rows_so_resultentry = $qry->result_array(); if (count($rows_so_resultentry) > 0) { foreach ($rows_so_resultentry as $key => $value) { $So_ResultEntryID = $value['So_ResultEntryID']; // object detail $data_so_resultentrydetail = $this->get_field_so_resultentrydetail_by_so_resultid($value['So_ResultEntryID']); // object detail_other $data_so_resultentrydetailother = $this->get_field_so_resultentrydetailother_by_so_resultid($value['So_ResultEntryID']); // object category_result $data_so_resultentrycategoryresult = $this->get_field_so_resultentrycategoryresult_by_so_resultid($value['So_ResultEntryID']); // object fisik_umum $data_so_resultentryfisikumum = $this->get_field_so_resultentryfisikumum_by_so_resultid($value['So_ResultEntryID']); // object other $data_so_resultentryother = $this->get_field_so_resultentryother_by_so_resultid($value['So_ResultEntryID']); // smwt $data_smwt = $this->get_field_so_resultentrysmwt_by_so_resultid($value['So_ResultEntryID']); $result[] = [ // "So_ResultEntryID" => $So_ResultEntryID, // $value, "So_ResultEntryID"=> $value['So_ResultEntryID'], "So_ResultEntryT_OrderHeaderID"=> $value['So_ResultEntryT_OrderHeaderID'], "So_ResultEntryT_OrderDetailID"=> $value['So_ResultEntryT_OrderDetailID'], "So_ResultEntryPhysic"=> $value['So_ResultEntryPhysic'], "So_ResultEntryIsNormal"=> $value['So_ResultEntryIsNormal'], "So_ResultEntryM_LangID"=> $value['So_ResultEntryM_LangID'], "So_ResultEntrySo_TemplateID"=> $value['So_ResultEntrySo_TemplateID'], "So_ResultEntrySo_TemplateFlagOther"=> $value['So_ResultEntrySo_TemplateFlagOther'], "So_ResultEntrySo_TemplateOther"=> $value['So_ResultEntrySo_TemplateOther'], "So_ResultEntrySo_TemplateName"=> $value['So_ResultEntrySo_TemplateName'], "So_ResultEntryValidation1"=> $value['So_ResultEntryValidation1'], "So_ResultEntryValidation2"=> $value['So_ResultEntryValidation2'], "So_ResultEntryStatus"=> $value['So_ResultEntryStatus'], "So_ResultEntryNote"=> $value['So_ResultEntryNote'], "So_ResultEntryFlagPrintNote"=> $value['So_ResultEntryFlagPrintNote'], "So_ResultEntryCreated" => $value['So_ResultEntryCreated'], "So_ResultEntryIsActive"=> $value['So_ResultEntryIsActive'], "So_ResultEntryLastUpdated"=> $value['So_ResultEntryLastUpdated'], "So_ResultEntryUserID"=> $value['So_ResultEntryUserID'], "detail" => [], "detail_other" => [], "category_result" => [], "fisik_umum" => [], "other" => [], "smwt" => [] ]; $idx = count($result) - 1; // $result[$idx]["0"] = $rows_so_resultentry[0]; // object detail push if (count($data_so_resultentrydetail) > 0) { $result[$idx]["detail"] = $data_so_resultentrydetail; } // object detail_other push if (count($data_so_resultentrydetailother) > 0) { $result[$idx]["detail_other"] = $data_so_resultentrydetailother; } // object category_result push if (count($data_so_resultentrycategoryresult) > 0) { $result[$idx]["category_result"] = $data_so_resultentrycategoryresult; } // object fisik_umum push if (count($data_so_resultentryfisikumum) > 0) { $result[$idx]["fisik_umum"] = $data_so_resultentryfisikumum; } // object other push if(count($data_so_resultentryother) > 0){ $result[$idx]["other"] = $data_so_resultentryother; } // object smwt push if(count($data_smwt) > 0){ $result[$idx]["smwt"] = $data_smwt; foreach ($data_smwt as $key => $value) { // $idxx untuk mendapatkan length dari array smwt, lalu kemudian di push sesuai // length smwt_details $idxx = count($result[$idx]["smwt"]) - 1; $data_detail_smwt = $this->get_field_so_resultentrysmwtdetails_by_smwt_id($value['So_ResultentrySmwtID']); // object smwt_detail push if(count($data_detail_smwt) > 0){ // $So_ResultentrySmwtID = $value['So_ResultentrySmwtID']; // $result[$idx]["smwt"][$idxx]['So_ResultentrySmwtID'] = $So_ResultentrySmwtID; $result[$idx]["smwt"][$idxx]['smwt_details'] = $data_detail_smwt; } } } } } return $result; } // process upload function process_upload() { $max_data = 3; $sql_data_upload = "select OneResultConfirmT_OrderHeaderID from one_result_confirm where OneResultConfirmStatus IN ('C','R') AND OneResultConfirmIsActive = 'Y' limit 0, $max_data"; $qry_data_upload = $this->db->query($sql_data_upload); if (!$qry_data_upload) { $this->db->trans_rollback(); $this->sys_error_db("select one_result_confirm", $this->db); exit; } $rows_data_upload = $qry_data_upload->result_array(); if (count($rows_data_upload) > 0) { foreach ($rows_data_upload as $key => $value) { $this->individu($value['OneResultConfirmT_OrderHeaderID']); } } else { $this->db->trans_rollback(); // print_r($j_resp['status']); $this->reply([ "status" => "OK", 'message' => "Tidak Ada Data", 'debug' => "" ]); } } }