FHM09062601IBL - buat t_screening_answer, update screening/search return template+forms dinamis vs DEFAULT

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sas.fajri
2026-06-11 08:58:03 +07:00
parent beb11cc40f
commit b45f284784
2 changed files with 79 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ class Screening extends MY_Controller
orderIsCheck,
orderAge as patient_age,
DATE_FORMAT(orderDate,'%d-%m-%Y') as order_date,
orderM_ClinicUnitID,
'N' divider,
M_PatientID,
M_PatientNoReg,
@@ -93,6 +94,65 @@ class Screening extends MY_Controller
$info = $this->db_onedev->query("SELECT fn_fo_patient_visit(?) info", [$v['M_PatientID']])->row();
$rows[$k]['info'] = json_decode($info->info);
// Screening template berdasarkan poli order
$cu_id = $v['orderM_ClinicUnitID'] ?? null;
$rows[$k]['screening_template'] = null;
$rows[$k]['screening_forms'] = null;
$rows[$k]['order_screening'] = null;
if ($cu_id) {
$tpl = $this->db_oneklinik->query(
"SELECT st.M_ScreeningTemplateID, st.M_ScreeningTemplateCode, st.M_ScreeningTemplateName
FROM one_klinik.m_clinic_unit cu
JOIN one_klinik.m_screening_template st
ON st.M_ScreeningTemplateID = cu.M_ClinicUnitM_ScreeningTemplateID
WHERE cu.M_ClinicUnitID = ?", [$cu_id]
)->row_array();
$rows[$k]['screening_template'] = $tpl ?: null;
if ($tpl && $tpl['M_ScreeningTemplateCode'] !== 'DEFAULT') {
// Template dinamis (VAKSINASI / KHITAN): ambil form + jawaban yang sudah ada
$forms = $this->db_oneklinik->query(
"SELECT sf.M_ScreeningFormID,
sf.M_ScreeningFormQuestion,
sf.M_ScreeningFormAnswerType,
sf.M_ScreeningFormOptions,
sf.M_ScreeningFormSortOrder,
sf.M_ScreeningFormIsRequired,
sa.T_ScreeningAnswerValue AS answer
FROM one_klinik.m_screening_form sf
LEFT JOIN one_klinik.t_screening_answer sa
ON sa.T_ScreeningAnswerM_ScreeningFormID = sf.M_ScreeningFormID
AND sa.T_ScreeningAnswerOrderID = ?
AND sa.T_ScreeningAnswerIsActive = 'Y'
WHERE sf.M_ScreeningFormM_ScreeningTemplateID = ?
AND sf.M_ScreeningFormIsActive = 'Y'
ORDER BY sf.M_ScreeningFormSortOrder",
[$v['orderID'], $tpl['M_ScreeningTemplateID']]
)->result_array();
foreach ($forms as &$f) {
$f['M_ScreeningFormOptions'] = $f['M_ScreeningFormOptions']
? json_decode($f['M_ScreeningFormOptions'], true)
: null;
$f['answer'] = $f['answer'] !== null
? json_decode($f['answer'], true)
: null;
}
unset($f);
$rows[$k]['screening_forms'] = $forms;
} else {
// DEFAULT: pakai order_screening lama
$rows[$k]['order_screening'] = $this->db_oneklinik->query(
"SELECT * FROM one_klinik.order_screening
WHERE orderScreeningOrderID = ? AND orderScreeningIsActive = 'Y'",
[$v['orderID']]
)->row_array() ?: null;
}
}
}
$this->sys_ok(["total" => count($rows), "records" => $rows]);