FHM09062601IBL - ibl_registration/order/load_klinik: endpoint baru dengan decrypt PDP

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sas.fajri
2026-06-12 10:58:43 +07:00
parent 917115684c
commit c80bd8b6c1

View File

@@ -4641,4 +4641,184 @@ GROUP BY T_SampleStationID ";
exit;
}
function load_klinik()
{
if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; }
$prm = $this->sys_input;
$klinik_number = trim($prm['klinik_number'] ?? '');
if (!$klinik_number) { $this->sys_error("klinik_number required"); exit; }
// Ambil header order klinik
$row_header = $this->db_onedev->query(
"SELECT o.*, od.orderDoctorDiagnosePrimer
FROM one_klinik.`order` o
LEFT JOIN one_klinik.order_doctor od
ON od.orderDoctorOrderID = o.orderID
AND od.orderDoctorIsActive = 'Y'
AND od.orderDoctorType = 'FORM'
WHERE o.OrderNumber = ?
LIMIT 1",
[$klinik_number]
)->row_array();
if (!$row_header) { $this->sys_error("Order tidak ditemukan"); exit; }
$rst = [];
$rst['klinik'] = $row_header;
$enc = $this->ibl_encryptor;
// Patient
$patient_row = $this->db_onedev->query(
"SELECT m_patient.*,
M_TitleID, M_TitleName,
M_SexID, M_SexName,
M_PatientAddressM_KelurahanID as M_KelurahanID,
M_PatientAddressDescription,
IFNULL(M_ReligionName,'-') as M_ReligionName
FROM m_patient
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN m_patientaddress ON M_PatientAddressM_PatientID = M_PatientID AND M_PatientAddressIsActive = 'Y'
LEFT JOIN m_religion ON M_PatientM_ReligionID = M_ReligionID
WHERE M_PatientID = ?
GROUP BY M_PatientID
LIMIT 1",
[$row_header['orderM_PatientID']]
)->row_array();
if ($patient_row) {
$p_name = $enc->decrypt($patient_row['M_PatientName_enc'] ?? '') ?: $patient_row['M_PatientName'];
$p_hp = $enc->decrypt($patient_row['M_PatientHP_enc'] ?? '') ?: $patient_row['M_PatientHP'];
$p_email = $enc->decrypt($patient_row['M_PatientEmail_enc'] ?? '') ?: $patient_row['M_PatientEmail'];
$p_idnum = $enc->decrypt($patient_row['M_PatientIDNumber_enc']?? '') ?: $patient_row['M_PatientIDNumber'];
$p_dob_raw = $enc->decrypt($patient_row['M_PatientDOB_enc'] ?? '');
// p_dob_raw is d-m-Y; convert to Y-m-d for M_PatientDOB, keep d-m-Y for dob_ina
$p_dob_ina = $p_dob_raw ?: $patient_row['M_PatientDOB'];
$p_dob_sql = '';
if ($p_dob_raw) {
$parts = explode('-', $p_dob_raw);
$p_dob_sql = count($parts) === 3 ? "{$parts[2]}-{$parts[1]}-{$parts[0]}" : '';
}
$title = $patient_row['M_TitleName'] ? $patient_row['M_TitleName'] . ' ' : '';
$prefix = $patient_row['M_PatientPrefix'] ? $patient_row['M_PatientPrefix'] . ' ': '';
$suffix = $patient_row['M_PatientSuffix'] ? ' ' . $patient_row['M_PatientSuffix']: '';
$patient_row['M_PatientName'] = trim($title . $prefix . $p_name . $suffix);
$patient_row['M_PatientRealName'] = $p_name;
$patient_row['M_PatientHP'] = $p_hp;
$patient_row['M_PatientEmail'] = $p_email;
$patient_row['M_PatientIDNumber'] = $p_idnum;
$patient_row['M_PatientDOB'] = $p_dob_sql ?: $patient_row['M_PatientDOB'];
$patient_row['dob_ina'] = $p_dob_ina;
$patient_row['divider'] = 'N';
$patient_row['hp'] = $p_hp;
$patient_row['M_PatientAddress'] = '';
$patient_row['M_DistrictID'] = 0;
$patient_row['M_CityID'] = 0;
$patient_row['M_ProvinceID'] = 0;
if ($patient_row['M_KelurahanID']) {
$addr = $this->db_onedev->query(
"SELECT *, CONCAT(IFNULL(?,''),'\n\n',M_KelurahanName,', ',M_DistrictName,'\n',M_CityName,', ',M_ProvinceName) as xaddress
FROM m_kelurahan
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
JOIN m_city ON M_DistrictM_CityID = M_CityID
JOIN m_province ON M_CityM_ProvinceID = M_ProvinceID
WHERE M_KelurahanID = ?",
[$patient_row['M_PatientAddressDescription'], $patient_row['M_KelurahanID']]
)->row_array();
if ($addr) {
$patient_row['M_PatientAddress'] = stripslashes($addr['xaddress']);
$patient_row['M_DistrictID'] = $addr['M_DistrictID'];
$patient_row['M_CityID'] = $addr['M_CityID'];
$patient_row['M_ProvinceID'] = $addr['M_ProvinceID'];
}
}
$info = $this->db_onedev->query("SELECT fn_fo_patient_visit(?) info", [$patient_row['M_PatientID']])->row();
$patient_row['info'] = $info ? json_decode($info->info) : null;
// Hapus kolom enc sebelum return
foreach (['M_PatientName_enc','M_PatientName_bidx','M_PatientHP_enc','M_PatientHP_bidx',
'M_PatientEmail_enc','M_PatientIDNumber_enc','M_PatientNIK_bidx',
'M_PatientDOB_enc','M_PatientDOB_bidx'] as $col) {
unset($patient_row[$col]);
}
$rst['patient'] = $patient_row;
} else {
$rst['patient'] = [];
}
// MOU & Company dari order
$mou_id = intval($row_header['orderM_MouID'] ?? 0);
$row_mou = $this->db_onedev->query(
"SELECT M_MouM_CompanyID, M_MouStatus, M_MouEmail, M_MouEmailIsDefault,
M_MouEndDate, M_MouID, M_MouIsBill, M_MouIsDefault, M_MouName,
M_MouNote, M_MouStartDate
FROM m_mou WHERE M_MouID = ?",
[$mou_id]
)->row_array();
$row_company = [];
if ($row_mou) {
$row_company = $this->db_onedev->query(
"SELECT * FROM m_company WHERE M_CompanyID = ?",
[$row_mou['M_MouM_CompanyID']]
)->row_array();
$row_company['mou'] = $this->db_onedev->query(
"SELECT M_MouStatus, M_MouEmail, M_MouEmailIsDefault, M_MouEndDate, M_MouID,
M_MouIsBill, M_MouIsDefault, M_MouName, M_MouNote, M_MouStartDate
FROM m_mou
WHERE M_MouM_CompanyID = ? AND M_MouStatus = 'R' AND M_MouIsActive = 'Y'",
[$row_company['M_CompanyID']]
)->result_array();
}
$rst['selected_mou'] = $row_mou ?: [];
$rst['selected_company'] = $row_company ?: [];
$rst['companies'] = $row_company ? [$row_company] : [];
// Tests dari order_detail_order
$detail_rows = $this->db_onedev->query(
"SELECT odo.*,
t.T_TestName, t.T_TestSasCode, t.T_TestIsResult,
t.T_TestCode
FROM one_klinik.order_detail_order odo
LEFT JOIN t_test t ON odo.orderDetailOrderT_TestID = t.T_TestID
WHERE odo.orderDetailOrderOrderID = ? AND odo.orderDetailOrderIsActive = 'Y'
ORDER BY odo.orderDetailOrderID ASC",
[$row_header['orderID']]
)->result_array();
$tests = [];
foreach ($detail_rows as $d) {
$child = json_decode($d['orderDetailOrderJsonChildren'] ?? '[]', true) ?: [];
$tests[] = [
'ss_price_mou_id' => $d['orderDetailOrderSsPriceMouID'],
'pxid' => $d['orderDetailOrderT_TestID'] ?: $d['orderDetailOrderT_PacketID'],
'pxcode' => $d['T_TestCode'] ?? $d['orderDetailOrderT_PacketName'],
'pxsascode' => $d['T_TestSasCode'] ?? '',
'test_name' => $d['orderDetailOrderT_TestName'] ?: $d['orderDetailOrderT_PacketName'],
'pxname' => ($d['T_TestSasCode'] ?? '') . ' ' . ($d['orderDetailOrderT_TestName'] ?: $d['orderDetailOrderT_PacketName']),
'is_packet' => $d['orderDetailOrderIsPacket'],
'type' => $d['orderDetailOrderPacketType'],
'bruto' => $d['orderDetailOrderT_PriceAmount'],
'discountpersen' => $d['orderDetailOrderT_PriceDisc'],
'discountrp' => $d['orderDetailOrderT_PriceDiscRp'],
'total' => $d['orderDetailOrderT_PriceTotal'],
'child_test' => $child,
'isresult' => $d['T_TestIsResult'] ?? 'N',
];
}
$rst['tests'] = $tests;
$rst['diagnose'] = $row_header['orderDoctorDiagnosePrimer'] ?? '';
$this->sys_ok(['records' => $rst]);
exit;
}
}