feat(cemo): modify schema

This commit is contained in:
riefive
2025-10-31 13:09:59 +07:00
parent 45cc019ec1
commit 7119f67402
2 changed files with 83 additions and 14 deletions
+10 -14
View File
@@ -4,22 +4,18 @@ import Block from '~/components/pub/my-ui/doc-entry/block.vue'
import Cell from '~/components/pub/my-ui/doc-entry/cell.vue'
import Field from '~/components/pub/my-ui/doc-entry/field.vue'
import Label from '~/components/pub/my-ui/doc-entry/label.vue'
import Input from '~/components/pub/ui/input/Input.vue'
import Button from '~/components/pub/ui/button/Button.vue'
import Combobox from '~/components/pub/my-ui/combobox/combobox.vue'
import Input from '~/components/pub/ui/input/Input.vue'
import DatepickerSingle from '~/components/pub/my-ui/datepicker/datepicker-single.vue'
// Types
import type { Ref } from 'vue'
import type { PaginationMeta } from '~/components/pub/my-ui/pagination/pagination.type'
// Helpers
import type z from 'zod'
import { useForm } from 'vee-validate'
import { toTypedSchema } from '@vee-validate/zod'
import { cemotherapySchema } from "~/schemas/cemotherapy.schema"
interface Props {
schema: z.ZodSchema<any>
values?: any
isLoading?: boolean
isReadonly?: boolean
@@ -41,7 +37,7 @@ const emit = defineEmits<{
}>()
const { defineField, errors, meta } = useForm({
validationSchema: toTypedSchema(props.schema),
validationSchema: toTypedSchema(cemotherapySchema),
initialValues: {
namaPasien: '',
tanggalLahir: '',
@@ -74,12 +70,12 @@ const [dokterKRJ, dokterKRJAttrs] = defineField('dokterKRJ')
// Set initial values if provided
if (props.values) {
Object.entries(props.values).forEach(([key, value]) => {
if (value !== undefined) {
const field = defineField(key)[0]
field.value = value
}
})
// Object.entries(props.values).forEach(([key, value]) => {
// if (value !== undefined) {
// const field = defineField(key)[0]
// field.value = value
// }
// })
}
const resetForm = () => {
@@ -268,7 +264,7 @@ function onCancelForm() {
<Label height="compact">Dokter Ruang Tindakan</Label>
<Field :errMessage="errors.dokterKRJ">
<Combobox
id="doktor"
id="doctor"
v-model="dokterKRJ"
v-bind="dokterKRJAttrs"
:items="items"
+73
View File
@@ -0,0 +1,73 @@
import { z } from 'zod'
const dateStringSchema = z.string().min(1)
export const cemotherapySchema = z.object({
// Data Pasien
namaPasien: z.string({
required_error: 'Nama pasien harus diisi',
}).min(1, 'Nama pasien harus diisi'),
tanggalLahir: z.string({
required_error: 'Tanggal lahir harus diisi',
}).min(1, 'Tanggal lahir harus diisi'),
noRM: z.string({
required_error: 'Nomor RM harus diisi',
}).min(1, 'Nomor RM harus diisi'),
alamat: z.string({
required_error: 'Alamat harus diisi',
}).min(1, 'Alamat harus diisi'),
beratBadan: z.union([
z.string(),
z.number()
]).transform(val => val === '' ? null : Number(val))
.refine(val => val === null || (val >= 0 && val <= 500), {
message: 'Berat badan harus di antara 0-500 kg',
}),
tinggiBadan: z.union([
z.string(),
z.number()
]).transform(val => val === '' ? null : Number(val))
.refine(val => val === null || (val >= 0 && val <= 300), {
message: 'Tinggi badan harus di antara 0-300 cm',
}),
diagnosa: z.string({
required_error: 'Diagnosa harus dipilih',
}).min(1, 'Diagnosa harus dipilih'),
// Protokol Kemoterapi
siklus: z.string({
required_error: 'Siklus harus diisi',
}).min(1, 'Siklus harus diisi'),
periodeAwal: z.string({
required_error: 'Periode awal harus diisi',
}).min(1, 'Periode awal harus diisi'),
periodeAkhir: dateStringSchema.refine((val) => {
if (!val) return false
const date = new Date(val)
return !isNaN(date.getTime())
}, {
message: 'Format tanggal tidak valid'
}),
tanggalKemoterapi: dateStringSchema.refine((val) => {
if (!val) return false
const date = new Date(val)
return !isNaN(date.getTime())
}, {
message: 'Format tanggal tidak valid'
}),
dokterKRJ: z.string({
required_error: 'Dokter harus dipilih',
}).refine(val => val !== '', {
message: 'Dokter harus dipilih',
}),
})