form cleanup

feat(patient): add edit functionality to patient form

- Modify genPatientEntity to accept existing patient data for updates
- Add handleActionEdit handler for edit mode
- Update form to handle both create and edit modes
- Rename patient ref to patientDetail for clarity

refactor(patient): update marital status codes and job options mapping

- Change marital status enum values to standardized codes (S, M, D, W)
- Simplify job options and marital status options mapping using mapToComboboxOptList
- Add error handling in patient data loading

ajust styling text based on combobox

wip: edit patient redirect

refactor(models): update type definitions and form field handling

- Add field-name prop to SelectDob component for better form handling
- Update Person and Patient interfaces to use null for optional fields
- Add maritalStatus_code field to Person interface
- Improve type safety by replacing undefined with null for optional fields

fix casting radio str to boolean and parsing date error
This commit is contained in:
Khafid Prayoga
2025-12-08 20:43:30 +07:00
parent e967ee1cf0
commit 910b641750
13 changed files with 175 additions and 194 deletions
+23 -21
View File
@@ -1,12 +1,12 @@
import { type Base, genBase } from './_base'
import { type Person, genPerson } from './person'
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 { genPerson, type Person } from './person'
import type { PersonAddress } from './person-address'
import type { PersonContact } from './person-contact'
import type { PersonRelative } from './person-relative'
@@ -14,11 +14,11 @@ import type { PersonRelative } from './person-relative'
import { contactTypeMapping } from '~/lib/constants'
export interface PatientBase extends Base {
person_id?: number
person_id?: number | null
newBornStatus?: boolean
registeredAt?: Date | string | null
status_code?: string
number?: string
status_code?: string | null
number?: string | null
}
export interface PatientEntity extends PatientBase {
@@ -37,10 +37,10 @@ export interface genPatientProps {
responsible: PersonRelativeFormData
}
export function genPatientEntity(props: genPatientProps): PatientEntity {
export function genPatientEntity(props: genPatientProps, patientData: PatientEntity | null): PatientEntity {
const { patient, residentAddress, cardAddress, familyData, contacts, responsible } = props
const addresses: PersonAddress[] = [{ ...genBase(), person_id: 0, ...residentAddress }]
const addresses: PersonAddress[] = [{ ...genBase(), person_id: patientData?.person?.id || 0, ...residentAddress }]
const familiesContact: PersonRelative[] = []
const personContacts: PersonContact[] = []
@@ -50,14 +50,14 @@ export function genPatientEntity(props: genPatientProps): PatientEntity {
...genBase(),
...residentAddress,
person_id: 0,
locationType_code: cardAddress.locationType_code || 'identity'
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,
person_id: patientData?.person?.id || 0,
locationType_code: cardAddress.locationType_code || 'identity',
address: cardAddress.address || '',
province_code: cardAddress.province_code || '',
@@ -94,7 +94,7 @@ export function genPatientEntity(props: genPatientProps): PatientEntity {
personContacts.push({
...genBase(),
person_id: 0,
person_id: patientData?.person?.id || 0,
type_code: mappedContactType || '',
value: contact.contactNumber,
})
@@ -117,15 +117,15 @@ export function genPatientEntity(props: genPatientProps): PatientEntity {
return {
person: {
id: 0,
id: patientData?.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,
residentIdentityNumber: patient.identityNumber || null,
passportNumber: patient.passportNumber || null,
drivingLicenseNumber: patient.drivingLicenseNumber || null,
religion_code: patient.religion,
education_code: patient.education,
occupation_code: patient.job,
@@ -139,6 +139,8 @@ export function genPatientEntity(props: genPatientProps): PatientEntity {
// passportFileUrl: patient.passportFileUrl,
// drivingLicenseFileUrl: patient.drivingLicenseFileUrl,
// familyIdentityFileUrl: patient.familyIdentityFileUrl,
maritalStatus_code: patient.maritalStatus,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
deletedAt: null,
@@ -149,9 +151,9 @@ export function genPatientEntity(props: genPatientProps): PatientEntity {
registeredAt: new Date(),
status_code: 'active',
newBornStatus: patient.isNewBorn,
person_id: 0,
id: 0,
number: '',
person_id: patientData?.person?.id || null,
id: patientData?.id || 0,
number: patientData?.number || null,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
deletedAt: null,
@@ -160,12 +162,12 @@ export function genPatientEntity(props: genPatientProps): PatientEntity {
// New model
export interface Patient extends Base {
person_id?: number
person_id?: number | null
person: Person
newBornStatus?: boolean
registeredAt?: Date | string | null
status_code?: string
number?: string
status_code?: string | null
number?: string | null
}
export function genPatient(): Patient {
@@ -178,4 +180,4 @@ export function genPatient(): Patient {
newBornStatus: false,
person: genPerson(),
}
}
}
+20 -19
View File
@@ -9,27 +9,28 @@ import type { Regency } from './regency'
export interface Person extends Base {
name: string
// alias?: string
frontTitle?: string
endTitle?: string
frontTitle?: string | null
endTitle?: string | null
birthDate?: string
birthRegency_code?: string
gender_code?: string
residentIdentityNumber?: string
passportNumber?: string
drivingLicenseNumber?: string
religion_code?: string
education_code?: string
occupation_code?: string
occupation_name?: string
ethnic_code?: string
language_code?: string
nationality?: string
birthRegency_code?: string | null
gender_code?: string | null
residentIdentityNumber?: string | null
passportNumber?: string | null
drivingLicenseNumber?: string | null
religion_code?: string | null
education_code?: string | null
occupation_code?: string | null
occupation_name?: string | null
ethnic_code?: string | null
language_code?: string | null
nationality?: string | null
communicationIssueStatus?: boolean
disability?: string
residentIdentityFileUrl?: string
passportFileUrl?: string
drivingLicenseFileUrl?: string
familyIdentityFileUrl?: string
disability?: string | null
residentIdentityFileUrl?: string | null
passportFileUrl?: string | null
drivingLicenseFileUrl?: string | null
familyIdentityFileUrl?: string | null
maritalStatus_code?: string
// preload data for detail patient
birthRegency?: Regency | null