2459 lines
104 KiB
PHP
2459 lines
104 KiB
PHP
<?php
|
|
class Resume extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
var $load;
|
|
var $kesimpulanfisik;
|
|
|
|
public function index()
|
|
{
|
|
echo "CPONE RESUME INDIVIDU API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
$this->load->library('Genkelainan');
|
|
// $this->load->library("SsPriceMou");
|
|
}
|
|
|
|
public function getsetup()
|
|
{
|
|
try {
|
|
// if (!$this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
$sql = "SELECT * FROM mgm_mcu WHERE Mgm_McuIsActive = 'Y'";
|
|
$qry = $this->db_onedev->query($sql, []);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$last_qry = $this->db_onedev->last_query();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$data = $qry->result_array();
|
|
$result = [
|
|
"records" => $data,
|
|
];
|
|
$this->sys_ok($result);
|
|
}
|
|
catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function search()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$search = '%' . $prm['search'] . '%';
|
|
$page = $prm["page"];
|
|
$startDate = $prm["startDate"] . ' 00:00:00';
|
|
$endDate = $prm["endDate"] . ' 23:59:59';
|
|
//$setupID = $prm["setupID"];
|
|
$ROW_PER_PAGE = 20;
|
|
$start_offset = 0;
|
|
$filter_company = '';
|
|
if (isset($prm["companyID"])) {
|
|
$filter_company = " AND M_CompanyID = {$prm["companyID"]}";
|
|
}
|
|
// print_r($prm);
|
|
|
|
if (isset($prm["page"])) {
|
|
if (
|
|
is_numeric($prm["page"]) && $prm["page"] > 0
|
|
) {
|
|
$start_offset = ($page - 1) * $ROW_PER_PAGE;
|
|
}
|
|
}
|
|
$sql = "SELECT
|
|
COUNT(T_OrderHeaderID) AS total
|
|
FROM t_orderheader
|
|
JOIN t_orderheaderaddon ON T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID AND T_OrderHeaderAddOnIsActive = 'Y'
|
|
JOIN m_patient
|
|
ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_company
|
|
ON T_OrderHeaderM_CompanyID = M_CompanyID {$filter_company}
|
|
LEFT JOIN m_title
|
|
ON M_PatientM_TitleID = M_TitleID
|
|
WHERE T_OrderHeaderDate >= ? AND T_OrderHeaderDate <= ?
|
|
AND (M_PatientName LIKE ? OR T_OrderHeaderLabNumber LIKE ?)
|
|
AND T_OrderHeaderIsActive = 'Y'
|
|
ORDER BY T_OrderHeaderLabNumber
|
|
";
|
|
$query = $this->db_onedev->query($sql, [$startDate, $endDate, $search, $search]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$totalPage = $query->row_array()['total'];
|
|
$sql = "SELECT
|
|
T_OrderHeaderID AS orderID,
|
|
0 AS reIDHaji,
|
|
IFNULL(Mcu_ResumeStatus, 'NEW') as status,
|
|
DATE_FORMAT(T_OrderHeaderDate, '%d-%m-%Y') AS orderDate,
|
|
T_OrderHeaderLabNumber AS labNumber,
|
|
T_OrderHeaderM_PatientID AS patientID,
|
|
T_OrderHeaderM_CompanyID AS corporateID,
|
|
-1 AS setupID,
|
|
'DFLT' AS bg_code,
|
|
'' AS bg_prm,
|
|
UPPER(T_OrderHeaderM_PatientAge) AS patientAge,
|
|
DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') AS patientDOB,
|
|
M_PatientNoReg AS patientReg,
|
|
M_PatientName AS patientName,
|
|
UPPER(CONCAT(IF(ISNULL(M_TitleName),'',CONCAT(M_TitleName,'.')),
|
|
' ',
|
|
IFNULL(M_PatientPrefix,''),
|
|
' ',
|
|
M_PatientName,
|
|
' ',
|
|
IFNULL(M_PatientSuffix,''))) AS patientFullname,
|
|
UPPER(M_SexName) AS patientGender,
|
|
M_PatientPhoto AS patientFoto,
|
|
M_PatientPhotoThumb AS patientFotoThumb,
|
|
M_CompanyNumber AS corporateCode,
|
|
UPPER(M_CompanyName) AS corporateName
|
|
FROM t_orderheader
|
|
JOIN t_orderheaderaddon ON T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID AND T_OrderHeaderAddOnIsActive = 'Y'
|
|
JOIN m_patient
|
|
ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
|
|
JOIN m_sex ON M_PatientM_SexID = M_SexID
|
|
JOIN m_company
|
|
ON T_OrderHeaderM_CompanyID = M_CompanyID {$filter_company}
|
|
LEFT JOIN m_title
|
|
ON M_PatientM_TitleID = M_TitleID
|
|
LEFT JOIN mcu_resume
|
|
ON T_OrderHeaderID = Mcu_ResumeT_OrderHeaderID
|
|
AND Mcu_ResumeIsActive = 'Y'
|
|
WHERE T_OrderHeaderDate >= ? AND T_OrderHeaderDate <= ?
|
|
AND (M_PatientName LIKE ? OR T_OrderHeaderLabNumber LIKE ?)
|
|
AND T_OrderHeaderIsActive = 'Y'
|
|
GROUP BY T_OrderHeaderID
|
|
ORDER BY T_OrderHeaderLabNumber
|
|
LIMIT ? OFFSET ? ";
|
|
$query = $this->db_onedev->query($sql, [$startDate, $endDate, $search, $search, $ROW_PER_PAGE, $start_offset]);
|
|
$sql_search = $this->db_onedev->last_query();
|
|
//echo $this->db_onedev->last_query();
|
|
if (!$query) {
|
|
//echo $this->db_onedev->last_query();
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
// echo $this->db_onedev->last_query();
|
|
$result = [
|
|
"total" => ceil($totalPage / $ROW_PER_PAGE),
|
|
"records" => $query->result_array(),
|
|
"sql" => $sql_search
|
|
];
|
|
$this->sys_ok($result);
|
|
}
|
|
|
|
function getdetail()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$orderid = $prm['orderid'];
|
|
|
|
$sql = "SELECT
|
|
M_LangID as id,
|
|
M_LangName as name,
|
|
M_LangCode as code,
|
|
'' as details
|
|
FROM t_orderheader
|
|
JOIN m_lang ON T_OrderHeaderM_LangID = M_LangID AND M_LangIsActive = 'Y'
|
|
WHERE
|
|
T_OrderHeaderID = ? AND T_OrderHeaderIsActive = 'Y'
|
|
UNION
|
|
SELECT
|
|
M_LangID as id,
|
|
M_LangName as name,
|
|
M_LangCode as code,
|
|
'' as details
|
|
FROM t_orderheader
|
|
JOIN t_orderheaderaddon ON T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderAddOnIsActive = 'Y'
|
|
JOIN m_lang ON T_OrderHeaderAddOnSecondM_LangID = M_LangID AND M_LangIsActive = 'Y'
|
|
WHERE
|
|
T_OrderHeaderID = ? AND T_OrderHeaderIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, [$orderid, $orderid]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$dataLangs = $query->result_array();
|
|
$conclusions = [];
|
|
|
|
|
|
$sql = "SELECT Mcu_ResumeID,
|
|
Mcu_ResumeStatus as status,
|
|
Mcu_ResumeMcu_FitnessCategoryID,
|
|
IFNULL(Mcu_FitnessCategoryName, '') as fitnessCategoryName,
|
|
IFNULL(Mcu_FitnessCategoryEng, '') as fitnessCategoryEng,
|
|
IFNULL(Mcu_FitnessCategoryLevel, '') as fitnessCategoryLevel,
|
|
CONCAT(M_DoctorPrefix,' ',M_DoctorPrefix2, ' ', M_DoctorName, ' ',M_DoctorSufix,' ', M_DoctorSufix2, ' ') doctorName,
|
|
IFNULL(M_DoctorID, 0) as doctorID,
|
|
'' as selectedDoctor,
|
|
'' as conclusions
|
|
FROM mcu_resume
|
|
LEFT JOIN m_doctor ON Mcu_ResumeM_DoctorID = M_DoctorID AND M_DoctorIsActive = 'Y'
|
|
LEFT JOIN mcu_fitness_category ON Mcu_ResumeMcu_FitnessCategoryID = Mcu_FitnessCategoryID AND
|
|
Mcu_FitnessCategoryIsActive = 'Y'
|
|
WHERE Mcu_ResumeT_OrderHeaderID = ? AND Mcu_ResumeIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, [$orderid]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$row_header = $query->result_array();
|
|
|
|
if (count($row_header) > 0) {
|
|
$dataHeader = $row_header[0];
|
|
$dataHeader['fitnessCategory'] = [
|
|
"id" => $dataHeader['Mcu_ResumeMcu_FitnessCategoryID'],
|
|
"name" => $dataHeader['Mcu_FitnessCategoryName'],
|
|
"nameEng" => $dataHeader['Mcu_FitnessCategoryEng'],
|
|
"level" => $dataHeader['Mcu_FitnessCategoryLevel']
|
|
];
|
|
$dataHeader['selectedDoctor'] = [
|
|
"id" => $dataHeader['M_DoctorID'],
|
|
"name" => $dataHeader['M_DoctorID'] > 0 ? $dataHeader['doctorName'] : ''
|
|
];
|
|
}
|
|
else {
|
|
|
|
$generateFitnessCategory = $this->genkelainan->generate_fitness_category($orderid);
|
|
$fitnessCategory = $generateFitnessCategory['status'];
|
|
$data = $generateFitnessCategory['data'];
|
|
$dataHeader = [
|
|
"Mcu_ResumeID" => 0,
|
|
"status" => 'NEW',
|
|
"fitnessCategory" => [$fitnessCategory],
|
|
"selectedDoctor" => []
|
|
];
|
|
}
|
|
|
|
foreach ($dataLangs as $key => $lang) {
|
|
$langid = $lang['id'];
|
|
$sql = "SELECT Mcu_ResumeConclusionID as id,
|
|
Mcu_ResumeConclusionKesimpulan as kesimpulan,
|
|
Mcu_ResumeConclusionRekomendasi as rekomendasi,
|
|
Mcu_ResumeConclusionSaran as saran
|
|
FROM mcu_resume_conclusion
|
|
WHERE
|
|
Mcu_ResumeConclusionMcu_ResumeID = ? AND
|
|
Mcu_ResumeConclusionM_LangID = ? AND
|
|
Mcu_ResumeConclusionIsActive = 'Y'
|
|
LIMIT 1";
|
|
$query = $this->db_onedev->query($sql, [$dataHeader['Mcu_ResumeID'], $langid]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$dataConclusion = $query->result_array();
|
|
if (count($dataConclusion) > 0) {
|
|
$lang['details'] = $dataConclusion[0];
|
|
}
|
|
else {
|
|
$lang['details'] = [
|
|
"id" => 0,
|
|
"kesimpulan" => '',
|
|
"rekomendasi" => '',
|
|
"saran" => ''
|
|
];
|
|
}
|
|
$conclusions[] = $lang;
|
|
}
|
|
|
|
$dataHeader['conclusions'] = $conclusions;
|
|
|
|
|
|
|
|
$sql = "SELECT T_OrderHeaderGroupResultT_OrderHeaderID as orderid,
|
|
Mcu_ResumeResultsType as type,
|
|
T_OrderHeaderGroupResultGroup_ResultID as group_resultid,
|
|
T_OrderHeaderGroupResultT_TestID as test_id,
|
|
IFNULL(Mcu_ResumeResultsName,T_OrderHeaderGroupResultGroup_ResultName) as t_name,
|
|
IFNULL(Mcu_ResumeResultsJSON, 'Hasil belum divalidasi') as dt_json
|
|
FROM t_orderheader_group_result
|
|
LEFT JOIN mcu_resume_results ON Mcu_ResumeResultsT_OrderHeaderID = T_OrderHeaderGroupResultT_OrderHeaderID AND
|
|
Mcu_ResumeResultsIsActive = 'Y' AND (
|
|
( T_OrderHeaderGroupResultGroup_ResultID = Mcu_ResumeResultsGroupResultID AND
|
|
T_OrderHeaderGroupResultT_TestID = 0
|
|
)
|
|
OR
|
|
(
|
|
T_OrderHeaderGroupResultT_TestID = Mcu_ResumeResultsT_TestID AND Mcu_ResumeResultsT_TestID > 0
|
|
)
|
|
)
|
|
WHERE T_OrderHeaderGroupResultT_OrderHeaderID = ? AND T_OrderHeaderGroupResultIsActive = 'Y' ";
|
|
$query = $this->db_onedev->query($sql, [$orderid]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$dataResults = count($query->result_array()) > 0 ? $query->result_array() : [];
|
|
|
|
$fisikResultRows = [];
|
|
if (count($dataResults) > 0) {
|
|
$hasFisikResult = false;
|
|
foreach ($dataResults as $result) {
|
|
if ($result['type'] === 'FISIK') {
|
|
$hasFisikResult = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ($hasFisikResult) {
|
|
$sql = "SELECT
|
|
ResultFisikUmumType as type,
|
|
IFNULL(Result_FisikAliasLabelName, ResultFisikUmumLabel) as label,
|
|
ResultFisikUmumValue as value
|
|
FROM result_fisik_umum
|
|
LEFT JOIN result_fisikaliaslabel
|
|
ON Result_FisikAliasLabelCode = ResultFisikUmumLabel
|
|
AND Result_FisikAliasLabelIsActive = 'Y'
|
|
WHERE
|
|
ResultFisikUmumT_OrderHeaderID = ? AND
|
|
ResultFisikUmumIsActive = 'Y' AND
|
|
ResultFisikUmumValue <> 'Err'
|
|
ORDER BY ResultFisikUmumID";
|
|
$query = $this->db_onedev->query($sql, [$orderid]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$fisikResultRows = $query->result_array();
|
|
}
|
|
}
|
|
|
|
if (count($dataResults) > 0) {
|
|
foreach ($dataResults as $key => $result) {
|
|
$decodedJson = json_decode($result['dt_json'], true);
|
|
if (
|
|
$result['type'] === 'FISIK' &&
|
|
(trim((string)$result['dt_json']) === '' || $decodedJson === null)
|
|
) {
|
|
$dataResults[$key]['dt_json'] = $fisikResultRows;
|
|
}
|
|
else {
|
|
$dataResults[$key]['dt_json'] = $decodedJson;
|
|
}
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT
|
|
MIN(kelainans.id) AS id,
|
|
kelainans.Mcu_KelainanID,
|
|
kelainans.type,
|
|
IFNULL(GROUP_CONCAT(DISTINCT NULLIF(kelainans.Nat_TestName, '') ORDER BY kelainans.Nat_TestName SEPARATOR ', '), '') AS Nat_TestName,
|
|
kelainans.Mcu_KelainanName,
|
|
kelainans.Mcu_KelainanClasification,
|
|
kelainans.Mcu_KelainanGroupName,
|
|
IFNULL(MIN(kelainans.Mcu_FitnessCategoryID), 0) AS Mcu_FitnessCategoryID,
|
|
IFNULL(MIN(kelainans.Mcu_FitnessCategoryLevel), 0) AS Mcu_FitnessCategoryLevel,
|
|
IFNULL(MIN(NULLIF(kelainans.Mcu_FitnessCategoryName, '')), '') AS Mcu_FitnessCategoryName
|
|
FROM (
|
|
SELECT
|
|
kl.T_KelainanLabID AS id,
|
|
mk.Mcu_KelainanID,
|
|
'lab' AS type,
|
|
IFNULL(nt.Nat_TestName, '') AS Nat_TestName,
|
|
mk.Mcu_KelainanName,
|
|
mk.Mcu_KelainanClasification,
|
|
mkg.Mcu_KelainanGroupName,
|
|
mfc.Mcu_FitnessCategoryID,
|
|
mfc.Mcu_FitnessCategoryName,
|
|
mfc.Mcu_FitnessCategoryLevel
|
|
FROM t_kelainan_lab kl
|
|
JOIN mcu_summarylab ms
|
|
ON kl.T_KelainanLabMcu_SummaryLabID = ms.Mcu_SummaryLabID
|
|
AND ms.Mcu_SummaryLabIsActive = 'Y'
|
|
JOIN mcu_kelainan mk
|
|
ON ms.Mcu_SummaryLabMcu_KelainanID = mk.Mcu_KelainanID
|
|
AND mk.Mcu_KelainanIsActive = 'Y'
|
|
JOIN mcu_kelainangroup mkg
|
|
ON mk.Mcu_KelainanMcu_KelainanGroupID = mkg.Mcu_KelainanGroupID
|
|
AND mkg.Mcu_KelainanGroupIsActive = 'Y'
|
|
LEFT JOIN mcu_fitness_category mfc
|
|
ON ms.Mcu_SummaryLabMcu_FitnessCategoryID = mfc.Mcu_FitnessCategoryID
|
|
AND mfc.Mcu_FitnessCategoryIsActive = 'Y'
|
|
LEFT JOIN nat_test nt
|
|
ON kl.T_KelainanLabNat_TestID = nt.Nat_TestID
|
|
AND nt.Nat_TestIsActive = 'Y'
|
|
WHERE
|
|
kl.T_KelainanLabT_OrderHeaderID = ? AND
|
|
kl.T_KelainanLabIsActive = 'Y'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
kn.T_KelainanNonLabID AS id,
|
|
mk.Mcu_KelainanID,
|
|
'fisik' AS type,
|
|
IFNULL(nt.Nat_TestName, '') AS Nat_TestName,
|
|
mk.Mcu_KelainanName,
|
|
mk.Mcu_KelainanClasification,
|
|
mkg.Mcu_KelainanGroupName,
|
|
mfc.Mcu_FitnessCategoryID,
|
|
mfc.Mcu_FitnessCategoryName,
|
|
mfc.Mcu_FitnessCategoryLevel
|
|
FROM t_kelainan_nonlab kn
|
|
JOIN mcu_summarynonlab msn
|
|
ON kn.T_KelainanNonLabMcu_SummaryNonlabID = msn.Mcu_SummaryNonlabID
|
|
AND msn.Mcu_SummaryNonlabIsActive = 'Y'
|
|
JOIN mcu_kelainan mk
|
|
ON msn.Mcu_SummaryNonlabMcu_KelainanID = mk.Mcu_KelainanID
|
|
AND mk.Mcu_KelainanIsActive = 'Y'
|
|
JOIN mcu_kelainangroup mkg
|
|
ON mk.Mcu_KelainanMcu_KelainanGroupID = mkg.Mcu_KelainanGroupID
|
|
AND mkg.Mcu_KelainanGroupIsActive = 'Y'
|
|
LEFT JOIN mcu_fitness_category mfc
|
|
ON msn.Mcu_SummaryNonlabMcu_FitnessCategoryID = mfc.Mcu_FitnessCategoryID
|
|
AND mfc.Mcu_FitnessCategoryIsActive = 'Y'
|
|
LEFT JOIN nat_test nt
|
|
ON kn.T_KelainanNonLabNat_TestID = nt.Nat_TestID
|
|
AND nt.Nat_TestIsActive = 'Y'
|
|
WHERE
|
|
kn.T_KelainanNonLabT_OrderHeaderID = ? AND
|
|
kn.T_KelainanNonLabIsActive = 'Y'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
kf.T_KelainanFiskID AS id,
|
|
mk.Mcu_KelainanID,
|
|
'fisik' AS type,
|
|
'' AS Nat_TestName,
|
|
mk.Mcu_KelainanName,
|
|
mk.Mcu_KelainanClasification,
|
|
mkg.Mcu_KelainanGroupName,
|
|
mfc.Mcu_FitnessCategoryID,
|
|
mfc.Mcu_FitnessCategoryName,
|
|
mfc.Mcu_FitnessCategoryLevel
|
|
FROM t_kelainan_fisik kf
|
|
JOIN mcu_fisiksummary mf
|
|
ON kf.T_KelainanFiskMcu_FisikSummaryID = mf.Mcu_FisikSummaryID
|
|
AND mf.Mcu_FisikSummaryIsActive = 'Y'
|
|
JOIN mcu_kelainan mk
|
|
ON mf.Mcu_FisikSummaryMcu_KelainanID = mk.Mcu_KelainanID
|
|
AND mk.Mcu_KelainanIsActive = 'Y'
|
|
JOIN mcu_kelainangroup mkg
|
|
ON mk.Mcu_KelainanMcu_KelainanGroupID = mkg.Mcu_KelainanGroupID
|
|
AND mkg.Mcu_KelainanGroupIsActive = 'Y'
|
|
LEFT JOIN mcu_fitness_category mfc
|
|
ON mf.Mcu_FisikSummaryMcu_FitnessCategoryID = mfc.Mcu_FitnessCategoryID
|
|
AND mfc.Mcu_FitnessCategoryIsActive = 'Y'
|
|
WHERE
|
|
kf.T_KelainanFiskT_OrderHeaderID = ? AND
|
|
kf.T_KelainanFiskIsActive = 'Y'
|
|
) kelainans
|
|
GROUP BY
|
|
kelainans.type,
|
|
kelainans.Mcu_KelainanID,
|
|
kelainans.Mcu_KelainanName,
|
|
kelainans.Mcu_KelainanClasification,
|
|
kelainans.Mcu_KelainanGroupName
|
|
ORDER BY kelainans.type, Nat_TestName, kelainans.Mcu_KelainanName";
|
|
$query = $this->db_onedev->query($sql, [$orderid, $orderid, $orderid]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$dataKelainans = $query->result_array();
|
|
|
|
$dataAdvices = [];
|
|
$arrKelainanIDs = array_values(array_unique(array_filter(array_column($dataKelainans, 'Mcu_KelainanID'))));
|
|
foreach ($dataKelainans as $key => $kelainan) {
|
|
unset($dataKelainans[$key]['Mcu_KelainanID']);
|
|
}
|
|
if (count($arrKelainanIDs) > 0) {
|
|
$sql = "SELECT DISTINCT
|
|
na.Nat_AdviceID,
|
|
na.Nat_AdviceIna,
|
|
IF(na.Nat_AdviceEng = '', na.Nat_AdviceIna, na.Nat_AdviceEng) AS Nat_AdviceEng
|
|
FROM nat_advice_kelainan nak
|
|
JOIN nat_advice na
|
|
ON nak.Nat_AdvicekelainanNat_AdviceID = na.Nat_AdviceID
|
|
AND na.Nat_AdviceIsActive = 'Y'
|
|
WHERE nak.Nat_AdvicekelainanMcu_KelainanID IN ?
|
|
AND nak.Nat_AdvicekelainanIsActive = 'Y'
|
|
ORDER BY na.Nat_AdviceIna";
|
|
$query = $this->db_onedev->query($sql, [$arrKelainanIDs]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$dataAdvices = $query->result_array();
|
|
}
|
|
|
|
$sql = "SELECT Mcu_FitnessCategoryID as id,
|
|
Mcu_FitnessCategoryName as name,
|
|
Mcu_FitnessCategoryEng as nameEng,
|
|
Mcu_FitnessCategoryLevel as level
|
|
FROM mcu_fitness_category
|
|
WHERE Mcu_FitnessCategoryIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$dataFitnessCategory = $query->result_array();
|
|
|
|
|
|
|
|
$result = [
|
|
"header" => $dataHeader,
|
|
"records" => $data,
|
|
"results" => $dataResults,
|
|
"kelainans" => $dataKelainans,
|
|
"advices" => $dataAdvices,
|
|
"fitnessCategory" => $dataFitnessCategory
|
|
// 'kesimpulan' => $kesimpulanFisik
|
|
];
|
|
$this->sys_ok($result);
|
|
}
|
|
|
|
function generateFitnessCategory()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$orderid = $prm['orderid'];
|
|
$conclusions = $prm['conclusions'];
|
|
|
|
|
|
$generateFitnessCategory = $this->genkelainan->generate_fitness_category($orderid);
|
|
$generateKesimpulanSaran = $this->genkelainan->generateKesimpulanSaran($orderid);
|
|
foreach ($conclusions as $key => $conclusion) {
|
|
if (intval($conclusion['id']) == 1) {
|
|
$conclusions[$key]['details']['kesimpulan'] = $generateKesimpulanSaran['kesimpulan'];
|
|
$conclusions[$key]['details']['saran'] = $generateKesimpulanSaran['saran'];
|
|
}
|
|
if (intval($conclusion['id']) == 2) {
|
|
$conclusions[$key]['details']['kesimpulan'] = $generateKesimpulanSaran['conclusion'];
|
|
$conclusions[$key]['details']['saran'] = $generateKesimpulanSaran['advice'];
|
|
}
|
|
}
|
|
$this->sys_ok([
|
|
"fitnessCategory" => $generateFitnessCategory,
|
|
"conclusions" => $conclusions
|
|
]);
|
|
}
|
|
|
|
function getdoctor()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$search = $prm['search'];
|
|
$query = " SELECT M_DoctorID as id,
|
|
CONCAT(M_DoctorPrefix,' ',M_DoctorPrefix2, ' ', M_DoctorName, ' ',M_DoctorSufix,' ', M_DoctorSufix2, ' ') as name
|
|
FROM m_doctor
|
|
WHERE M_DoctorIsActive = 'Y'
|
|
AND CONCAT(M_DoctorPrefix,' ',M_DoctorPrefix2, ' ', M_DoctorName, ' ',M_DoctorSufix,' ', M_DoctorSufix2, ' ') LIKE '%$search%'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
"query" => $this->db_onedev->last_query()
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function getFitnessCategory()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$query = "SELECT
|
|
Mcu_FitnessCategoryID id,
|
|
CONCAT(Mcu_FitnessCategoryName, ' (',Mcu_FitnessCategoryEng,')' ) as name,
|
|
Mcu_FitnessCategoryEng as nameEng,
|
|
Mcu_FitnessCategoryLevel as level
|
|
FROM `mcu_fitness_category`
|
|
WHERE `Mcu_FitnessCategoryIsActive` = 'Y';
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
"query" => $this->db_onedev->last_query()
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function save()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$act = $prm['data']['act'];
|
|
$data = $prm['data'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
if ($act == 'VAL') {
|
|
if (
|
|
$data['fitnessCategory'] == '' ||
|
|
intval($data['fitnessCategory']) == 0 ||
|
|
$data['fitnessCategory'] == null
|
|
) {
|
|
$this->sys_error("Pilih kategori fitness atau generate terlebih dahulu");
|
|
exit;
|
|
}
|
|
|
|
$sql = "";
|
|
$query = $this->db_onedev->query($sql, [$data['orderID']]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error_db("Error cek validasi " . $this->db_onedev->last_query());
|
|
exit;
|
|
}
|
|
$cekValidation = $query->row_array();
|
|
$expdCek = explode(',', $cekValidation['val']);
|
|
if (in_array('N', $expdCek) && $cekValidation['val'] != null && trim($cekValidation['val']) != '' && count($expdCek) > 0) {
|
|
$this->sys_error("Hasil Nonlab atau fisik belum di validasi .....");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$status = 'NEW';
|
|
$statusLog = $act;
|
|
$val = 'N';
|
|
$dt = '0000-00-00 00:00:00';
|
|
if ($act == 'VAL') {
|
|
$status = 'VAL';
|
|
$val = 'Y';
|
|
$dt = date("Y-m-d h:i:s");
|
|
}
|
|
else if ($act == 'UNVAL') {
|
|
$val = 'N';
|
|
$status = 'NEW';
|
|
$dt = date("Y-m-d h:i:s");
|
|
}
|
|
$jsonBefore = "";
|
|
$jsonAfter = "";
|
|
//insert mcu_resume
|
|
$resumeID = 0;
|
|
$sql = "SELECT *
|
|
FROM mcu_resume
|
|
WHERE Mcu_ResumeT_OrderHeaderID = ?
|
|
AND Mcu_ResumeIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, [$data['orderID']]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$dataCek = $query->result_array();
|
|
if (count($dataCek) == 0) {
|
|
$sql = "INSERT INTO mcu_resume
|
|
(Mcu_ResumeT_OrderHeaderID,
|
|
Mcu_ResumeStatus,
|
|
Mcu_ResumeValidation,
|
|
Mcu_ResumeValidationDateTime,
|
|
Mcu_ResumeValidationUserID,
|
|
Mcu_ResumeKesimpulan,
|
|
Mcu_ResumeRekomendasi,
|
|
Mcu_ResumeSaran,
|
|
Mcu_ResumeMcu_FitnessCategoryID)
|
|
VALUES(?,?,?,?,?,?,?,?,?)";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$data['orderID'],
|
|
$status,
|
|
$val,
|
|
$dt,
|
|
$userid,
|
|
$data['header']['kesimpulan'],
|
|
$data['header']['rekomendasi'],
|
|
$data['header']['saran'],
|
|
$data['fitnessCategory'],
|
|
]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$resumeID = $this->db_onedev->insert_id();
|
|
|
|
$sql = "INSERT INTO mcu_resume_eng(
|
|
Mcu_ResumeEngMcu_ResumeID,
|
|
Mcu_ResumeEngAdvice,
|
|
Mcu_ResumeEngConlusion,
|
|
Mcu_ResumeEngRecomendation,
|
|
Mcu_ResumeEngCreated,
|
|
Mcu_ResumeEngCreatedUserID)
|
|
VALUES(?,?,?,?,NOW(),?)";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$resumeID,
|
|
$data['header']['advice'],
|
|
$data['header']['conclusion'],
|
|
$data['header']['recomendation'],
|
|
$userid
|
|
]);
|
|
}
|
|
else {
|
|
if ($act != 'VAL' && $act != 'UNVAL') {
|
|
$statusLog = "UPDATE";
|
|
}
|
|
// if ($act == 'VAL') {
|
|
// // $this->generate_kelainan_lab($data['orderID']);
|
|
|
|
// }
|
|
$jsonBefore = $dataCek[0];
|
|
|
|
|
|
$resumeID = $dataCek[0]['Mcu_ResumeID'];
|
|
|
|
//get detail for log
|
|
$sql = "SELECT *
|
|
FROM mcu_resumedetails
|
|
WHERE
|
|
Mcu_ResumeDetailsMcu_ResumeID = ?
|
|
AND Mcu_ResumeDetailsIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, [$resumeID, ]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$detail = $query->result_array();
|
|
$jsonBefore['detail'] = $detail;
|
|
$sql = "UPDATE mcu_resume
|
|
SET Mcu_ResumeStatus = ?,
|
|
Mcu_ResumeValidation = ?,
|
|
Mcu_ResumeValidationDateTime = ?,
|
|
Mcu_ResumeValidationUserID = ?,
|
|
Mcu_ResumeKesimpulan = ?,
|
|
Mcu_ResumeRekomendasi = ?,
|
|
Mcu_ResumeSaran = ?,
|
|
Mcu_ResumeMcu_FitnessCategoryID = ?
|
|
WHERE Mcu_ResumeID = ?";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$status,
|
|
$val,
|
|
$dt,
|
|
$userid,
|
|
$data['header']['kesimpulan'],
|
|
$data['header']['rekomendasi'],
|
|
$data['header']['saran'],
|
|
$data['fitnessCategory'],
|
|
$resumeID,
|
|
]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$sql = "SELECT * FROM mcu_resume_eng WHERE Mcu_ResumeEngMcu_ResumeID = ? AND Mcu_ResumeEngIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$resumeID,
|
|
]);
|
|
$cekEng = $query->result_array();
|
|
if (empty($cekEng)) {
|
|
$sql = "INSERT INTO mcu_resume_eng(
|
|
Mcu_ResumeEngMcu_ResumeID,
|
|
Mcu_ResumeEngAdvice,
|
|
Mcu_ResumeEngConlusion,
|
|
Mcu_ResumeEngRecomendation,
|
|
Mcu_ResumeEngCreated,
|
|
Mcu_ResumeEngCreatedUserID)
|
|
VALUES(?,?,?,?,NOW(),?)";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$resumeID,
|
|
$data['header']['advice'],
|
|
$data['header']['conclusion'],
|
|
$data['header']['recomendation'],
|
|
$userid
|
|
]);
|
|
}
|
|
else {
|
|
$sql = "UPDATE mcu_resume_eng
|
|
SET Mcu_ResumeEngAdvice = ?,
|
|
Mcu_ResumeEngConlusion = ?,
|
|
Mcu_ResumeEngRecomendation = ?
|
|
WHERE Mcu_ResumeEngMcu_ResumeID = ? AND Mcu_ResumeEngIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$data['header']['advice'],
|
|
$data['header']['conclusion'],
|
|
$data['header']['recomendation'],
|
|
$resumeID,
|
|
]);
|
|
}
|
|
}
|
|
for ($i = 0; $i < count($data['detail']); $i++) {
|
|
$detail = $data['detail'][$i];
|
|
$result = $detail['result'];
|
|
if ($result == null) {
|
|
$result = '';
|
|
}
|
|
if ($detail['category'] == 'LAB') {
|
|
|
|
$sql = "SELECT Mcu_ResumeDetailsID
|
|
FROM mcu_resumedetails
|
|
WHERE Mcu_ResumeDetailsNat_SubSubGroupID = ?
|
|
AND Mcu_ResumeDetailsMcu_ResumeID = ?
|
|
AND Mcu_ResumeDetailsIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, [$detail['subGroupID'], $resumeID, ]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$cekDetail = $query->result_array();
|
|
// print_r($cekDetail);
|
|
if (count($cekDetail) == 0) {
|
|
$sql = "INSERT INTO mcu_resumedetails(
|
|
Mcu_ResumeDetailsMcu_ResumeID,
|
|
Mcu_ResumeDetailsCategory,
|
|
Mcu_ResumeDetailsNat_SubSubGroupID,
|
|
Mcu_ResumeDetailsResult,
|
|
Mcu_ResumeDetailsCreated,
|
|
Mcu_ResumeDetailsUserID)
|
|
VALUES(?,?,?,?,NOW(),?)";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$resumeID,
|
|
$detail['category'],
|
|
$detail['subGroupID'],
|
|
$result,
|
|
$userid,
|
|
]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
else {
|
|
$sql = "UPDATE mcu_resumedetails
|
|
SET Mcu_ResumeDetailsResult = ?,
|
|
Mcu_ResumeDetailsLastUpdated = NOW(),
|
|
Mcu_ResumeDetailsUserID = ?
|
|
WHERE Mcu_ResumeDetailsID = ?";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$result,
|
|
$userid,
|
|
$cekDetail[0]['Mcu_ResumeDetailsID']
|
|
]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
$sql = "SELECT Mcu_ResumeDetailsID
|
|
FROM mcu_resumedetails
|
|
WHERE Mcu_ResumeDetailsT_OrderDetailID = ?
|
|
AND Mcu_ResumeDetailsT_TestID = ?
|
|
AND Mcu_ResumeDetailsCategory = ?
|
|
AND Mcu_ResumeDetailsIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$detail['detailOrderID'],
|
|
$detail['testID'],
|
|
$detail['category'],
|
|
]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$cekDetail = $query->result_array();
|
|
if (count($cekDetail) == 0) {
|
|
$sql = "INSERT INTO mcu_resumedetails(
|
|
Mcu_ResumeDetailsMcu_ResumeID,
|
|
Mcu_ResumeDetailsCategory,
|
|
Mcu_ResumeDetailsT_OrderDetailID,
|
|
Mcu_ResumeDetailsT_TestID,
|
|
Mcu_ResumeDetailsResult,
|
|
Mcu_ResumeDetailsCreated,
|
|
Mcu_ResumeDetailsUserID)
|
|
VALUES(?,?,?,?,?,NOW(),?)";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$resumeID,
|
|
$detail['category'],
|
|
$detail['detailOrderID'],
|
|
$detail['testID'],
|
|
$result,
|
|
$userid,
|
|
]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
else {
|
|
$sql = "UPDATE mcu_resumedetails
|
|
SET Mcu_ResumeDetailsResult = ?,
|
|
Mcu_ResumeDetailsLastUpdated = NOW(),
|
|
Mcu_ResumeDetailsUserID = ?
|
|
WHERE Mcu_ResumeDetailsID = ?";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$result,
|
|
$userid,
|
|
$cekDetail[0]['Mcu_ResumeDetailsID']
|
|
]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$sql = "SELECT *
|
|
FROM mcu_resume
|
|
WHERE Mcu_ResumeID = ?
|
|
AND Mcu_ResumeIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, [$resumeID]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$jsonAfter = $query->result_array()[0];
|
|
//get detail for log
|
|
$sql = "SELECT *
|
|
FROM mcu_resumedetails
|
|
WHERE
|
|
Mcu_ResumeDetailsMcu_ResumeID = ?
|
|
AND Mcu_ResumeDetailsIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, [$resumeID, ]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$detail = $query->result_array();
|
|
$jsonAfter['detail'] = $detail;
|
|
|
|
$sql = "INSERT INTO one_lab_log.log_mcu_resume
|
|
(log_Mcu_ResumeMcu_ResumeID,
|
|
log_Mcu_ResumeJsonBefore,
|
|
log_Mcu_ResumeJsonAfter,
|
|
log_Mcu_ResumeJsonPrm,
|
|
log_Mcu_ResumeType,
|
|
log_Mcu_ResumeUserID,
|
|
log_Mcu_ResumeCreated)
|
|
VALUES(?,?,?,?,?,?,NOW())";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$resumeID,
|
|
json_encode($jsonBefore),
|
|
json_encode($jsonAfter),
|
|
json_encode($prm),
|
|
$statusLog,
|
|
$userid
|
|
]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$this->sys_ok('ok');
|
|
}
|
|
function getlab($id, $isApi)
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
// Mcu_KelainanName AS kelainanName,
|
|
// Mcu_KelainanGroupName AS kelainanGroupName,
|
|
// LEFT JOIN t_kelainan_lab
|
|
// ON T_OrderDetailT_OrderHeaderID = T_KelainanLabT_OrderHeaderID
|
|
// AND T_OrderDetailID = T_KelainanLabT_OrderDetailID
|
|
// AND T_TestNat_TestID = T_KelainanLabNat_TestID
|
|
// AND T_KelainanLabIsActive = 'Y'
|
|
// LEFT JOIN mcu_summarylab
|
|
// ON T_KelainanLabMcu_SummaryLabID = Mcu_SummaryLabID
|
|
// AND T_TestNat_TestID = Mcu_SummaryLabNat_TestID
|
|
// AND Mcu_SummaryLabIsActive = 'Y'
|
|
// LEFT join mcu_kelainan on Mcu_SummaryLabMcu_KelainanID = Mcu_KelainanID
|
|
// AND Mcu_KelainanIsActive = 'Y'
|
|
// LEFT join mcu_kelainangroup on Mcu_KelainanMcu_KelainanGroupID = Mcu_KelainanGroupID
|
|
// AND Mcu_KelainanGroupIsActive = 'Y'
|
|
$sql = "SELECT
|
|
T_OrderDetailID,
|
|
'' AS smLabID,
|
|
'' AS natTestID,
|
|
'' AS value,
|
|
'' AS kelainanID,
|
|
'' AS smLabType,
|
|
'' AS isNormal,
|
|
'' AS methode,
|
|
'' AS methodeID,
|
|
'' AS kelainanSaran,
|
|
T_OrderDetailT_OrderHeaderID AS orderID,
|
|
T_OrderDetailID AS orderDetailID,
|
|
T_OrderDetailT_TestID AS testID,
|
|
T_OrderDetailT_TestCode AS testCode,
|
|
T_OrderDetailT_TestSasCode AS testSasCode,
|
|
T_OrderDetailT_TestName AS testName,
|
|
T_OrderDetailResult AS result,
|
|
Nat_SubSubGroupID AS subGroupID,
|
|
T_OrderDetailMinValue AS minValues,
|
|
T_OrderDetailMaxValue AS maxValues,
|
|
Nat_SubSubGroupName AS groupName,
|
|
T_TestNat_TestID AS natTestID,
|
|
T_TestIsQuantitative as isKuantitatif,
|
|
CASE
|
|
WHEN T_OrderDetailResultFlag IS NULL THEN 'Y'
|
|
WHEN T_OrderDetailResultFlag = '' THEN 'Y'
|
|
ELSE 'N'
|
|
END testNormal,
|
|
T_OrderDetailResultFlag,
|
|
null AS resultID,
|
|
'N' AS resultValidation,
|
|
'NEW' AS resultStatus,
|
|
Mcu_ResumeDetailsID AS resumeDetailsID,
|
|
CASE
|
|
WHEN Mcu_ResumeDetailsMcu_ResumeID IS NULL THEN 'N'
|
|
WHEN Mcu_ResumeDetailsMcu_ResumeID IS NOT NULL THEN 'Y'
|
|
END as hasResult,
|
|
Mcu_ResumeID AS resumeID ,
|
|
Mcu_ResumeKesimpulan AS resumeKesimpulan ,
|
|
Mcu_ResumeRekomendasi AS resumeRekomendasi ,
|
|
Mcu_ResumeSaran AS resumeSaran ,
|
|
Mcu_ResumeDetailsResult AS resumeDetailResult ,
|
|
Mcu_ResumeDetailsResult AS resumeEntryResult
|
|
FROM t_orderdetail
|
|
JOIN group_resultdetail
|
|
ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID
|
|
AND Group_ResultDetailIsActive ='Y'
|
|
JOIN group_result
|
|
ON Group_ResultID = Group_ResultDetailGroup_ResultID
|
|
AND Group_ResultResumeMcu IN ('LAB')
|
|
JOIN t_test
|
|
ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN nat_test ON T_TestNat_TestID = Nat_TestID
|
|
JOIN nat_subsubgroup
|
|
ON T_TestNat_SubSubGroupID=Nat_SubSubGroupID
|
|
LEFT JOIN mcu_resume
|
|
ON T_OrderDetailT_OrderHeaderID = Mcu_ResumeT_OrderHeaderID
|
|
AND Mcu_ResumeIsActive = 'Y'
|
|
LEFT JOIN mcu_resumedetails
|
|
-- ON T_OrderDetailID = Mcu_ResumeDetailsT_OrderDetailID
|
|
ON Mcu_ResumeDetailsMcu_ResumeID = Mcu_ResumeID
|
|
AND T_TestNat_SubSubGroupID = Mcu_ResumeDetailsNat_SubSubGroupID
|
|
AND Mcu_ResumeDetailsIsActive = 'Y'
|
|
WHERE T_OrderDetailT_OrderHeaderID = {$id}
|
|
AND T_OrderDetailIsActive = 'Y'
|
|
AND Nat_TestIsResult = 'Y'";
|
|
|
|
// echo $sql;
|
|
$query = $this->db_onedev->query($sql, []);
|
|
//echo $this->db_onedev->last_query();
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$test = $query->result_array();
|
|
for ($i = 0; $i < count($test); $i++) {
|
|
$e = $test[$i];
|
|
$kelainan = '';
|
|
$saran = '';
|
|
$rstNormal = 'Y';
|
|
if ($e['hasResult'] == 'Y' && ($e['resumeDetailResult'] != null || trim($e['resumeDetailResult']) != "")) {
|
|
$kelainan = $e['resumeDetailResult'];
|
|
if (trim($e['resumeDetailResult']) !== 'Dalam batas normal') {
|
|
$rstNormal = 'N';
|
|
}
|
|
}
|
|
else {
|
|
if ($e['result'] !== null) {
|
|
# code...
|
|
if ($e['testNormal'] == 'N' && is_numeric($e['result'])) {
|
|
if (floatval($e['result']) >= floatval($e['maxValues'])) {
|
|
$kelainan = $e['testName'] . " meningkat ({$e['result']})";
|
|
}
|
|
if (floatval($e['result']) < floatval($e['minValues'])) {
|
|
$kelainan = $e['testName'] . " menurun ({$e['result']})";
|
|
}
|
|
$rstNormal = 'N';
|
|
}
|
|
if ($e['testNormal'] == 'N' && !is_numeric($e['result'])) {
|
|
$kelainan = $e['testName'] . " ({$e['result']})";
|
|
$rstNormal = 'N';
|
|
}
|
|
if ($e['testNormal'] == 'Y') {
|
|
$kelainan = "Dalam batas normal";
|
|
$rstNormal = 'Y';
|
|
}
|
|
}
|
|
}
|
|
$test[$i]['kelainan'] = $kelainan;
|
|
$test[$i]['generateKelainan'] = $this->generatekelainancek($e);
|
|
$test[$i]['resultIsNormal'] = $rstNormal;
|
|
$test[$i]['saran'] = $saran;
|
|
}
|
|
$newGab = [];
|
|
|
|
$group = [];
|
|
//penggabungan test
|
|
for ($i = 0; $i < count($test); $i++) {
|
|
$e = $test[$i];
|
|
|
|
if (!in_array($e['groupName'], $group)) {
|
|
$group[] = $e['groupName'];
|
|
if ($e['resultIsNormal'] == 'Y') {
|
|
$e['kelainan'] = '';
|
|
$e['generateKelainan'] = '';
|
|
}
|
|
$newGab[] = $e;
|
|
}
|
|
else {
|
|
for ($k = 0; $k < count($newGab); $k++) {
|
|
$nv = $newGab[$k];
|
|
if ($e['groupName'] == $nv['groupName']) {
|
|
|
|
if ($test[$i]['resultIsNormal'] == 'N') {
|
|
# code...
|
|
if (trim($newGab[$k]['kelainan']) == "") {
|
|
$newGab[$k]['kelainan'] = $test[$i]['kelainan'];
|
|
}
|
|
else {
|
|
if ($newGab[$k]['kelainan'] != $test[$i]['kelainan']) {
|
|
$newGab[$k]['kelainan'] = $newGab[$k]['kelainan'] . ', ' . $test[$i]['kelainan'];
|
|
}
|
|
}
|
|
if (trim($newGab[$k]['saran']) == "" && trim($test[$i]['saran']) != '') {
|
|
$newGab[$k]['saran'] = $test[$i]['saran'];
|
|
$newGab[$k]['saranArr'][] = $test[$i]['saran'];
|
|
}
|
|
else {
|
|
if (trim($test[$i]['saran']) != '') {
|
|
$newGab[$k]['saran'] = $newGab[$k]['saran'] . '@' . $test[$i]['saran'];
|
|
}
|
|
}
|
|
if ($newGab[$k]['testIDKelainan'] == '' && !isset($newGab[$k]['testIDKelainan'])) {
|
|
# code...
|
|
$newGab[$k]['testIDKelainan'] = $test[$i]['testID'];
|
|
}
|
|
else {
|
|
$newGab[$k]['testIDKelainan'] = $newGab[$k]['testIDKelainan'] . ',' . $test[$i]['testID'];
|
|
}
|
|
}
|
|
if (trim($newGab[$k]['generateKelainan']) == "") {
|
|
$newGab[$k]['generateKelainan'] = $test[$i]['generateKelainan'];
|
|
}
|
|
else {
|
|
if ($newGab[$k]['generateKelainan'] != $test[$i]['generateKelainan']) {
|
|
$newGab[$k]['generateKelainan'] = $newGab[$k]['generateKelainan'] . ', ' . $test[$i]['generateKelainan'];
|
|
}
|
|
}
|
|
$newGab[$k]['testID'] = $newGab[$k]['testID'] . ', ' . $test[$i]['testID'];
|
|
// $newGab[$k]['generateKelainan'] = $newGab[$k]['generateKelainan'] . ', ' . $test[$i]['generateKelainan'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for ($i = 0; $i < count($newGab); $i++) {
|
|
$newGab[$i]['normalValue'] = '';
|
|
if (trim(str_replace(',', '', $newGab[$i]['kelainan'])) != '') {
|
|
$newGab[$i]['resultIsNormal'] = 'N';
|
|
}
|
|
else {
|
|
$newGab[$i]['resultIsNormal'] = 'Y';
|
|
$newGab[$i]['kelainan'] = 'Dalam batas normal';
|
|
}
|
|
|
|
//saran unique
|
|
$expldSaran = explode('@', $newGab[$i]['saran']);
|
|
$expldSaranUnique = array_unique($expldSaran);
|
|
$newGab[$i]['saran'] = implode('@', $expldSaranUnique);
|
|
$expldTestIdKelainan = explode('@', $newGab[$i]['testIDKelainan']);
|
|
$expldTestIdKelainanUnique = array_unique($expldTestIdKelainan);
|
|
$newGab[$i]['testIDKelainan'] = implode(',', $expldTestIdKelainanUnique);
|
|
}
|
|
if ($isApi == 'Y') {
|
|
$this->sys_ok([
|
|
"test" => $test,
|
|
'gab' => $newGab
|
|
]);
|
|
}
|
|
else {
|
|
return $newGab;
|
|
}
|
|
}
|
|
function generatekelainancek($e)
|
|
{
|
|
$kelainan = "";
|
|
$rstNormal = "";
|
|
if ($e['result'] !== null) {
|
|
if ($e['testNormal'] == 'N' && is_numeric($e['result'])) {
|
|
if (floatval($e['result']) >= floatval($e['maxValues'])) {
|
|
$kelainan = $e['testName'] . " meningkat ({$e['result']})";
|
|
}
|
|
if (floatval($e['result']) < floatval($e['minValues'])) {
|
|
$kelainan = $e['testName'] . " menurun ({$e['result']})";
|
|
}
|
|
$rstNormal = 'N';
|
|
}
|
|
if ($e['testNormal'] == 'N' && !is_numeric($e['result'])) {
|
|
$kelainan = $e['testName'] . " ({$e['result']})";
|
|
$rstNormal = 'N';
|
|
}
|
|
if ($e['testNormal'] == 'Y') {
|
|
$kelainan = $e['testName'] . " ({$e['result']}) " . "dalam batas normal";
|
|
$rstNormal = 'Y';
|
|
}
|
|
}
|
|
else {
|
|
$kelainan = "<span style='color: red;'>" . $e['testName'] . " belum ada hasil" . "</span>";
|
|
$rstNormal = 'Y';
|
|
}
|
|
return $kelainan;
|
|
}
|
|
function getlabtest($id, $isApi)
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
$this->generate_kelainan_lab($id);
|
|
// Mcu_KelainanName AS kelainanName,
|
|
// Mcu_KelainanGroupName AS kelainanGroupName,
|
|
// LEFT JOIN t_kelainan_lab
|
|
// ON T_OrderDetailT_OrderHeaderID = T_KelainanLabT_OrderHeaderID
|
|
// AND T_OrderDetailID = T_KelainanLabT_OrderDetailID
|
|
// AND T_TestNat_TestID = T_KelainanLabNat_TestID
|
|
// AND T_KelainanLabIsActive = 'Y'
|
|
// LEFT JOIN mcu_summarylab
|
|
// ON T_KelainanLabMcu_SummaryLabID = Mcu_SummaryLabID
|
|
// AND T_TestNat_TestID = Mcu_SummaryLabNat_TestID
|
|
// AND Mcu_SummaryLabIsActive = 'Y'
|
|
// LEFT join mcu_kelainan on Mcu_SummaryLabMcu_KelainanID = Mcu_KelainanID
|
|
// AND Mcu_KelainanIsActive = 'Y'
|
|
// LEFT join mcu_kelainangroup on Mcu_KelainanMcu_KelainanGroupID = Mcu_KelainanGroupID
|
|
// AND Mcu_KelainanGroupIsActive = 'Y'
|
|
$sql = "SELECT
|
|
T_OrderDetailID,
|
|
'' AS smLabID,
|
|
'' AS natTestID,
|
|
'' AS value,
|
|
'' AS kelainanID,
|
|
'' AS smLabType,
|
|
'' AS isNormal,
|
|
'' AS methode,
|
|
'' AS methodeID,
|
|
'' AS kelainanSaran,
|
|
T_OrderDetailT_OrderHeaderID AS orderID,
|
|
T_OrderDetailID AS orderDetailID,
|
|
T_OrderDetailT_TestID AS testID,
|
|
T_OrderDetailT_TestCode AS testCode,
|
|
T_OrderDetailT_TestSasCode AS testSasCode,
|
|
T_OrderDetailT_TestName AS testName,
|
|
T_OrderDetailResult AS result,
|
|
Nat_SubSubGroupID AS subGroupID,
|
|
T_OrderDetailMinValue AS minValues,
|
|
T_OrderDetailMaxValue AS maxValues,
|
|
Nat_SubSubGroupName AS groupName,
|
|
T_TestNat_TestID AS natTestID,
|
|
T_TestIsQuantitative as isKuantitatif,
|
|
CASE
|
|
WHEN T_OrderDetailResultFlag IS NULL THEN 'Y'
|
|
WHEN T_OrderDetailResultFlag = '' THEN 'Y'
|
|
ELSE 'N'
|
|
END testNormal,
|
|
T_OrderDetailResultFlag,
|
|
null AS resultID,
|
|
'N' AS resultValidation,
|
|
'NEW' AS resultStatus,
|
|
Mcu_ResumeDetailsID AS resumeDetailsID,
|
|
CASE
|
|
WHEN Mcu_ResumeDetailsMcu_ResumeID IS NULL THEN 'N'
|
|
WHEN Mcu_ResumeDetailsMcu_ResumeID IS NOT NULL THEN 'Y'
|
|
END as hasResult,
|
|
Mcu_ResumeID AS resumeID ,
|
|
Mcu_ResumeKesimpulan AS resumeKesimpulan ,
|
|
Mcu_ResumeRekomendasi AS resumeRekomendasi ,
|
|
Mcu_ResumeSaran AS resumeSaran ,
|
|
Mcu_ResumeDetailsResult AS resumeDetailResult ,
|
|
Mcu_ResumeDetailsResult AS resumeEntryResult
|
|
FROM t_orderdetail
|
|
JOIN group_resultdetail
|
|
ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID
|
|
AND Group_ResultDetailIsActive ='Y'
|
|
JOIN group_result
|
|
ON Group_ResultID = Group_ResultDetailGroup_ResultID
|
|
AND Group_ResultResumeMcu IN ('LAB')
|
|
JOIN t_test
|
|
ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN nat_test ON T_TestNat_TestID = Nat_TestID
|
|
JOIN nat_subsubgroup
|
|
ON T_TestNat_SubSubGroupID=Nat_SubSubGroupID
|
|
LEFT JOIN mcu_resume
|
|
ON T_OrderDetailT_OrderHeaderID = Mcu_ResumeT_OrderHeaderID
|
|
AND Mcu_ResumeIsActive = 'Y'
|
|
LEFT JOIN mcu_resumedetails
|
|
-- ON T_OrderDetailID = Mcu_ResumeDetailsT_OrderDetailID
|
|
ON Mcu_ResumeDetailsMcu_ResumeID = Mcu_ResumeID
|
|
AND T_TestNat_SubSubGroupID = Mcu_ResumeDetailsNat_SubSubGroupID
|
|
AND Mcu_ResumeDetailsIsActive = 'Y'
|
|
WHERE T_OrderDetailT_OrderHeaderID = {$id}
|
|
AND T_OrderDetailIsActive = 'Y'
|
|
AND Nat_TestIsResult = 'Y'";
|
|
|
|
// echo $sql;
|
|
$query = $this->db_onedev->query($sql, []);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$test = $query->result_array();
|
|
for ($i = 0; $i < count($test); $i++) {
|
|
$e = $test[$i];
|
|
$kelainan = '';
|
|
$saran = '';
|
|
$rstNormal = 'Y';
|
|
// if ($e['hasResult'] == 'Y') {
|
|
// $kelainan = $e['resumeDetailResult'];
|
|
// if (trim($e['resumeDetailResult']) !== 'Dalam batas normal') {
|
|
// $rstNormal = 'N';
|
|
// }
|
|
// } else
|
|
if (true) {
|
|
if ($e['result'] !== null) {
|
|
# code...
|
|
if ($e['testNormal'] == 'N' && is_numeric($e['result'])) {
|
|
if (floatval($e['result']) >= floatval($e['maxValues'])) {
|
|
$kelainan = $e['testName'] . " meningkat ({$e['result']})";
|
|
}
|
|
if (floatval($e['result']) < floatval($e['minValues'])) {
|
|
$kelainan = $e['testName'] . " menurun ({$e['result']})";
|
|
}
|
|
$rstNormal = 'N';
|
|
}
|
|
if ($e['testNormal'] == 'N' && !is_numeric($e['result'])) {
|
|
$kelainan = $e['testName'] . " ({$e['result']})";
|
|
$rstNormal = 'N';
|
|
}
|
|
if ($e['testNormal'] == 'Y') {
|
|
$kelainan = "Dalam batas normal";
|
|
$rstNormal = 'Y';
|
|
}
|
|
}
|
|
// if ($e['smLabID'] != null) {
|
|
// // print_r("masuk else");
|
|
// if ($e['testNormal'] == 'Y') {
|
|
// if ($e['smLabType'] == '<' || $e['smLabType'] == '<=') {
|
|
// $ket = 'menurun';
|
|
// $value_comparison = $e['minValues'];
|
|
// }
|
|
// if ($e['smLabType'] == '>' || $e['smLabType'] == '>=') {
|
|
// $ket = 'meningkat';
|
|
// $value_comparison = $e['maxValues'];
|
|
// }
|
|
// //echo "Y";
|
|
// // if ($e['methode'] == 'N' && $this->dynamic_comparison($e['value'], $e['smLabType'], $value_comparison)) {
|
|
// if ($e['smLabType'] == '<' || $e['smLabType'] == '<=') {
|
|
// $ket = 'menurun';
|
|
// }
|
|
// if ($e['smLabType'] == '>' || $e['smLabType'] == '>=') {
|
|
// $ket = 'meningkat';
|
|
// }
|
|
// $kelainan = "";
|
|
// // $kelainan = $e['testName'] . " " . $ket . "({$e['result']})";
|
|
// if ($e['kelainanSaran'] != null) {
|
|
// # code...
|
|
// $saran = $e['kelainanSaran'];
|
|
// }
|
|
// $rstNormal = 'Y';
|
|
// // }
|
|
// } else {
|
|
// $value_comparison = $e['value'];
|
|
// if ($e['smLabType'] == '!=' || $e['smLabType'] == '==') {
|
|
// // if ($this->dynamic_comparison($e['value'], $e['smLabType'], $value_comparison)) {
|
|
// //echo $r['T_TestName']." : ".$r['Mcu_KelainanName'].", ";
|
|
// //langsung hasil
|
|
// // $kelainan = $e;
|
|
// $kelainan = $e['testName'] . " " . "{$e['result']}";
|
|
// if ($e['kelainanSaran'] != null) {
|
|
// # code...
|
|
// $saran = $e['kelainanSaran'];
|
|
// }
|
|
// $rstNormal = 'N';
|
|
// // }
|
|
// } else {
|
|
// // if (is_numeric($e['value']) && $this->dynamic_comparison($e['value'], $e['smLabType'], $value_comparison)) {
|
|
// if ($e['smLabType'] == '<' || $e['smLabType'] == '<=') {
|
|
// $ket = 'menurun';
|
|
// }
|
|
// if ($e['smLabType'] == '>' || $e['smLabType'] == '>=') {
|
|
// $ket = 'meningkat';
|
|
// }
|
|
// // $kelainan = $e;
|
|
// $kelainan = $e['testName'] . " " . $ket . "({$e['result']})";
|
|
// if ($e['kelainanSaran'] != null) {
|
|
// # code...
|
|
// $saran = $e['kelainanSaran'];
|
|
// }
|
|
// $rstNormal = 'N';
|
|
// // }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
|
|
// $sql = "SELECT
|
|
// Mcu_SummaryLabID AS smLabID,
|
|
// Mcu_SummaryLabNat_TestID AS natTestID,
|
|
// Mcu_SummaryLabValue AS value,
|
|
// Mcu_summaryLabMcu_KelainanID AS kelainanID,
|
|
// Mcu_SummaryLabType AS smLabType,
|
|
// Mcu_SummaryLabIsNormalValue AS isNormal,
|
|
// Mcu_SummaryLabWithMethode AS methode,
|
|
// Mcu_SummaryLabNat_MethodeID AS methodeID,
|
|
// Mcu_KelainanName AS kelainanName,
|
|
// Mcu_KelainanGroupName AS kelainanGroupName,
|
|
// `fn_getadvicebykelainanid`(Mcu_summaryLabMcu_KelainanID) AS kelainanSaran
|
|
// FROM mcu_summarylab
|
|
// join mcu_kelainan on Mcu_SummaryLabMcu_KelainanID = Mcu_KelainanID
|
|
// join mcu_kelainangroup on Mcu_KelainanMcu_KelainanGroupID = Mcu_KelainanGroupID
|
|
// WHERE Mcu_SummaryLabNat_TestID = '{$e['natTestID']}'
|
|
// AND Mcu_SummaryLabIsActive = 'Y'";
|
|
// $query = $this->db_onedev->query($sql, []);
|
|
// // echo $this->db_onedev->last_query();
|
|
// // exit;
|
|
// if (!$query) {
|
|
// $message = $this->db_onedev->error();
|
|
// $message['qry'] = $this->db_onedev->last_query();
|
|
// $this->sys_error($message);
|
|
// exit;
|
|
// }
|
|
// $normalValue = $query->result_array();
|
|
// // echo $normalValue;
|
|
// // exit;
|
|
// $test[$i]['normalValue'] = $normalValue;
|
|
// // $test[$i]['test'] = $normalValue;
|
|
|
|
// for ($k = 0; $k < count($normalValue); $k++) {
|
|
// $ket = '';
|
|
// $nv = $normalValue[$k];
|
|
// // if ($e['value'] != null && trim($e['value']) != '') {
|
|
|
|
// if ($nv['isNormal'] == 'Y') {
|
|
// if ($nv['smLabType'] == '<' || $nv['smLabType'] == '<=') {
|
|
// $ket = 'menurun';
|
|
// $value_comparison = $e['minValues'];
|
|
// }
|
|
// if ($nv['smLabType'] == '>' || $nv['smLabType'] == '>=') {
|
|
// $ket = 'meningkat';
|
|
// $value_comparison = $e['maxValues'];
|
|
// }
|
|
// //echo "Y";
|
|
// if ($nv['methode'] == 'N' && $this->dynamic_comparison($e['value'], $nv['smLabType'], $value_comparison)) {
|
|
// if ($nv['smLabType'] == '<' || $nv['smLabType'] == '<=') {
|
|
// $ket = 'menurun';
|
|
// }
|
|
// if ($nv['smLabType'] == '>' || $nv['smLabType'] == '>=') {
|
|
// $ket = 'meningkat';
|
|
// }
|
|
// $kelainan = $e['testName'] . " " . $ket . "({$e['result']})";
|
|
// $saran = $nv['kelainanSaran'];
|
|
// $rstNormal = 'N';
|
|
// }
|
|
// } else {
|
|
// $value_comparison = $nv['value'];
|
|
// if ($nv['smLabType'] == '!=' || $nv['smLabType'] == '==') {
|
|
// if ($this->dynamic_comparison($e['value'], $nv['smLabType'], $value_comparison)) {
|
|
// //echo $r['T_TestName']." : ".$r['Mcu_KelainanName'].", ";
|
|
// //langsung hasil
|
|
// // $kelainan = $nv;
|
|
// $kelainan = $e['testName'] . " " . "{$e['result']}";
|
|
// $saran = $nv['kelainanSaran'];
|
|
// $rstNormal = 'N';
|
|
// }
|
|
// } else {
|
|
// if (is_numeric($e['value']) && $this->dynamic_comparison($e['value'], $nv['smLabType'], $value_comparison)) {
|
|
// if ($nv['smLabType'] == '<' || $nv['smLabType'] == '<=') {
|
|
// $ket = 'menurun';
|
|
// }
|
|
// if ($nv['smLabType'] == '>' || $nv['smLabType'] == '>=') {
|
|
// $ket = 'meningkat';
|
|
// }
|
|
// // $kelainan = $nv;
|
|
// $kelainan = $e['testName'] . " " . $ket . "({$e['result']})";
|
|
// $saran = $nv['kelainanSaran'];
|
|
// $rstNormal = 'N';
|
|
// }
|
|
// }
|
|
// }
|
|
// // }
|
|
// }
|
|
}
|
|
$test[$i]['kelainan'] = $kelainan;
|
|
$test[$i]['resultIsNormal'] = $rstNormal;
|
|
$test[$i]['saran'] = $saran;
|
|
}
|
|
$newGab = [];
|
|
|
|
$group = [];
|
|
//penggabungan test
|
|
for ($i = 0; $i < count($test); $i++) {
|
|
$e = $test[$i];
|
|
|
|
if (!in_array($e['groupName'], $group)) {
|
|
$group[] = $e['groupName'];
|
|
if ($e['resultIsNormal'] == 'Y') {
|
|
$e['kelainan'] = '';
|
|
}
|
|
$newGab[] = $e;
|
|
}
|
|
else {
|
|
for ($k = 0; $k < count($newGab); $k++) {
|
|
$nv = $newGab[$k];
|
|
if ($e['groupName'] == $nv['groupName']) {
|
|
|
|
if ($test[$i]['resultIsNormal'] == 'N') {
|
|
# code...
|
|
if (trim($newGab[$k]['kelainan']) == "") {
|
|
$newGab[$k]['kelainan'] = $test[$i]['kelainan'];
|
|
}
|
|
else {
|
|
if ($newGab[$k]['kelainan'] != $test[$i]['kelainan']) {
|
|
$newGab[$k]['kelainan'] = $newGab[$k]['kelainan'] . ', ' . $test[$i]['kelainan'];
|
|
}
|
|
}
|
|
if (trim($newGab[$k]['saran']) == "" && trim($test[$i]['saran']) != '') {
|
|
$newGab[$k]['saran'] = $test[$i]['saran'];
|
|
$newGab[$k]['saranArr'][] = $test[$i]['saran'];
|
|
}
|
|
else {
|
|
if (trim($test[$i]['saran']) != '') {
|
|
$newGab[$k]['saran'] = $newGab[$k]['saran'] . '@' . $test[$i]['saran'];
|
|
}
|
|
}
|
|
if ($newGab[$k]['testIDKelainan'] == '' && !isset($newGab[$k]['testIDKelainan'])) {
|
|
# code...
|
|
$newGab[$k]['testIDKelainan'] = $test[$i]['testID'];
|
|
}
|
|
else {
|
|
$newGab[$k]['testIDKelainan'] = $newGab[$k]['testIDKelainan'] . ',' . $test[$i]['testID'];
|
|
}
|
|
}
|
|
$newGab[$k]['testID'] = $newGab[$k]['testID'] . ', ' . $test[$i]['testID'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for ($i = 0; $i < count($newGab); $i++) {
|
|
$newGab[$i]['normalValue'] = '';
|
|
if (trim(str_replace(',', '', $newGab[$i]['kelainan'])) != '') {
|
|
$newGab[$i]['resultIsNormal'] = 'N';
|
|
}
|
|
else {
|
|
$newGab[$i]['resultIsNormal'] = 'Y';
|
|
$newGab[$i]['kelainan'] = 'Dalam batas normal';
|
|
}
|
|
|
|
//saran unique
|
|
$expldSaran = explode('@', $newGab[$i]['saran']);
|
|
$expldSaranUnique = array_unique($expldSaran);
|
|
$newGab[$i]['saran'] = implode('@', $expldSaranUnique);
|
|
$expldTestIdKelainan = explode('@', $newGab[$i]['testIDKelainan']);
|
|
$expldTestIdKelainanUnique = array_unique($expldTestIdKelainan);
|
|
$newGab[$i]['testIDKelainan'] = implode(',', $expldTestIdKelainanUnique);
|
|
}
|
|
if ($isApi == 'Y') {
|
|
$this->sys_ok([
|
|
"test" => $test,
|
|
'gab' => $newGab
|
|
]);
|
|
}
|
|
else {
|
|
return $newGab;
|
|
}
|
|
}
|
|
function dynamic_comparison($varleft, $op, $varright)
|
|
{
|
|
|
|
switch ($op) {
|
|
case "=":
|
|
return $varleft == $varright;
|
|
case "!=":
|
|
return $varleft != $varright;
|
|
case ">=":
|
|
return $varleft >= $varright;
|
|
case "<=":
|
|
return $varleft <= $varright;
|
|
case ">":
|
|
return $varleft > $varright;
|
|
case "<":
|
|
return $varleft < $varright;
|
|
default:
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function generate_kelainan_lab($orderid)
|
|
{
|
|
$sql = "SELECT
|
|
T_OrderHeaderID,T_OrderHeaderLabNumber,
|
|
T_TestName, T_OrderDetailID, T_OrderDetailResult, T_OrderDetailNat_MethodeID,
|
|
T_OrderDetailNat_MethodeID, T_OrderDetailNat_MethodeName,
|
|
T_OrderDetailMinValue, T_OrderDetailMaxValue, T_OrderDetailMinValueInclusive,
|
|
T_OrderDetailMaxValueInclusive,
|
|
Mcu_SummaryLabID,
|
|
Mcu_SummaryLabValue,
|
|
Mcu_SummaryLabNat_MethodeID,
|
|
Mcu_SummaryLabWithMethode,
|
|
Mcu_SummaryLabType,
|
|
Mcu_SummaryLabIsNormalValue,
|
|
Mcu_SummaryLabIsRange,
|
|
Mcu_SummaryLabMinInclusive,
|
|
Mcu_SummaryLabMinValue,
|
|
Mcu_SummaryLabMaxInclusive,
|
|
Mcu_SummaryLabMaxValue,
|
|
Mcu_KelainanID, Mcu_KelainanName, Mcu_KelainanClasification,
|
|
Nat_TestID,
|
|
Nat_TestCode,
|
|
mcu_kelainangroup.*
|
|
from t_orderdetail
|
|
join t_orderheader on T_OrderHeaderID = {$orderid}
|
|
and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and T_OrderDetailIsActive = 'Y'
|
|
JOIN m_patient
|
|
ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_sex ON M_PatientM_SexID = M_SexID
|
|
join t_test
|
|
on T_OrderDetailT_TestID = T_TestID
|
|
join nat_test ON T_TestNat_TestID = Nat_TestID
|
|
join mcu_summarylab on T_TestNat_TestID = Mcu_SummaryLabNat_TestID AND Mcu_SummaryLabIsActive = 'Y'
|
|
AND (Mcu_SummaryLabGender = 'A' OR (Mcu_SummaryLabGender <> 'A' AND Mcu_SummaryLabGender = CASE
|
|
WHEN LOWER(M_SexNameLang) = 'male' THEN 'M'
|
|
WHEN LOWER(M_SexNameLang) = 'female' THEN 'F'
|
|
else ''
|
|
END))
|
|
join mcu_kelainan on Mcu_SummaryLabMcu_KelainanID = Mcu_KelainanID
|
|
join mcu_kelainangroup on Mcu_KelainanMcu_KelainanGroupID = Mcu_KelainanGroupID";
|
|
//echo $sql;
|
|
$qry = $this->db_onedev->query($sql);
|
|
if (!$qry) {
|
|
echo $this->db_onedev->last_query();
|
|
echo json_encode([
|
|
"status" => "ERR",
|
|
"message" => "Error get order | " . $this->db_onedev->error()["message"]
|
|
]);
|
|
exit;
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
$results = [];
|
|
|
|
|
|
|
|
foreach ($rows as $r) {
|
|
$result_value = $r['T_OrderDetailResult'];
|
|
|
|
$value_comparison = 0;
|
|
//echo $r['Mcu_SummaryLabIsNormalValue'];
|
|
$kelainan = [];
|
|
$notavailable = [];
|
|
if (trim($result_value) == 'NA') {
|
|
$notavailable = $r;
|
|
}
|
|
elseif ($r['Mcu_SummaryLabIsNormalValue'] == 'Y') {
|
|
if ($r['Mcu_SummaryLabType'] == '<' || $r['Mcu_SummaryLabType'] == '<=') {
|
|
$value_comparison = $r['T_OrderDetailMinValue'];
|
|
}
|
|
if ($r['Mcu_SummaryLabType'] == '>' || $r['Mcu_SummaryLabType'] == '>=') {
|
|
$value_comparison = $r['T_OrderDetailMaxValue'];
|
|
}
|
|
//echo "Y";
|
|
if ($r['Mcu_SummaryLabWithMethode'] == 'N' && $this->dynamic_comparison($result_value, $r['Mcu_SummaryLabType'], $value_comparison)) {
|
|
//echo $r['T_TestName']." : ".$r['Mcu_KelainanName'].", ";
|
|
$kelainan = $r;
|
|
$results[] = array('test' => $r['T_TestName'], 'nat_test' => $r['Nat_TestCode'], 'kelainan' => $r['Mcu_KelainanName'], 'orderdetailID' => $r['T_OrderDetailID'], 'orderheaderID' => $r['T_OrderHeaderID'], 'nat_testID' => $r['Nat_TestID'], 'mcu_summarylabID' => $r['Mcu_SummaryLabID']);
|
|
}
|
|
}
|
|
else if ($r['Mcu_SummaryLabIsRange'] == 'Y') {
|
|
// Mcu_SummaryLabIsNormalValue,
|
|
// Mcu_SummaryLabIsRange,
|
|
// Mcu_SummaryLabMinInclusive,
|
|
// Mcu_SummaryLabMinValue,
|
|
// Mcu_SummaryLabMaxInclusive,
|
|
// Mcu_SummaryLabMaxValue,
|
|
$isWithinMin = $r['Mcu_SummaryLabMinInclusive'] === 'Y' ? floatval($result_value) >= floatval($r['Mcu_SummaryLabMinValue']) : floatval($result_value) > floatval($r['Mcu_SummaryLabMinValue']);
|
|
$isWithinMax = $r['Mcu_SummaryLabMaxInclusive'] === 'Y' ? floatval($result_value) <= floatval($r['Mcu_SummaryLabMaxValue']) : floatval($result_value) < floatval($r['Mcu_SummaryLabMaxValue']);
|
|
|
|
if ($isWithinMax && $isWithinMin) {
|
|
$kelainan = $r;
|
|
$results[] = array('test' => $r['T_TestName'], 'nat_test' => $r['Nat_TestCode'], 'kelainan' => $r['Mcu_KelainanName'], 'orderdetailID' => $r['T_OrderDetailID'], 'orderheaderID' => $r['T_OrderHeaderID'], 'nat_testID' => $r['Nat_TestID'], 'mcu_summarylabID' => $r['Mcu_SummaryLabID']);
|
|
}
|
|
}
|
|
else {
|
|
$value_comparison = $r['Mcu_SummaryLabValue'];
|
|
if ($r['Mcu_SummaryLabType'] == '!=' || $r['Mcu_SummaryLabType'] == '==') {
|
|
if ($this->dynamic_comparison($result_value, $r['Mcu_SummaryLabType'], $value_comparison)) {
|
|
//echo $r['T_TestName']." : ".$r['Mcu_KelainanName'].", ";
|
|
$kelainan = $r;
|
|
$results[] = array('test' => $r['T_TestName'], 'nat_test' => $r['Nat_TestCode'], 'kelainan' => $r['Mcu_KelainanName'], 'orderdetailID' => $r['T_OrderDetailID'], 'orderheaderID' => $r['T_OrderHeaderID'], 'nat_testID' => $r['Nat_TestID'], 'mcu_summarylabID' => $r['Mcu_SummaryLabID']);
|
|
}
|
|
}
|
|
else {
|
|
if (is_numeric($result_value) && $this->dynamic_comparison($result_value, $r['Mcu_SummaryLabType'], $value_comparison)) {
|
|
//echo $r['T_TestName']." : ".$r['Mcu_KelainanName'].", ";
|
|
$kelainan = $r;
|
|
$results[] = array('test' => $r['T_TestName'], 'nat_test' => $r['Nat_TestCode'], 'kelainan' => $r['Mcu_KelainanName'], 'orderdetailID' => $r['T_OrderDetailID'], 'orderheaderID' => $r['T_OrderHeaderID'], 'nat_testID' => $r['Nat_TestID'], 'mcu_summarylabID' => $r['Mcu_SummaryLabID']);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (count($results) > 0) {
|
|
$sql = "UPDATE t_kelainan_lab
|
|
SET T_KelainanLabIsActive = 'N'
|
|
WHERE
|
|
T_KelainanLabT_OrderHeaderID = {$orderid}";
|
|
$this->db_onedev->query($sql);
|
|
|
|
foreach ($results as $v_result) {
|
|
$sql_kel_lab = "SELECT *
|
|
FROM t_kelainan_lab
|
|
WHERE T_KelainanLabT_OrderDetailID = ?
|
|
GROUP BY T_KelainanLabT_OrderDetailID";
|
|
$qry_kel_lab = $this->db_onedev->query($sql_kel_lab, array($v_result['orderdetailID']));
|
|
if ($qry_kel_lab) {
|
|
$rows_kel = $qry_kel_lab->result_array();
|
|
}
|
|
else {
|
|
$this->sys_error_db("select kelainan lab", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
if (count($rows_kel) > 0) {
|
|
|
|
// print_r($v_result['orderdetailID']);
|
|
// exit;
|
|
|
|
$sql_update_kel = "UPDATE t_kelainan_lab
|
|
SET T_KelainanLabT_OrderDetailID = {$v_result['orderdetailID']},
|
|
T_KelainanLabT_OrderHeaderID = {$v_result['orderheaderID']},
|
|
T_KelainanLabNat_TestID = {$v_result['nat_testID']},
|
|
T_KelainanLabMcu_SummaryLabID = {$v_result['mcu_summarylabID']},
|
|
T_KelainanLabCreatedUserID = 1,
|
|
T_KelainanLabIsActive = 'Y',
|
|
T_KelainanLabCreated = NOW()
|
|
WHERE T_KelainanLabID = {$rows_kel[0]['T_KelainanLabID']}";
|
|
$qry_update_kel = $this->db_onedev->query($sql_update_kel);
|
|
if (!$qry_update_kel) {
|
|
echo $this->db_onedev->last_query();
|
|
//$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db('error', 'Error update lab: ' . $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
else {
|
|
// print_r('insert');
|
|
// exit;
|
|
$sql_insert_lab = "INSERT INTO t_kelainan_lab(
|
|
T_KelainanLabT_OrderDetailID,
|
|
T_KelainanLabT_OrderHeaderID,
|
|
T_KelainanLabNat_TestID,
|
|
T_KelainanLabMcu_SummaryLabID,
|
|
T_KelainanLabCreatedUserID,
|
|
T_KelainanLabCreated)
|
|
VALUES(
|
|
'{$v_result['orderdetailID']}',
|
|
'{$v_result['orderheaderID']}',
|
|
'{$v_result['nat_testID']}',
|
|
'{$v_result['mcu_summarylabID']}',
|
|
1,
|
|
NOW())";
|
|
$qry_insert_lab = $this->db_onedev->query($sql_insert_lab);
|
|
|
|
if (!$qry_insert_lab) {
|
|
//$this->db_onedev->trans_rollback();
|
|
echo $this->db_onedev->last_query();
|
|
$this->sys_error_db('error', 'Error insert kelainan lab: ' . $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function savedoctor()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$id = $prm['id'];
|
|
$doctorid = $prm['doctorid'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
//insert mcu_resume
|
|
$resumeID = 0;
|
|
$jsonBefore = "";
|
|
$jsonAfter = "";
|
|
$status = 'NEW DOCTOR';
|
|
$sql = "SELECT *
|
|
FROM mcu_resume
|
|
WHERE Mcu_ResumeT_OrderHeaderID = ?
|
|
AND Mcu_ResumeIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, [$id]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$dataCek = $query->result_array();
|
|
$jsonBefore = $dataCek;
|
|
if (count($dataCek) == 0) {
|
|
$sql = "INSERT INTO mcu_resume
|
|
(Mcu_ResumeT_OrderHeaderID,
|
|
Mcu_ResumeStatus,
|
|
Mcu_ResumeM_DoctorID,
|
|
Mcu_ResumeCreated,
|
|
Mcu_ResumeUserID
|
|
)
|
|
VALUES(?,'NEW',?,NOW(),?)";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$id,
|
|
$doctorid,
|
|
$userid,
|
|
]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$resumeID = $this->db_onedev->insert_id();
|
|
}
|
|
else {
|
|
$status = 'UPDATE DOCTOR';
|
|
$resumeID = $dataCek[0]['Mcu_ResumeID'];
|
|
$sql = "UPDATE mcu_resume
|
|
SET Mcu_ResumeM_DoctorID = ?,
|
|
Mcu_ResumeUserID = ?
|
|
WHERE Mcu_ResumeID = ?";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$doctorid,
|
|
$userid,
|
|
$resumeID,
|
|
]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
$sql = "SELECT *
|
|
FROM mcu_resume
|
|
WHERE Mcu_ResumeT_OrderHeaderID = ?
|
|
AND Mcu_ResumeIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, [$id]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$dataCek = $query->result_array();
|
|
$jsonAfter = $dataCek;
|
|
$sql = "INSERT INTO one_lab_log.log_mcu_resume
|
|
(log_Mcu_ResumeMcu_ResumeID,
|
|
log_Mcu_ResumeJsonBefore,
|
|
log_Mcu_ResumeJsonAfter,
|
|
log_Mcu_ResumeJsonPrm,
|
|
log_Mcu_ResumeType,
|
|
log_Mcu_ResumeUserID,
|
|
log_Mcu_ResumeCreated)
|
|
VALUES(?,?,?,?,?,?,NOW())";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$resumeID,
|
|
json_encode($jsonBefore),
|
|
json_encode($jsonAfter),
|
|
json_encode($prm),
|
|
$status,
|
|
$userid
|
|
]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$this->sys_ok('OK');
|
|
exit;
|
|
}
|
|
function cobaGenerate($orderID, $userID)
|
|
{
|
|
$this->load->library('Etlfisik');
|
|
$rtn = $this->etlfisik->generate_kelainan_by_order($orderID, $userID);
|
|
echo json_encode($rtn);
|
|
}
|
|
function generateKesimpulanSaran($id, $debug = 'N')
|
|
{
|
|
//get kelainan nonlab
|
|
$sql = "SELECT
|
|
T_KelainanNonLabID AS kelainanNonlabID,
|
|
T_KelainanNonLabT_OrderHeaderID as orderID,
|
|
Mcu_KelainanID as kelainanID,
|
|
T_KelainanNonLabMcu_SummaryNonlabID As summaryID,
|
|
Mcu_KelainanName as kelainanName,
|
|
fn_get_translate_word_separator_comma(Mcu_KelainanName,2) as kelainanNameEng,
|
|
'NONLAB' as type
|
|
FROM
|
|
t_kelainan_nonlab
|
|
JOIN mcu_summarynonlab
|
|
ON T_KelainanNonLabMcu_SummaryNonlabID = Mcu_SummaryNonlabID
|
|
AND T_KelainanNonLabT_OrderHeaderID = ?
|
|
AND T_KelainanNonLabIsActive = 'Y'
|
|
JOIN mcu_kelainan
|
|
ON Mcu_SummaryNonlabMcu_KelainanID = Mcu_KelainanID
|
|
AND Mcu_KelainanIsActive = 'Y'
|
|
GROUP BY Mcu_KelainanID
|
|
";
|
|
$query = $this->db_onedev->query($sql, [$id]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error_db("Error get kelainan nonlab");
|
|
exit;
|
|
}
|
|
$kelainanNonlab = $query->result_array();
|
|
|
|
//get kelainan lab
|
|
$sql = "SELECT
|
|
T_KelainanLabID as kelainanLabID,
|
|
T_KelainanLabT_OrderHeaderID as orderID,
|
|
Mcu_KelainanID as kelainanID,
|
|
Mcu_SummaryLabID as summaryID,
|
|
Mcu_KelainanName as kelainanName,
|
|
fn_get_translate_word_separator_comma(Mcu_KelainanName,2) as kelainanNameEng,
|
|
'LAB' as type
|
|
FROM t_kelainan_lab
|
|
JOIN mcu_summarylab
|
|
ON T_KelainanLabMcu_SummaryLabID = Mcu_SummaryLabID
|
|
AND Mcu_SummaryLabIsActive = 'Y'
|
|
AND T_KelainanLabT_OrderHeaderID = ?
|
|
JOIN mcu_kelainan
|
|
ON Mcu_summaryLabMcu_KelainanID = Mcu_KelainanID
|
|
AND Mcu_KelainanIsActive = 'Y'
|
|
AND T_KelainanLabIsActive = 'Y'
|
|
GROUP BY Mcu_KelainanID
|
|
";
|
|
$query = $this->db_onedev->query($sql, [$id]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error_db("Error get kelainan lab");
|
|
exit;
|
|
}
|
|
$kelainanLab = $query->result_array();
|
|
|
|
//get kelainan fisik
|
|
$sql = "SELECT
|
|
T_KelainanFiskID as kelainanFisikID,
|
|
T_KelainanFiskT_OrderHeaderID orderID,
|
|
Mcu_FisikSummaryID summaryID,
|
|
Mcu_KelainanID as kelainanID ,
|
|
Mcu_KelainanName as kelainanName,
|
|
fn_get_translate_word_separator_comma(Mcu_KelainanName,2) as kelainanNameEng,
|
|
'FISIK' as type
|
|
FROM t_kelainan_fisik
|
|
JOIN mcu_fisiksummary
|
|
ON T_KelainanFiskMcu_FisikSummaryID = Mcu_FisikSummaryID
|
|
AND Mcu_FisikSummaryIsActive = 'Y'
|
|
AND T_KelainanFiskT_OrderHeaderID = ?
|
|
AND T_KelainanFiskIsActive = 'Y'
|
|
JOIN mcu_kelainan
|
|
ON Mcu_FisikSummaryMcu_KelainanID = Mcu_KelainanID
|
|
AND Mcu_KelainanIsActive = 'Y'
|
|
GROUP BY Mcu_KelainanID
|
|
";
|
|
$query = $this->db_onedev->query($sql, [$id]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error_db("Error get kelainan fisik");
|
|
exit;
|
|
}
|
|
$kelainanFisik = $query->result_array();
|
|
|
|
$arrMcuKelainanID = array();
|
|
$arrMcuKelainanIDEng = array();
|
|
$kesimpulan = "";
|
|
$counterKesimpulan = 1;
|
|
$conclusion = "";
|
|
$counterConclusion = 1;
|
|
for ($i = 0; $i < count($kelainanNonlab); $i++) {
|
|
$kesimpulan .= "- " . $kelainanNonlab[$i]['kelainanName'] . "\n";
|
|
$counterKesimpulan += 1;
|
|
array_push($arrMcuKelainanID, $kelainanNonlab[$i]['kelainanID']);
|
|
|
|
$conclusion .= "- " . $kelainanNonlab[$i]['kelainanNameEng'] . "\n";
|
|
$counterConclusion += 1;
|
|
array_push($arrMcuKelainanIDEng, $kelainanNonlab[$i]['kelainanNameEng']);
|
|
}
|
|
for ($i = 0; $i < count($kelainanLab); $i++) {
|
|
$kesimpulan .= "- " . $kelainanLab[$i]['kelainanName'] . "\n";
|
|
$counterKesimpulan += 1;
|
|
array_push($arrMcuKelainanID, $kelainanLab[$i]['kelainanID']);
|
|
|
|
$conclusion .= "- " . $kelainanLab[$i]['kelainanNameEng'] . "\n";
|
|
$counterConclusion += 1;
|
|
array_push($arrMcuKelainanIDEng, $kelainanLab[$i]['kelainanNameEng']);
|
|
}
|
|
for ($i = 0; $i < count($kelainanFisik); $i++) {
|
|
$kesimpulan .= "- " . $kelainanFisik[$i]['kelainanName'] . "\n";
|
|
$counterKesimpulan += 1;
|
|
array_push($arrMcuKelainanID, $kelainanFisik[$i]['kelainanID']);
|
|
|
|
$conclusion .= "- " . $kelainanFisik[$i]['kelainanNameEng'] . "\n";
|
|
$counterConclusion += 1;
|
|
array_push($arrMcuKelainanIDEng, $kelainanFisik[$i]['kelainanNameEng']);
|
|
}
|
|
//get kelainan saran nonlab
|
|
$sql = "SELECT
|
|
Nat_AdvicekelainanID adviceID,
|
|
Nat_AdvicekelainanMcu_KelainanID mcuKelainanID,
|
|
Nat_AdviceIna saranIna,
|
|
IF(Nat_AdviceEng = '',Nat_AdviceIna, Nat_AdviceEng) saranEng,
|
|
fn_get_translate_word_separator_comma(Nat_AdviceIna,2) as translate_eng
|
|
FROM nat_advice_kelainan
|
|
JOIN nat_advice
|
|
ON Nat_AdvicekelainanNat_AdviceID = Nat_AdviceID
|
|
AND Nat_AdvicekelainanMcu_KelainanID IN ?
|
|
AND Nat_AdviceIsActive = 'Y'
|
|
AND Nat_AdvicekelainanIsActive = 'Y'
|
|
group by Nat_AdviceIna
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql, [$arrMcuKelainanID]);
|
|
//echo $this->db_onedev->last_query();
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error_db("Error cek validasi 3 " . $this->db_onedev->last_query());
|
|
exit;
|
|
}
|
|
$arrSaran = $query->result_array();
|
|
if (count($arrSaran) > 0) {
|
|
foreach ($arrSaran as $key => $value) {
|
|
$adv = $value['saranEng'];
|
|
if (trim($adv) == '' || $adv == $value['saranIna']) {
|
|
$adv = $value['translate_eng'];
|
|
}
|
|
$arrSaran[$key]['saranEng'] = $adv;
|
|
}
|
|
}
|
|
|
|
$saran = "";
|
|
$counterSaran = 1;
|
|
$advice = "";
|
|
$counterAdvice = 1;
|
|
for ($i = 0; $i < count($arrSaran); $i++) {
|
|
$saran .= "- " . $arrSaran[$i]['saranIna'] . "\n";
|
|
$counterSaran += 1;
|
|
$advice .= "- " . $arrSaran[$i]['saranEng'] . "\n";
|
|
$counterAdvice += 1;
|
|
}
|
|
if ($debug == 'Y') {
|
|
$this->sys_ok(array(
|
|
"kesimpulan" => $kesimpulan,
|
|
"saran" => $saran,
|
|
"advice" => $advice,
|
|
"conclusion" => $conclusion,
|
|
));
|
|
}
|
|
else {
|
|
return array(
|
|
"kesimpulan" => $kesimpulan,
|
|
"saran" => $saran,
|
|
"advice" => $advice,
|
|
"conclusion" => $conclusion,
|
|
);
|
|
}
|
|
}
|
|
function XXX()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$id = $prm['orderid'];
|
|
$kesimpulanPrm = $prm['kesimpulan'];
|
|
$saranPrm = $prm['saran'];
|
|
$rekomendasiPrm = $prm['rekomendasi'];
|
|
$conclusionPrm = $prm['conclusion'];
|
|
$advicePrm = $prm['advice'];
|
|
$recomendationPrm = $prm['recomendation'];
|
|
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$sql = "SELECT IFNULL(GROUP_CONCAT(DISTINCT So_ResultEntryValidation1), 'Y') as val
|
|
FROM t_orderdetail
|
|
JOIN so_resultentry
|
|
ON T_OrderDetailT_OrderHeaderID = So_ResultEntryT_OrderHeaderID
|
|
AND T_OrderDetailID = So_ResultEntryT_OrderDetailID
|
|
AND So_ResultEntryIsActive = 'Y' AND T_OrderDetailIsActive = 'Y'
|
|
AND So_ResultEntryT_OrderHeaderID = ?
|
|
JOIN group_resultdetail
|
|
ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID
|
|
AND T_OrderDetailT_TestID NOT IN (2571,2573,2573,3450,2572)
|
|
AND Group_ResultDetailIsActive ='Y'
|
|
JOIN group_result
|
|
ON Group_ResultID = Group_ResultDetailGroup_ResultID AND Group_ResultID <> 35
|
|
AND Group_ResultResumeMcu IN ('NONLAB', 'FISIK')
|
|
AND Group_ResultIsActive ='Y'";
|
|
$query = $this->db_onedev->query($sql, [$id]);
|
|
// echo $this->db_onedev->last_query();
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error_db("Error cek validasi 2" . $this->db_onedev->last_query());
|
|
exit;
|
|
}
|
|
$cekValidation = $query->row_array();
|
|
$expdCek = explode(',', $cekValidation['val']);
|
|
if (in_array('N', $expdCek) && $cekValidation['val'] != null && trim($cekValidation['val']) != '' && count($expdCek) > 0) {
|
|
$this->sys_error("Hasil Nonlab atau fisik belum di validasi .....");
|
|
exit;
|
|
}
|
|
//insert mcu_resume
|
|
$resumeID = 0;
|
|
$jsonBefore = "";
|
|
$jsonAfter = "";
|
|
$status = 'FITNESS NEW';
|
|
$sql = "SELECT *
|
|
FROM mcu_resume
|
|
WHERE Mcu_ResumeT_OrderHeaderID = ?
|
|
AND Mcu_ResumeIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, [$id]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$dataCek = $query->result_array();
|
|
$jsonBefore = $dataCek;
|
|
|
|
|
|
|
|
$this->load->library('Etlfisik');
|
|
$rtn = $this->etlfisik->generate_kelainan_by_order($id, $userid);
|
|
$rtnStatus = $rtn['status'];
|
|
$rtnGenerateResult = $rtn['data'];
|
|
$fitnessID = $rtn['status']['id'] ?? '0';
|
|
|
|
$rekomendasi = $rtn['status']['name'];
|
|
$recomendation = $rtn['status']['name_eng'];
|
|
if (trim($rekomendasiPrm) == '') {
|
|
$rekomendasi = $rtn['status']['name'];
|
|
}
|
|
else {
|
|
$rekomendasi = $rekomendasiPrm;
|
|
}
|
|
if (trim($recomendationPrm) == '') {
|
|
$recomendation = $rtn['status']['name_eng'];
|
|
}
|
|
else {
|
|
$recomendation = $recomendationPrm;
|
|
}
|
|
$kesimpulan = '';
|
|
$saran = '';
|
|
$advice = '';
|
|
$conclusion = '';
|
|
|
|
if (count($dataCek) == 0) {
|
|
$generateKesimpulanSaran = $this->generateKesimpulanSaran($id);
|
|
$kesimpulan = $generateKesimpulanSaran['kesimpulan'];
|
|
$saran = $generateKesimpulanSaran['saran'];
|
|
$advice = $generateKesimpulanSaran['advice'];
|
|
$conclusion = $generateKesimpulanSaran['conclusion'];
|
|
$sql = "INSERT INTO mcu_resume
|
|
(Mcu_ResumeT_OrderHeaderID,
|
|
Mcu_ResumeStatus,
|
|
Mcu_ResumeMcu_FitnessCategoryID,
|
|
Mcu_ResumeCreated,
|
|
Mcu_ResumeUserID,
|
|
Mcu_ResumeKesimpulan,
|
|
Mcu_ResumeRekomendasi,
|
|
Mcu_ResumeSaran
|
|
)
|
|
VALUES(?,'NEW',?,NOW(),?,?,?,?)";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$id,
|
|
$fitnessID,
|
|
$userid,
|
|
$kesimpulan,
|
|
$rekomendasi,
|
|
$saran
|
|
]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$resumeID = $this->db_onedev->insert_id();
|
|
$sql = "INSERT INTO mcu_resume_eng
|
|
(Mcu_ResumeEngMcu_ResumeID,
|
|
Mcu_ResumeEngConlusion,
|
|
Mcu_ResumeEngRecomendation,
|
|
Mcu_ResumeEngAdvice,
|
|
Mcu_ResumeEngCreated,
|
|
Mcu_ResumeEngCreatedUserID
|
|
)
|
|
VALUES(?,?,?,?,NOW(),?)";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$resumeID,
|
|
$conclusion,
|
|
$recomendation,
|
|
$advice,
|
|
$userid
|
|
]);
|
|
}
|
|
else {
|
|
if (trim($kesimpulanPrm) == "" || trim($saranPrm == '')) {
|
|
$generateKesimpulanSaran = $this->generateKesimpulanSaran($id);
|
|
if (trim($kesimpulanPrm) == '') {
|
|
$kesimpulan = $generateKesimpulanSaran['kesimpulan'];
|
|
$conclusion = $generateKesimpulanSaran['conclusion'];
|
|
}
|
|
else {
|
|
$kesimpulan = $kesimpulanPrm;
|
|
}
|
|
if (trim($saranPrm) == '') {
|
|
$saran = $generateKesimpulanSaran['saran'];
|
|
$advice = $generateKesimpulanSaran['advice'];
|
|
}
|
|
else {
|
|
$saran = $saranPrm;
|
|
}
|
|
}
|
|
else {
|
|
$kesimpulan = $kesimpulanPrm;
|
|
$saran = $saranPrm;
|
|
$advice = $advicePrm;
|
|
$conclusion = $conclusionPrm;
|
|
$recomendation = $recomendationPrm;
|
|
}
|
|
$status = 'FITNESS UPDATE';
|
|
$resumeID = $dataCek[0]['Mcu_ResumeID'];
|
|
$sql = "UPDATE mcu_resume
|
|
SET Mcu_ResumeMcu_FitnessCategoryID = ?,
|
|
Mcu_ResumeUserID = ?,
|
|
Mcu_ResumeKesimpulan = ?,
|
|
Mcu_ResumeRekomendasi = ?,
|
|
Mcu_ResumeSaran = ?
|
|
WHERE Mcu_ResumeID = ?";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$fitnessID,
|
|
$userid,
|
|
$kesimpulan,
|
|
$rekomendasi,
|
|
$saran,
|
|
$resumeID,
|
|
]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT * FROM mcu_resume_eng
|
|
WHERE Mcu_ResumeEngMcu_ResumeID = ? AND Mcu_ResumeEngIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, [$resumeID]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$dataCekEng = $query->result_array();
|
|
if (count($dataCekEng) == 0) {
|
|
$sql = "INSERT INTO mcu_resume_eng
|
|
(Mcu_ResumeEngMcu_ResumeID,
|
|
Mcu_ResumeEngConlusion,
|
|
Mcu_ResumeEngRecomendation,
|
|
Mcu_ResumeEngAdvice,
|
|
Mcu_ResumeEngCreated,
|
|
Mcu_ResumeEngCreatedUserID
|
|
)
|
|
VALUES(?,?,?,?,NOW(),?)";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$resumeID,
|
|
$conclusion,
|
|
$recomendation,
|
|
$advice,
|
|
$userid
|
|
]);
|
|
}
|
|
else {
|
|
$sql = "UPDATE mcu_resume_eng
|
|
SET Mcu_ResumeEngConlusion = ?,
|
|
Mcu_ResumeEngRecomendation = ?,
|
|
Mcu_ResumeEngAdvice = ?
|
|
WHERE Mcu_ResumeEngMcu_ResumeID = ? AND Mcu_ResumeEngIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$conclusion,
|
|
$recomendation,
|
|
$advice,
|
|
$resumeID,
|
|
]);
|
|
}
|
|
}
|
|
//insert log
|
|
$sql = "SELECT *
|
|
FROM mcu_resume
|
|
LEFT JOIN mcu_resume_eng ON Mcu_ResumeEngMcu_ResumeID = Mcu_ResumeID AND Mcu_ResumeEngIsActive = 'Y'
|
|
WHERE Mcu_ResumeT_OrderHeaderID = ?
|
|
AND Mcu_ResumeIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, [$id]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$dataCek = $query->result_array();
|
|
$jsonAfter = $dataCek;
|
|
$sql = "INSERT INTO one_lab_log.log_mcu_resume
|
|
(log_Mcu_ResumeMcu_ResumeID,
|
|
log_Mcu_ResumeJsonBefore,
|
|
log_Mcu_ResumeJsonAfter,
|
|
log_Mcu_ResumeJsonPrm,
|
|
log_Mcu_ResumeType,
|
|
log_Mcu_ResumeUserID,
|
|
log_Mcu_ResumeCreated)
|
|
VALUES(?,?,?,?,?,?,NOW())";
|
|
$query = $this->db_onedev->query($sql, [
|
|
$resumeID,
|
|
json_encode($jsonBefore),
|
|
json_encode($jsonAfter),
|
|
json_encode($prm),
|
|
$status,
|
|
$userid
|
|
]);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
for ($i = 0; $i < count($rtn['data']); $i++) {
|
|
$rtn['data'][$i]['Nat_TestName'] = str_replace("|", ", ", $rtn['data'][$i]['Nat_TestName']);
|
|
}
|
|
$this->sys_ok($rtn);
|
|
exit;
|
|
}
|
|
|
|
public function getcompany()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
if ($prm['search'] != '') {
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
$sql = "SELECT * FROM m_company WHERE M_CompanyIsActive = 'Y'";
|
|
if ($prm['search'] != '') {
|
|
$sql .= " AND M_CompanyName LIKE ?";
|
|
}
|
|
$qry = $this->db_onedev->query($sql, [$q['search']]);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$last_qry = $this->db_onedev->last_query();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$data = $qry->result_array();
|
|
$result = [
|
|
"records" => $data,
|
|
];
|
|
$this->sys_ok($result);
|
|
}
|
|
catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|