-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) O3-3243: Ward App - add configurable extension to include pati…
…ent identifier (#1197) * configure patient identifier * correct config syntax * fix test --------- Co-authored-by: chibongho <[email protected]>
- Loading branch information
Showing
5 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/esm-ward-app/src/ward-patient-card/row-elements/ward-patient-identifier.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import { type WardPatientCardElement } from '../../types'; | ||
import { type PatientCardElementConfig } from '../../config-schema'; | ||
import { Tag } from '@carbon/react'; | ||
import { translateFrom, type PatientIdentifier } from '@openmrs/esm-framework'; | ||
import { moduleName } from '../../constant'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
//sort the identifiers by preferred first.The identifier with value of true | ||
//takes precedence over false. if both identifiers have same preferred value | ||
//sort them by (dateChanged or dateCreated) in descending order | ||
const identifierCompareFunction = (pi1: PatientIdentifier, pi2: PatientIdentifier) => { | ||
let comp = (pi2.preferred ? 1 : 0) - (pi1.preferred ? 1 : 0); | ||
|
||
if (comp == 0) { | ||
const date1 = pi1.auditInfo.dateChanged ?? pi1.auditInfo.dateCreated; | ||
const date2 = pi2.auditInfo.dateChanged ?? pi2.auditInfo.dateCreated; | ||
comp = date2.localeCompare(date1); | ||
} | ||
return comp; | ||
}; | ||
|
||
const wardPatientIdentifier = (config: PatientCardElementConfig) => { | ||
const WardPatientIdentifier: WardPatientCardElement = ({ patient }) => { | ||
const { t } = useTranslation(); | ||
const { identifier } = config; | ||
const { identifierTypeUuid, labelI18nModule: labelModule, label } = identifier; | ||
const patientIdentifiers = patient.identifiers.filter( | ||
(patientIdentifier: PatientIdentifier) => | ||
identifierTypeUuid == null || patientIdentifier.identifierType?.uuid === identifierTypeUuid, | ||
); | ||
patientIdentifiers.sort(identifierCompareFunction); | ||
const patientIdentifier = patientIdentifiers[0]; | ||
const labelToDisplay = | ||
label != null ? translateFrom(labelModule ?? moduleName, label) : patientIdentifier?.identifierType?.name; | ||
return ( | ||
<div> | ||
{labelToDisplay ? <Tag>{t('identifierTypelabel', '{{label}}:', { label: labelToDisplay })}</Tag> : <></>} | ||
<span>{patientIdentifier?.identifier}</span> | ||
</div> | ||
); | ||
}; | ||
return WardPatientIdentifier; | ||
}; | ||
|
||
export default wardPatientIdentifier; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters