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
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import { type Base, genBase } from './_base'
|
|
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_code: AddressLocationTypeCode
|
|
address: string
|
|
rt?: string
|
|
rw?: string
|
|
postalRegion_code?: string
|
|
village_code: string
|
|
|
|
// preload
|
|
postalRegion?: PostalRegion | null
|
|
locationType?: AddressLocationTypeCode
|
|
}
|
|
|
|
export function genPersonAddress(): PersonAddress {
|
|
return {
|
|
...genBase(),
|
|
person_id: 0,
|
|
locationType_code: '',
|
|
address: '',
|
|
village_code: '',
|
|
}
|
|
}
|
|
|
|
export function formatAddress(builder?: PersonAddress) {
|
|
if (!builder) return ''
|
|
|
|
const village = builder?.postalRegion?.village
|
|
const district = village?.district
|
|
const regency = district?.regency
|
|
const province = regency?.province
|
|
|
|
const parts = [
|
|
builder?.address,
|
|
village?.name,
|
|
district?.name,
|
|
toTitleCase(regency?.name || ''),
|
|
toTitleCase(province?.name || ''),
|
|
builder?.postalRegion_code,
|
|
].filter(Boolean)
|
|
|
|
return parts.join(', ')
|
|
}
|