feat: implement encounter edit mode with GET/PATCH endpoints and comprehensive testing documentation
This commit is contained in:
@@ -339,23 +339,31 @@ export function useEncounterEntry(props: {
|
||||
|
||||
try {
|
||||
isLoadingDetail.value = true
|
||||
console.log('📥 [EDIT MODE] Loading encounter detail:', { id: props.id })
|
||||
|
||||
const result = await getEncounterDetail(props.id, {
|
||||
includes: 'patient,patient-person,specialist,subspecialist',
|
||||
})
|
||||
|
||||
console.log('📥 [EDIT MODE] API Response:', { success: result.success, data: result.body?.data })
|
||||
|
||||
if (result.success && result.body?.data) {
|
||||
encounterData.value = result.body.data
|
||||
await mapEncounterToForm(encounterData.value)
|
||||
isLoadingDetail.value = false
|
||||
console.log('✅ [EDIT MODE] Encounter detail loaded and form mapped successfully')
|
||||
} else {
|
||||
const errorMsg = result.body?.message || 'Gagal memuat data kunjungan'
|
||||
console.error('❌ [EDIT MODE] Failed to load encounter:', errorMsg)
|
||||
toast({
|
||||
title: 'Gagal',
|
||||
description: 'Gagal memuat data kunjungan',
|
||||
description: errorMsg,
|
||||
variant: 'destructive',
|
||||
})
|
||||
await navigateTo(getListPath())
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('Error loading encounter detail:', error)
|
||||
console.error('❌ [EDIT MODE] Error loading encounter detail:', error)
|
||||
toast({
|
||||
title: 'Gagal',
|
||||
description: error?.message || 'Gagal memuat data kunjungan',
|
||||
@@ -439,8 +447,24 @@ export function useEncounterEntry(props: {
|
||||
|
||||
formData.cardNumber = encounter.member_number || ''
|
||||
formData.sepNumber = encounter.ref_number || ''
|
||||
formData.sepType = encounter.sep_type || ''
|
||||
formData.patientCategory = encounter.participant_group_code || ''
|
||||
|
||||
// Map BPJS reference data if available
|
||||
if (encounter.vclaimReference) {
|
||||
formData.sepReference = encounter.vclaimReference?.noSep || ''
|
||||
} else if (encounter.ref_number) {
|
||||
formData.sepReference = encounter.ref_number
|
||||
}
|
||||
|
||||
formObjects.value = formData
|
||||
|
||||
console.log('📋 [EDIT MODE] Mapped encounter to form:', {
|
||||
encounterData: encounter,
|
||||
formData: formData,
|
||||
timestamp: new Date().toISOString(),
|
||||
})
|
||||
|
||||
if (formData.sepNumber) {
|
||||
sepNumber.value = formData.sepNumber
|
||||
}
|
||||
@@ -543,21 +567,27 @@ export function useEncounterEntry(props: {
|
||||
|
||||
let result
|
||||
if (isEditMode.value) {
|
||||
console.log('💾 [EDIT MODE] Sending PATCH request:', { id: props.id, payload })
|
||||
result = await updateEncounter(props.id, payload)
|
||||
} else {
|
||||
console.log('💾 [ADD MODE] Sending POST request:', { payload })
|
||||
result = await createEncounter(payload)
|
||||
}
|
||||
|
||||
console.log('📤 [SAVE] API Response:', { success: result.success, message: result.body?.message })
|
||||
|
||||
if (result.success) {
|
||||
toast({
|
||||
title: 'Berhasil',
|
||||
description: isEditMode.value ? 'Kunjungan berhasil diperbarui' : 'Kunjungan berhasil dibuat',
|
||||
variant: 'default',
|
||||
})
|
||||
console.log('✅ [SAVE] Success - Redirecting to list page')
|
||||
await navigateTo(getListPath())
|
||||
} else {
|
||||
const errorMessage =
|
||||
result.body?.message || (isEditMode.value ? 'Gagal memperbarui kunjungan' : 'Gagal membuat kunjungan')
|
||||
console.error('❌ [SAVE] Failed:', errorMessage)
|
||||
toast({
|
||||
title: 'Gagal',
|
||||
description: errorMessage,
|
||||
@@ -565,7 +595,7 @@ export function useEncounterEntry(props: {
|
||||
})
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('Error saving encounter:', error)
|
||||
console.error('❌ [SAVE] Error saving encounter:', error)
|
||||
toast({
|
||||
title: 'Gagal',
|
||||
description: error?.message || (isEditMode.value ? 'Gagal memperbarui kunjungan' : 'Gagal membuat kunjungan'),
|
||||
|
||||
Reference in New Issue
Block a user