refactor(person-relative): update schema and form components for family data

- Change value format in radio-parents-input from '1'/'0' to 'yes'/'no'
- Remove default labels from select-education and select-job components
- Update schema to make fields optional and add new fields
- Modify family-parents-form to use new schema and improve UI
- Update patient form and models to align with schema changes
This commit is contained in:
Khafid Prayoga
2025-12-10 20:30:34 +07:00
parent 3cac23ce8a
commit 97d2b76ee3
10 changed files with 110 additions and 152 deletions

No files matched your search

@@ -21,7 +21,6 @@ const props = defineProps<{
const { const {
fieldName = 'education', fieldName = 'education',
label = 'Pendidikan',
placeholder = 'Pilih pendidikan terakhir', placeholder = 'Pilih pendidikan terakhir',
errors, errors,
class: containerClass, class: containerClass,
@@ -47,6 +46,7 @@ const educationOptions = [
<template> <template>
<DE.Cell :class="cn('select-field-group', fieldGroupClass, containerClass)"> <DE.Cell :class="cn('select-field-group', fieldGroupClass, containerClass)">
<DE.Label <DE.Label
v-if="label"
:label-for="fieldName" :label-for="fieldName"
:class="cn('select-field-label', labelClass)" :class="cn('select-field-label', labelClass)"
:is-required="isRequired && !isDisabled" :is-required="isRequired && !isDisabled"
@@ -21,7 +21,6 @@ const props = defineProps<{
const { const {
fieldName = 'job', fieldName = 'job',
label = 'Pekerjaan',
placeholder = 'Pilih pekerjaan', placeholder = 'Pilih pekerjaan',
errors, errors,
class: containerClass, class: containerClass,
@@ -39,9 +38,10 @@ const jobOptions = mapToComboboxOptList(occupationCodes).map(({ label, value })
<template> <template>
<DE.Cell :class="cn('select-field-group', fieldGroupClass, containerClass)"> <DE.Cell :class="cn('select-field-group', fieldGroupClass, containerClass)">
<DE.Label <DE.Label
v-if="label"
:label-for="fieldName" :label-for="fieldName"
:class="cn('select-field-label', labelClass)" :class="cn('select-field-label', labelClass)"
:is-required="isRequired" :is-required="isRequired && !isDisabled"
> >
{{ label }} {{ label }}
</DE.Label> </DE.Label>
@@ -3,7 +3,7 @@ import { useForm, FieldArray } from 'vee-validate'
import { toTypedSchema } from '@vee-validate/zod' import { toTypedSchema } from '@vee-validate/zod'
// schemas // schemas
import { type PersonRelativeFormData, ResponsiblePersonSchema } from '~/schemas/person-relative.schema' import { type PersonRelativeFormData, ResponsiblePersonRelativeSchema } from '~/schemas/person-relative.schema'
// components // components
import * as DE from '~/components/pub/my-ui/doc-entry' import * as DE from '~/components/pub/my-ui/doc-entry'
@@ -20,7 +20,7 @@ interface Props {
} }
const props = defineProps<Props>() const props = defineProps<Props>()
const formSchema = toTypedSchema(ResponsiblePersonSchema) const formSchema = toTypedSchema(ResponsiblePersonRelativeSchema)
const { values, resetForm, setValues, validate } = useForm<FormData>({ const { values, resetForm, setValues, validate } = useForm<FormData>({
name: 'personRelativeForm', name: 'personRelativeForm',
@@ -1,37 +1,32 @@
<script setup lang="ts"> <script setup lang="ts">
import type { PersonFamilyFormData as FamilyData, PersonFamiliesFormData } from '~/schemas/person-family.schema' import { type PersonRelativeFormData, ResponsiblePersonRelativeSchema } from '~/schemas/person-relative.schema'
import { PersonFamiliesSchema } from '~/schemas/person-family.schema'
import { toTypedSchema } from '@vee-validate/zod' import { toTypedSchema } from '@vee-validate/zod'
import { useForm, FieldArray } from 'vee-validate' import { useForm, FieldArray } from 'vee-validate'
// component // component
import * as DE from '~/components/pub/my-ui/doc-entry' import * as DE from '~/components/pub/my-ui/doc-entry'
import { SelectEducation } from '~/components/app/patient/fields'
import { InputBase } from '~/components/pub/my-ui/form' import { InputBase } from '~/components/pub/my-ui/form'
import { RadioParentsInput } from './fields' import { RadioParentsInput } from './fields'
import { SelectJob, SelectEducation } from '~/components/app/patient/fields'
import { SelectRelations } from '~/components/app/person-relative/fields'
interface FormData extends PersonFamiliesFormData {} interface FormData extends PersonRelativeFormData {}
interface Props { interface Props {
title: string title: string
isReadonly: boolean isReadonly: boolean
initialValues?: any initialValues?: FormData
} }
const props = defineProps<Props>() const props = defineProps<Props>()
const formSchema = toTypedSchema(PersonFamiliesSchema) const formSchema = toTypedSchema(ResponsiblePersonRelativeSchema)
const isFamilyFormDisabled = ref(true) const isFamilyFormDisabled = ref(true)
const { values, resetForm, setValues, validate, setFieldValue } = useForm<FormData>({ const { values, resetForm, setValues, validate, setFieldValue } = useForm<FormData>({
name: 'familyParentsForm', name: 'familyParentsForm',
validationSchema: formSchema, validationSchema: formSchema,
initialValues: props.initialValues initialValues: props.initialValues ? props.initialValues : {},
? props.initialValues
: {
shareFamilyData: '0',
families: [],
},
validateOnMount: false, validateOnMount: false,
}) })
@@ -43,11 +38,11 @@ defineExpose({
}) })
watch( watch(
() => values.shareFamilyData, () => values._shareFamilyData,
(newValue) => { (newValue) => {
if (!newValue) return if (!newValue) return
if (newValue === '1') { if (newValue === 'yes') {
isFamilyFormDisabled.value = false isFamilyFormDisabled.value = false
const fam = values?.families || [] const fam = values?.families || []
@@ -56,8 +51,8 @@ watch(
if (needsReset) { if (needsReset) {
setFieldValue('families', [ setFieldValue('families', [
{ relation: 'mother', name: '', education: '', occupation: '' }, { relation: 'mother', name: '', education_code: '', occupation_code: '' },
{ relation: 'father', name: '', education: '', occupation: '' }, { relation: 'father', name: '', education_code: '', occupation_code: '' },
]) ])
} }
@@ -83,95 +78,59 @@ watch(
</p> </p>
</div> </div>
<div class="mb-5 border-b border-b-slate-300 pb-3 text-lg xl:text-xl"> <div class="mb-5 pb-3 text-lg xl:text-xl">
<div class="mb-6"> <div>
<RadioParentsInput <RadioParentsInput
field-name="shareFamilyData" field-name="_shareFamilyData"
:is-disabled="isReadonly" :is-disabled="isReadonly"
/> />
</div> </div>
<div <div :key="values._shareFamilyData">
class="space-y-6" <FieldArray
:key="values.shareFamilyData" v-slot="{ fields, push, remove }"
> name="families"
<template v-if="values.shareFamilyData === '1'"> >
<FieldArray <template v-if="fields.length === 0">
v-slot="{ fields }" {{ push({ relation: 'mother', name: '', address: '', education_code: '' }) }}
name="families" {{ push({ relation: 'father', name: '', address: '', education_code: '' }) }}
> </template>
<div class="grid grid-cols-1 gap-6 lg:grid-cols-2"> <div class="space-y-4">
<div <DE.Block
v-for="(field, idx) in fields" v-for="(field, idx) in fields"
:key="field.key" :key="field.key"
class="space-y-4 rounded-lg border border-gray-200 bg-gray-50/50 p-4 dark:border-gray-700 dark:bg-gray-800/50" :col-count="5"
> :cell-flex="false"
<h4 class="text-sm font-medium text-gray-700 dark:text-gray-300">
{{ (field.value as FamilyData).relation === 'mother' ? 'Data Ibu' : 'Data Ayah' }}
</h4>
<DE.Block>
<InputBase
:field-name="`families[${idx}].name`"
label="Nama"
placeholder="Masukkan nama"
:is-disabled="isReadonly || isFamilyFormDisabled"
/>
<SelectEducation
:field-name="`families[${idx}].education`"
label="Pendidikan"
placeholder="Pilih"
:is-disabled="isReadonly || isFamilyFormDisabled"
/>
<InputBase
:field-name="`families[${idx}].occupation`"
label="Pekerjaan"
placeholder="Masukkan pekerjaan"
:is-disabled="isReadonly || isFamilyFormDisabled"
/>
</DE.Block>
</div>
</div>
</FieldArray>
</template>
<template v-else>
<div class="grid grid-cols-1 gap-6 lg:grid-cols-2">
<div
v-for="relation in ['mother', 'father']"
:key="relation"
class="space-y-4 rounded-lg border border-gray-200 bg-gray-50/50 p-4 dark:border-gray-700 dark:bg-gray-800/50"
> >
<h4 class="text-sm font-medium text-gray-700 dark:text-gray-300"> <SelectRelations
{{ relation === 'mother' ? 'Data Ibu' : 'Data Ayah' }} :label="idx === 0 ? 'Hubungan dengan Pasien' : undefined"
</h4> :field-name="`families[${idx}].relation`"
placeholder="Pilih"
<DE.Block> is-disabled
<InputBase />
:field-name="`families[${relation}].name`" <InputBase
is-disabled :label="idx === 0 ? 'Nama' : undefined"
label="Nama" :field-name="`families[${idx}].name`"
placeholder="-" placeholder="Masukkan Nama"
/> :is-disabled="isReadonly || values._shareFamilyData === 'no'"
/>
<SelectEducation <!-- <SelectJob
:field-name="`families[${relation}].education`" :label="idx === 0 ? 'Pekerjaan' : undefined"
is-disabled :field-name="`families[${idx}].occupation_code`"
label="Pendidikan" placeholder="Pilih pekerjaan"
placeholder="-" is-required
/> :is-disabled="isReadonly || values.shareFamilyData === 'no'"
/> -->
<InputBase <SelectEducation
:field-name="`families[${relation}].occupation`" :label="idx === 0 ? 'Pendidikan' : undefined"
is-disabled :field-name="`families[${idx}].education_code`"
label="Pekerjaan" placeholder="Pilih pendidikan"
placeholder="-" is-required
/> :is-disabled="isReadonly || values._shareFamilyData === 'no'"
</DE.Block> />
</div> </DE.Block>
</div> </div>
</template> </FieldArray>
</div> </div>
</div> </div>
</form> </form>
@@ -29,8 +29,8 @@ const {
} = props } = props
const residenceOptions = [ const residenceOptions = [
{ label: 'Ya', value: '1' }, { label: 'Ya', value: 'yes' },
{ label: 'Tidak', value: '0' }, { label: 'Tidak', value: 'no' },
] ]
</script> </script>
+1 -1
View File
@@ -18,7 +18,7 @@ import Action from '~/components/pub/my-ui/nav-footer/ba-dr-su.vue'
import AppPatientEntryForm from '~/components/app/patient/entry-form.vue' import AppPatientEntryForm from '~/components/app/patient/entry-form.vue'
import AppPersonAddressEntryForm from '~/components/app/person-address/entry-form.vue' import AppPersonAddressEntryForm from '~/components/app/person-address/entry-form.vue'
import AppPersonAddressEntryFormRelative from '~/components/app/person-address/entry-form-relative.vue' import AppPersonAddressEntryFormRelative from '~/components/app/person-address/entry-form-relative.vue'
import AppPersonFamilyParentsForm from '~/components/app/person/family-parents-form.vue' import AppPersonFamilyParentsForm from '~/components/app/person/family-parents-form-bak.vue'
import AppPersonContactEntryForm from '~/components/app/person-contact/entry-form.vue' import AppPersonContactEntryForm from '~/components/app/person-contact/entry-form.vue'
import AppPersonRelativeEntryForm from '~/components/app/person-relative/entry-form.vue' import AppPersonRelativeEntryForm from '~/components/app/person-relative/entry-form.vue'
+6 -14
View File
@@ -25,16 +25,7 @@ import { id as localeID } from 'date-fns/locale'
// services // services
import { getPatientDetail, uploadAttachment } from '~/services/patient.service' import { getPatientDetail, uploadAttachment } from '~/services/patient.service'
import { import { isReadonly, isProcessing, handleActionSave, handleActionEdit } from '~/handlers/patient.handler'
isReadonly,
isProcessing,
isFormEntryDialogOpen,
isRecordConfirmationOpen,
onResetState,
handleActionSave,
handleActionEdit,
handleCancelForm,
} from '~/handlers/patient.handler'
import { toast } from '~/components/pub/ui/toast' import { toast } from '~/components/pub/ui/toast'
@@ -180,19 +171,19 @@ const familyFormInitialValues = computed(() => {
if (parents.length === 0) { if (parents.length === 0) {
return { return {
shareFamilyData: '0', _shareFamilyData: 'no' as const,
families: [], families: [],
} }
} }
return { return {
shareFamilyData: '1', _shareFamilyData: 'yes' as const,
families: parents.map((parent: PersonRelative) => ({ families: parents.map((parent: PersonRelative) => ({
id: parent.id || 0, id: parent.id || 0,
relation: parent.relationship_code || '', relation: parent.relationship_code || '',
name: parent.name || '', name: parent.name || '',
education: parent.education_code || '', occupation_code: parent.occupation_code || '',
occupation: parent.occupation_name || parent.occupation_code || '', education_code: parent.education_code || '',
})), })),
} }
}) })
@@ -253,6 +244,7 @@ async function composeFormData(): Promise<PatientEntity> {
const results = [patient, address, addressRelative, families, contacts, emergencyContact] const results = [patient, address, addressRelative, families, contacts, emergencyContact]
const allValid = results.every((r) => r?.valid) const allValid = results.every((r) => r?.valid)
console.log(results)
// exit, if form errors happend during validation // exit, if form errors happend during validation
// for example: dropdown not selected // for example: dropdown not selected
if (!allValid) return Promise.reject('Form validation failed') if (!allValid) return Promise.reject('Form validation failed')
+18 -16
View File
@@ -11,7 +11,7 @@ import { PersonAddressRelativeSchema } from '~/schemas/person-address-relative.s
import { PersonAddressSchema } from '~/schemas/person-address.schema' import { PersonAddressSchema } from '~/schemas/person-address.schema'
import { PersonContactListSchema } from '~/schemas/person-contact.schema' import { PersonContactListSchema } from '~/schemas/person-contact.schema'
import { PersonFamiliesSchema } from '~/schemas/person-family.schema' import { PersonFamiliesSchema } from '~/schemas/person-family.schema'
import { ResponsiblePersonSchema } from '~/schemas/person-relative.schema' import { ResponsiblePersonRelativeSchema } from '~/schemas/person-relative.schema'
import { uploadAttachment } from '~/services/patient.service' import { uploadAttachment } from '~/services/patient.service'
import { getDetail, update } from '~/services/surgery-report.service' import { getDetail, update } from '~/services/surgery-report.service'
import type { SurgeryReport } from '~/models/surgery-report' import type { SurgeryReport } from '~/models/surgery-report'
@@ -28,17 +28,18 @@ import { handleActionEdit } from '~/handlers/surgery-report.handler'
import type { HeaderPrep, RefSearchNav } from '~/components/pub/my-ui/data/types' import type { HeaderPrep, RefSearchNav } from '~/components/pub/my-ui/data/types'
// #region Props & Emits // #region Props & Emits
const props = withDefaults(defineProps<{ const props = withDefaults(
encounter_id: number defineProps<{
callbackUrl?: string encounter_id: number
record_id: number callbackUrl?: string
}>(), { record_id: number
}>(),
}) {},
)
// form related state // form related state
const { data, isLoading, paginationMeta, searchInput, handlePageChange, handleSearch, fetchData } = usePaginatedList({ const { data, isLoading, paginationMeta, searchInput, handlePageChange, handleSearch, fetchData } = usePaginatedList({
fetchFn: (params) => getList({ ...params, includes: 'specialist,subspecialist,doctor-employee-person', }), fetchFn: (params) => getList({ ...params, includes: 'specialist,subspecialist,doctor-employee-person' }),
entityName: 'surgery-report', entityName: 'surgery-report',
}) })
// #endregion // #endregion
@@ -56,7 +57,7 @@ const selectedOperativeAction = ref<any>(null)
onMounted(async () => { onMounted(async () => {
const result = await getDetail(props.record_id) const result = await getDetail(props.record_id)
if (result.success) { if (result.success) {
const responseData = {...result.body.data, date: formatDateYyyyMmDd(result.body.data.date)} const responseData = { ...result.body.data, date: formatDateYyyyMmDd(result.body.data.date) }
surgeryReport.value = responseData surgeryReport.value = responseData
inputForm.value?.setValues(responseData) inputForm.value?.setValues(responseData)
} }
@@ -72,17 +73,15 @@ async function handleConfirmAdd() {
const response = await handleActionEdit( const response = await handleActionEdit(
props.record_id, props.record_id,
await composeFormData(), await composeFormData(),
() => { }, () => {},
() => { }, () => {},
toast, toast,
) )
goBack() goBack()
} }
async function composeFormData(): Promise<SurgeryReport> { async function composeFormData(): Promise<SurgeryReport> {
const [input,] = await Promise.all([ const [input] = await Promise.all([inputForm.value?.validate()])
inputForm.value?.validate(),
])
const results = [input] const results = [input]
const allValid = results.every((r) => r?.valid) const allValid = results.every((r) => r?.valid)
@@ -131,7 +130,10 @@ function handleCancelAdd() {
/> />
<div class="my-2 flex justify-end py-2"> <div class="my-2 flex justify-end py-2">
<Action :enable-draft="false" @click="handleActionClick" /> <Action
:enable-draft="false"
@click="handleActionClick"
/>
</div> </div>
<Confirmation <Confirmation
+6 -7
View File
@@ -4,7 +4,6 @@ import { type Person, genPerson } from './person'
import type { PatientFormData } from '~/schemas/patient.schema' import type { PatientFormData } from '~/schemas/patient.schema'
import type { PersonAddressFormData } from '~/schemas/person-address.schema' import type { PersonAddressFormData } from '~/schemas/person-address.schema'
import type { PersonAddressRelativeFormData } from '~/schemas/person-address-relative.schema' import type { PersonAddressRelativeFormData } from '~/schemas/person-address-relative.schema'
import type { PersonFamiliesFormData } from '~/schemas/person-family.schema'
import type { PersonContactFormData } from '~/schemas/person-contact.schema' import type { PersonContactFormData } from '~/schemas/person-contact.schema'
import type { PersonRelativeFormData } from '~/schemas/person-relative.schema' import type { PersonRelativeFormData } from '~/schemas/person-relative.schema'
import type { PersonAddress } from './person-address' import type { PersonAddress } from './person-address'
@@ -32,7 +31,7 @@ export interface genPatientProps {
patient: PatientFormData patient: PatientFormData
residentAddress: PersonAddressFormData residentAddress: PersonAddressFormData
cardAddress: PersonAddressRelativeFormData cardAddress: PersonAddressRelativeFormData
familyData: PersonFamiliesFormData familyData: PersonRelativeFormData
contacts: PersonContactFormData contacts: PersonContactFormData
responsible: PersonRelativeFormData responsible: PersonRelativeFormData
} }
@@ -75,15 +74,15 @@ export function genPatientEntity(props: genPatientProps, patientData: PatientEnt
} }
// add data orang tua // add data orang tua
if (familyData.shareFamilyData === '1') { if (familyData._shareFamilyData === 'yes' && familyData.families && familyData.families.length > 0) {
for (const family of familyData.families) { for (const family of familyData.families) {
familiesContact.push({ familiesContact.push({
id: family.id || 0, id: family.id || 0,
relationship_code: family.relation, relationship_code: family.relation,
name: family.name, name: family.name,
education_code: family.education, education_code: family.education_code,
occupation_name: family.occupation, occupation_name: family.occupation_name,
occupation_code: family.occupation, occupation_code: family.occupation_code,
responsible: false, responsible: false,
}) })
} }
@@ -106,7 +105,7 @@ export function genPatientEntity(props: genPatientProps, patientData: PatientEnt
} }
// add penanggung jawab // add penanggung jawab
if (responsible) { if (responsible.contacts && responsible.contacts.length > 0) {
for (const contact of responsible.contacts) { for (const contact of responsible.contacts) {
familiesContact.push({ familiesContact.push({
id: contact.id || 0, id: contact.id || 0,
+14 -8
View File
@@ -1,22 +1,28 @@
import { z } from 'zod' import { z } from 'zod'
const ResponsibleContactPersonSchema = z.object({ const PersonRelativeSchema = z.object({
id: z.number().optional(), id: z.number().optional(),
relation: z.string({ required_error: 'Pilih jenis Penanggung Jawab' }).min(1, 'Pilih jenis Penanggung Jawab'), relation: z.string({ required_error: 'Pilih jenis Penanggung Jawab' }).min(1, 'Pilih jenis Penanggung Jawab'),
name: z.string({ required_error: 'Mohon lengkapi Nama' }).min(3, 'Mohon lengkapi Nama'), name: z.string({ required_error: 'Mohon lengkapi Nama' }).optional(),
address: z.string({ required_error: 'Mohon lengkapi Alamat' }).min(3, 'Mohon lengkapi Alamat'), address: z.string({ required_error: 'Mohon lengkapi Alamat' }).optional(),
phone: z phone: z
.string({ required_error: 'Mohon lengkapi Nomor HP' }) .string({ required_error: 'Mohon lengkapi Nomor HP' })
.min(8, 'Nomor HP minimal 10 digit') .min(8, 'Nomor HP minimal 10 digit')
.max(15, 'Nomor HP maksimal 15 digit'), .max(15, 'Nomor HP maksimal 15 digit')
.optional(),
occupation_name: z.string().optional(),
occupation_code: z.string().optional(),
education_code: z.string().optional(),
}) })
const ResponsiblePersonSchema = z.object({ const ResponsiblePersonRelativeSchema = z.object({
contacts: z.array(ResponsibleContactPersonSchema).min(1, 'Minimal harus ada 1 penanggung jawab'), contacts: z.array(PersonRelativeSchema).optional(),
families: z.array(PersonRelativeSchema).optional(),
_shareFamilyData: z.enum(['yes', 'no']).optional(),
}) })
type PersonRelativeFormData = z.infer<typeof ResponsiblePersonSchema> type PersonRelativeFormData = z.infer<typeof ResponsiblePersonRelativeSchema>
export { ResponsiblePersonSchema } export { ResponsiblePersonRelativeSchema }
export type { PersonRelativeFormData } export type { PersonRelativeFormData }