From 03d3de2d9eb6aed11a2838d065aea046a0df8c6a Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Thu, 26 Sep 2024 18:51:13 +0300 Subject: [PATCH 01/30] fix/03-2825: Medications that have been discontinued should have a Discontinued label --- .../src/orders/types.ts | 1 + .../active-medications.test.tsx | 2 +- .../src/api/api.ts | 4 ++-- .../medications-details-table.component.tsx | 19 +++++++++++-------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/esm-patient-common-lib/src/orders/types.ts b/packages/esm-patient-common-lib/src/orders/types.ts index 81478cd16..78caa2b36 100644 --- a/packages/esm-patient-common-lib/src/orders/types.ts +++ b/packages/esm-patient-common-lib/src/orders/types.ts @@ -85,6 +85,7 @@ export interface Order { asNeeded: boolean; asNeededCondition?: string; autoExpireDate: string; + autoStopDate: string; brandName?: string; careSetting: OpenmrsResource; commentToFulfiller: string; diff --git a/packages/esm-patient-medications-app/src/active-medications/active-medications.test.tsx b/packages/esm-patient-medications-app/src/active-medications/active-medications.test.tsx index dba13504d..6b775caa9 100644 --- a/packages/esm-patient-medications-app/src/active-medications/active-medications.test.tsx +++ b/packages/esm-patient-medications-app/src/active-medications/active-medications.test.tsx @@ -90,7 +90,7 @@ describe('ActiveMedications', () => { const expectedTableRows = [ /14-Aug-2023 Admin User Acetaminophen 325 mg — 325mg — tablet DOSE 2 tablet — oral — twice daily — indefinite duration — take it sometimes INDICATION Bad boo-boo/, - /14-Aug-2023 Admin User Acetaminophen 325 mg — 325mg — tablet DOSE 2 tablet — oral — twice daily — indefinite duration INDICATION No good — DISCONTINUED DATE 14-Aug-2023/, + /14-Aug-2023 Admin User Acetaminophen 325 mg — 325mg — tablet DOSE 2 tablet — oral — twice daily — indefinite duration INDICATION No good — DISCONTINUED DATE 14-Aug-2023 — DISCONTINUED/, /14-Aug-2023 Admin User Sulfacetamide 0.1 — 10% DOSE 1 application — for {{duration}} weeks — REFILLS 1 — apply it INDICATION Pain — QUANTITY 8 Application/, /14-Aug-2023 Admin User Aspirin 162.5mg — 162.5mg — tablet DOSE 1 tablet — oral — once daily — for {{duration}} days INDICATION Heart — QUANTITY 30 Tablet/, ]; diff --git a/packages/esm-patient-medications-app/src/api/api.ts b/packages/esm-patient-medications-app/src/api/api.ts index 158afd7e0..4d9e03742 100644 --- a/packages/esm-patient-medications-app/src/api/api.ts +++ b/packages/esm-patient-medications-app/src/api/api.ts @@ -14,7 +14,7 @@ export const careSettingUuid = '6f0c9a92-6f24-11e3-af88-005056821db0'; * @param patientUuid The UUID of the patient whose orders should be fetched. * @param status Allows fetching either all orders or only active orders. */ -export function usePatientOrders(patientUuid: string, status: 'ACTIVE' | 'any') { +export function usePatientOrders(patientUuid: string) { const { drugOrderTypeUUID } = useConfig() as ConfigObject; const customRepresentation = 'custom:(uuid,dosingType,orderNumber,accessionNumber,' + @@ -23,7 +23,7 @@ export function usePatientOrders(patientUuid: string, status: 'ACTIVE' | 'any') 'commentToFulfiller,drug:(uuid,display,strength,dosageForm:(display,uuid),concept),dose,doseUnits:ref,' + 'frequency:ref,asNeeded,asNeededCondition,quantity,quantityUnits:ref,numRefills,dosingInstructions,' + 'duration,durationUnits:ref,route:ref,brandName,dispenseAsWritten)'; - const ordersUrl = `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&status=${status}&orderType=${drugOrderTypeUUID}&v=${customRepresentation}`; + const ordersUrl = `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&orderTypes=${drugOrderTypeUUID}&v=${customRepresentation}`; const { data, error, isLoading, isValidating } = useSWR, Error>( patientUuid ? ordersUrl : null, diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx index 1d67284c0..fc36fff0b 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx @@ -128,26 +128,29 @@ const MedicationsDetailsTable: React.FC = ({

- {medication.orderReasonNonCoded ? ( + {medication.orderReasonNonCoded && ( {t('indication', 'Indication').toUpperCase()}{' '} {medication.orderReasonNonCoded} - ) : null} - {medication.quantity ? ( + )} + {medication.quantity && ( — {t('quantity', 'Quantity').toUpperCase()}{' '} {medication.quantity} {medication?.quantityUnits?.display} - ) : null} - {medication.dateStopped ? ( + )} + {(medication.dateStopped || medication.autoStopDate) && ( - — {t('discontinuedDate', 'Discontinued date').toUpperCase()} + — {t('discontinuedDate', 'Discontinued date').toUpperCase()}:{' '} + {formatDate(new Date(medication.dateStopped || medication.autoStopDate))} - {formatDate(new Date(medication.dateStopped))} - ) : null} + )} + {(medication.dateStopped != null || medication.autoStopDate != null) && ( + — {t('discontinued', 'Discontinued').toUpperCase()} + )}

), From 5ffaf90e21cc5585da9cc2b2907bd5a96d792fde Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Fri, 27 Sep 2024 17:56:32 +0300 Subject: [PATCH 02/30] fix build error --- .../src/active-medications/active-medications.component.tsx | 2 +- .../drug-search/order-basket-search-results.component.tsx | 2 +- .../src/medications-summary/medications-summary.component.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx b/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx index 13dce82f6..ee351e715 100644 --- a/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx +++ b/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx @@ -14,7 +14,7 @@ const ActiveMedications: React.FC = ({ patient }) => { const displayText = t('activeMedicationsDisplayText', 'Active medications'); const headerTitle = t('activeMedicationsHeaderTitle', 'active medications'); - const { data: activePatientOrders, error, isLoading, isValidating } = usePatientOrders(patient?.id, 'ACTIVE'); + const { data: activePatientOrders, error, isLoading, isValidating } = usePatientOrders(patient?.id); const launchAddDrugWorkspace = useLaunchWorkspaceRequiringVisit('add-drug-order'); diff --git a/packages/esm-patient-medications-app/src/add-drug-order/drug-search/order-basket-search-results.component.tsx b/packages/esm-patient-medications-app/src/add-drug-order/drug-search/order-basket-search-results.component.tsx index fae33af2f..e3aa27704 100644 --- a/packages/esm-patient-medications-app/src/add-drug-order/drug-search/order-basket-search-results.component.tsx +++ b/packages/esm-patient-medications-app/src/add-drug-order/drug-search/order-basket-search-results.component.tsx @@ -119,7 +119,7 @@ const DrugSearchResultItem: React.FC = ({ drug, openO const isTablet = useLayoutType() === 'tablet'; const { orders, setOrders } = useOrderBasket('medications', prepMedicationOrderPostData); const patient = usePatient(); - const { data: activeOrders, isLoading: isLoadingActiveOrders } = usePatientOrders(patient.patientUuid, 'ACTIVE'); + const { data: activeOrders, isLoading: isLoadingActiveOrders } = usePatientOrders(patient.patientUuid); const drugAlreadyInBasket = useMemo( () => orders?.some((order) => ordersEqual(order, getTemplateOrderBasketItem(drug))), [orders, drug], diff --git a/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx b/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx index 759619188..833b08c89 100644 --- a/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx +++ b/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx @@ -21,7 +21,7 @@ export default function MedicationsSummary({ patient }: MedicationsSummaryProps) error: error, isLoading: isLoading, isValidating: isValidating, - } = usePatientOrders(patient?.id, 'any'); + } = usePatientOrders(patient?.id); const [pastOrders, activeOrders] = useMemo(() => { const currentDate = new Date(); From 9487c7f2035139ed269f2efcc7c98eca7174a5f2 Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Mon, 30 Sep 2024 14:24:41 +0300 Subject: [PATCH 03/30] DISCONTINUED' should be a grey Carbon Tag --- .../src/components/medications-details-table.component.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx index fc36fff0b..a53682b3c 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx @@ -41,6 +41,7 @@ import { type DrugOrderBasketItem } from '../types'; import { type ConfigObject } from '../config-schema'; import PrintComponent from '../print/print.component'; import styles from './medications-details-table.scss'; +import { Tag } from '@carbon/react'; export interface ActiveMedicationsProps { isValidating?: boolean; @@ -146,11 +147,11 @@ const MedicationsDetailsTable: React.FC = ({ — {t('discontinuedDate', 'Discontinued date').toUpperCase()}:{' '} {formatDate(new Date(medication.dateStopped || medication.autoStopDate))} + + {t('discontinued', 'Discontinued').toUpperCase()} + )} - {(medication.dateStopped != null || medication.autoStopDate != null) && ( - — {t('discontinued', 'Discontinued').toUpperCase()} - )}

), From 3eb9c805fdf73953c6199c2c36e7a9d50c396c73 Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Mon, 30 Sep 2024 16:23:53 +0300 Subject: [PATCH 04/30] Add margin on Discontinued Label --- .../src/components/medications-details-table.component.tsx | 4 ++-- packages/esm-patient-medications-app/translations/en.json | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx index a53682b3c..d7793b30a 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx @@ -144,10 +144,10 @@ const MedicationsDetailsTable: React.FC = ({ {(medication.dateStopped || medication.autoStopDate) && ( - — {t('discontinuedDate', 'Discontinued date').toUpperCase()}:{' '} + — {t('Date', 'date').toUpperCase()}:{' '} {formatDate(new Date(medication.dateStopped || medication.autoStopDate))} - + {t('discontinued', 'Discontinued').toUpperCase()} diff --git a/packages/esm-patient-medications-app/translations/en.json b/packages/esm-patient-medications-app/translations/en.json index a389715c8..6ae47b930 100644 --- a/packages/esm-patient-medications-app/translations/en.json +++ b/packages/esm-patient-medications-app/translations/en.json @@ -11,6 +11,7 @@ "directlyAddToBasket": "Add to basket", "discard": "Discard", "discontinue": "Discontinue", + "discontinued": "Discontinued", "discontinuedDate": "Discontinued date", "dispensingInformation": "3. Dispensing instructions", "dosageInstructions": "1. Dosage instructions", From eb76988e77b26049f029555bef15bc12ecd29a2b Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Tue, 1 Oct 2024 00:19:05 +0300 Subject: [PATCH 05/30] Code refactor --- .../medications-details-table.component.tsx | 11 +++++++---- .../src/components/medications-details-table.scss | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx index d7793b30a..668f38a9c 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx @@ -15,6 +15,8 @@ import { TableHead, TableHeader, TableRow, + Tag, + Tooltip, } from '@carbon/react'; import { CardHeader, @@ -41,7 +43,6 @@ import { type DrugOrderBasketItem } from '../types'; import { type ConfigObject } from '../config-schema'; import PrintComponent from '../print/print.component'; import styles from './medications-details-table.scss'; -import { Tag } from '@carbon/react'; export interface ActiveMedicationsProps { isValidating?: boolean; @@ -147,9 +148,11 @@ const MedicationsDetailsTable: React.FC = ({ — {t('Date', 'date').toUpperCase()}:{' '} {formatDate(new Date(medication.dateStopped || medication.autoStopDate))} - - {t('discontinued', 'Discontinued').toUpperCase()} - + + + {t('discontinued_Caps', 'DISCONTINUED')} + + )}

diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.scss b/packages/esm-patient-medications-app/src/components/medications-details-table.scss index 079cbbb2e..277523d9d 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.scss +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.scss @@ -66,3 +66,7 @@ border-bottom: none !important; } } + +.tag { + margin-left: 10px; +} From e0a51a994dfd61f5b43b2f77948b743ff678b6ac Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Tue, 1 Oct 2024 01:04:07 +0300 Subject: [PATCH 06/30] Remove the black borders on Tag --- .../src/components/medications-details-table.scss | 1 + packages/esm-patient-medications-app/translations/en.json | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.scss b/packages/esm-patient-medications-app/src/components/medications-details-table.scss index 277523d9d..27859dc58 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.scss +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.scss @@ -69,4 +69,5 @@ .tag { margin-left: 10px; + border: none; } diff --git a/packages/esm-patient-medications-app/translations/en.json b/packages/esm-patient-medications-app/translations/en.json index 6ae47b930..7609a877f 100644 --- a/packages/esm-patient-medications-app/translations/en.json +++ b/packages/esm-patient-medications-app/translations/en.json @@ -6,13 +6,14 @@ "addDrugOrderWorkspaceTitle": "Add drug order", "backToOrderBasket": "Back to order basket", "clearSearchResults": "Clear Results", + "Date": "date", "decrement": "Decrement", "details": "Details", "directlyAddToBasket": "Add to basket", "discard": "Discard", "discontinue": "Discontinue", - "discontinued": "Discontinued", - "discontinuedDate": "Discontinued date", + "discontinued_Caps": "DISCONTINUED", + "discontinuedTooltip": "This request is discontinued", "dispensingInformation": "3. Dispensing instructions", "dosageInstructions": "1. Dosage instructions", "dosageRequiredErrorMessage": "Dosage is required", From ab98f8b7d2ce7137f698395af15c7b40b0652dc8 Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Tue, 1 Oct 2024 15:34:14 +0300 Subject: [PATCH 07/30] Flag discontinued requests with a tooltip --- .../src/active-medications/active-medications.test.tsx | 2 +- .../src/components/medications-details-table.component.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/esm-patient-medications-app/src/active-medications/active-medications.test.tsx b/packages/esm-patient-medications-app/src/active-medications/active-medications.test.tsx index 6b775caa9..0dd76fef3 100644 --- a/packages/esm-patient-medications-app/src/active-medications/active-medications.test.tsx +++ b/packages/esm-patient-medications-app/src/active-medications/active-medications.test.tsx @@ -95,7 +95,7 @@ describe('ActiveMedications', () => { /14-Aug-2023 Admin User Aspirin 162.5mg — 162.5mg — tablet DOSE 1 tablet — oral — once daily — for {{duration}} days INDICATION Heart — QUANTITY 30 Tablet/, ]; - expectedTableRows.map((row) => + expectedTableRows.forEach((row) => expect(within(table).getByRole('row', { name: new RegExp(row, 'i') })).toBeInTheDocument(), ); }); diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx index 668f38a9c..883c3cbe9 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx @@ -145,7 +145,7 @@ const MedicationsDetailsTable: React.FC = ({ {(medication.dateStopped || medication.autoStopDate) && ( - — {t('Date', 'date').toUpperCase()}:{' '} + — {t('discontinuedDate', 'Discontinued date')}: {formatDate(new Date(medication.dateStopped || medication.autoStopDate))} From 754f57bb78d058668a066e9d540728694ffc5aba Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Tue, 1 Oct 2024 18:37:37 +0300 Subject: [PATCH 08/30] Discontinued date appears in the tooltip --- .../components/medications-details-table.component.tsx | 10 +++++----- .../esm-patient-medications-app/translations/en.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx index 883c3cbe9..895ef0d65 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx @@ -144,11 +144,11 @@ const MedicationsDetailsTable: React.FC = ({ )} {(medication.dateStopped || medication.autoStopDate) && ( - - — {t('discontinuedDate', 'Discontinued date')}: - {formatDate(new Date(medication.dateStopped || medication.autoStopDate))} - - + {t('discontinued_Caps', 'DISCONTINUED')} diff --git a/packages/esm-patient-medications-app/translations/en.json b/packages/esm-patient-medications-app/translations/en.json index 7609a877f..c06288e03 100644 --- a/packages/esm-patient-medications-app/translations/en.json +++ b/packages/esm-patient-medications-app/translations/en.json @@ -6,13 +6,13 @@ "addDrugOrderWorkspaceTitle": "Add drug order", "backToOrderBasket": "Back to order basket", "clearSearchResults": "Clear Results", - "Date": "date", "decrement": "Decrement", "details": "Details", "directlyAddToBasket": "Add to basket", "discard": "Discard", "discontinue": "Discontinue", "discontinued_Caps": "DISCONTINUED", + "discontinuedDate": "Discontinued date", "discontinuedTooltip": "This request is discontinued", "dispensingInformation": "3. Dispensing instructions", "dosageInstructions": "1. Dosage instructions", From 9ee105747c8d000938a18759dcb7f85ebc76556b Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Wed, 2 Oct 2024 01:12:54 +0300 Subject: [PATCH 09/30] Display Discontinued date in the tooltip --- .../components/medications-details-table.component.tsx | 8 ++------ .../src/components/medications-details-table.scss | 4 +++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx index 895ef0d65..baf7c4e2d 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx @@ -144,13 +144,9 @@ const MedicationsDetailsTable: React.FC = ({ )} {(medication.dateStopped || medication.autoStopDate) && ( - + - {t('discontinued_Caps', 'DISCONTINUED')} + {t('discontinued', 'Discontinued')} diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.scss b/packages/esm-patient-medications-app/src/components/medications-details-table.scss index 27859dc58..5d31fab1e 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.scss +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.scss @@ -68,6 +68,8 @@ } .tag { - margin-left: 10px; + margin: 0 !important; + margin-left: 0.5rem !important; border: none; + text-transform: uppercase; } From 023d2670493096b3c9411c32bbef14204872b903 Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Thu, 3 Oct 2024 01:44:15 +0300 Subject: [PATCH 10/30] Add the Discontinued Date Label Inside the Tooltip --- .../src/orders/types.ts | 1 - .../medications-details-table.component.tsx | 25 ++++++++++++------- .../translations/en.json | 3 +-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/packages/esm-patient-common-lib/src/orders/types.ts b/packages/esm-patient-common-lib/src/orders/types.ts index 78caa2b36..81478cd16 100644 --- a/packages/esm-patient-common-lib/src/orders/types.ts +++ b/packages/esm-patient-common-lib/src/orders/types.ts @@ -85,7 +85,6 @@ export interface Order { asNeeded: boolean; asNeededCondition?: string; autoExpireDate: string; - autoStopDate: string; brandName?: string; careSetting: OpenmrsResource; commentToFulfiller: string; diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx index baf7c4e2d..53d59f6a3 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx @@ -104,6 +104,22 @@ const MedicationsDetailsTable: React.FC = ({ {capitalize(medication.drug?.display)}{' '} {medication.drug?.strength && <>— {medication.drug?.strength.toLowerCase()}}{' '} {medication.drug?.dosageForm?.display && <>— {medication.drug.dosageForm.display.toLowerCase()}} + + {formatDate(new Date(medication.dateStopped || medication.autoExpireDate))} +
+ — {t('discontinuedDate', 'Discontinued date').toUpperCase()} + + } + > + {(medication.dateStopped || medication.autoExpireDate) && ( + + {t('discontinued', 'Discontinued')} + + )} +

{t('dose', 'Dose').toUpperCase()}{' '} @@ -142,15 +158,6 @@ const MedicationsDetailsTable: React.FC = ({ {medication.quantity} {medication?.quantityUnits?.display} )} - {(medication.dateStopped || medication.autoStopDate) && ( - - - - {t('discontinued', 'Discontinued')} - - - - )}

), diff --git a/packages/esm-patient-medications-app/translations/en.json b/packages/esm-patient-medications-app/translations/en.json index c06288e03..66032cd45 100644 --- a/packages/esm-patient-medications-app/translations/en.json +++ b/packages/esm-patient-medications-app/translations/en.json @@ -11,9 +11,8 @@ "directlyAddToBasket": "Add to basket", "discard": "Discard", "discontinue": "Discontinue", + "discontinued": "Discontinued", "discontinued_Caps": "DISCONTINUED", - "discontinuedDate": "Discontinued date", - "discontinuedTooltip": "This request is discontinued", "dispensingInformation": "3. Dispensing instructions", "dosageInstructions": "1. Dosage instructions", "dosageRequiredErrorMessage": "Dosage is required", From e9ee19d1ba8b3562327fd711fe9fbb403f347685 Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Mon, 7 Oct 2024 20:33:56 +0300 Subject: [PATCH 11/30] Only discontinued medication to display the tag --- .../medications-details-table.component.tsx | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx index 53d59f6a3..55aa7c84c 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx @@ -104,22 +104,21 @@ const MedicationsDetailsTable: React.FC = ({ {capitalize(medication.drug?.display)}{' '} {medication.drug?.strength && <>— {medication.drug?.strength.toLowerCase()}}{' '} {medication.drug?.dosageForm?.display && <>— {medication.drug.dosageForm.display.toLowerCase()}} - - {formatDate(new Date(medication.dateStopped || medication.autoExpireDate))} -
- — {t('discontinuedDate', 'Discontinued date').toUpperCase()} - - } - > - {(medication.dateStopped || medication.autoExpireDate) && ( + {(medication.dateStopped || medication.autoExpireDate) && medication.action === 'DISCONTINUE' && ( + + {t('discontinuedDate', 'Discontinued date').toUpperCase()} — + {formatDate(new Date(medication.dateStopped || medication.autoExpireDate))} + + } + > {t('discontinued', 'Discontinued')} - )} - +
+ )}

{t('dose', 'Dose').toUpperCase()}{' '} From 467c87c86575e4b24bde8f0af0328d7517c7a076 Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Tue, 8 Oct 2024 13:15:39 +0300 Subject: [PATCH 12/30] Active medication to be displayed on all the Active tables --- .../tests-summary.component.tsx | 2 +- .../active-medications.component.tsx | 18 ++++++++++++------ .../translations/en.json | 1 + 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/tests-summary.component.tsx b/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/tests-summary.component.tsx index eebd5c7f2..f7506ef42 100644 --- a/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/tests-summary.component.tsx +++ b/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/tests-summary.component.tsx @@ -14,7 +14,7 @@ const TestsSummary = ({ patientUuid, encounters }: { patientUuid: string; encoun return ( ); }; diff --git a/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx b/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx index ee351e715..30643653a 100644 --- a/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx +++ b/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx @@ -6,13 +6,13 @@ import MedicationsDetailsTable from '../components/medications-details-table.com import { usePatientOrders } from '../api/api'; interface ActiveMedicationsProps { - patient: fhir.Patient; + patient: fhir.Patient | null; } const ActiveMedications: React.FC = ({ patient }) => { const { t } = useTranslation(); - const displayText = t('activeMedicationsDisplayText', 'Active medications'); - const headerTitle = t('activeMedicationsHeaderTitle', 'active medications'); + const displayText = t('activeMedicationsDisplayText', 'Active medication'); + const headerTitle = t('activeMedicationsHeaderTitle', 'Active Medication'); const { data: activePatientOrders, error, isLoading, isValidating } = usePatientOrders(patient?.id); @@ -22,12 +22,17 @@ const ActiveMedications: React.FC = ({ patient }) => { if (error) return ; - if (activePatientOrders?.length) { + const activeMedications = activePatientOrders?.filter((order) => { + const isActive = !order.dateStopped && order.action !== 'DISCONTINUE'; + return isActive || (!order.autoExpireDate && order.action !== 'DISCONTINUE'); + }); + + if (activeMedications?.length) { return ( = ({ patient }) => { /> ); } + return launchAddDrugWorkspace()} />; }; diff --git a/packages/esm-patient-medications-app/translations/en.json b/packages/esm-patient-medications-app/translations/en.json index 66032cd45..ace0d283d 100644 --- a/packages/esm-patient-medications-app/translations/en.json +++ b/packages/esm-patient-medications-app/translations/en.json @@ -13,6 +13,7 @@ "discontinue": "Discontinue", "discontinued": "Discontinued", "discontinued_Caps": "DISCONTINUED", + "discontinuedDate": "Discontinued date", "dispensingInformation": "3. Dispensing instructions", "dosageInstructions": "1. Dosage instructions", "dosageRequiredErrorMessage": "Dosage is required", From 2feca970a8de6402be85e995b02884061455b326 Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Wed, 9 Oct 2024 03:05:43 +0300 Subject: [PATCH 13/30] fix build error --- .../active-medications/active-medications.component.tsx | 8 ++++---- .../src/active-medications/active-medications.test.tsx | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx b/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx index 30643653a..03e33d19d 100644 --- a/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx +++ b/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx @@ -6,13 +6,13 @@ import MedicationsDetailsTable from '../components/medications-details-table.com import { usePatientOrders } from '../api/api'; interface ActiveMedicationsProps { - patient: fhir.Patient | null; + patient: fhir.Patient; } const ActiveMedications: React.FC = ({ patient }) => { const { t } = useTranslation(); - const displayText = t('activeMedicationsDisplayText', 'Active medication'); - const headerTitle = t('activeMedicationsHeaderTitle', 'Active Medication'); + const displayText = t('activeMedicationsDisplayText', 'Active medications'); + const headerTitle = t('activeMedicationsHeaderTitle', 'Active Medications'); const { data: activePatientOrders, error, isLoading, isValidating } = usePatientOrders(patient?.id); @@ -31,7 +31,7 @@ const ActiveMedications: React.FC = ({ patient }) => { return ( { const expectedTableRows = [ /14-Aug-2023 Admin User Acetaminophen 325 mg — 325mg — tablet DOSE 2 tablet — oral — twice daily — indefinite duration — take it sometimes INDICATION Bad boo-boo/, - /14-Aug-2023 Admin User Acetaminophen 325 mg — 325mg — tablet DOSE 2 tablet — oral — twice daily — indefinite duration INDICATION No good — DISCONTINUED DATE 14-Aug-2023 — DISCONTINUED/, + /14-Aug-2023 Admin User Acetaminophen 325 mg — 325mg — tablet DOSE 2 tablets — oral — twice daily — indefinite duration INDICATION Not specified — DISCONTINUED Tag Tooltip DATE 14-Aug-2023 DISCONTINUED/, /14-Aug-2023 Admin User Sulfacetamide 0.1 — 10% DOSE 1 application — for {{duration}} weeks — REFILLS 1 — apply it INDICATION Pain — QUANTITY 8 Application/, /14-Aug-2023 Admin User Aspirin 162.5mg — 162.5mg — tablet DOSE 1 tablet — oral — once daily — for {{duration}} days INDICATION Heart — QUANTITY 30 Tablet/, ]; From 0c59911a2daffc2128583f2cba21e422bf3ac081 Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Wed, 9 Oct 2024 15:33:46 +0300 Subject: [PATCH 14/30] Fix Active medications conditions --- .../past-visits-components/tests-summary.component.tsx | 2 +- .../active-medications/active-medications.component.tsx | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/tests-summary.component.tsx b/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/tests-summary.component.tsx index f7506ef42..eebd5c7f2 100644 --- a/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/tests-summary.component.tsx +++ b/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/tests-summary.component.tsx @@ -14,7 +14,7 @@ const TestsSummary = ({ patientUuid, encounters }: { patientUuid: string; encoun return ( ); }; diff --git a/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx b/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx index 03e33d19d..34779e1fa 100644 --- a/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx +++ b/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx @@ -23,8 +23,11 @@ const ActiveMedications: React.FC = ({ patient }) => { if (error) return ; const activeMedications = activePatientOrders?.filter((order) => { - const isActive = !order.dateStopped && order.action !== 'DISCONTINUE'; - return isActive || (!order.autoExpireDate && order.action !== 'DISCONTINUE'); + const isDateStoppedUnset = !order.dateStopped; + const isActionValid = order.action !== 'DISCONTINUE'; + const isAutoExpireDateValid = !order.autoExpireDate || new Date(order.autoExpireDate) > new Date(); + + return isDateStoppedUnset && isActionValid && isAutoExpireDateValid; }); if (activeMedications?.length) { From 7229ede2c12aea5e5899f89b1afb772930dc5924 Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Thu, 24 Oct 2024 13:36:32 +0300 Subject: [PATCH 15/30] Add hooks separate active patient orders and past patient orders --- .../src/api/api.ts | 50 +++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/packages/esm-patient-medications-app/src/api/api.ts b/packages/esm-patient-medications-app/src/api/api.ts index 4d9e03742..b889416bf 100644 --- a/packages/esm-patient-medications-app/src/api/api.ts +++ b/packages/esm-patient-medications-app/src/api/api.ts @@ -12,7 +12,6 @@ export const careSettingUuid = '6f0c9a92-6f24-11e3-af88-005056821db0'; * SWR-based data fetcher for patient orders. * * @param patientUuid The UUID of the patient whose orders should be fetched. - * @param status Allows fetching either all orders or only active orders. */ export function usePatientOrders(patientUuid: string) { const { drugOrderTypeUUID } = useConfig() as ConfigObject; @@ -23,7 +22,7 @@ export function usePatientOrders(patientUuid: string) { 'commentToFulfiller,drug:(uuid,display,strength,dosageForm:(display,uuid),concept),dose,doseUnits:ref,' + 'frequency:ref,asNeeded,asNeededCondition,quantity,quantityUnits:ref,numRefills,dosingInstructions,' + 'duration,durationUnits:ref,route:ref,brandName,dispenseAsWritten)'; - const ordersUrl = `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&orderTypes=${drugOrderTypeUUID}&v=${customRepresentation}`; + const ordersUrl = `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&orderTypes=${drugOrderTypeUUID}&v=${customRepresentation}&excludeDiscontinueOrders=true&excludeCanceledAndExpired=true`; const { data, error, isLoading, isValidating } = useSWR, Error>( patientUuid ? ordersUrl : null, @@ -54,6 +53,51 @@ export function usePatientOrders(patientUuid: string) { }; } +/** + * Hook to get active patient orders. + * + * @param patientUuid The UUID of the patient whose active orders should be fetched. + */ +export function useActivePatientOrders(patientUuid: string) { + const { data: allOrders, error, isLoading, isValidating, mutate } = usePatientOrders(patientUuid); + + const activeOrders = useMemo( + () => (allOrders ? allOrders.filter((order) => !order.autoExpireDate && !order.dateStopped) : null), + [allOrders], + ); + + return { + data: activeOrders, + error, + isLoading, + isValidating, + mutate, + }; +} + +/** + * Hook to get past patient orders. + * + * @param patientUuid The UUID of the patient whose past orders should be fetched. + */ +export function usePastPatientOrders(patientUuid: string) { + const { data: allOrders, error, isLoading, isValidating, mutate } = usePatientOrders(patientUuid); + const { data: activeOrders } = useActivePatientOrders(patientUuid); + + const pastOrders = useMemo( + () => (allOrders && activeOrders ? allOrders.filter((order) => !activeOrders.includes(order)) : null), + [allOrders, activeOrders], + ); + + return { + data: pastOrders, + error, + isLoading, + isValidating, + mutate, + }; +} + export function prepMedicationOrderPostData( order: DrugOrderBasketItem, patientUuid: string, @@ -153,7 +197,7 @@ export function useRequireOutpatientQuantity(): { const results = useMemo( () => ({ - requireOutpatientQuantity: data?.data?.value && data.data.value === 'true', + requireOutpatientQuantity: data?.data?.value === 'true', error, isLoading, }), From 6ddfcddb421dbe59f59e34a2c544f516184af9df Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Thu, 24 Oct 2024 16:43:42 +0300 Subject: [PATCH 16/30] Remove filtering logic in the MedicationsSummary component --- .../src/api/api.ts | 33 ++++++++++---- .../medications-summary.component.tsx | 45 ++++--------------- 2 files changed, 34 insertions(+), 44 deletions(-) diff --git a/packages/esm-patient-medications-app/src/api/api.ts b/packages/esm-patient-medications-app/src/api/api.ts index b889416bf..91eb76bd1 100644 --- a/packages/esm-patient-medications-app/src/api/api.ts +++ b/packages/esm-patient-medications-app/src/api/api.ts @@ -62,7 +62,10 @@ export function useActivePatientOrders(patientUuid: string) { const { data: allOrders, error, isLoading, isValidating, mutate } = usePatientOrders(patientUuid); const activeOrders = useMemo( - () => (allOrders ? allOrders.filter((order) => !order.autoExpireDate && !order.dateStopped) : null), + () => + allOrders + ? allOrders.filter((order) => !order.autoExpireDate && !order.dateStopped && order.action !== 'DISCONTINUE') + : null, [allOrders], ); @@ -81,20 +84,34 @@ export function useActivePatientOrders(patientUuid: string) { * @param patientUuid The UUID of the patient whose past orders should be fetched. */ export function usePastPatientOrders(patientUuid: string) { - const { data: allOrders, error, isLoading, isValidating, mutate } = usePatientOrders(patientUuid); - const { data: activeOrders } = useActivePatientOrders(patientUuid); + const { + data: allOrders, + error: allOrdersError, + isLoading: allOrdersLoading, + isValidating: allOrdersValidating, + } = usePatientOrders(patientUuid); + const { + data: activeOrders, + error: activeOrdersError, + isLoading: activeOrdersLoading, + isValidating: activeOrdersValidating, + } = useActivePatientOrders(patientUuid); - const pastOrders = useMemo( - () => (allOrders && activeOrders ? allOrders.filter((order) => !activeOrders.includes(order)) : null), - [allOrders, activeOrders], - ); + const pastOrders = useMemo(() => { + if (!allOrders || !activeOrders) return null; + return allOrders.filter((order) => !activeOrders.some((activeOrder) => activeOrder.uuid === order.uuid)); + }, [allOrders, activeOrders]); + + const error = allOrdersError || activeOrdersError; + const isLoading = allOrdersLoading || activeOrdersLoading; + const isValidating = allOrdersValidating || activeOrdersValidating; return { data: pastOrders, error, isLoading, isValidating, - mutate, + mutate: () => {}, }; } diff --git a/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx b/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx index 833b08c89..7cdae6906 100644 --- a/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx +++ b/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx @@ -1,8 +1,7 @@ -import React, { useMemo } from 'react'; +import React from 'react'; import { useTranslation } from 'react-i18next'; import { DataTableSkeleton } from '@carbon/react'; -import { parseDate } from '@openmrs/esm-framework'; -import { EmptyState, ErrorState, useLaunchWorkspaceRequiringVisit, type Order } from '@openmrs/esm-patient-common-lib'; +import { EmptyState, ErrorState, useLaunchWorkspaceRequiringVisit } from '@openmrs/esm-patient-common-lib'; import { usePatientOrders } from '../api'; import MedicationsDetailsTable from '../components/medications-details-table.component'; import { type AddDrugOrderWorkspaceAdditionalProps } from '../add-drug-order/add-drug-order.workspace'; @@ -16,51 +15,25 @@ export default function MedicationsSummary({ patient }: MedicationsSummaryProps) const launchAddDrugWorkspace = useLaunchWorkspaceRequiringVisit('add-drug-order'); - const { - data: allOrders, - error: error, - isLoading: isLoading, - isValidating: isValidating, - } = usePatientOrders(patient?.id); - - const [pastOrders, activeOrders] = useMemo(() => { - const currentDate = new Date(); - const pastOrders: Array = []; - const activeOrders: Array = []; - - if (allOrders) { - for (let i = 0; i < allOrders.length; i++) { - const order = allOrders[i]; - if (order.autoExpireDate && parseDate(order.autoExpireDate) < currentDate) { - pastOrders.push(order); - } else if (order.dateStopped && parseDate(order.dateStopped) < currentDate) { - pastOrders.push(order); - } else { - activeOrders.push(order); - } - } - } - - return [pastOrders, activeOrders]; - }, [allOrders]); + const { data: allOrders, error, isLoading, isValidating } = usePatientOrders(patient?.id); return (

{(() => { const displayText = t('activeMedicationsDisplayText', 'Active medications'); - const headerTitle = t('activeMedicationsHeaderTitle', 'active medications'); + const headerTitle = t('activeMedicationsHeaderTitle', 'Active medications'); if (isLoading) return ; if (error) return ; - if (activeOrders?.length) { + if (allOrders?.length) { return ( {(() => { const displayText = t('pastMedicationsDisplayText', 'Past medications'); - const headerTitle = t('pastMedicationsHeaderTitle', 'past medications'); + const headerTitle = t('pastMedicationsHeaderTitle', 'Past medications'); if (isLoading) return ; if (error) return ; - if (pastOrders?.length) { + if (allOrders?.length) { return ( Date: Thu, 24 Oct 2024 23:24:49 +0300 Subject: [PATCH 17/30] Ensure past medication is displayed --- .../src/api/api.ts | 40 ++++++------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/packages/esm-patient-medications-app/src/api/api.ts b/packages/esm-patient-medications-app/src/api/api.ts index 91eb76bd1..971fa11ee 100644 --- a/packages/esm-patient-medications-app/src/api/api.ts +++ b/packages/esm-patient-medications-app/src/api/api.ts @@ -1,10 +1,11 @@ import { useCallback, useMemo } from 'react'; import useSWR, { mutate } from 'swr'; +import useSWRImmutable from 'swr/immutable'; +import { openmrsFetch, restBaseUrl, useConfig } from '@openmrs/esm-framework'; +import { type FetchResponse } from '@openmrs/esm-framework'; import { type ConfigObject } from '../config-schema'; -import { type FetchResponse, openmrsFetch, restBaseUrl, useConfig } from '@openmrs/esm-framework'; import { type OrderPost, type PatientOrderFetchResponse } from '@openmrs/esm-patient-common-lib'; import { type DrugOrderBasketItem } from '../types'; -import useSWRImmutable from 'swr/immutable'; export const careSettingUuid = '6f0c9a92-6f24-11e3-af88-005056821db0'; @@ -22,7 +23,7 @@ export function usePatientOrders(patientUuid: string) { 'commentToFulfiller,drug:(uuid,display,strength,dosageForm:(display,uuid),concept),dose,doseUnits:ref,' + 'frequency:ref,asNeeded,asNeededCondition,quantity,quantityUnits:ref,numRefills,dosingInstructions,' + 'duration,durationUnits:ref,route:ref,brandName,dispenseAsWritten)'; - const ordersUrl = `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&orderTypes=${drugOrderTypeUUID}&v=${customRepresentation}&excludeDiscontinueOrders=true&excludeCanceledAndExpired=true`; + const ordersUrl = `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&orderTypes=${drugOrderTypeUUID}&v=${customRepresentation}&excludeDiscontinueOrders=true&excludeCanceledAndExpired=false`; const { data, error, isLoading, isValidating } = useSWR, Error>( patientUuid ? ordersUrl : null, @@ -62,10 +63,7 @@ export function useActivePatientOrders(patientUuid: string) { const { data: allOrders, error, isLoading, isValidating, mutate } = usePatientOrders(patientUuid); const activeOrders = useMemo( - () => - allOrders - ? allOrders.filter((order) => !order.autoExpireDate && !order.dateStopped && order.action !== 'DISCONTINUE') - : null, + () => (allOrders ? allOrders.filter((order) => !order.autoExpireDate && !order.dateStopped) : null), [allOrders], ); @@ -84,34 +82,22 @@ export function useActivePatientOrders(patientUuid: string) { * @param patientUuid The UUID of the patient whose past orders should be fetched. */ export function usePastPatientOrders(patientUuid: string) { - const { - data: allOrders, - error: allOrdersError, - isLoading: allOrdersLoading, - isValidating: allOrdersValidating, - } = usePatientOrders(patientUuid); - const { - data: activeOrders, - error: activeOrdersError, - isLoading: activeOrdersLoading, - isValidating: activeOrdersValidating, - } = useActivePatientOrders(patientUuid); + const { data: allOrders, error, isLoading, isValidating, mutate } = usePatientOrders(patientUuid); + const { data: activeOrders } = useActivePatientOrders(patientUuid); - const pastOrders = useMemo(() => { - if (!allOrders || !activeOrders) return null; - return allOrders.filter((order) => !activeOrders.some((activeOrder) => activeOrder.uuid === order.uuid)); - }, [allOrders, activeOrders]); + const activeOrderUUIDs = useMemo(() => activeOrders?.map((order) => order.uuid) || [], [activeOrders]); - const error = allOrdersError || activeOrdersError; - const isLoading = allOrdersLoading || activeOrdersLoading; - const isValidating = allOrdersValidating || activeOrdersValidating; + const pastOrders = useMemo( + () => (allOrders && activeOrderUUIDs ? allOrders.filter((order) => !activeOrderUUIDs.includes(order.uuid)) : null), + [allOrders, activeOrderUUIDs], + ); return { data: pastOrders, error, isLoading, isValidating, - mutate: () => {}, + mutate, }; } From e61f67b94e79fbae6b4e9f90d9bbc76d76243132 Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Fri, 25 Oct 2024 00:19:15 +0300 Subject: [PATCH 18/30] fix exclude discontinue orders parameter --- packages/esm-patient-medications-app/src/api/api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/esm-patient-medications-app/src/api/api.ts b/packages/esm-patient-medications-app/src/api/api.ts index 971fa11ee..ab7d4f20a 100644 --- a/packages/esm-patient-medications-app/src/api/api.ts +++ b/packages/esm-patient-medications-app/src/api/api.ts @@ -23,7 +23,7 @@ export function usePatientOrders(patientUuid: string) { 'commentToFulfiller,drug:(uuid,display,strength,dosageForm:(display,uuid),concept),dose,doseUnits:ref,' + 'frequency:ref,asNeeded,asNeededCondition,quantity,quantityUnits:ref,numRefills,dosingInstructions,' + 'duration,durationUnits:ref,route:ref,brandName,dispenseAsWritten)'; - const ordersUrl = `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&orderTypes=${drugOrderTypeUUID}&v=${customRepresentation}&excludeDiscontinueOrders=true&excludeCanceledAndExpired=false`; + const ordersUrl = `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&orderTypes=${drugOrderTypeUUID}&v=${customRepresentation}&excludeDiscontinueOrders=false&excludeCanceledAndExpired=false`; const { data, error, isLoading, isValidating } = useSWR, Error>( patientUuid ? ordersUrl : null, From 53159c79876f95da707f62d2ab42ceaa0e8af866 Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Mon, 28 Oct 2024 14:31:23 +0300 Subject: [PATCH 19/30] Remove redundant conditions --- .../src/api/api.ts | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/esm-patient-medications-app/src/api/api.ts b/packages/esm-patient-medications-app/src/api/api.ts index ab7d4f20a..18673abea 100644 --- a/packages/esm-patient-medications-app/src/api/api.ts +++ b/packages/esm-patient-medications-app/src/api/api.ts @@ -62,10 +62,7 @@ export function usePatientOrders(patientUuid: string) { export function useActivePatientOrders(patientUuid: string) { const { data: allOrders, error, isLoading, isValidating, mutate } = usePatientOrders(patientUuid); - const activeOrders = useMemo( - () => (allOrders ? allOrders.filter((order) => !order.autoExpireDate && !order.dateStopped) : null), - [allOrders], - ); + const activeOrders = allOrders; return { data: activeOrders, @@ -76,6 +73,11 @@ export function useActivePatientOrders(patientUuid: string) { }; } +/** + * Hook to get past patient orders. + * + * @param patientUuid The UUID of the patient whose past orders should be fetched. + */ /** * Hook to get past patient orders. * @@ -85,12 +87,13 @@ export function usePastPatientOrders(patientUuid: string) { const { data: allOrders, error, isLoading, isValidating, mutate } = usePatientOrders(patientUuid); const { data: activeOrders } = useActivePatientOrders(patientUuid); - const activeOrderUUIDs = useMemo(() => activeOrders?.map((order) => order.uuid) || [], [activeOrders]); + const activeOrderUUIDs = useMemo(() => { + return activeOrders?.map((order) => order.uuid) || []; + }, [activeOrders]); - const pastOrders = useMemo( - () => (allOrders && activeOrderUUIDs ? allOrders.filter((order) => !activeOrderUUIDs.includes(order.uuid)) : null), - [allOrders, activeOrderUUIDs], - ); + const pastOrders = useMemo(() => { + return allOrders ? allOrders.filter((order) => !activeOrderUUIDs.includes(order.uuid)) : []; + }, [allOrders, activeOrderUUIDs]); return { data: pastOrders, From 7398ec6fabc96b41c3b4d5d06aed9499f2d17d01 Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Mon, 28 Oct 2024 15:05:33 +0300 Subject: [PATCH 20/30] Code refactor --- .../src/api/api.ts | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/packages/esm-patient-medications-app/src/api/api.ts b/packages/esm-patient-medications-app/src/api/api.ts index 18673abea..b2d98c5c3 100644 --- a/packages/esm-patient-medications-app/src/api/api.ts +++ b/packages/esm-patient-medications-app/src/api/api.ts @@ -9,6 +9,14 @@ import { type DrugOrderBasketItem } from '../types'; export const careSettingUuid = '6f0c9a92-6f24-11e3-af88-005056821db0'; +const customRepresentation = + 'custom:(uuid,dosingType,orderNumber,accessionNumber,' + + 'patient:ref,action,careSetting:ref,previousOrder:ref,dateActivated,scheduledDate,dateStopped,autoExpireDate,' + + 'orderType:ref,encounter:ref,orderer:(uuid,display,person:(display)),orderReason,orderReasonNonCoded,orderType,urgency,instructions,' + + 'commentToFulfiller,drug:(uuid,display,strength,dosageForm:(display,uuid),concept),dose,doseUnits:ref,' + + 'frequency:ref,asNeeded,asNeededCondition,quantity,quantityUnits:ref,numRefills,dosingInstructions,' + + 'duration,durationUnits:ref,route:ref,brandName,dispenseAsWritten)'; + /** * SWR-based data fetcher for patient orders. * @@ -16,14 +24,8 @@ export const careSettingUuid = '6f0c9a92-6f24-11e3-af88-005056821db0'; */ export function usePatientOrders(patientUuid: string) { const { drugOrderTypeUUID } = useConfig() as ConfigObject; - const customRepresentation = - 'custom:(uuid,dosingType,orderNumber,accessionNumber,' + - 'patient:ref,action,careSetting:ref,previousOrder:ref,dateActivated,scheduledDate,dateStopped,autoExpireDate,' + - 'orderType:ref,encounter:ref,orderer:(uuid,display,person:(display)),orderReason,orderReasonNonCoded,orderType,urgency,instructions,' + - 'commentToFulfiller,drug:(uuid,display,strength,dosageForm:(display,uuid),concept),dose,doseUnits:ref,' + - 'frequency:ref,asNeeded,asNeededCondition,quantity,quantityUnits:ref,numRefills,dosingInstructions,' + - 'duration,durationUnits:ref,route:ref,brandName,dispenseAsWritten)'; - const ordersUrl = `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&orderTypes=${drugOrderTypeUUID}&v=${customRepresentation}&excludeDiscontinueOrders=false&excludeCanceledAndExpired=false`; + + const ordersUrl = `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&orderTypes=${drugOrderTypeUUID}&v=${customRepresentation}&excludeDiscontinueOrders=false`; const { data, error, isLoading, isValidating } = useSWR, Error>( patientUuid ? ordersUrl : null, @@ -60,12 +62,21 @@ export function usePatientOrders(patientUuid: string) { * @param patientUuid The UUID of the patient whose active orders should be fetched. */ export function useActivePatientOrders(patientUuid: string) { - const { data: allOrders, error, isLoading, isValidating, mutate } = usePatientOrders(patientUuid); - - const activeOrders = allOrders; + const { drugOrderTypeUUID } = useConfig() as ConfigObject; + const ordersUrl = useMemo( + () => + patientUuid + ? `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&orderTypes=${drugOrderTypeUUID}&excludeCanceledAndExpired=true&v=${customRepresentation}` + : null, + [patientUuid, drugOrderTypeUUID], + ); + const { data, error, isLoading, isValidating } = useSWR, Error>( + ordersUrl, + openmrsFetch, + ); return { - data: activeOrders, + data: data?.data?.results, error, isLoading, isValidating, From 8d54ea2c51c7b04ded4db549fda70c5a62541cbb Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Tue, 29 Oct 2024 13:54:51 +0300 Subject: [PATCH 21/30] Revert changes --- .../medications-summary.component.tsx | 45 +++++++++++++++---- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx b/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx index 7cdae6906..833b08c89 100644 --- a/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx +++ b/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx @@ -1,7 +1,8 @@ -import React from 'react'; +import React, { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { DataTableSkeleton } from '@carbon/react'; -import { EmptyState, ErrorState, useLaunchWorkspaceRequiringVisit } from '@openmrs/esm-patient-common-lib'; +import { parseDate } from '@openmrs/esm-framework'; +import { EmptyState, ErrorState, useLaunchWorkspaceRequiringVisit, type Order } from '@openmrs/esm-patient-common-lib'; import { usePatientOrders } from '../api'; import MedicationsDetailsTable from '../components/medications-details-table.component'; import { type AddDrugOrderWorkspaceAdditionalProps } from '../add-drug-order/add-drug-order.workspace'; @@ -15,25 +16,51 @@ export default function MedicationsSummary({ patient }: MedicationsSummaryProps) const launchAddDrugWorkspace = useLaunchWorkspaceRequiringVisit('add-drug-order'); - const { data: allOrders, error, isLoading, isValidating } = usePatientOrders(patient?.id); + const { + data: allOrders, + error: error, + isLoading: isLoading, + isValidating: isValidating, + } = usePatientOrders(patient?.id); + + const [pastOrders, activeOrders] = useMemo(() => { + const currentDate = new Date(); + const pastOrders: Array = []; + const activeOrders: Array = []; + + if (allOrders) { + for (let i = 0; i < allOrders.length; i++) { + const order = allOrders[i]; + if (order.autoExpireDate && parseDate(order.autoExpireDate) < currentDate) { + pastOrders.push(order); + } else if (order.dateStopped && parseDate(order.dateStopped) < currentDate) { + pastOrders.push(order); + } else { + activeOrders.push(order); + } + } + } + + return [pastOrders, activeOrders]; + }, [allOrders]); return (
{(() => { const displayText = t('activeMedicationsDisplayText', 'Active medications'); - const headerTitle = t('activeMedicationsHeaderTitle', 'Active medications'); + const headerTitle = t('activeMedicationsHeaderTitle', 'active medications'); if (isLoading) return ; if (error) return ; - if (allOrders?.length) { + if (activeOrders?.length) { return ( {(() => { const displayText = t('pastMedicationsDisplayText', 'Past medications'); - const headerTitle = t('pastMedicationsHeaderTitle', 'Past medications'); + const headerTitle = t('pastMedicationsHeaderTitle', 'past medications'); if (isLoading) return ; if (error) return ; - if (allOrders?.length) { + if (pastOrders?.length) { return ( Date: Tue, 29 Oct 2024 14:50:44 +0300 Subject: [PATCH 22/30] Refactor hooks --- .../src/api/api.ts | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/packages/esm-patient-medications-app/src/api/api.ts b/packages/esm-patient-medications-app/src/api/api.ts index b2d98c5c3..984593b92 100644 --- a/packages/esm-patient-medications-app/src/api/api.ts +++ b/packages/esm-patient-medications-app/src/api/api.ts @@ -17,6 +17,18 @@ const customRepresentation = 'frequency:ref,asNeeded,asNeededCondition,quantity,quantityUnits:ref,numRefills,dosingInstructions,' + 'duration,durationUnits:ref,route:ref,brandName,dispenseAsWritten)'; +/** + * Sorts orders by date activated in descending order. + * + * @param orders The orders to sort. + * @returns The sorted orders. + */ +function sortOrdersByDateActivated(orders: any[]) { + return orders?.sort( + (order1, order2) => new Date(order2.dateActivated).getTime() - new Date(order1.dateActivated).getTime(), + ); +} + /** * SWR-based data fetcher for patient orders. * @@ -40,9 +52,7 @@ export function usePatientOrders(patientUuid: string) { const drugOrders = useMemo( () => data?.data?.results - ? data.data.results - .filter((order) => order.orderType.display === 'Drug Order') - ?.sort((order1, order2) => (order2.dateActivated > order1.dateActivated ? 1 : -1)) + ? sortOrdersByDateActivated(data.data.results.filter((order) => order.orderType.display === 'Drug Order')) : null, [data], ); @@ -75,8 +85,13 @@ export function useActivePatientOrders(patientUuid: string) { openmrsFetch, ); + const activeOrders = useMemo( + () => (data?.data?.results ? sortOrdersByDateActivated(data.data.results) : null), + [data], + ); + return { - data: data?.data?.results, + data: activeOrders, error, isLoading, isValidating, @@ -84,11 +99,6 @@ export function useActivePatientOrders(patientUuid: string) { }; } -/** - * Hook to get past patient orders. - * - * @param patientUuid The UUID of the patient whose past orders should be fetched. - */ /** * Hook to get past patient orders. * @@ -98,13 +108,16 @@ export function usePastPatientOrders(patientUuid: string) { const { data: allOrders, error, isLoading, isValidating, mutate } = usePatientOrders(patientUuid); const { data: activeOrders } = useActivePatientOrders(patientUuid); - const activeOrderUUIDs = useMemo(() => { - return activeOrders?.map((order) => order.uuid) || []; - }, [activeOrders]); - const pastOrders = useMemo(() => { - return allOrders ? allOrders.filter((order) => !activeOrderUUIDs.includes(order.uuid)) : []; - }, [allOrders, activeOrderUUIDs]); + if (!allOrders || !activeOrders) { + return []; + } + + const filteredDrugOrders = allOrders.filter( + (order) => !activeOrders.some((activeOrder) => activeOrder.uuid === order.uuid), + ); + return sortOrdersByDateActivated(filteredDrugOrders); + }, [allOrders, activeOrders]); return { data: pastOrders, @@ -214,7 +227,7 @@ export function useRequireOutpatientQuantity(): { const results = useMemo( () => ({ - requireOutpatientQuantity: data?.data?.value === 'true', + requireOutpatientQuantity: data?.data?.value && data.data.value === 'true', error, isLoading, }), From d06ca5e5bcf930447a5fe5025a70df0a12a3f889 Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Tue, 29 Oct 2024 18:36:58 +0300 Subject: [PATCH 23/30] Code refactor --- .../active-medications.component.tsx | 14 +---- .../src/api/api.ts | 11 +--- .../medications-summary.component.tsx | 57 +++++++------------ 3 files changed, 26 insertions(+), 56 deletions(-) diff --git a/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx b/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx index 34779e1fa..b2790968a 100644 --- a/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx +++ b/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx @@ -12,7 +12,7 @@ interface ActiveMedicationsProps { const ActiveMedications: React.FC = ({ patient }) => { const { t } = useTranslation(); const displayText = t('activeMedicationsDisplayText', 'Active medications'); - const headerTitle = t('activeMedicationsHeaderTitle', 'Active Medications'); + const headerTitle = t('activeMedicationsHeaderTitle', 'active medications'); const { data: activePatientOrders, error, isLoading, isValidating } = usePatientOrders(patient?.id); @@ -22,20 +22,12 @@ const ActiveMedications: React.FC = ({ patient }) => { if (error) return ; - const activeMedications = activePatientOrders?.filter((order) => { - const isDateStoppedUnset = !order.dateStopped; - const isActionValid = order.action !== 'DISCONTINUE'; - const isAutoExpireDateValid = !order.autoExpireDate || new Date(order.autoExpireDate) > new Date(); - - return isDateStoppedUnset && isActionValid && isAutoExpireDateValid; - }); - - if (activeMedications?.length) { + if (activePatientOrders?.length) { return ( - data?.data?.results - ? sortOrdersByDateActivated(data.data.results.filter((order) => order.orderType.display === 'Drug Order')) - : null, - [data], - ); + const drugOrders = useMemo(() => (data?.data?.results ? sortOrdersByDateActivated(data.data.results) : null), [data]); return { data: data ? drugOrders : null, diff --git a/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx b/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx index 833b08c89..b5c174a51 100644 --- a/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx +++ b/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx @@ -1,9 +1,8 @@ -import React, { useMemo } from 'react'; +import React from 'react'; import { useTranslation } from 'react-i18next'; import { DataTableSkeleton } from '@carbon/react'; -import { parseDate } from '@openmrs/esm-framework'; import { EmptyState, ErrorState, useLaunchWorkspaceRequiringVisit, type Order } from '@openmrs/esm-patient-common-lib'; -import { usePatientOrders } from '../api'; +import { useActivePatientOrders, usePastPatientOrders } from '../api'; import MedicationsDetailsTable from '../components/medications-details-table.component'; import { type AddDrugOrderWorkspaceAdditionalProps } from '../add-drug-order/add-drug-order.workspace'; @@ -17,48 +16,34 @@ export default function MedicationsSummary({ patient }: MedicationsSummaryProps) useLaunchWorkspaceRequiringVisit('add-drug-order'); const { - data: allOrders, - error: error, - isLoading: isLoading, - isValidating: isValidating, - } = usePatientOrders(patient?.id); + data: activeOrders, + error: activeOrdersError, + isLoading: isActiveLoading, + isValidating: isActiveValidating, + } = useActivePatientOrders(patient?.id); - const [pastOrders, activeOrders] = useMemo(() => { - const currentDate = new Date(); - const pastOrders: Array = []; - const activeOrders: Array = []; - - if (allOrders) { - for (let i = 0; i < allOrders.length; i++) { - const order = allOrders[i]; - if (order.autoExpireDate && parseDate(order.autoExpireDate) < currentDate) { - pastOrders.push(order); - } else if (order.dateStopped && parseDate(order.dateStopped) < currentDate) { - pastOrders.push(order); - } else { - activeOrders.push(order); - } - } - } - - return [pastOrders, activeOrders]; - }, [allOrders]); + const { + data: pastOrders, + error: pastOrdersError, + isLoading: isPastLoading, + isValidating: isPastValidating, + } = usePastPatientOrders(patient?.id); return (
{(() => { const displayText = t('activeMedicationsDisplayText', 'Active medications'); - const headerTitle = t('activeMedicationsHeaderTitle', 'active medications'); + const headerTitle = t('activeMedicationsHeaderTitle', 'Active Medications'); - if (isLoading) return ; + if (isActiveLoading) return ; - if (error) return ; + if (activeOrdersError) return ; if (activeOrders?.length) { return ( {(() => { const displayText = t('pastMedicationsDisplayText', 'Past medications'); - const headerTitle = t('pastMedicationsHeaderTitle', 'past medications'); + const headerTitle = t('pastMedicationsHeaderTitle', 'Past Medications'); - if (isLoading) return ; + if (isPastLoading) return ; - if (error) return ; + if (pastOrdersError) return ; if (pastOrders?.length) { return ( Date: Tue, 29 Oct 2024 20:53:11 +0300 Subject: [PATCH 24/30] Code refactor --- .../esm-patient-medications-app/src/api/api.ts | 9 +++------ .../medications-summary.component.tsx | 18 +++++++++--------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/packages/esm-patient-medications-app/src/api/api.ts b/packages/esm-patient-medications-app/src/api/api.ts index 9c7b5c839..da328fab7 100644 --- a/packages/esm-patient-medications-app/src/api/api.ts +++ b/packages/esm-patient-medications-app/src/api/api.ts @@ -36,7 +36,7 @@ function sortOrdersByDateActivated(orders: any[]) { export function usePatientOrders(patientUuid: string) { const { drugOrderTypeUUID } = useConfig() as ConfigObject; - const ordersUrl = `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&orderTypes=${drugOrderTypeUUID}&v=${customRepresentation}&excludeDiscontinueOrders=false`; + const ordersUrl = `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&orderTypes=${drugOrderTypeUUID}&v=${customRepresentation}&excludeDiscontinueOrders=true`; const { data, error, isLoading, isValidating } = useSWR, Error>( patientUuid ? ordersUrl : null, @@ -48,7 +48,7 @@ export function usePatientOrders(patientUuid: string) { [patientUuid], ); - const drugOrders = useMemo(() => (data?.data?.results ? sortOrdersByDateActivated(data.data.results) : null), [data]); + const drugOrders = useMemo(() => sortOrdersByDateActivated(data?.data?.results) ?? null, [data]); return { data: data ? drugOrders : null, @@ -78,10 +78,7 @@ export function useActivePatientOrders(patientUuid: string) { openmrsFetch, ); - const activeOrders = useMemo( - () => (data?.data?.results ? sortOrdersByDateActivated(data.data.results) : null), - [data], - ); + const activeOrders = useMemo(() => sortOrdersByDateActivated(data?.data?.results) ?? null, [data]); return { data: activeOrders, diff --git a/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx b/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx index b5c174a51..c87d1e8a2 100644 --- a/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx +++ b/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx @@ -18,15 +18,15 @@ export default function MedicationsSummary({ patient }: MedicationsSummaryProps) const { data: activeOrders, error: activeOrdersError, - isLoading: isActiveLoading, - isValidating: isActiveValidating, + isLoading: isLoadingActiveOrders, + isValidating: isValidatingActiveOrders, } = useActivePatientOrders(patient?.id); const { data: pastOrders, error: pastOrdersError, - isLoading: isPastLoading, - isValidating: isPastValidating, + isLoading: isLoadingPastOrders, + isValidating: isValidatingPastOrders, } = usePastPatientOrders(patient?.id); return ( @@ -34,16 +34,16 @@ export default function MedicationsSummary({ patient }: MedicationsSummaryProps)
{(() => { const displayText = t('activeMedicationsDisplayText', 'Active medications'); - const headerTitle = t('activeMedicationsHeaderTitle', 'Active Medications'); + const headerTitle = t('activeMedicationsHeaderTitle', 'active medications'); - if (isActiveLoading) return ; + if (isLoadingActiveOrders) return ; if (activeOrdersError) return ; if (activeOrders?.length) { return ( ; + if (isValidatingPastOrders) return ; if (pastOrdersError) return ; if (pastOrders?.length) { return ( Date: Tue, 29 Oct 2024 21:16:51 +0300 Subject: [PATCH 25/30] Updates the hook from usePatientOrders to useActivePatientOrders --- .../src/active-medications/active-medications.component.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx b/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx index b2790968a..dcfa0a82e 100644 --- a/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx +++ b/packages/esm-patient-medications-app/src/active-medications/active-medications.component.tsx @@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next'; import { DataTableSkeleton } from '@carbon/react'; import { EmptyState, ErrorState, useLaunchWorkspaceRequiringVisit } from '@openmrs/esm-patient-common-lib'; import MedicationsDetailsTable from '../components/medications-details-table.component'; -import { usePatientOrders } from '../api/api'; +import { useActivePatientOrders } from '../api/api'; interface ActiveMedicationsProps { patient: fhir.Patient; @@ -14,7 +14,7 @@ const ActiveMedications: React.FC = ({ patient }) => { const displayText = t('activeMedicationsDisplayText', 'Active medications'); const headerTitle = t('activeMedicationsHeaderTitle', 'active medications'); - const { data: activePatientOrders, error, isLoading, isValidating } = usePatientOrders(patient?.id); + const { data: activePatientOrders, error, isLoading, isValidating } = useActivePatientOrders(patient?.id); const launchAddDrugWorkspace = useLaunchWorkspaceRequiringVisit('add-drug-order'); From b430dbb7eb6fc7d13a2c056d8f808c5cee9b47a4 Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Tue, 29 Oct 2024 21:52:25 +0300 Subject: [PATCH 26/30] Display Discontinued tag --- .../src/components/medications-details-table.component.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx index 55aa7c84c..015baee49 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx @@ -104,7 +104,7 @@ const MedicationsDetailsTable: React.FC = ({ {capitalize(medication.drug?.display)}{' '} {medication.drug?.strength && <>— {medication.drug?.strength.toLowerCase()}}{' '} {medication.drug?.dosageForm?.display && <>— {medication.drug.dosageForm.display.toLowerCase()}} - {(medication.dateStopped || medication.autoExpireDate) && medication.action === 'DISCONTINUE' && ( + {(medication.dateStopped || medication.autoExpireDate) && ( Date: Wed, 30 Oct 2024 15:02:25 +0300 Subject: [PATCH 27/30] Display Discontinued tag on past medication --- .../src/components/medications-details-table.component.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx index 015baee49..ca8aac27f 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx @@ -104,13 +104,13 @@ const MedicationsDetailsTable: React.FC = ({ {capitalize(medication.drug?.display)}{' '} {medication.drug?.strength && <>— {medication.drug?.strength.toLowerCase()}}{' '} {medication.drug?.dosageForm?.display && <>— {medication.drug.dosageForm.display.toLowerCase()}} - {(medication.dateStopped || medication.autoExpireDate) && ( + {medication.dateStopped && ( {t('discontinuedDate', 'Discontinued date').toUpperCase()} — - {formatDate(new Date(medication.dateStopped || medication.autoExpireDate))} + {formatDate(new Date(medication.dateStopped))} } > From 41d835b4411151511240ff88cd6d4480fad285cf Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Thu, 31 Oct 2024 13:03:41 +0300 Subject: [PATCH 28/30] Code refactor --- packages/esm-patient-medications-app/src/api/api.ts | 4 ++-- .../components/medications-details-table.component.tsx | 10 +--------- .../src/components/medications-details-table.scss | 2 +- .../medications-summary.component.tsx | 2 +- .../esm-patient-medications-app/translations/en.json | 1 - 5 files changed, 5 insertions(+), 14 deletions(-) diff --git a/packages/esm-patient-medications-app/src/api/api.ts b/packages/esm-patient-medications-app/src/api/api.ts index da328fab7..acceaf57e 100644 --- a/packages/esm-patient-medications-app/src/api/api.ts +++ b/packages/esm-patient-medications-app/src/api/api.ts @@ -34,7 +34,7 @@ function sortOrdersByDateActivated(orders: any[]) { * @param patientUuid The UUID of the patient whose orders should be fetched. */ export function usePatientOrders(patientUuid: string) { - const { drugOrderTypeUUID } = useConfig() as ConfigObject; + const { drugOrderTypeUUID } = useConfig(); const ordersUrl = `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&orderTypes=${drugOrderTypeUUID}&v=${customRepresentation}&excludeDiscontinueOrders=true`; @@ -65,7 +65,7 @@ export function usePatientOrders(patientUuid: string) { * @param patientUuid The UUID of the patient whose active orders should be fetched. */ export function useActivePatientOrders(patientUuid: string) { - const { drugOrderTypeUUID } = useConfig() as ConfigObject; + const { drugOrderTypeUUID } = useConfig(); const ordersUrl = useMemo( () => patientUuid diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx index ca8aac27f..3c0f60291 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx @@ -105,15 +105,7 @@ const MedicationsDetailsTable: React.FC = ({ {medication.drug?.strength && <>— {medication.drug?.strength.toLowerCase()}}{' '} {medication.drug?.dosageForm?.display && <>— {medication.drug.dosageForm.display.toLowerCase()}} {medication.dateStopped && ( - - {t('discontinuedDate', 'Discontinued date').toUpperCase()} — - {formatDate(new Date(medication.dateStopped))} - - } - > + {formatDate(new Date(medication.dateStopped))}}> {t('discontinued', 'Discontinued')} diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.scss b/packages/esm-patient-medications-app/src/components/medications-details-table.scss index 5d31fab1e..af365c988 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.scss +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.scss @@ -69,7 +69,7 @@ .tag { margin: 0 !important; - margin-left: 0.5rem !important; + margin-left: ((layout.$spacing-03)) !important; border: none; text-transform: uppercase; } diff --git a/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx b/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx index c87d1e8a2..50ba16f51 100644 --- a/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx +++ b/packages/esm-patient-medications-app/src/medications-summary/medications-summary.component.tsx @@ -60,7 +60,7 @@ export default function MedicationsSummary({ patient }: MedicationsSummaryProps)
{(() => { const displayText = t('pastMedicationsDisplayText', 'Past medications'); - const headerTitle = t('pastMedicationsHeaderTitle', 'Past Medications'); + const headerTitle = t('pastMedicationsHeaderTitle', 'past medications'); if (isValidatingPastOrders) return ; diff --git a/packages/esm-patient-medications-app/translations/en.json b/packages/esm-patient-medications-app/translations/en.json index d0ef8ef3b..dc9bf9021 100644 --- a/packages/esm-patient-medications-app/translations/en.json +++ b/packages/esm-patient-medications-app/translations/en.json @@ -12,7 +12,6 @@ "discard": "Discard", "discontinue": "Discontinue", "discontinued": "Discontinued", - "discontinued_Caps": "DISCONTINUED", "discontinuedDate": "Discontinued date", "dispensingInformation": "3. Dispensing instructions", "dosageInstructions": "1. Dosage instructions", From d51ef144d91ab5cb510c2f299b73e2dffa4769e6 Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Fri, 1 Nov 2024 00:20:42 +0300 Subject: [PATCH 29/30] fix the failing test --- .../src/active-medications/active-medications.test.tsx | 2 +- .../src/components/medications-details-table.scss | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/esm-patient-medications-app/src/active-medications/active-medications.test.tsx b/packages/esm-patient-medications-app/src/active-medications/active-medications.test.tsx index 987264612..b21173256 100644 --- a/packages/esm-patient-medications-app/src/active-medications/active-medications.test.tsx +++ b/packages/esm-patient-medications-app/src/active-medications/active-medications.test.tsx @@ -90,7 +90,7 @@ describe('ActiveMedications', () => { const expectedTableRows = [ /14-Aug-2023 Admin User Acetaminophen 325 mg — 325mg — tablet DOSE 2 tablet — oral — twice daily — indefinite duration — take it sometimes INDICATION Bad boo-boo/, - /14-Aug-2023 Admin User Acetaminophen 325 mg — 325mg — tablet DOSE 2 tablets — oral — twice daily — indefinite duration INDICATION Not specified — DISCONTINUED Tag Tooltip DATE 14-Aug-2023 DISCONTINUED/, + /14-Aug-2023 Admin User Acetaminophen 325 mg — 325mg — tablet 14-Aug-2023 DOSE 2 tablet — oral — twice daily — indefinite duration INDICATION No good 0/, /14-Aug-2023 Admin User Sulfacetamide 0.1 — 10% DOSE 1 application — for {{duration}} weeks — REFILLS 1 — apply it INDICATION Pain — QUANTITY 8 Application/, /14-Aug-2023 Admin User Aspirin 162.5mg — 162.5mg — tablet DOSE 1 tablet — oral — once daily — for {{duration}} days INDICATION Heart — QUANTITY 30 Tablet/, ]; diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.scss b/packages/esm-patient-medications-app/src/components/medications-details-table.scss index af365c988..0f2418605 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.scss +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.scss @@ -69,7 +69,7 @@ .tag { margin: 0 !important; - margin-left: ((layout.$spacing-03)) !important; + margin-left: layout.$spacing-03 !important; border: none; text-transform: uppercase; } From e242b339895f796d012055ef479e0d3737f4bb87 Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Fri, 1 Nov 2024 00:31:58 +0300 Subject: [PATCH 30/30] Fix the tooltip position --- .../src/components/medications-details-table.component.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx index 3c0f60291..813239cb2 100644 --- a/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx +++ b/packages/esm-patient-medications-app/src/components/medications-details-table.component.tsx @@ -105,7 +105,7 @@ const MedicationsDetailsTable: React.FC = ({ {medication.drug?.strength && <>— {medication.drug?.strength.toLowerCase()}}{' '} {medication.drug?.dosageForm?.display && <>— {medication.drug.dosageForm.display.toLowerCase()}} {medication.dateStopped && ( - {formatDate(new Date(medication.dateStopped))}}> + {formatDate(new Date(medication.dateStopped))}}> {t('discontinued', 'Discontinued')}