Files
simrsx-fe/app/models/patient.ts
Khafid Prayoga 55239606af feat(patient): address integration to backend apis
feat(patient): add newborn status field and validation

- Add radio button component for newborn status selection
- Update patient schema with newborn status validation
- Remove deprecated alias field from person model
- Refactor disability type handling in patient schema

fix(patient): correct address comparison logic and schema

Update the patient address comparison to use boolean instead of string '1' and modify the schema to transform the string value to boolean. This ensures consistent type usage throughout the application.

feat(models): add village and district model interfaces

Add new model interfaces for Village and District with their respective generator functions. These models will be used to handle administrative division data in the application.

feat(address): implement dynamic province selection with caching

- Add province service for CRUD operations
- Create useProvinces composable with caching and loading states
- Update select-province component to use dynamic data
- Export SelectItem interface for type consistency
- Improve combobox styling and accessibility

feat(address-form): implement dynamic regency selection with caching

- Add new regency service for CRUD operations
- Create useRegencies composable with caching and loading states
- Update SelectRegency component to use dynamic data based on province selection
- Improve placeholder and disabled state handling

feat(address-form): implement dynamic district selection

- Add district service for CRUD operations
- Create useDistricts composable with caching and loading states
- Update SelectDistrict component to use dynamic data
- Remove hardcoded district options and implement regency-based filtering

feat(address-form): implement dynamic village selection with caching

- Add village service for CRUD operations
- Create useVillages composable with caching and loading states
- Update SelectVillage component to fetch villages based on district
- Remove hardcoded village options in favor of API-driven data

feat(address-form): improve address selection with debouncing and request deduplication

- Add debouncing to prevent rapid API calls when selecting addresses
- Implement request deduplication to avoid duplicate API calls
- Add delayed form reset to ensure proper composable cleanup
- Add isUserAction flag to force refresh when user changes selection
2025-10-08 15:58:22 +07:00

138 lines
4.5 KiB
TypeScript

import { type Base, genBase } from './_base'
import type { PatientFormData } from '~/schemas/patient.schema'
import type { PersonAddressFormData } from '~/schemas/person-address.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 { PersonRelativeFormData } from '~/schemas/person-relative.schema'
import type { Person } from './person'
import type { PersonAddress } from './person-address'
import type { PersonContact } from './person-contact'
import type { PersonRelative } from './person-relative'
import { contactTypeMapping } from '~/lib/constants'
export interface PatientBase extends Base {
person_id?: number
newBornStatus?: boolean
registeredAt?: Date | string | null
status_code?: string
number?: string
}
export interface PatientEntity extends PatientBase {
person: Person
personAddresses: PersonAddress[]
personContacts: PersonContact[]
personRelatives: PersonRelative[]
}
export interface genPatientProps {
patient: PatientFormData
residentAddress: PersonAddressFormData
cardAddress: PersonAddressRelativeFormData
familyData: PersonFamiliesFormData
contacts: PersonContactFormData
responsible: PersonRelativeFormData
}
export function genPatient(props: genPatientProps): PatientEntity {
const { patient, residentAddress, cardAddress, familyData, contacts, responsible } = props
const addresses: PersonAddress[] = [{ ...genBase(), person_id: 0, locationType: '', ...residentAddress }]
const familiesContact: PersonRelative[] = []
const personContacts: PersonContact[] = []
// jika alamat ktp sama dengan domisili saat ini
if (cardAddress.isSameAddress) {
addresses.push({ ...genBase(), person_id: 0, locationType: '', ...residentAddress })
}
// add data orang tua
if (familyData.shareFamilyData === '1') {
for (const family of familyData.families) {
familiesContact.push({
id: 0,
relationship_code: family.relation,
name: family.name,
education_code: family.education,
occupation_name: family.occupation,
occupation_code: family.occupation,
responsible: false,
})
}
}
// add kontak pasien
if (contacts && contacts.contacts.length > 0) {
for (const contact of contacts.contacts) {
// Convert UI contactType to backend type_code using mapping
const mappedContactType = contactTypeMapping[contact.contactType]
personContacts.push({
...genBase(),
person_id: 0,
type_code: mappedContactType || '',
value: contact.contactNumber,
})
}
}
// add penanggung jawab
if (responsible) {
for (const contact of responsible.contacts) {
familiesContact.push({
id: 0,
relationship_code: contact.relation,
name: contact.name,
address: contact.address,
phoneNumber: contact.phone,
responsible: true,
})
}
}
return {
person: {
id: 0,
name: patient.fullName,
// alias: patient.alias,
birthDate: patient.birthDate,
birthRegency_code: patient.birthPlace,
gender_code: patient.gender,
residentIdentityNumber: patient.identityNumber,
passportNumber: patient.passportNumber,
drivingLicenseNumber: patient.drivingLicenseNumber,
religion_code: patient.religion,
education_code: patient.education,
occupation_code: patient.job,
occupation_name: patient.job,
ethnic_code: patient.ethnicity,
language_code: patient.language,
communicationIssueStatus: patient.communicationBarrier,
disability: patient.disabilityType || '',
nationality: patient.nationality,
// residentIdentityFileUrl: patient.residentIdentityFileUrl,
// passportFileUrl: patient.passportFileUrl,
// drivingLicenseFileUrl: patient.drivingLicenseFileUrl,
// familyIdentityFileUrl: patient.familyIdentityFileUrl,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
deletedAt: null,
},
personAddresses: addresses,
personContacts: personContacts,
personRelatives: familiesContact,
registeredAt: new Date(),
status_code: 'active',
newBornStatus: patient.isNewBorn,
person_id: 0,
id: 0,
number: '0x000000000000000000000000000000',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
deletedAt: null,
}
}