Skip to content

Commit

Permalink
(fix) remove undefined entries on attributes and identifiers (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldkibet authored Aug 26, 2024
1 parent 3d60df1 commit 31f605a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { add, capitalize } from 'lodash-es';
import { type PatientIdentifierValue, type FormValues } from '../../patient-registration/patient-registration.types';
import { APIClientConfig, type MapperConfig, type HIEPatient, type ErrorResponse } from './hie-types';
import { type MapperConfig, type HIEPatient, type ErrorResponse } from './hie-types';
import { getConfig } from '@openmrs/esm-framework';
import { type RegistrationConfig } from '../../config-schema';
import { v4 } from 'uuid';
/**
* Represents a client for interacting with a Health Information Exchange (HIE) resource.
* @template T - The type of the resource being fetched.
Expand Down Expand Up @@ -59,13 +60,18 @@ class PatientMapper extends Mapper<HIEPatient, FormValues> {
address: extensionAddressEntries,
identifiers: updatedIdentifiers,
attributes: telecomAttributes,
relationships: [],
patientUuid: v4(),
} as FormValues;
}

private mapTelecomToAttributes(telecom: Array<fhir.ContactPoint>): Record<string, string> {
return telecom.reduce<Record<string, string>>((acc, { system, value }) => {
if (system && value && this.config.teleComMap[system]) {
acc[this.config.teleComMap[system]] = value.replace(/^254/, '0');
const filteredValue = value.replace(/^254/, '0');
if (filteredValue) {
acc[this.config.teleComMap[system]] = filteredValue;
}
}
return acc;
}, {});
Expand Down Expand Up @@ -95,17 +101,27 @@ class PatientMapper extends Mapper<HIEPatient, FormValues> {
}
});

// Filter out undefined keys and values
Object.keys(updatedIdentifiers).forEach((key) => {
if (updatedIdentifiers[key] === undefined || updatedIdentifiers[key].identifierValue === undefined) {
delete updatedIdentifiers[key];
}
});

return updatedIdentifiers;
}

private mapExtensionsToAddress(extensions: HIEPatient['extension']): Record<string, string> {
return extensions
.map((ext) => {
const identifierType = ext.url.split('/').pop();
const identifierValue = ext.valueString;
return { [this.config.addressHierarchyMap[identifierType]]: capitalize(identifierValue) };
})
.reduce<Record<string, string>>((acc, curr) => ({ ...acc, ...curr }), {});
return extensions.reduce<Record<string, string>>((acc, ext) => {
const identifierType = ext.url.split('/').pop();
const mappedKey = this.config.addressHierarchyMap[identifierType];

if (mappedKey && ext.valueString) {
acc[mappedKey] = capitalize(ext.valueString);
}

return acc;
}, {});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const HIEConfirmationModal: React.FC<HIEConfirmationModalProps> = ({ closeModal,
label={t('maritalStatus', 'Marital status')}
value={patient.maritalStatus.coding.map((m) => m.code).join('')}
/>
<PatientInfo label={t('relationships', 'Relationships')} value="--" />
<PatientInfo label={t('dependents', 'Dependents')} value="--" />
</div>
</div>
<div>
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-patient-registration-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"deleteIdentifierTooltip": "Delete",
"deleteRelationshipTooltipText": "Delete",
"demographicsSection": "Basic Info",
"dependants": "Dependants",
"discard": "Discard",
"discardModalBody": "The changes you made to this patient's details have not been saved. Discard changes?",
"discardModalHeader": "Confirm Discard Changes",
Expand Down Expand Up @@ -95,7 +96,6 @@
"relationshipPersonMustExist": "Related person must be an existing person",
"relationshipPlaceholder": "Relationship",
"relationshipRemovedText": "Relationship removed",
"relationships": "Relationships",
"relationshipsSection": "Relationships",
"relationshipToPatient": "Relationship to patient",
"relativeFullNameLabelText": "Related person",
Expand Down

0 comments on commit 31f605a

Please sign in to comment.