Skip to content

Commit

Permalink
(fix) O3-2120: Move OpenMRS ID patient search identifier to `defaul…
Browse files Browse the repository at this point in the history
…tIdentifierTypes` (#1061)

* refactor: move OpenMRS ID identifier to defaultIdentifierTypes in the config-schema

* refactor: proper description to defaultIndentifierTypes

* feat: use preferred identifier as fallback

* fix: fix tests

* fix: remove unrelated comment

---------

Co-authored-by: Brandon Istenes <[email protected]>
  • Loading branch information
usamaidrsk and brandones authored Jul 1, 2024
1 parent 96e8ff7 commit 02ad417
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Tag } from '@carbon/react';
import {
age,
ConfigurableLink,
ExtensionSlot,
PatientPhoto,
age,
getPatientName,
interpolateString,
PatientPhoto,
useConfig,
} from '@openmrs/esm-framework';
import classNames from 'classnames';
Expand Down Expand Up @@ -98,9 +98,17 @@ const CompactPatientBanner = forwardRef<HTMLDivElement, CompactPatientBannerProp
return (
<div ref={ref}>
{fhirPatients.map((patient, index) => {
const patientIdentifiers = patients[index].identifiers.filter((identifier) =>
config.defaultIdentifierTypes.includes(identifier.identifierType.uuid),
const preferredIdentifier = patients[index].identifiers.find((identifier) => identifier.preferred);

const configuredIdentifiers = patients[index].identifiers.filter(
(identifier) =>
!identifier.preferred && config.defaultIdentifierTypes.includes(identifier.identifierType.uuid),
);

const patientIdentifiers = preferredIdentifier
? [preferredIdentifier, ...configuredIdentifiers]
: configuredIdentifiers;

const patientName = getPatientName(patient);

return (
Expand All @@ -120,19 +128,9 @@ const CompactPatientBanner = forwardRef<HTMLDivElement, CompactPatientBannerProp
<div className={styles.demographics}>
{getGender(patient.gender)} <span className={styles.middot}>&middot;</span> {age(patient.birthDate)}
<span className={styles.middot}>&middot;</span>
{config.defaultIdentifierTypes.length ? (
<>
{patientIdentifiers.length > 1 ? (
<DefaultIdentifiers identifiers={patientIdentifiers} />
) : (
<FallbackIdentifier patient={patients[index]} identifierName={config.defaultIdentifier} />
)}
</>
) : (
<>
<span className={styles.middot}>&middot;</span> {patients[index].identifiers?.[0]?.identifier}
</>
)}
{patientIdentifiers.map((identifier) => (
<IdentifierTag identifier={identifier} />
))}
</div>
</div>
</ClickablePatientContainer>
Expand Down Expand Up @@ -189,20 +187,4 @@ const IdentifierTag: React.FC<IdentifierTagProps> = ({ identifier }) => {
);
};

const DefaultIdentifiers: React.FC<IdentifiersProps> = ({ identifiers }) => {
return (
<>
{identifiers.map((identifier) => (
<IdentifierTag identifier={identifier} />
))}
</>
);
};

const FallbackIdentifier: React.FC<CustomIdentifierProps> = ({ patient, identifierName }) => {
const identifier = patient.identifiers.find((identifier) => identifier.identifierType.display === identifierName);

return identifier ? <IdentifierTag identifier={identifier} /> : null;
};

export default CompactPatientBanner;
15 changes: 6 additions & 9 deletions packages/esm-patient-search-app/src/config-schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Type, validators } from '@openmrs/esm-framework';

export const configSchema = {
search: {
patientResultUrl: {
Expand Down Expand Up @@ -41,15 +42,11 @@ export const configSchema = {
_elements: {
_type: Type.UUID,
},
_description:
'A list of identifier types to be displayed in the patient search results as banner tags. If no defaultIdentifierTypes are provided, the defaultIdentifier will be displayed.',
// This UUID is for the OpenMRS ID
_default: ['05a29f94-c0ed-11e2-94be-8c13b969e334'],
},
defaultIdentifier: {
_type: Type.String,
_description: 'Identifer type to be displayed when no defaultIdentifierTypes are provided. Default is OpenMRS ID.',
_default: 'OpenMRS ID',
_description: 'A list of identifier types to be displayed in the patient search results as banner tags.',
_default: [
// This UUID is for the OpenMRS ID identifier
'05a29f94-c0ed-11e2-94be-8c13b969e334',
],
},
};

Expand Down
4 changes: 4 additions & 0 deletions packages/esm-patient-search-app/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export interface Identifier {
identifierType: OpenmrsResource;
location: OpenmrsResource;
uuid: string;
preferred: boolean;
}

export interface Address {
preferred: boolean;
voided: boolean;
Expand All @@ -36,6 +38,7 @@ export interface Address {
postalCode: string;
stateProvince: string;
}

export interface FHIRPatientType {
id: string;
identifier: Array<FHIRIdentifier>;
Expand Down Expand Up @@ -77,6 +80,7 @@ export interface FHIRPatientSearchResponse {
resource: FHIRPatientType;
}>;
}

export interface PatientSearchResponse {
data?: Array<SearchedPatient>;
isLoading: boolean;
Expand Down

0 comments on commit 02ad417

Please sign in to comment.