From 7119f67402b5261226257b3aa6e193d516f33041 Mon Sep 17 00:00:00 2001 From: riefive Date: Fri, 31 Oct 2025 13:09:59 +0700 Subject: [PATCH] feat(cemo): modify schema --- app/components/app/cemotherapy/entry-form.vue | 24 +++--- app/schemas/cemotherapy.schema.ts | 73 +++++++++++++++++++ 2 files changed, 83 insertions(+), 14 deletions(-) create mode 100644 app/schemas/cemotherapy.schema.ts diff --git a/app/components/app/cemotherapy/entry-form.vue b/app/components/app/cemotherapy/entry-form.vue index 1b6e9140..3a4104b8 100644 --- a/app/components/app/cemotherapy/entry-form.vue +++ b/app/components/app/cemotherapy/entry-form.vue @@ -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 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() { 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', + }), +}) \ No newline at end of file