= ({
{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')}