From aa5c953fbeb1b1cfb9c0565046910569b161e484 Mon Sep 17 00:00:00 2001 From: Vineet Sharma Date: Tue, 29 Oct 2024 15:13:51 +0530 Subject: [PATCH] Remove the dependency of gettting patient uuid from the URL --- .../src/add-drug-order/add-drug-order.workspace.tsx | 4 +++- .../add-drug-order/drug-order-form.component.tsx | 11 +++++++++-- .../drug-search/drug-search.component.tsx | 4 +++- .../order-basket-search-results.component.tsx | 12 ++++++++---- .../add-lab-order/add-lab-order.workspace.tsx | 3 ++- .../test-results/grouped-timeline/useObstreeData.ts | 6 ++---- .../panel-view/panel-view.component.tsx | 2 +- .../src/test-results/panel-view/usePanelData.tsx | 13 ++++++++----- .../print-modal/print-modal.extension.tsx | 2 +- .../results-viewer/results-viewer.extension.tsx | 2 +- .../tree-view/tree-view-wrapper.component.tsx | 2 +- .../test-results/tree-view/tree-view.component.tsx | 2 +- 12 files changed, 40 insertions(+), 23 deletions(-) diff --git a/packages/esm-patient-medications-app/src/add-drug-order/add-drug-order.workspace.tsx b/packages/esm-patient-medications-app/src/add-drug-order/add-drug-order.workspace.tsx index 9b31dc15e4..4b373024f4 100644 --- a/packages/esm-patient-medications-app/src/add-drug-order/add-drug-order.workspace.tsx +++ b/packages/esm-patient-medications-app/src/add-drug-order/add-drug-order.workspace.tsx @@ -25,6 +25,7 @@ export default function AddDrugOrderWorkspace({ closeWorkspace, closeWorkspaceWithSavedChanges, promptBeforeClosing, + patientUuid, }: AddDrugOrderWorkspace) { const { t } = useTranslation(); const isTablet = useLayoutType() === 'tablet'; @@ -89,7 +90,7 @@ export default function AddDrugOrderWorkspace({ )} - + ); } else { @@ -99,6 +100,7 @@ export default function AddDrugOrderWorkspace({ onSave={saveDrugOrder} onCancel={cancelDrugOrder} promptBeforeClosing={promptBeforeClosing} + patientUuid={patientUuid} /> ); } diff --git a/packages/esm-patient-medications-app/src/add-drug-order/drug-order-form.component.tsx b/packages/esm-patient-medications-app/src/add-drug-order/drug-order-form.component.tsx index 3480dc3d40..fe2a4d5e62 100644 --- a/packages/esm-patient-medications-app/src/add-drug-order/drug-order-form.component.tsx +++ b/packages/esm-patient-medications-app/src/add-drug-order/drug-order-form.component.tsx @@ -57,6 +57,7 @@ export interface DrugOrderFormProps { onSave: (finalizedOrder: DrugOrderBasketItem) => void; onCancel: () => void; promptBeforeClosing: (testFcn: () => boolean) => void; + patientUuid: string; } const createMedicationOrderFormSchema = (requireOutpatientQuantity: boolean, t: TFunction) => { @@ -215,7 +216,13 @@ function InputWrapper({ children }) { ); } -export function DrugOrderForm({ initialOrderBasketItem, onSave, onCancel, promptBeforeClosing }: DrugOrderFormProps) { +export function DrugOrderForm({ + initialOrderBasketItem, + onSave, + onCancel, + promptBeforeClosing, + patientUuid, +}: DrugOrderFormProps) { const { t } = useTranslation(); const config = useConfig(); const isTablet = useLayoutType() === 'tablet'; @@ -354,7 +361,7 @@ export function DrugOrderForm({ initialOrderBasketItem, onSave, onCancel, prompt }, []); const [showStickyMedicationHeader, setShowMedicationHeader] = useState(false); - const { patient, isLoading: isLoadingPatientDetails } = usePatient(); + const { patient, isLoading: isLoadingPatientDetails } = usePatient(patientUuid); const patientName = patient ? getPatientName(patient) : ''; const { maxDispenseDurationInDays } = useConfig(); diff --git a/packages/esm-patient-medications-app/src/add-drug-order/drug-search/drug-search.component.tsx b/packages/esm-patient-medications-app/src/add-drug-order/drug-search/drug-search.component.tsx index 59fdf95a8c..71a9eb4abd 100644 --- a/packages/esm-patient-medications-app/src/add-drug-order/drug-search/drug-search.component.tsx +++ b/packages/esm-patient-medications-app/src/add-drug-order/drug-search/drug-search.component.tsx @@ -10,9 +10,10 @@ import styles from './order-basket-search.scss'; export interface DrugSearchProps { openOrderForm: (searchResult: DrugOrderBasketItem) => void; + patientUuid: string; } -export default function DrugSearch({ openOrderForm }: DrugSearchProps) { +export default function DrugSearch({ openOrderForm, patientUuid }: DrugSearchProps) { const { t } = useTranslation(); const isTablet = useLayoutType() === 'tablet'; const [searchTerm, setSearchTerm] = useState(''); @@ -51,6 +52,7 @@ export default function DrugSearch({ openOrderForm }: DrugSearchProps) { searchTerm={debouncedSearchTerm} openOrderForm={openOrderForm} focusAndClearSearchInput={focusAndClearSearchInput} + patientUuid={patientUuid} /> {isTablet && (
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 6f566a79c0..ed77683d6c 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 @@ -29,17 +29,20 @@ export interface OrderBasketSearchResultsProps { searchTerm: string; openOrderForm: (searchResult: DrugOrderBasketItem) => void; focusAndClearSearchInput: () => void; + patientUuid: string; } interface DrugSearchResultItemProps { drug: DrugSearchResult; openOrderForm: (searchResult: DrugOrderBasketItem) => void; + patientUuid: string; } export default function OrderBasketSearchResults({ searchTerm, openOrderForm, focusAndClearSearchInput, + patientUuid, }: OrderBasketSearchResultsProps) { const { t } = useTranslation(); const isTablet = useLayoutType() === 'tablet'; @@ -105,17 +108,18 @@ export default function OrderBasketSearchResults({
- {drugs?.map((drug) => )} + {drugs?.map((drug) => ( + + ))}
); } -const DrugSearchResultItem: React.FC = ({ drug, openOrderForm }) => { +const DrugSearchResultItem: React.FC = ({ drug, openOrderForm, patientUuid }) => { 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(patientUuid, 'ACTIVE'); const drugAlreadyInBasket = useMemo( () => orders?.some((order) => ordersEqual(order, getTemplateOrderBasketItem(drug))), [orders, drug], diff --git a/packages/esm-patient-tests-app/src/lab-orders/add-lab-order/add-lab-order.workspace.tsx b/packages/esm-patient-tests-app/src/lab-orders/add-lab-order/add-lab-order.workspace.tsx index eedcd66017..9380de228f 100644 --- a/packages/esm-patient-tests-app/src/lab-orders/add-lab-order/add-lab-order.workspace.tsx +++ b/packages/esm-patient-tests-app/src/lab-orders/add-lab-order/add-lab-order.workspace.tsx @@ -34,10 +34,11 @@ export default function AddLabOrderWorkspace({ closeWorkspace, closeWorkspaceWithSavedChanges, promptBeforeClosing, + patientUuid, }: AddLabOrderWorkspace) { const { t } = useTranslation(); const isTablet = useLayoutType() === 'tablet'; - const { patient, isLoading: isLoadingPatient, patientUuid } = usePatient(); + const { patient, isLoading: isLoadingPatient } = usePatient(patientUuid); const [currentLabOrder, setCurrentLabOrder] = useState(initialOrder as LabOrderBasketItem); const patientName = patient ? getPatientName(patient) : ''; diff --git a/packages/esm-patient-tests-app/src/test-results/grouped-timeline/useObstreeData.ts b/packages/esm-patient-tests-app/src/test-results/grouped-timeline/useObstreeData.ts index 4281aba00a..45d3e83ce3 100644 --- a/packages/esm-patient-tests-app/src/test-results/grouped-timeline/useObstreeData.ts +++ b/packages/esm-patient-tests-app/src/test-results/grouped-timeline/useObstreeData.ts @@ -42,8 +42,7 @@ const augmentObstreeData = (node: ObsTreeNode, prefix: string | undefined) => { return { ...outData } as ObsTreeNode; }; -const useGetObstreeData = (conceptUuid: string) => { - const { patientUuid } = usePatient(); +const useGetObstreeData = (patientUuid: string, conceptUuid: string) => { const response = useSWR, Error>( `${restBaseUrl}/obstree?patient=${patientUuid}&concept=${conceptUuid}`, openmrsFetch, @@ -64,8 +63,7 @@ const useGetObstreeData = (conceptUuid: string) => { return result; }; -const useGetManyObstreeData = (uuidArray: Array) => { - const { patientUuid } = usePatient(); +const useGetManyObstreeData = (patientUuid: string, uuidArray: Array) => { const getObstreeUrl = (index: number) => { if (index < uuidArray.length && patientUuid) { return `${restBaseUrl}/obstree?patient=${patientUuid}&concept=${uuidArray[index]}`; diff --git a/packages/esm-patient-tests-app/src/test-results/panel-view/panel-view.component.tsx b/packages/esm-patient-tests-app/src/test-results/panel-view/panel-view.component.tsx index 1ee970e668..97795e4f40 100644 --- a/packages/esm-patient-tests-app/src/test-results/panel-view/panel-view.component.tsx +++ b/packages/esm-patient-tests-app/src/test-results/panel-view/panel-view.component.tsx @@ -33,7 +33,7 @@ const PanelView: React.FC = ({ expanded, testUuid, basePath, typ const layout = useLayoutType(); const isTablet = layout === 'tablet'; const trendlineView = testUuid && type === 'trendline'; - const { panels, isLoading, groupedObservations } = usePanelData(); + const { panels, isLoading, groupedObservations } = usePanelData(patientUuid); const [searchTerm, setSearchTerm] = useState(''); const [activePanel, setActivePanel] = useState(null); diff --git a/packages/esm-patient-tests-app/src/test-results/panel-view/usePanelData.tsx b/packages/esm-patient-tests-app/src/test-results/panel-view/usePanelData.tsx index 0e050581b3..8b6cc6eec9 100644 --- a/packages/esm-patient-tests-app/src/test-results/panel-view/usePanelData.tsx +++ b/packages/esm-patient-tests-app/src/test-results/panel-view/usePanelData.tsx @@ -1,5 +1,5 @@ import { useCallback, useEffect, useMemo } from 'react'; -import { type FetchResponse, openmrsFetch, usePatient, restBaseUrl } from '@openmrs/esm-framework'; +import { type FetchResponse, openmrsFetch, restBaseUrl } from '@openmrs/esm-framework'; import useSWRInfinite from 'swr/infinite'; import { extractMetaInformation, getConceptUuid } from './helper'; import { @@ -10,8 +10,7 @@ import { type ObsRecord, } from '../../types'; -export function useObservations() { - const { patientUuid } = usePatient(); +export function useObservations(patientUuid: string) { const getUrl = useCallback( (pageIndex: number, prevPageData: FetchResponse>) => { if (prevPageData && !prevPageData?.data?.link.some(({ relation }) => relation === 'next')) { @@ -93,8 +92,12 @@ function useConcepts(conceptUuids: Array) { return results; } -export default function usePanelData() { - const { observations: fhirObservations, conceptUuids, isLoading: isLoadingObservations } = useObservations(); +export default function usePanelData(patientUuid: string) { + const { + observations: fhirObservations, + conceptUuids, + isLoading: isLoadingObservations, + } = useObservations(patientUuid); const { concepts } = useConcepts(conceptUuids); const conceptData: Record = useMemo( diff --git a/packages/esm-patient-tests-app/src/test-results/print-modal/print-modal.extension.tsx b/packages/esm-patient-tests-app/src/test-results/print-modal/print-modal.extension.tsx index 093b01e685..0c0e6e42b4 100644 --- a/packages/esm-patient-tests-app/src/test-results/print-modal/print-modal.extension.tsx +++ b/packages/esm-patient-tests-app/src/test-results/print-modal/print-modal.extension.tsx @@ -38,7 +38,7 @@ function PrintModal({ patientUuid, closeDialog }) { const { t } = useTranslation(); const isTablet = useLayoutType() === 'tablet'; const session = useSession(); - const { panels } = usePanelData(); + const { panels } = usePanelData(patientUuid); const printContainerRef = useRef(null); const [selectedFromDate, setSelectedFromDate] = useState(null); const [selectedToDate, setSelectedToDate] = useState(null); diff --git a/packages/esm-patient-tests-app/src/test-results/results-viewer/results-viewer.extension.tsx b/packages/esm-patient-tests-app/src/test-results/results-viewer/results-viewer.extension.tsx index 8b4dc46534..4f5131292b 100644 --- a/packages/esm-patient-tests-app/src/test-results/results-viewer/results-viewer.extension.tsx +++ b/packages/esm-patient-tests-app/src/test-results/results-viewer/results-viewer.extension.tsx @@ -33,7 +33,7 @@ const RoutedResultsViewer: React.FC = ({ basePath, patientUu const { t } = useTranslation(); const config = useConfig(); const conceptUuids = config.resultsViewerConcepts.map((concept) => concept.conceptUuid) ?? []; - const { roots, isLoading, error } = useGetManyObstreeData(conceptUuids); + const { roots, isLoading, error } = useGetManyObstreeData(patientUuid, conceptUuids); if (error) { return ; diff --git a/packages/esm-patient-tests-app/src/test-results/tree-view/tree-view-wrapper.component.tsx b/packages/esm-patient-tests-app/src/test-results/tree-view/tree-view-wrapper.component.tsx index 341d5cbb94..2355524db8 100644 --- a/packages/esm-patient-tests-app/src/test-results/tree-view/tree-view-wrapper.component.tsx +++ b/packages/esm-patient-tests-app/src/test-results/tree-view/tree-view-wrapper.component.tsx @@ -20,7 +20,7 @@ const TreeViewWrapper: React.FC = (props) => { const { t } = useTranslation(); const config = useConfig(); const conceptUuids = config?.resultsViewerConcepts?.map((c) => c.conceptUuid) ?? []; - const { roots, isLoading, error } = useGetManyObstreeData(conceptUuids); + const { roots, isLoading, error } = useGetManyObstreeData(props.patientUuid, conceptUuids); if (error) return ; diff --git a/packages/esm-patient-tests-app/src/test-results/tree-view/tree-view.component.tsx b/packages/esm-patient-tests-app/src/test-results/tree-view/tree-view.component.tsx index d38f28ae5e..078e5528d9 100644 --- a/packages/esm-patient-tests-app/src/test-results/tree-view/tree-view.component.tsx +++ b/packages/esm-patient-tests-app/src/test-results/tree-view/tree-view.component.tsx @@ -73,7 +73,7 @@ const TreeView: React.FC = ({ patientUuid, basePath, testUuid, is const { t } = useTranslation(); const { timelineData, resetTree, someChecked } = useContext(FilterContext); - const { panels, isLoading: isLoadingPanelData, groupedObservations } = usePanelData(); + const { panels, isLoading: isLoadingPanelData, groupedObservations } = usePanelData(patientUuid); if (tablet) { return (