Files
simrsx-fe/app/components/content/prescription/entry.vue
2025-11-15 20:13:42 +07:00

161 lines
4.2 KiB
Vue

<script setup lang="ts">
import Nav from '~/components/pub/my-ui/nav-footer/ba-de-su.vue'
import Header from '~/components/pub/my-ui/nav-header/prep.vue'
import Dialog from '~/components/pub/my-ui/modal/dialog.vue'
import { useQueryCRUDMode } from '~/composables/useQueryCRUD'
import type { HeaderPrep } from '~/components/pub/my-ui/data/types'
// medicine
import { type Medicine } from '~/models/medicine'
// prescription
import { getDetail } from '~/services/prescription.service'
import { getList as getMedicineList } from '~/services/medicine.service'
import Detail from '~/components/app/prescription/detail.vue'
// prescription items
import {
getList as getPrescriptionItemList,
create as createPrescriptionItem,
remove as removePrescriptionItem,
} from '~/services/prescription-item.service'
import { type PrescriptionItem, genPrescriptionItem } from '~/models/prescription-item'
import ItemListEntry from '~/components/app/prescription-item/list-entry.vue'
import type { MedicinemixItem } from '~/models/medicinemix-item';
import { recItem } from '~/handlers/prescription-item.handler'
import NonMixItemEntry from '~/components/app/prescription-item/non-mix-entry.vue'
import MixItemEntry from '~/components/app/prescription-item/mix-entry.vue'
// props
const props = defineProps<{
encounter_id: number
}>()
// declaration & flows
// Prescription
const { getQueryParam } = useQueryParam()
const id = getQueryParam('id')
const dataRes = await getDetail(
typeof id === 'string' ? parseInt(id) : 0,
{ includes: 'encounter,doctor,doctor-employee,doctor-employee-person' }
)
const data = dataRes.body?.data || null
// Prescription Items
const items = ref<PrescriptionItem[]>([])
const mixItem = ref<PrescriptionItem>(genPrescriptionItem())
const medicinemixItems = ref<MedicinemixItem[]>([])
const nonMixItem = ref<PrescriptionItem>(genPrescriptionItem())
mixItem.value.prescription_id = typeof id === 'string' ? parseInt(id) : 0
nonMixItem.value.prescription_id = typeof id === 'string' ? parseInt(id) : 0
const { backToList } = useQueryCRUDMode()
const headerPrep: HeaderPrep = {
title: 'Tambah Order Obat / Resep',
icon: 'i-lucide-box',
}
const mixDialogOpen = ref(false)
const nonMixDialogOpen = ref(false)
const medicines = ref<Medicine[]>([])
onMounted(async () => {
await getItems()
})
function navClick(type: 'back' | 'delete' | 'draft' | 'submit') {
if (type === 'back') {
backToList()
}
}
function addItem(mode: 'mix' | 'non-mix') {
if (mode === 'mix') {
mixDialogOpen.value = true
} else if (mode === 'non-mix') {
nonMixDialogOpen.value = true
}
}
function saveMix() {
createPrescriptionItem(mixItem.value)
}
function saveNonMix() {
createPrescriptionItem(nonMixItem.value)
}
async function getItems() {
const res = await getPrescriptionItemList({ 'prescription-id': id, includes: 'medicine,medicine-medicineForm,medicineMix' })
if (res.success) {
items.value = res.body.data
} else {
items.value = []
}
}
async function getMedicines(value: string) {
const res = await getMedicineList({ 'search': value, 'includes': 'medicineForm' })
if (res.success) {
medicines.value = res.body.data
} else {
medicines.value = []
}
}
</script>
<template>
<Header
:prep="headerPrep"
:ref-search-nav="headerPrep.refSearchNav"
class="mb-4 xl:mb-5"
/>
<Detail :data="data" />
<ItemListEntry
:data="items"
@add="addItem"/>
<Separator class="my-5" />
<div class="w-full flex justify-center">
<Nav @click="navClick" />
</div>
<Dialog
v-model:open="mixDialogOpen"
:title="recItem?.id ? 'Edit Racikan' : 'Tambah Racikan'"
size="lg"
prevent-outside
>
<MixItemEntry
:data="mixItem"
:items="medicinemixItems"
:medicines="medicines"
@close="mixDialogOpen = false"
@save="saveMix"
@update:searchText="getMedicines"
/>
</Dialog>
<Dialog
v-model:open="nonMixDialogOpen"
:title="recItem?.id ? 'Edit Non Racikan' : 'Tambah Non Racikan'"
size="lg"
prevent-outside
>
<NonMixItemEntry
:data="nonMixItem"
:medicines="medicines"
@close="mixDialogOpen = false"
@save="saveNonMix"
@update:searchText="getMedicines"
/>
</Dialog>
</template>