From a5d5e8acd154b89bfcf7190ffae416f56c796e20 Mon Sep 17 00:00:00 2001 From: Khafid Prayoga Date: Fri, 10 Oct 2025 10:30:00 +0700 Subject: [PATCH] refactor(patient): restructure patient data handling to use nested properties Move address, contact and relative data into nested properties of Person model Update preview component to access data through person object Remove separate props for addresses, contacts and relatives --- app/components/app/patient/preview.vue | 44 ++++++++++++++++------- app/components/content/patient/detail.vue | 3 -- app/models/person.ts | 10 ++++-- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/app/components/app/patient/preview.vue b/app/components/app/patient/preview.vue index a72233a5..79eba5a3 100644 --- a/app/components/app/patient/preview.vue +++ b/app/components/app/patient/preview.vue @@ -7,15 +7,19 @@ import type { PersonRelative } from '~/models/person-relative' import DetailRow from '~/components/pub/my-ui/form/view/detail-row.vue' import DetailSection from '~/components/pub/my-ui/form/view/detail-section.vue' -import { educationCodes, genderCodes, occupationCodes, personContactTypes, relationshipCodes, religionCodes } from '~/lib/constants' +import { + educationCodes, + genderCodes, + occupationCodes, + personContactTypes, + relationshipCodes, + religionCodes, +} from '~/lib/constants' import { mapToComboboxOptList } from '~/lib/utils' // #region Props & Emits const props = defineProps<{ person: Person - personAddresses: PersonAddress[] - personContacts: PersonContact[] - personRelatives: PersonRelative[] }>() const emit = defineEmits<{ @@ -32,8 +36,18 @@ const occupationOptions = mapToComboboxOptList(occupationCodes) const relationshipOptions = mapToComboboxOptList(relationshipCodes) const personContactTypeOptions = mapToComboboxOptList(personContactTypes) -const residentAddress = 'Jl. Puncak Borobudur Blok M No. 321, Lowokwaru, Kota Malang, Jawa Timur' -const primaryAddress = 'Perumahan Araya Cluster B, No 22, Blimbing, Kota Malang, Jawa Timur' +// Computed addresses from nested data +const residentAddress = computed(() => { + const addresses = props.person.addresses + const resident = addresses?.find((addr) => addr.locationType === 'resident') + return resident?.address || 'Jl. Puncak Borobudur Blok M No. 321, Lowokwaru, Kota Malang, Jawa Timur' +}) + +const primaryAddress = computed(() => { + const addresses = props.person.addresses + const primary = addresses?.find((addr) => addr.locationType === 'primary') + return primary?.address || 'Perumahan Araya Cluster B, No 22, Blimbing, Kota Malang, Jawa Timur' +}) const patientAge = computed(() => { if (!props.person.birthDate) { @@ -96,7 +110,9 @@ function onClick(type: string) { {{ educationOptions.find((item) => item.code === person.education_code)?.label || '-' }} - {{ occupationOptions.find((item) => item.code === person.occupation_code)?.label || person.occupation_name || '-' }} + {{ + occupationOptions.find((item) => item.code === person.occupation_code)?.label || person.occupation_name || '-' + }} @@ -105,13 +121,13 @@ function onClick(type: string) { {{ primaryAddress || '-' }} - -