feat/prescription: added submit
This commit is contained in:
@@ -5,7 +5,6 @@ import Nav from '~/components/pub/my-ui/nav-footer/ca-ed-su.vue'
|
|||||||
|
|
||||||
import type { Prescription } from '~/models/prescription';
|
import type { Prescription } from '~/models/prescription';
|
||||||
import PrescriptionItem from '~/components/app/prescription-item/list.vue';
|
import PrescriptionItem from '~/components/app/prescription-item/list.vue';
|
||||||
import { add } from 'date-fns';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
data: Prescription[]
|
data: Prescription[]
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import {
|
|||||||
import { getList, getDetail } from '~/services/prescription.service'
|
import { getList, getDetail } from '~/services/prescription.service'
|
||||||
import List from '~/components/app/prescription/list.vue'
|
import List from '~/components/app/prescription/list.vue'
|
||||||
import type { Prescription } from '~/models/prescription'
|
import type { Prescription } from '~/models/prescription'
|
||||||
|
import { submit } from '~/services/prescription.service'
|
||||||
|
import type { ToastFn } from '~/handlers/_handler'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
encounter_id: number
|
encounter_id: number
|
||||||
@@ -31,6 +33,7 @@ const route = useRoute()
|
|||||||
const { setQueryParams } = useQueryParam()
|
const { setQueryParams } = useQueryParam()
|
||||||
|
|
||||||
const title = ref('')
|
const title = ref('')
|
||||||
|
const isSubmitConfirmationOpen = ref(false)
|
||||||
|
|
||||||
const plainEid = route.params.id
|
const plainEid = route.params.id
|
||||||
const encounter_id = (plainEid && typeof plainEid == 'string') ? parseInt(plainEid) : 0
|
const encounter_id = (plainEid && typeof plainEid == 'string') ? parseInt(plainEid) : 0
|
||||||
@@ -125,13 +128,13 @@ watch([isFormEntryDialogOpen], async () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function cancel(data: Prescription) {
|
function confirmCancel(data: Prescription) {
|
||||||
recId.value = data.id
|
recId.value = data.id
|
||||||
recItem.value = data
|
recItem.value = data
|
||||||
isRecordConfirmationOpen.value = true
|
isRecordConfirmationOpen.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
function edit(data: Prescription) {
|
function goToEdit(data: Prescription) {
|
||||||
setQueryParams({
|
setQueryParams({
|
||||||
'mode': 'entry',
|
'mode': 'entry',
|
||||||
'id': data.id.toString()
|
'id': data.id.toString()
|
||||||
@@ -139,9 +142,21 @@ function edit(data: Prescription) {
|
|||||||
recItem.value = data
|
recItem.value = data
|
||||||
}
|
}
|
||||||
|
|
||||||
function submit(data: Prescription) {
|
function confirmSubmit(data: Prescription) {
|
||||||
|
recId.value = data.id
|
||||||
|
recItem.value = data
|
||||||
|
isSubmitConfirmationOpen.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleActionSubmit(id: number, refresh: () => void, toast: ToastFn) {
|
||||||
|
const result = await submit(id)
|
||||||
|
if (result.success) {
|
||||||
|
toast({ title: 'Berhasil', description: 'Resep telah di ajukan', variant: 'default' })
|
||||||
|
setTimeout(refresh, 300)
|
||||||
|
} else {
|
||||||
|
toast({ title: 'Gagal', description: 'Gagal menjalankan perintah', variant: 'destructive' })
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -150,9 +165,9 @@ function submit(data: Prescription) {
|
|||||||
v-if="!isLoading.dataListLoading"
|
v-if="!isLoading.dataListLoading"
|
||||||
:data="data"
|
:data="data"
|
||||||
:pagination-meta="paginationMeta"
|
:pagination-meta="paginationMeta"
|
||||||
@cancel="cancel"
|
@cancel="confirmCancel"
|
||||||
@edit="edit"
|
@edit="goToEdit"
|
||||||
@submit="submit"
|
@submit="confirmSubmit"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<RecordConfirmation
|
<RecordConfirmation
|
||||||
@@ -163,4 +178,16 @@ function submit(data: Prescription) {
|
|||||||
@cancel=""
|
@cancel=""
|
||||||
>
|
>
|
||||||
</RecordConfirmation>
|
</RecordConfirmation>
|
||||||
|
|
||||||
|
<RecordConfirmation
|
||||||
|
v-model:open="isSubmitConfirmationOpen"
|
||||||
|
action="delete"
|
||||||
|
customTitle="Ajukan Resep"
|
||||||
|
customMessage="Proses akan mengajukan resep ini untuk diproses lebih lanjut. Lanjutkan?"
|
||||||
|
customConfirmText="Ajukan"
|
||||||
|
:record="recItem"
|
||||||
|
@confirm="() => handleActionSubmit(recId, getMyList, toast)"
|
||||||
|
@cancel=""
|
||||||
|
>
|
||||||
|
</RecordConfirmation>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -119,8 +119,9 @@ function handleCancel() {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Confirmation
|
<Confirmation
|
||||||
v-model:open="isOpen" :title="finalTitle" :message="finalMessage" :confirm-text="finalConfirmText"
|
v-model:open="isOpen" :title="finalTitle" :message="finalMessage" :confirm-text="finalConfirmText"
|
||||||
:cancel-text="finalCancelText" :variant="actionConfig.variant" size="md" @confirm="handleConfirm"
|
:cancel-text="finalCancelText" :variant="actionConfig.variant" size="md"
|
||||||
|
@confirm="handleConfirm"
|
||||||
@cancel="handleCancel"
|
@cancel="handleCancel"
|
||||||
>
|
>
|
||||||
<!-- Slot untuk informasi tambahan record -->
|
<!-- Slot untuk informasi tambahan record -->
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { createCrudHandler, genCrudHandler } from '~/handlers/_handler'
|
import { genCrudHandler } from '~/handlers/_handler'
|
||||||
import { create, update, remove } from '~/services/prescription.service'
|
import { create, update, remove } from '~/services/prescription.service'
|
||||||
|
|
||||||
export const {
|
export const {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import * as base from './_crud-base'
|
import * as base from './_crud-base'
|
||||||
|
import { xfetch } from '~/composables/useXfetch'
|
||||||
|
|
||||||
const path = '/api/v1/prescription'
|
const path = '/api/v1/prescription'
|
||||||
const name = 'prescription'
|
const name = 'prescription'
|
||||||
@@ -22,3 +23,16 @@ export function update(id: number | string, data: any) {
|
|||||||
export function remove(id: number | string) {
|
export function remove(id: number | string) {
|
||||||
return base.remove(path, id)
|
return base.remove(path, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function submit(id: number) {
|
||||||
|
try {
|
||||||
|
const resp = await xfetch(`${path}/${id}/submit`, 'PATCH')
|
||||||
|
const result: any = {}
|
||||||
|
result.success = resp.success
|
||||||
|
result.body = (resp.body as Record<string, any>) || {}
|
||||||
|
return result
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error submitting ${name}:`, error)
|
||||||
|
throw new Error(`Failed to submit ${name}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user