fix(sep): add fetch patient

This commit is contained in:
riefive
2025-10-14 14:28:21 +07:00
parent 0c26be3c07
commit 76992b09f2
+39 -15
View File
@@ -1,24 +1,45 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue'
import { getPatients } from '~/services/patient.service'
const openPatient = ref(false) const openPatient = ref(false)
const openLetter = ref(false) const openLetter = ref(false)
const openHistory = ref(false) const openHistory = ref(false)
const selectedPatient = ref('3456512345678880') const selectedPatient = ref('3456512345678880')
const selectedLetter = ref('SK22334442') const selectedLetter = ref('SK22334442')
const patients = [ // patients used by AppSepTableSearchPatient (will be filled from API)
{ const patients = ref<Array<{ ktp: string; rm: string; bpjs: string; nama: string }>>([
ktp: '3456512345678880', // fallback empty list until fetched
rm: 'RM23311224', ])
bpjs: '334423213214', const isPatientsLoading = ref(false)
nama: 'Ahmad Baidowi',
}, function mapPatientToRow(p: any) {
{ // Defensive mapping: try common field names that might be returned by the API
ktp: '345678804565123', const ktp = p.ktp || p.noKtp || p.ktpNumber || p.person?.identityNo || ''
rm: 'RM23455667', const rm = p.rm || p.noRm || p.medicalRecordNo || ''
bpjs: '33442367656', const bpjs = p.bpjs || p.noBpjs || p.bpjsNo || ''
nama: 'Bian Maulana', const nama = p.nama || p.name || p.fullName || p.person?.name || p.person?.fullName || p.person?.nama || ''
}, return { ktp, rm, bpjs, nama }
] }
async function fetchPatients(params: any = { 'page-size': 100 }) {
try {
isPatientsLoading.value = true
const result = await getPatients(params)
if (result && result.success && result.body && Array.isArray(result.body.data)) {
patients.value = result.body.data.map(mapPatientToRow)
} else {
// fallback to empty array
patients.value = []
}
} catch (err) {
console.error('Failed to fetch patients for SEP search:', err)
patients.value = []
} finally {
isPatientsLoading.value = false
}
}
const letters = [ const letters = [
{ {
@@ -70,7 +91,10 @@ function handleSaveLetter() {
function handleEvent(value: string) { function handleEvent(value: string) {
if (value === 'search-patient') { if (value === 'search-patient') {
openPatient.value = true // fetch patients from API then open the dialog
fetchPatients().then(() => {
openPatient.value = true
})
return return
} }
if (value === 'search-letter') { if (value === 'search-letter') {