db_onedev = $this->load->database("onedev", true); // $this->load->helper(array('form', 'url')); // $this->load->library('Nonlabtemplate'); // $this->load->library('Kesimpulanfisik'); // $this->load->library("Soresultlog"); } public function getInterpretationValue() { $prm = $this->sys_input; $limit = 50; if (isset($prm['limit'])) { $limit = $prm['limit']; } $reID = $prm['reID']; $interpretationID = $prm['interpretationID']; $sqlRe = ''; if (intval($reID) != 0 && $reID != null) { $sqlRe = "AND So_ResultEntrySDSInterpretationTypeSo_ResultEntryID = {$reID}"; } $sql = "SELECT T_OrderHeaderLabNumber as labNumber, T_OrderHeaderDate as orderDate, So_ResultEntrySDSInterpretationTypeSo_ResultEntryID as reID, So_ResultEntrySDSInterpretationSDSInterpretationID as interpretationID, So_ResultEntrySDSInterpretationScore as interpretationScore, So_ResultEntrySDSInterpretationDisplay as interpretationDisplay FROM so_resultentrysdsinterpretation JOIN so_resultentry ON So_ResultEntrySDSInterpretationTypeSo_ResultEntryID = So_ResultEntryID AND So_ResultEntryIsActive = 'Y' JOIN t_orderheader ON So_ResultEntryT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive = 'Y' WHERE So_ResultEntrySDSInterpretationIsActive = 'Y' $sqlRe LIMIT ?"; $query = $this->db_onedev->query($sql, [$limit]); if (!$query) { $this->sys_error_db("Error get detail"); exit; } $interpretation = $query->result_array(); $notSame = array(); for ($i = 0; $i < count($interpretation); $i++) { $data = $interpretation[$i]; $interpretationID = $data['interpretationID']; $sql = "SELECT SDS_InterpretationID, SDS_InterpretationOrder NomorInterpretation, SDS_InterpretationText Interpretation, SDS_InterpretationType tipe, GROUP_CONCAT(SDS_TemplateQuestionOrder) NomorPertanyaan FROM sds_interpretation JOIN sds_interpretationmap ON SDS_InterpretationID = SDS_InterpretationMapSDS_InterpretationID AND SDS_InterpretationID = ? AND SDS_InterpretationMapIsActive = 'Y' JOIN sds_templatequestion ON SDS_InterpretationMapSDS_TemplateQuestionID = SDS_TemplateQuestionID GROUP BY SDS_InterpretationID order by SDS_InterpretationType, SDS_InterpretationOrder, SDS_TemplateQuestionOrder;"; $query = $this->db_onedev->query($sql, [$interpretationID]); if (!$query) { $this->sys_error_db("Error get detail"); exit; } $mapping = $query->row_array(); $qstID = explode(',', $mapping['NomorPertanyaan']); $interpretation[$i]['questionID'] = $mapping['NomorPertanyaan']; $sql = "SELECT So_ResultEntrySDSSo_ResultEntryID, So_ResultEntrySDSSDS_TemplateQuestionID, So_ResultEntrySDSType, So_ResultEntrySDSSDS_TemplateOptionID, SDS_TemplateOptionValue FROM so_resultentrysds JOIN sds_templateoption ON So_ResultEntrySDSSDS_TemplateOptionID = SDS_TemplateOptionID WHERE So_ResultEntrySDSSo_ResultEntryID = ? AND So_ResultEntrySDSSDS_TemplateQuestionID IN ?"; $query = $this->db_onedev->query($sql, [$data['reID'], $qstID]); if (!$query) { $this->sys_error_db("Error get detail"); exit; } $newRst = $query->result_array(); $newCount = 0; for ($k = 0; $k < count($newRst); $k++) { $newCount = $newCount + intval($newRst[$k]['SDS_TemplateOptionValue']); } $interpretation[$i]['newInterpretationScore'] = $newCount; if (intval($data['interpretationScore']) != $newCount) { $notSame[] = $interpretation[$i]; } } $finalRst = [ 'records' => $notSame, 'total' => count($notSame) ]; $this->sys_ok($finalRst); } function getall() { $prm = $this->sys_input; $limit = 50; if (isset($prm['limit'])) { $limit = $prm['limit']; } $sql = "SELECT T_OrderHeaderLabNumber as labNumber, T_OrderHeaderDate as orderDate, So_ResultEntrySDSSo_ResultEntryID as reID FROM so_resultentrysds JOIN so_resultentry ON So_ResultEntrySDSSo_ResultEntryID = So_ResultEntryID AND So_ResultEntryIsActive = 'Y' JOIN t_orderheader ON So_ResultEntryT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive = 'Y' GROUP BY So_ResultEntrySDSSo_ResultEntryID LIMIT ?"; $query = $this->db_onedev->query($sql, [$limit]); if (!$query) { $this->sys_error_db("Error get detail"); exit; } $order = $query->result_array(); for ($i = 0; $i < count($order); $i++) { $sql = "SELECT So_ResultEntrySDSInterpretationID reInterpretationID, So_ResultEntrySDSInterpretationType , So_ResultEntrySDSInterpretationTypeSo_ResultEntryID as reID, So_ResultEntrySDSInterpretationSDSInterpretationID as interpretationID, So_ResultEntrySDSInterpretationScore as interpretationScore, So_ResultEntrySDSInterpretationDisplay as interpretationDisplay FROM so_resultentrysdsinterpretation JOIN so_resultentry ON So_ResultEntrySDSInterpretationTypeSo_ResultEntryID = So_ResultEntryID AND So_ResultEntryIsActive = 'Y' JOIN sds_interpretation ON So_ResultEntrySDSInterpretationSDSInterpretationID = SDS_InterpretationID AND SDS_InterpretationType = 30 WHERE So_ResultEntrySDSInterpretationIsActive = 'Y' AND So_ResultEntrySDSInterpretationTypeSo_ResultEntryID = ?"; $query = $this->db_onedev->query($sql, [$order[$i]['reID']]); if (!$query) { $this->sys_error_db("Error get detail"); exit; } $score = $query->result_array(); for ($k = 0; $k < count($score); $k++) { $score[$k]['coba'] = "test"; $dataScore = $score[$k]; $interpretationID = $dataScore['interpretationID']; $sql = "SELECT SDS_InterpretationID, SDS_InterpretationOrder NomorInterpretation, SDS_InterpretationText Interpretation, SDS_InterpretationType tipe, GROUP_CONCAT(SDS_TemplateQuestionOrder) NomorPertanyaan FROM sds_interpretation JOIN sds_interpretationmap ON SDS_InterpretationID = SDS_InterpretationMapSDS_InterpretationID AND SDS_InterpretationID = ? AND SDS_InterpretationMapIsActive = 'Y' JOIN sds_templatequestion ON SDS_InterpretationMapSDS_TemplateQuestionID = SDS_TemplateQuestionID GROUP BY SDS_InterpretationID order by SDS_InterpretationType, SDS_InterpretationOrder, SDS_TemplateQuestionOrder;"; $query = $this->db_onedev->query($sql, [$interpretationID]); if (!$query) { $this->sys_error_db("Error get detail"); exit; } $mapping = $query->row_array(); $qstID = explode(',', $mapping['NomorPertanyaan']); $score[$k]['qst'] = $mapping['NomorPertanyaan']; // $score[$k]['questionID'] = $mapping['NomorPertanyaan']; // print_r($interpretationID); // print_r("cobaaa"); $sql = "SELECT So_ResultEntrySDSSo_ResultEntryID, So_ResultEntrySDSSDS_TemplateQuestionID, So_ResultEntrySDSType, So_ResultEntrySDSSDS_TemplateOptionID, SDS_TemplateOptionValue FROM so_resultentrysds JOIN sds_templateoption ON So_ResultEntrySDSSDS_TemplateOptionID = SDS_TemplateOptionID WHERE So_ResultEntrySDSSo_ResultEntryID = ? AND So_ResultEntrySDSSDS_TemplateQuestionID IN ?"; $query = $this->db_onedev->query($sql, [$dataScore['reID'], $qstID]); if (!$query) { $this->sys_error_db("Error get detail"); exit; } $newRst = $query->result_array(); $newCount = 0; for ($m = 0; $m < count($newRst); $m++) { $newCount = $newCount + intval($newRst[$m]['SDS_TemplateOptionValue']); } $score[$k]['newInterpretationScore'] = $newCount; if (intval($dataScore['interpretationScore']) != $newCount) { // $notSame[] = $interpretation[$k]; $score[$k]['isDiff'] = 'Y'; //Update $this->inject($newCount, $dataScore['reInterpretationID'], $dataScore['reID']); } else { $score[$k]['isDiff'] = 'N'; } } $order[$i]['score'] = $score; } $result = [ 'order' => $order, 'total' => count($order), ]; $this->sys_ok($result); } function inject($score, $interpretationID, $reID) { $jsonBefore = $this->getSDS($reID, $interpretationID); $display = ''; if (intval($score) <= 9) { $display = 'Ringan'; } if (intval($score) >= 10 && intval($score) <= 24) { # code... $display = 'Sedang'; } if (intval($score) > 24) { $display = 'Tinggi'; } $sql = "UPDATE so_resultentrysdsinterpretation SET So_ResultEntrySDSInterpretationDisplay = ?, So_ResultEntrySDSInterpretationScore = ?, So_ResultEntrySDSInterpretationUpdated = CURRENT_TIMESTAMP, So_ResultEntrySDSInterpretationUpdatedUserID = 9898 WHERE So_ResultEntrySDSInterpretationID = ? AND So_ResultEntrySDSInterpretationIsActive = 'Y';"; $query = $this->db_onedev->query($sql, [$display, $score, $interpretationID]); if (!$query) { $this->sys_error_db("Error update data"); exit; } $jsonAfter = $this->getSDS($reID, $interpretationID); $sql = "INSERT INTO cpone_log.log_sds_inject ( Log_SDSResultSo_ResultEntryID, Log_SDSResultReSdsInterpretationID, Log_SDSResultType, Log_SDSResultJsonBefore, Log_SDSResultJsonAfter, Log_SDSResultJsonPrm, Log_SDSResultUserID, Log_SDSResultCreated ) VALUES ( ?, ?,'UPDATE INTERPRETATION', ?, ?, ?, 9898, CURRENT_TIMESTAMP );"; $query = $this->db_onedev->query($sql, [ $reID, $interpretationID, json_encode($jsonBefore), json_encode($jsonAfter), $score ]); if (!$query) { $this->sys_error_db("Error insert log"); exit; } // $this->sys_ok('ok'); } function getSDS($trxID, $rstInterpretationID) { // $type = 'SDS30'; // $sql = "SELECT * // FROM so_resultentrysds_type // WHERE // So_ResultEntrySDSTypeSo_ResultEntryID = '{$trxID}' AND // So_ResultEntrySDSTypeIsActive = 'Y' // "; // $query = $this->db_onedev->query($sql); // if (!$query) { // $this->sys_error_db("error get sds question"); // exit; // } // $rst_type = $query->result_array(); // //print_r($rst_type); // if (count($rst_type) > 0) { // if (intval($rst_type[0]['So_ResultEntrySDSTypeValue']) == 20) // $type = 'SRQ20'; // } // //get sds30 questions // $sql = "SELECT // IFNULL(So_ResultEntrySDSID, 0) sdsReID, // IFNULL(So_ResultEntrySDSSo_ResultEntryID, 0) reID, // SDS_TemplateQuestionID as id, // SDS_TemplateQuestionOrder AS orderNumber, // SDS_TemplateQuestionText AS display, // IFNULL(So_ResultEntrySDSSDS_TemplateOptionID,`fn_getDefaultsdsOption`('30')) as value // FROM sds_templatequestion // LEFT JOIN so_resultentrysds // ON SDS_TemplateQuestionID = So_ResultEntrySDSSDS_TemplateQuestionID // AND So_ResultEntrySDSSo_ResultEntryID = '{$trxID}' // LEFT JOIN sds_templateoption // ON SDS_TemplateOptionID = So_ResultEntrySDSSDS_TemplateOptionID // WHERE SDS_TemplateQuestionType = 30 // AND SDS_TemplateQuestionIsActive = 'Y' // ORDER BY SDS_TemplateQuestionOrder asc"; // $query = $this->db_onedev->query($sql, []); // if (!$query) { // $this->sys_error_db("error get sds question"); // exit; // } // $sds30Question = $query->result_array(); // $sql = "SELECT // SDS_TemplateOptionID as id, // SDS_TemplateOptionOrder as orderNumber, // SDS_TemplateOptionText as display, // SDS_TemplateOptionValue as value // FROM sds_templateoption // WHERE SDS_TemplateOptionType = 30 // AND SDS_TemplateOptionIsActive = 'Y' // ORDER BY SDS_TemplateOptionOrder asc"; // $query = $this->db_onedev->query($sql, []); // if (!$query) { // $this->sys_error_db("error get sds option"); // exit; // } // $sds30Option = $query->result_array(); $sql = "SELECT * FROM so_resultentrysdsinterpretation WHERE So_ResultEntrySDSInterpretationTypeSo_ResultEntryID = $trxID AND So_ResultEntrySDSInterpretationID = $rstInterpretationID"; $query = $this->db_onedev->query($sql, []); if (!$query) { $this->sys_error_db("error get sds interpretation"); exit; } $sds30Interpretation = $query->result_array(); // $sql = "SELECT // SDS_InterpretationRuleID as id, // SDS_InterpretationRuleText as display, // SDS_InterpretationRuleMin as min, // SDS_InterpretationRuleMax as max, // SDS_InterpretationRuleValue as value, // SDS_InterpretationRuleIsFix as isFix, // SDS_InterpretationRuleIsRange as isRange, // SDS_InterpretationRuleFlag as flag // FROM sds_interpretationrule // WHERE SDS_InterpretationRuleType = 30 // AND SDS_InterpretationRuleIsActive = 'Y'"; // $query = $this->db_onedev->query($sql, []); // if (!$query) { // $this->sys_error_db("error get sds interpretation rule"); // exit; // } // $sds30InterpretationRule = $query->result_array(); // //get srq20 questions // $sql = "SELECT // IFNULL(So_ResultEntrySDSID, 0) sdsReID, // IFNULL(So_ResultEntrySDSSo_ResultEntryID, 0) reID, // SDS_TemplateQuestionID as id, // SDS_TemplateQuestionOrder AS orderNumber, // SDS_TemplateQuestionText AS display, // IFNULL(So_ResultEntrySDSSDS_TemplateOptionID, `fn_getDefaultsdsOption`('20')) as value // FROM sds_templatequestion // LEFT JOIN so_resultentrysds // ON SDS_TemplateQuestionID = So_ResultEntrySDSSDS_TemplateQuestionID // AND So_ResultEntrySDSSo_ResultEntryID = '{$trxID}' // LEFT JOIN sds_templateoption // ON SDS_TemplateOptionID = So_ResultEntrySDSSDS_TemplateOptionID // WHERE SDS_TemplateQuestionType = 20 // AND SDS_TemplateQuestionIsActive = 'Y' // ORDER BY SDS_TemplateQuestionOrder asc"; // $query = $this->db_onedev->query($sql, []); // if (!$query) { // $this->sys_error_db("error get srq question"); // exit; // } // $srq20Question = $query->result_array(); // $sql = "SELECT // SDS_TemplateOptionID as id, // SDS_TemplateOptionOrder as orderNumber, // SDS_TemplateOptionText as display, // SDS_TemplateOptionValue as value // FROM sds_templateoption // WHERE SDS_TemplateOptionType = 20 // AND SDS_TemplateOptionIsActive = 'Y' // ORDER BY SDS_TemplateOptionOrder asc"; // $query = $this->db_onedev->query($sql, []); // if (!$query) { // $this->sys_error_db("error get srq option"); // exit; // } // $srq20Option = $query->result_array(); // $sql = "SELECT // IFNULL(So_ResultEntrySDSInterpretationTypeSo_ResultEntryID, 0) reID, // IFNULL(So_ResultEntrySDSInterpretationID, 0) sdsReID, // SDS_InterpretationID as id, // SDS_InterpretationOrder as orderNumber, // SDS_InterpretationText as display, // GROUP_CONCAT(SDS_InterpretationMapSDS_TemplateQuestionID) as questionID, // IFNULL(So_ResultEntrySDSInterpretationScore, 0) as score, // 0 as level, // IFNULL(So_ResultEntrySDSInterpretationDisplay, 'Tidak ada') as levelDisplay // FROM sds_interpretation // JOIN sds_interpretationmap // ON SDS_InterpretationID = SDS_InterpretationMapSDS_InterpretationID // AND SDS_InterpretationMapIsActive = 'Y' // LEFT JOIN so_resultentrysdsinterpretation // ON SDS_InterpretationID = So_ResultEntrySDSInterpretationSDSInterpretationID // AND So_ResultEntrySDSInterpretationTypeSo_ResultEntryID = '{$trxID}' // WHERE SDS_InterpretationIsActive = 'Y' // AND SDS_InterpretationType = '20' // GROUP BY SDS_InterpretationID // ORDER BY SDS_InterpretationOrder asc"; // $query = $this->db_onedev->query($sql, []); // if (!$query) { // $this->sys_error_db("error get srq interpretation"); // exit; // } // $srq20Interpretation = $query->result_array(); // $sql = "SELECT // SDS_InterpretationRuleID as id, // SDS_InterpretationRuleText as display, // SDS_InterpretationRuleMin as min, // SDS_InterpretationRuleMax as max, // SDS_InterpretationRuleValue as value, // SDS_InterpretationRuleIsFix as isFix, // SDS_InterpretationRuleIsRange as isRange, // SDS_InterpretationRuleFlag as flag // FROM sds_interpretationrule // WHERE SDS_InterpretationRuleType = 20 // AND SDS_InterpretationRuleIsActive = 'Y'"; // $query = $this->db_onedev->query($sql, []); // if (!$query) { // $this->sys_error_db("error get sds interpretation rule"); // exit; // } // $srq20InterpretationRule = $query->result_array(); // $identitas = // array( // "nama" => "", // "usia" => "", // "masa_kerja" => "", // "departement" => "", // "jenis_kelamin" => "", // "jenis_kelamin_option" => array("Pria", "Wanita"), // "status_pekerja" => "", // "status_pekerja_option" => array("Tetap", "Tidak tetap (Kontrak)"), // "jenis_pekerjaan" => "", // "jenis_pekerjaan_option" => array("Kantor", "Lapangan"), // "level_jabatan" => "", // "level_jabatan_option" => array("Manager", "Supervisor", "Staff"), // "pendidikan" => "", // "pendidikan_option" => array("SLTA", "D3", "S1", "S2,S3"), // "status_perkawinan" => "", // "status_perkawinan_option" => array("Single", "Menikah", "Duda", "Janda"), // ); // //Get Identitas // $sql = "SELECT // IFNULL(So_ResultEntrySDSIdentityAge, T_OrderHeaderM_PatientAge) as age, // IFNULL(So_ResultEntrySDSIdentityName, CONCAT(M_TitleName,' ',M_PatientName)) as name, // IFNULL ( So_ResultEntrySDSIdentityGender, CASE // WHEN M_PatientGender = 'male' THEN 'Pria' // WHEN M_PatientGender = 'female' THEN 'Wanita' // END) as gender, // IFNULL(So_ResultEntrySDSIdentityDepartement,M_PatientDepartement) as departement, // IFNULL(So_ResultEntrySDSIdentityWorkingTime, '') as workingTime, // IFNULL(So_ResultEntrySDSIdentityJobStatus, '') as jobStatus, // IFNULL(So_ResultEntrySDSIdentityJobType, '') as jobType, // IFNULL(So_ResultEntrySDSIdentityPosition, '') as position, // IFNULL(So_ResultEntrySDSIdentityEducation, '') as education, // IFNULL(So_ResultEntrySDSIdentityMaritalStatus, '') as maritalStatus // FROM t_orderheader // JOIN m_patient // ON T_OrderHeaderM_PatientID = M_PatientID // AND T_OrderHeaderID = '{$orderID}' // LEFT JOIN m_title // ON M_PatientM_TitleID = M_TitleID // AND M_TitleIsActive = 'Y' // LEFT JOIN so_resultentry // ON T_OrderHeaderID = So_ResultEntryT_OrderHeaderID // AND So_ResultEntryID = '{$trxID}' // AND So_ResultEntryIsActive = 'Y' // LEFT JOIN so_resultentrysdsidentity // ON So_ResultEntryID = So_ResultEntrySDSIdentitySo_ResultEntryID // AND So_ResultEntrySDSIdentityIsActive = 'Y'"; // $query = $this->db_onedev->query($sql, []); // if (!$query) { // $this->sys_error_db("error get identitas"); // exit; // } // $getIdentitas = $query->result_array(); // if (count($getIdentitas) > 0) { // $identitas['nama'] = $getIdentitas[0]['name']; // $identitas['usia'] = $getIdentitas[0]['age']; // $identitas['jenis_kelamin'] = $getIdentitas[0]['gender']; // $identitas['departement'] = $getIdentitas[0]['departement']; // $identitas['masa_kerja'] = $getIdentitas[0]['workingTime']; // $identitas['status_pekerja'] = $getIdentitas[0]['jobStatus']; // $identitas['jenis_pekerjaan'] = $getIdentitas[0]['jobType']; // $identitas['level_jabatan'] = $getIdentitas[0]['position']; // $identitas['pendidikan'] = $getIdentitas[0]['education']; // $identitas['status_perkawinan'] = $getIdentitas[0]['maritalStatus']; // } // $result = array( // 'sds30' => array( // "questions" => $sds30Question, // "options" => $sds30Option, // "interpretation" => $sds30Interpretation, // "interpretationRule" => $sds30InterpretationRule, // ), // 'srq20' => array( // "questions" => $srq20Question, // "options" => $srq20Option, // "interpretation" => $srq20Interpretation, // "interpretationRule" => $srq20InterpretationRule, // ) // ); $result = $sds30Interpretation; return $result; } }