feat(encounter): add outpatient class and implement record deletion confirmation

This commit is contained in:
riefive
2025-11-09 18:58:05 +07:00
parent 5e309801ed
commit 6dcc9e6c30
2 changed files with 117 additions and 7 deletions
+30 -5
View File
@@ -38,7 +38,7 @@ import { useUserStore } from '~/stores/user'
const props = defineProps<{
id: number
classCode?: 'ambulatory' | 'emergency' | 'inpatient'
classCode?: 'ambulatory' | 'emergency' | 'inpatient' | 'outpatient'
subClassCode?: 'reg' | 'rehab' | 'chemo' | 'emg' | 'eon' | 'op' | 'icu' | 'hcu' | 'vk'
formType: string
}>()
@@ -64,6 +64,22 @@ const isSaveDisabled = computed(() => {
return !selectedPatient.value || !selectedPatientObject.value || isSaving.value
})
function getListPath(): string {
if (props.classCode === 'ambulatory' && props.subClassCode === 'rehab') {
return '/rehab/encounter'
}
if (props.classCode === 'emergency') {
return '/emergency/encounter'
}
if (props.classCode === 'outpatient') {
return '/outpatient/encounter'
}
if (props.classCode === 'inpatient') {
return '/inpatient/encounter'
}
return '/encounter' // fallback
}
function handleSavePatient() {
selectedPatientObject.value = null
setTimeout(() => {
@@ -148,10 +164,19 @@ async function handleSaveEncounter(formValues: any) {
}
if (subspecialist_id) {
payload.subspecialist_id = subspecialist_id
}
let paymentMethod = 'cash'
if (formValues.paymentType === 'jkn' || formValues.paymentType === 'jkmm') {
paymentMethod = 'insurance'
} else if (formValues.paymentType === 'spm') {
paymentMethod = 'cash'
} else if (formValues.paymentType === 'pks') {
paymentMethod = 'membership'
}
if (formValues.paymentType === 'jkn') {
payload.paymentMethod_code = 'insurance'
if (paymentMethod === 'insurance') {
payload.paymentMethod_code = paymentMethod
payload.insuranceCompany_id = null
payload.member_number = formValues.cardNumber
payload.ref_number = formValues.sepNumber
@@ -172,8 +197,8 @@ async function handleSaveEncounter(formValues: any) {
description: 'Kunjungan berhasil dibuat',
variant: 'default',
})
// Optionally navigate or reset form
// navigateTo(`/encounter/${result.body?.data?.id}`)
// Redirect to list page
await navigateTo(getListPath())
} else {
const errorMessage = result.body?.message || 'Gagal membuat kunjungan'
toast({
+87 -2
View File
@@ -5,14 +5,19 @@ import SummaryCard from '~/components/pub/my-ui/summary-card/summary-card.vue'
import Dialog from '~/components/pub/my-ui/modal/dialog.vue'
import Header from '~/components/pub/my-ui/nav-header/prep.vue'
import Filter from '~/components/pub/my-ui/nav-header/filter.vue'
import RecordConfirmation from '~/components/pub/my-ui/confirmation/record-confirmation.vue'
// Types
import type { DataTableLoader } from '~/components/pub/my-ui/data-table/type'
import type { Summary } from '~/components/pub/my-ui/summary-card/type'
import type { HeaderPrep, RefSearchNav } from '~/components/pub/my-ui/data/types'
import { ActionEvents } from '~/components/pub/my-ui/data/types'
// Services
import { getList as getEncounterList } from '~/services/encounter.service'
import { getList as getEncounterList, remove as removeEncounter } from '~/services/encounter.service'
// UI
import { toast } from '~/components/pub/ui/toast'
const props = defineProps<{
classCode?: 'ambulatory' | 'emergency' | 'inpatient' | 'outpatient'
@@ -29,6 +34,7 @@ const recId = ref<number>(0)
const recAction = ref<string>('')
const recItem = ref<any>(null)
const isFormEntryDialogOpen = ref(false)
const isRecordConfirmationOpen = ref(false)
const hreaderPrep: HeaderPrep = {
title: 'Kunjungan',
@@ -71,7 +77,11 @@ const refSearchNav: RefSearchNav = {
async function getPatientList() {
isLoading.isTableLoading = true
try {
const result = await getEncounterList({ includes: 'patient,patient-person' })
const params: any = { includes: 'patient,patient-person' }
if (props.classCode) {
params['class-code'] = props.classCode
}
const result = await getEncounterList(params)
if (result.success) {
data.value = result.body?.data || []
}
@@ -86,10 +96,59 @@ onMounted(() => {
getPatientList()
})
// Handle confirmation result
async function handleConfirmDelete(record: any, action: string) {
if (action === 'delete' && record?.id) {
try {
const result = await removeEncounter(record.id)
if (result.success) {
toast({
title: 'Berhasil',
description: 'Kunjungan berhasil dihapus',
variant: 'default',
})
await getPatientList() // Refresh list
} else {
const errorMessage = result.body?.message || 'Gagal menghapus kunjungan'
toast({
title: 'Gagal',
description: errorMessage,
variant: 'destructive',
})
}
} catch (error: any) {
console.error('Error deleting encounter:', error)
toast({
title: 'Gagal',
description: error?.message || 'Gagal menghapus kunjungan',
variant: 'destructive',
})
} finally {
// Reset state
recId.value = 0
recAction.value = ''
recItem.value = null
isRecordConfirmationOpen.value = false
}
}
}
function handleCancelConfirmation() {
// Reset record state when cancelled
recId.value = 0
recAction.value = ''
recItem.value = null
isRecordConfirmationOpen.value = false
}
watch(
() => recAction.value,
() => {
console.log('recAction.value', recAction.value)
if (recAction.value === ActionEvents.showConfirmDelete) {
isRecordConfirmationOpen.value = true
return
}
if (props.type === 'encounter') {
if (recAction.value === 'showDetail') {
navigateTo(`/rehab/encounter/${recId.value}/detail`)
@@ -139,4 +198,30 @@ provide('table_data_loader', isLoading)
>
<AppEncounterFilter />
</Dialog>
<!-- Record Confirmation Modal -->
<RecordConfirmation
v-model:open="isRecordConfirmationOpen"
action="delete"
:record="recItem"
@confirm="handleConfirmDelete"
@cancel="handleCancelConfirmation"
>
<template #default="{ record }">
<div class="text-sm">
<p>
<strong>ID:</strong>
{{ record?.id }}
</p>
<p v-if="record?.patient?.person?.name">
<strong>Pasien:</strong>
{{ record.patient.person.name }}
</p>
<p v-if="record?.class_code">
<strong>Kelas:</strong>
{{ record.class_code }}
</p>
</div>
</template>
</RecordConfirmation>
</template>