refactor: postal region, add new field on list

feat: implement postal region model and update address handling

- Add new PostalRegion model and service
- Replace postalCode with postalRegion in address-related components
- Update schemas and models to use locationType_code consistently
- Add usePostalRegion composable for postal code selection
- Modify patient form to handle address changes more robustly

feat(patient): add ID column and improve date formatting

- Add patient ID column to patient list
- Format dates using 'id-ID' locale in preview
- Update identity number display for foreign patients
- Include passport number for foreign nationals
This commit is contained in:
Khafid Prayoga
2025-10-13 11:18:10 +07:00
parent 44433d67c8
commit 46911514fb
16 changed files with 204 additions and 123 deletions
+25 -2
View File
@@ -38,6 +38,7 @@ export interface genPatientProps {
}
export function genPatient(props: genPatientProps): Patient {
console.log(props)
const { patient, residentAddress, cardAddress, familyData, contacts, responsible } = props
const addresses: PersonAddress[] = [{ ...genBase(), person_id: 0, ...residentAddress }]
@@ -46,7 +47,29 @@ export function genPatient(props: genPatientProps): Patient {
// jika alamat ktp sama dengan domisili saat ini
if (cardAddress.isSameAddress) {
addresses.push({ ...genBase(), ...residentAddress, person_id: 0, locationType: 'identity' })
addresses.push({
...genBase(),
...residentAddress,
person_id: 0,
locationType_code: cardAddress.locationType_code || 'identity'
})
} else {
// jika alamat berbeda, tambahkan alamat relatif
// Pastikan semua field yang diperlukan ada
const relativeAddress = {
...genBase(),
person_id: 0,
locationType_code: cardAddress.locationType_code || 'identity',
address: cardAddress.address || '',
province_code: cardAddress.province_code || '',
regency_code: cardAddress.regency_code || '',
district_code: cardAddress.district_code || '',
village_code: cardAddress.village_code || '',
postalRegion_code: cardAddress.postalRegion_code || '',
rt: cardAddress.rt,
rw: cardAddress.rw,
}
addresses.push(relativeAddress)
}
// add data orang tua
@@ -129,7 +152,7 @@ export function genPatient(props: genPatientProps): Patient {
newBornStatus: patient.isNewBorn,
person_id: 0,
id: 0,
number: '0x000000000000000000000000000000',
number: '',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
deletedAt: null,
+9 -8
View File
@@ -1,25 +1,26 @@
import { type Base, genBase } from './_base'
import type { PostalCode } from './postal-code'
import type { AddressLocationTypeCode } from '~/lib/constants'
import type { PostalRegion } from './postal-region'
import { toTitleCase } from '~/lib/utils'
export interface PersonAddress extends Base {
person_id: number
locationType: string
locationType_code: AddressLocationTypeCode
address: string
rt?: string
rw?: string
postalCode_code?: string
postalRegion_code?: string
village_code: string
// preload
postalCode?: PostalCode | null
postalRegion?: PostalRegion | null
locationType?: AddressLocationTypeCode
}
export function genPersonAddress(): PersonAddress {
return {
...genBase(),
person_id: 0,
locationType: '',
locationType_code: '',
address: '',
village_code: '',
}
@@ -28,7 +29,7 @@ export function genPersonAddress(): PersonAddress {
export function formatAddress(builder?: PersonAddress) {
if (!builder) return ''
const village = builder?.postalCode?.village
const village = builder?.postalRegion?.village
const district = village?.district
const regency = district?.regency
const province = regency?.province
@@ -39,7 +40,7 @@ export function formatAddress(builder?: PersonAddress) {
district?.name,
toTitleCase(regency?.name || ''),
toTitleCase(province?.name || ''),
builder?.postalCode_code,
builder?.postalRegion_code,
].filter(Boolean)
return parts.join(', ')
@@ -1,6 +1,7 @@
import { type Base, genBase } from './_base'
import type { Village } from './village'
export interface PostalCode extends Base {
export interface PostalRegion extends Base {
code: string
village_code: string
@@ -8,7 +9,7 @@ export interface PostalCode extends Base {
village?: Village | null
}
export function genPostalCode(): PostalCode {
export function genPostalRegion(): PostalRegion {
return {
...genBase(),
code: '',