fix edit form state
fix: id list for contacts and address list fix warning fix duplicate contacts responsible: true fix edit family fix nik required
This commit is contained in:
@@ -30,7 +30,7 @@ import {
|
||||
} from './fields'
|
||||
|
||||
interface FormData extends PatientFormData {
|
||||
_calculatedAge: string
|
||||
_calculatedAge: string | Date
|
||||
}
|
||||
|
||||
// Type untuk initial values (sebelum transform schema)
|
||||
@@ -66,7 +66,7 @@ interface Props {
|
||||
const props = defineProps<Props>()
|
||||
const formSchema = toTypedSchema(PatientSchema)
|
||||
|
||||
const { values, resetForm, setValues, setFieldValue, validate } = useForm<FormData>({
|
||||
const { values, resetForm, setValues, setFieldValue, validate, setFieldError } = useForm<FormData>({
|
||||
name: 'patientForm',
|
||||
validationSchema: formSchema,
|
||||
initialValues: (props.initialValues ?? {}) as any,
|
||||
@@ -106,6 +106,7 @@ watch(
|
||||
placeholder="Masukkan NIK"
|
||||
numeric-only
|
||||
:is-disabled="isReadonly"
|
||||
:max-length="16"
|
||||
/>
|
||||
<InputBase
|
||||
field-name="drivingLicenseNumber"
|
||||
|
||||
@@ -114,7 +114,9 @@ const patientFormInitialValues = computed(() => {
|
||||
|
||||
// Computed: unwrap alamat domisili (alamat sekarang)
|
||||
const addressFormInitialValues = computed(() => {
|
||||
const addresses = patientDetail.value.person?.addresses || patientDetail.value.personAddresses || []
|
||||
if (!patientDetail.value.person?.addresses) return {}
|
||||
|
||||
const addresses = patientDetail.value.person?.addresses
|
||||
const domicileAddress = addresses.find((a: PersonAddress) => a.locationType_code === 'domicile')
|
||||
if (!domicileAddress) return undefined
|
||||
|
||||
@@ -125,6 +127,7 @@ const addressFormInitialValues = computed(() => {
|
||||
const province = regency?.province
|
||||
|
||||
return {
|
||||
id: domicileAddress.id || 0,
|
||||
locationType_code: 'domicile',
|
||||
province_code: province?.code || '',
|
||||
regency_code: regency?.code || '',
|
||||
@@ -139,30 +142,11 @@ const addressFormInitialValues = computed(() => {
|
||||
|
||||
// Computed: unwrap alamat KTP (identity)
|
||||
const addressRelativeFormInitialValues = computed(() => {
|
||||
const addresses = patientDetail.value.person?.addresses || patientDetail.value.personAddresses || []
|
||||
const domicileAddress = addresses.find((a: PersonAddress) => a.locationType_code === 'domicile')
|
||||
const identityAddress = addresses.find((a: PersonAddress) => a.locationType_code === 'identity')
|
||||
if (!patientDetail.value.person?.addresses) return {}
|
||||
|
||||
// Jika tidak ada alamat KTP terpisah, berarti sama dengan domisili
|
||||
if (!identityAddress) {
|
||||
return {
|
||||
isSameAddress: '1',
|
||||
locationType_code: 'identity',
|
||||
}
|
||||
}
|
||||
|
||||
// Cek apakah alamat sama dengan domisili
|
||||
const isSame =
|
||||
domicileAddress &&
|
||||
identityAddress.village_code === domicileAddress.village_code &&
|
||||
identityAddress.address === domicileAddress.address
|
||||
|
||||
if (isSame) {
|
||||
return {
|
||||
isSameAddress: '1',
|
||||
locationType_code: 'identity',
|
||||
}
|
||||
}
|
||||
const addresses = patientDetail.value.person?.addresses
|
||||
const domicileAddress = addresses.find((a: PersonAddress) => a.locationType_code === 'domicile')!
|
||||
const identityAddress = addresses.find((a: PersonAddress) => a.locationType_code === 'identity')!
|
||||
|
||||
// extract kode wilayah dari preload data
|
||||
const village = identityAddress.postalRegion?.village
|
||||
@@ -170,8 +154,11 @@ const addressRelativeFormInitialValues = computed(() => {
|
||||
const regency = district?.regency
|
||||
const province = regency?.province
|
||||
|
||||
const isSame = domicileAddress.village_code === identityAddress.village_code ? '1' : '0'
|
||||
|
||||
return {
|
||||
isSameAddress: '0',
|
||||
isSameAddress: isSame,
|
||||
id: identityAddress.id || 0,
|
||||
locationType_code: 'identity',
|
||||
province_code: province?.code || '',
|
||||
regency_code: regency?.code || '',
|
||||
@@ -201,6 +188,7 @@ const familyFormInitialValues = computed(() => {
|
||||
return {
|
||||
shareFamilyData: '1',
|
||||
families: parents.map((parent: PersonRelative) => ({
|
||||
id: parent.id || 0,
|
||||
relation: parent.relationship_code || '',
|
||||
name: parent.name || '',
|
||||
education: parent.education_code || '',
|
||||
@@ -216,6 +204,7 @@ const contactFormInitialValues = computed(() => {
|
||||
|
||||
return {
|
||||
contacts: contacts.map((contact: PersonContact) => ({
|
||||
id: contact.id || 0,
|
||||
contactType: reverseContactTypeMapping[contact.type_code] || contact.type_code || '',
|
||||
contactNumber: contact.value || '',
|
||||
})),
|
||||
@@ -231,6 +220,7 @@ const responsibleFormInitialValues = computed(() => {
|
||||
|
||||
return {
|
||||
contacts: responsibles.map((r: PersonRelative) => ({
|
||||
id: r.id || 0,
|
||||
relation: r.relationship_code || '',
|
||||
name: r.name || '',
|
||||
address: r.address || '',
|
||||
@@ -272,6 +262,7 @@ async function composeFormData(): Promise<PatientEntity> {
|
||||
...patient?.values,
|
||||
|
||||
// casting comp. val to backend well known reflect value
|
||||
ethnic: patient?.values.nationality === 'WNI' ? patient?.values.ethnic : null,
|
||||
birthDate: parseISO(patient?.values.birthDate || ''),
|
||||
isNewBorn: patient?.values.isNewBorn === 'yes',
|
||||
communicationBarrier: patient?.values.communicationBarrier === 'yes',
|
||||
@@ -327,8 +318,7 @@ async function handleActionClick(eventType: string) {
|
||||
|
||||
let createdPatientId = 0
|
||||
let response: any
|
||||
|
||||
// If edit mode, update patient
|
||||
// return
|
||||
if (props.mode === 'edit' && props.patientId) {
|
||||
response = await handleActionEdit(
|
||||
patientDetail.value.id,
|
||||
@@ -337,9 +327,7 @@ async function handleActionClick(eventType: string) {
|
||||
() => {},
|
||||
toast,
|
||||
)
|
||||
}
|
||||
// If create mode, create patient
|
||||
else {
|
||||
} else {
|
||||
response = await handleActionSave(
|
||||
patient,
|
||||
() => {},
|
||||
|
||||
Reference in New Issue
Block a user