diff --git a/app/components/app/patient/entry-form.vue b/app/components/app/patient/entry-form.vue index 4f577091..7b6c578f 100644 --- a/app/components/app/patient/entry-form.vue +++ b/app/components/app/patient/entry-form.vue @@ -5,6 +5,9 @@ import { toTypedSchema } from '@vee-validate/zod' // types import { type PatientFormData, PatientSchema } from '~/schemas/patient.schema' +// utils +import { calculateAge } from '~/models/person' + // components import * as DE from '~/components/pub/my-ui/doc-entry' import { InputBase, FileField as FileUpload } from '~/components/pub/my-ui/form' @@ -26,7 +29,9 @@ import { SelectReligion, } from './fields' -interface FormData extends PatientFormData {} +interface FormData extends PatientFormData { + _calculatedAge: string +} // Type untuk initial values (sebelum transform schema) interface PatientFormInput { @@ -74,6 +79,18 @@ defineExpose({ setValues, values, }) + +watch( + () => values.birthDate, + (newValue) => { + if (newValue) { + setFieldValue('_calculatedAge', calculateAge(newValue)) + } + }, + { + immediate: true, + }, +)