From 7310d405d9225d2ac4007e5abc59d810fc0e5122 Mon Sep 17 00:00:00 2001 From: its-kios09 Date: Tue, 26 Nov 2024 12:50:10 +0300 Subject: [PATCH 1/2] (fix) fixed a bug on the error handling of the confirm modal --- .../hie-client-registry.component.tsx | 42 +++++++++++++++---- .../hie-client-registry/hie-resource.ts | 6 +-- .../hie-client-registry/hie-types.ts | 2 + .../hie-patient-detail-preview.component.tsx | 2 +- 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/hie-client-registry.component.tsx b/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/hie-client-registry.component.tsx index 22cfa8767..1062b4f42 100644 --- a/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/hie-client-registry.component.tsx +++ b/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/hie-client-registry.component.tsx @@ -11,7 +11,7 @@ import { type RegistrationConfig } from '../../config-schema'; import { useForm, Controller, type SubmitHandler } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { fetchPatientFromHIE, mapHIEPatientToFormValues } from './hie-resource'; -import { type HIEPatientResponse, type HIEPatient } from './hie-types'; +import { type HIEPatientResponse, type HIEPatient, type ErrorResponse } from './hie-types'; type HIEClientRegistryProps = { props: FormikProps; @@ -39,11 +39,34 @@ const HIEClientRegistry: React.FC = ({ setInitialFormVal hieClientRegistry: { identifierTypes }, } = useConfig(); + const isHIEPatientResponse = ( + response: HIEPatientResponse | ErrorResponse | undefined, + ): response is HIEPatientResponse => { + return response?.resourceType === 'Bundle' && 'total' in response; + }; + + const isOperationOutcome = (response: HIEPatientResponse | ErrorResponse | undefined): response is ErrorResponse => { + return response?.resourceType === 'OperationOutcome' && 'issue' in response; + }; + const onSubmit: SubmitHandler = async (data: HIEFormValues, event: React.BaseSyntheticEvent) => { try { const hieClientRegistry = await fetchPatientFromHIE(data.identifierType, data.identifierValue); - if (hieClientRegistry && hieClientRegistry.resourceType === 'Bundle') { + if (isHIEPatientResponse(hieClientRegistry)) { + if (hieClientRegistry.total === 0) { + const dispose = showModal('empty-client-registry-modal', { + onConfirm: () => dispose(), + close: () => dispose(), + title: t('clientRegistryEmpty', 'Create & Post Patient'), + message: t( + 'patientNotFound', + `No patient found with the provided ${data?.identifierType}. Proceed to register.`, + ), + }); + return; + } + const dispose = showModal('hie-confirmation-modal', { patient: hieClientRegistry, closeModal: () => dispose(), @@ -52,15 +75,20 @@ const HIEClientRegistry: React.FC = ({ setInitialFormVal mapHIEPatientToFormValues(hieClientRegistry as unknown as HIEPatientResponse, props.values), ), }); - } - - if (hieClientRegistry && hieClientRegistry?.resourceType === 'OperationOutcome') { - const issueMessage = hieClientRegistry?.['issue']?.map((issue) => issue.diagnostics).join(', '); + } else if (isOperationOutcome(hieClientRegistry)) { + const issueMessage = hieClientRegistry?.issue?.map((issue) => issue.diagnostics).join(', '); const dispose = showModal('empty-client-registry-modal', { onConfirm: () => dispose(), close: () => dispose(), title: t('clientRegistryEmpty', 'Create & Post Patient'), - message: issueMessage, + message: issueMessage || t('errorOccurred', ' There was an error processing the request. Try again later'), + }); + } else { + showSnackbar({ + title: t('unexpectedResponse', 'Unexpected Response'), + subtitle: t('contactAdmin', 'Please contact the administrator.'), + kind: 'error', + isLowContrast: true, }); } } catch (error) { diff --git a/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/hie-resource.ts b/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/hie-resource.ts index c1f263a4f..4f1cbbe10 100644 --- a/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/hie-resource.ts +++ b/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/hie-resource.ts @@ -147,15 +147,15 @@ const mapperConfig: MapperConfig = { }; // Create instances -const hieApiClient = new HealthInformationExchangeClient(); +const hieApiClient = new HealthInformationExchangeClient(); const patientMapper = new PatientMapper(mapperConfig); // Exported functions export const fetchPatientFromHIE = async ( identifierType: string, identifierValue: string, -): Promise => { - return hieApiClient.fetchResource('Patient', { [identifierType]: identifierValue }); +): Promise => { + return hieApiClient.fetchResource('Bundle', { [identifierType]: identifierValue }); }; export const mapHIEPatientToFormValues = ( diff --git a/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/hie-types.ts b/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/hie-types.ts index b9e903851..e4a4ced29 100644 --- a/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/hie-types.ts +++ b/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/hie-types.ts @@ -6,7 +6,9 @@ export type HIEPatient = fhir.Patient & { }; export interface HIEPatientResponse { + resourceType: string; id: string; + total: number; meta: Metadata; link: Link[]; entry: Entry[]; diff --git a/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/modal/hie-patient-detail-preview.component.tsx b/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/modal/hie-patient-detail-preview.component.tsx index 65f154944..fd02f26b3 100644 --- a/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/modal/hie-patient-detail-preview.component.tsx +++ b/packages/esm-patient-registration-app/src/client-registry/hie-client-registry/modal/hie-patient-detail-preview.component.tsx @@ -30,7 +30,7 @@ const HIEPatientDetailPreview: React.FC = ({ patie state={{ patientName: `${maskData(givenName)} . ${maskData(middleName)} . ${maskData(familyName)}` }} />
- + Date: Tue, 26 Nov 2024 12:50:41 +0300 Subject: [PATCH 2/2] (fix) fixed a bug on the error handling of the confirm modal --- packages/esm-patient-registration-app/translations/en.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/esm-patient-registration-app/translations/en.json b/packages/esm-patient-registration-app/translations/en.json index da51c50a8..bf123f389 100644 --- a/packages/esm-patient-registration-app/translations/en.json +++ b/packages/esm-patient-registration-app/translations/en.json @@ -24,6 +24,7 @@ "confirmDiscardChangesBody": "Your unsaved changes will be lost if you proceed to discard the form", "confirmDiscardChangesTitle": "Are you sure you want to discard these changes?", "confirmIdentifierDeletionText": "Are you sure you want to remove this identifier?", + "contactAdmin": "Please contact the administrator.", "contactSection": "Contact Details", "continue": "Continue", "createNewPatient": "Create new patient", @@ -59,6 +60,7 @@ "errorFetchingCodedCausesOfDeath": "Error fetching coded causes of death", "errorFetchingOrderedFields": "Error occured fetching ordered fields for address hierarchy", "errorFetchingPatient": "Error fetching patient", + "errorOccurred": " There was an error processing the request. Try again later", "estimatedAgeInMonthsLabelText": "Estimated age in months", "estimatedAgeInYearsLabelText": "Estimated age in years", "familyNameLabelText": "Family Name", @@ -145,6 +147,7 @@ "timeFormat": "Time Format", "timeOfDeathInputLabel": "Time of death (hh:mm)", "unableToFetch": "Unable to fetch person attribute type - {{personattributetype}}", + "unexpectedResponse": "Unexpected Response", "unknown": "Unknown", "unknownPatientAttributeType": "Patient attribute type has unknown format {{personAttributeTypeFormat}}", "unknownRelationship": "Unknown",