refactor(address): update address models and forms to use standardized fields
- Add preload relationships to address-related models - Rename postalCode to postalCode_code for consistency - Simplify location type handling with hidden fields - Update validation schemas and form components - Improve address display in patient preview
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
import { type Base, genBase } from './_base'
|
||||
import type { Regency } from './regency'
|
||||
|
||||
export interface District extends Base {
|
||||
regency_code: string
|
||||
code: string
|
||||
name: string
|
||||
|
||||
// preload
|
||||
regency?: Regency | null
|
||||
}
|
||||
|
||||
export function genDistrict(): District {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { type Base, genBase } from './_base'
|
||||
import type { PostalCode } from './postal-code'
|
||||
import { toTitleCase } from '~/lib/utils'
|
||||
|
||||
export interface PersonAddress extends Base {
|
||||
person_id: number
|
||||
@@ -6,8 +8,11 @@ export interface PersonAddress extends Base {
|
||||
address: string
|
||||
rt?: string
|
||||
rw?: string
|
||||
postalCode?: string
|
||||
postalCode_code?: string
|
||||
village_code: string
|
||||
|
||||
// preload
|
||||
postalCode?: PostalCode | null
|
||||
}
|
||||
|
||||
export function genPersonAddress(): PersonAddress {
|
||||
@@ -19,3 +24,23 @@ export function genPersonAddress(): PersonAddress {
|
||||
village_code: '',
|
||||
}
|
||||
}
|
||||
|
||||
export function formatAddress(builder?: PersonAddress) {
|
||||
if (!builder) return ''
|
||||
|
||||
const village = builder?.postalCode?.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?.postalCode_code,
|
||||
].filter(Boolean)
|
||||
|
||||
return parts.join(', ')
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { type Base, genBase } from './_base'
|
||||
import type { Ethnic } from './ethnic'
|
||||
import type { Language } from './language'
|
||||
import type { PersonAddress } from './person-address'
|
||||
import type { PersonContact } from './person-contact'
|
||||
import type { PersonRelative } from './person-relative'
|
||||
import type { Regency } from './regency'
|
||||
|
||||
export interface Person extends Base {
|
||||
name: string
|
||||
@@ -29,9 +32,12 @@ export interface Person extends Base {
|
||||
familyIdentityFileUrl?: string
|
||||
|
||||
// preload data for detail patient
|
||||
birthRegency?: Regency | null
|
||||
addresses?: PersonAddress[] | null
|
||||
contacts?: PersonContact[] | null
|
||||
relatives?: PersonRelative[] | null
|
||||
ethnic?: Ethnic | null
|
||||
language?: Language | null
|
||||
}
|
||||
|
||||
export function genPerson(): Person {
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { type Base, genBase } from './_base'
|
||||
|
||||
import type { Village } from './village'
|
||||
export interface PostalCode extends Base {
|
||||
code: string
|
||||
village_code: string
|
||||
|
||||
// preload
|
||||
village?: Village | null
|
||||
}
|
||||
|
||||
export function genPostalCode(): PostalCode {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { type Base, genBase } from "./_base"
|
||||
import { type Base, genBase } from './_base'
|
||||
import type { Province } from './province'
|
||||
|
||||
export interface Regency extends Base {
|
||||
code: string
|
||||
name: string
|
||||
province_code: string
|
||||
|
||||
province?: Province | null
|
||||
}
|
||||
|
||||
export function genRegency(): Regency {
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import { type Base, genBase } from './_base'
|
||||
import type { District } from './district'
|
||||
|
||||
export interface Village extends Base {
|
||||
district_code: string
|
||||
code: string
|
||||
name: string
|
||||
|
||||
// preload
|
||||
district?: District | null
|
||||
}
|
||||
|
||||
export function genVillage(): Village {
|
||||
|
||||
Reference in New Issue
Block a user