-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) O3-3737: Add configurable details about pending orders on the …
…patient card (#1296) * feat: configure pending orders * chore: translations * rename pending-orders to pending-items slot name
- Loading branch information
1 parent
4bff4b7
commit ba179e4
Showing
10 changed files
with
149 additions
and
4 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
packages/esm-ward-app/src/config-schema-pending-orders-extension.ts
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,25 @@ | ||
import { Type } from '@openmrs/esm-framework'; | ||
|
||
export const pendingOrdersExtensionConfigSchema = { | ||
orderTypes: { | ||
_type: Type.Array, | ||
_description: 'Defines order types displayed on the ward patient card pending items section.', | ||
_default: [{ label: 'Labs', uuid: '52a447d3-a64a-11e3-9aeb-50e549534c5e' }], | ||
_elements: { | ||
uuid: { | ||
_type: Type.UUID, | ||
_description: 'Identifies the order type.', | ||
}, | ||
label: { | ||
_type: Type.String, | ||
_description: "The label or i18n key to the translated label to display. If not provided, defaults to 'Orders'", | ||
_default: null, | ||
}, | ||
}, | ||
}, | ||
enabled: { | ||
_type: Type.Boolean, | ||
_description: 'Optional. Enable pending order visibility on ward card pending items', | ||
_default: true, | ||
}, | ||
}; |
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
16 changes: 16 additions & 0 deletions
16
packages/esm-ward-app/src/hooks/usePatientPendingOrders.ts
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,16 @@ | ||
import { type FetchResponse, openmrsFetch, type OpenmrsResource, restBaseUrl } from '@openmrs/esm-framework'; | ||
import useSWR from 'swr'; | ||
|
||
export function usePatientPendingOrders(patientUuid: string, orderTypeUUid: string, visitStartDate: string) { | ||
const apiUrl = | ||
patientUuid && orderTypeUUid && visitStartDate | ||
? `${restBaseUrl}/order?includeNullFulfillerStatus=true&patient=${patientUuid}&orderTypes=${orderTypeUUid}&activatedOnOrAfterDate=${visitStartDate}` | ||
: null; | ||
const { data, ...rest } = useSWR<FetchResponse<{ results: Array<OpenmrsResource> }>, Error>(apiUrl, openmrsFetch); | ||
|
||
return { | ||
orders: data?.data.results, | ||
count: data?.data.results.length, | ||
...rest, | ||
}; | ||
} |
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
28 changes: 28 additions & 0 deletions
28
packages/esm-ward-app/src/ward-patient-card/card-rows/pending-orders.extension.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,28 @@ | ||
import React from 'react'; | ||
import { type WardPatientCard } from '../../types'; | ||
import { useConfig } from '@openmrs/esm-framework'; | ||
import type { PendingOrderTypesDefinition } from '../../config-schema'; | ||
import { WardPatientPendingOrder } from '../row-elements/ward-patient-pending-order.component'; | ||
|
||
const PendingOrdersExtension: WardPatientCard = (wardPatient) => { | ||
const { orderTypes, enabled } = useConfig<PendingOrderTypesDefinition>(); | ||
|
||
if (!enabled || !orderTypes) { | ||
return <></>; | ||
} | ||
|
||
return ( | ||
<> | ||
{orderTypes.map(({ uuid, label }) => ( | ||
<WardPatientPendingOrder | ||
key={`pending-order-type-${uuid}`} | ||
wardPatient={wardPatient} | ||
orderUuid={uuid} | ||
label={label} | ||
/> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
export default PendingOrdersExtension; |
33 changes: 33 additions & 0 deletions
33
.../esm-ward-app/src/ward-patient-card/row-elements/ward-patient-pending-order.component.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,33 @@ | ||
import React from 'react'; | ||
import { ChemistryReference } from '@carbon/react/icons'; | ||
import styles from '../ward-patient-card.scss'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { type WardPatient } from '../../types'; | ||
import { usePatientPendingOrders } from '../../hooks/usePatientPendingOrders'; | ||
|
||
export interface WardPatientPendingOrderProps { | ||
wardPatient: WardPatient; | ||
orderUuid: string; | ||
label: string; | ||
} | ||
|
||
export const WardPatientPendingOrder: React.FC<WardPatientPendingOrderProps> = ({ wardPatient, orderUuid, label }) => { | ||
const { t } = useTranslation(); | ||
const { count, isLoading } = usePatientPendingOrders( | ||
wardPatient?.patient?.uuid, | ||
orderUuid, | ||
wardPatient?.visit?.startDatetime.split('T')[0], | ||
); | ||
|
||
if (isLoading || !count || count == 0) { | ||
return null; | ||
} | ||
|
||
const labelToDisplay = label ? t(label) : t('Orders', 'Orders'); | ||
return ( | ||
<div className={styles.wardPatientCardDispositionTypeContainer}> | ||
<ChemistryReference className={styles.chemistryReferenceIcon} size="24" /> | ||
{count} {labelToDisplay} | ||
</div> | ||
); | ||
}; |
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