Skip to content

Commit

Permalink
Update function name
Browse files Browse the repository at this point in the history
  • Loading branch information
vasharma05 committed Nov 2, 2024
1 parent 8673aa8 commit 7071e79
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 28 deletions.
10 changes: 7 additions & 3 deletions packages/esm-patient-common-lib/src/get-patient-uuid-from-url.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { getPatientUuidFromUrlOrStore } from './store/patient-chart-store';
import { getPatientUuidFromStore } from './store/patient-chart-store';

/**
* @deprecated This function is now replaced with `getPatientUuidFromUrlOrStore`. This function will be removed in upcoming releases.
* @deprecated This function is now replaced with `getPatientUuidFromStore`. This function will be removed in upcoming releases.
* @returns {string} patientUuid
*/
export const getPatientUuidFromUrl = getPatientUuidFromUrlOrStore;
export function getPatientUuidFromUrl(): string {
const match = /\/patient\/([a-zA-Z0-9\-]+)\/?/.exec(location.pathname);
const patientUuidFromUrl = match && match[1];
return patientUuidFromUrl || getPatientUuidFromStore();
}
4 changes: 2 additions & 2 deletions packages/esm-patient-common-lib/src/orders/postOrders.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { openmrsFetch, type OpenmrsResource, parseDate, restBaseUrl, type Visit } from '@openmrs/esm-framework';
import { getPatientUuidFromUrlOrStore } from '../store/patient-chart-store';
import { getPatientUuidFromStore } from '../store/patient-chart-store';
import { type OrderBasketStore, orderBasketStore } from './store';
import { type ExtractedOrderErrorObject, type OrderBasketItem, type OrderErrorObject, type OrderPost } from './types';

Expand Down Expand Up @@ -55,7 +55,7 @@ export async function postOrdersOnNewEncounter(
}

export async function postOrders(encounterUuid: string, abortController: AbortController) {
const patientUuid = getPatientUuidFromUrlOrStore();
const patientUuid = getPatientUuidFromStore();
const { items, postDataPrepFunctions }: OrderBasketStore = orderBasketStore.getState();
const patientItems = items[patientUuid];

Expand Down
8 changes: 4 additions & 4 deletions packages/esm-patient-common-lib/src/orders/useOrderBasket.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useStoreWithActions } from '@openmrs/esm-framework';
import type { OrderBasketItem, PostDataPrepFunction } from './types';
import { getPatientUuidFromUrlOrStore } from '../store/patient-chart-store';
import { getPatientUuidFromStore } from '../store/patient-chart-store';
import { useEffect } from 'react';
import { type OrderBasketStore, orderBasketStore } from './store';

Expand All @@ -10,7 +10,7 @@ const orderBasketStoreActions = {
grouping: string,
value: Array<OrderBasketItem> | (() => Array<OrderBasketItem>),
) {
const patientUuid = getPatientUuidFromUrlOrStore();
const patientUuid = getPatientUuidFromStore();
if (!Object.keys(state.postDataPrepFunctions).includes(grouping)) {
console.warn(`Programming error: You must register a postDataPrepFunction for grouping ${grouping} `);
}
Expand All @@ -35,7 +35,7 @@ const orderBasketStoreActions = {
};

function getOrderItems(items: OrderBasketStore['items'], grouping?: string | null): Array<OrderBasketItem> {
const patientUuid = getPatientUuidFromUrlOrStore();
const patientUuid = getPatientUuidFromStore();
const patientItems = items?.[patientUuid] ?? {};
return grouping ? patientItems[grouping] ?? [] : Object.values(patientItems).flat();
}
Expand All @@ -46,7 +46,7 @@ export interface ClearOrdersOptions {

function clearOrders(options?: ClearOrdersOptions) {
const exceptThoseMatchingFcn = options?.exceptThoseMatching ?? (() => false);
const patientUuid = getPatientUuidFromUrlOrStore();
const patientUuid = getPatientUuidFromStore();
const items = orderBasketStore.getState().items;
const patientItems = items[patientUuid] ?? {};
const newPatientItems = Object.fromEntries(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export function usePatientChartStore() {
* This function will get the patient UUID from either URL, or will look into the patient chart store.
* @returns {string} patientUuid
*/
export function getPatientUuidFromUrlOrStore() {
const match = /\/patient\/([a-zA-Z0-9\-]+)\/?/.exec(location.pathname);
const patientUuidFromUrl = match && match[1];
return patientUuidFromUrl || patientChartStore.getState().patientUuid;
export function getPatientUuidFromStore(): string {
return patientChartStore.getState()?.patientUuid;
}
4 changes: 2 additions & 2 deletions packages/esm-patient-common-lib/src/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
navigateAndLaunchWorkspace,
usePatient,
} from '@openmrs/esm-framework';
import { getPatientUuidFromUrlOrStore } from './store/patient-chart-store';
import { getPatientUuidFromStore } from './store/patient-chart-store';
import { useSystemVisitSetting } from './useSystemVisitSetting';
import { useVisitOrOfflineVisit } from './offline/visit';
import { useCallback } from 'react';
Expand All @@ -16,7 +16,7 @@ export interface DefaultPatientWorkspaceProps extends DefaultWorkspaceProps {
}

export function launchPatientWorkspace(workspaceName: string, additionalProps?: object) {
const patientUuid = getPatientUuidFromUrlOrStore();
const patientUuid = getPatientUuidFromStore();
launchWorkspace(workspaceName, {
patientUuid: patientUuid,
...additionalProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import React from 'react';
import { screen, render, renderHook } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { ActionMenuButton, launchWorkspace, useLayoutType, usePatient, useWorkspaces } from '@openmrs/esm-framework';
import {
getPatientUuidFromUrlOrStore,
type OrderBasketItem,
useOrderBasket,
usePatientChartStore,
} from '@openmrs/esm-patient-common-lib';
import { type OrderBasketItem, useOrderBasket } from '@openmrs/esm-patient-common-lib';
import { mockPatient } from 'tools';
import { orderBasketStore } from '@openmrs/esm-patient-common-lib/src/orders/store';
import OrderBasketActionButton from './order-basket-action-button.extension';
Expand Down Expand Up @@ -52,7 +47,7 @@ jest.mock('@openmrs/esm-patient-common-lib', () => {
return {
...originalModule,
getPatientUuidFromUrl: () => mockGetPatientUuidFromUrl(),
getPatientUuidFromUrlOrStore: () => mockGetPatientUuidFromUrl(),
getPatientUuidFromStore: () => mockGetPatientUuidFromUrl(),
launchPatientWorkspace: (arg) => mockLaunchPatientWorkspace(arg),
};
});
Expand All @@ -69,7 +64,7 @@ jest.mock('@openmrs/esm-patient-common-lib/src/launchStartVisitPrompt', () => {

jest.mock('@openmrs/esm-patient-common-lib/src/store/patient-chart-store', () => {
return {
getPatientUuidFromUrlOrStore: () => mockGetPatientUuidFromUrl(),
getPatientUuidFromStore: () => mockGetPatientUuidFromUrl(),
usePatientChartStore: () => ({ patientUuid: mockPatient.id }),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jest.mock('@openmrs/esm-patient-common-lib', () => ({
}));

jest.mock('@openmrs/esm-patient-common-lib/src/store/patient-chart-store', () => ({
getPatientUuidFromUrlOrStore: jest.fn(() => ptUuid),
getPatientUuidFromStore: jest.fn(() => ptUuid),
usePatientChartStore: jest.fn(() => ({
patientUuid: ptUuid,
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
TableRow,
} from '@carbon/react';
import { ArrowRightIcon, showModal, useLayoutType, isDesktop, formatDate } from '@openmrs/esm-framework';
import { getPatientUuidFromUrlOrStore, type OBSERVATION_INTERPRETATION } from '@openmrs/esm-patient-common-lib';
import { getPatientUuidFromStore, type OBSERVATION_INTERPRETATION } from '@openmrs/esm-patient-common-lib';
import { type RowData } from '../filter/filter-types';
import styles from './individual-results-table.scss';

Expand Down Expand Up @@ -56,7 +56,7 @@ const getClasses = (interpretation: OBSERVATION_INTERPRETATION) => {
const IndividualResultsTable: React.FC<IndividualResultsTableProps> = ({ isLoading, parent, subRows, index }) => {
const { t } = useTranslation();
const layout = useLayoutType();
const patientUuid = getPatientUuidFromUrlOrStore();
const patientUuid = getPatientUuidFromStore();

const headerTitle = t(parent.display);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import classNames from 'classnames';
import { formatDate, formatTime, parseDate, showModal } from '@openmrs/esm-framework';
import { type OBSERVATION_INTERPRETATION, getPatientUuidFromUrlOrStore } from '@openmrs/esm-patient-common-lib';
import { type OBSERVATION_INTERPRETATION, getPatientUuidFromStore } from '@openmrs/esm-patient-common-lib';
import { type ParsedTimeType } from '../filter/filter-types';
import type { ObsRecord } from '../../types';
import styles from './timeline.scss';
Expand Down Expand Up @@ -121,7 +121,7 @@ export const TimelineCell: React.FC<{
};

export const RowStartCell = ({ title, range, units, shadow = false, testUuid, isString = false }) => {
const patientUuid = getPatientUuidFromUrlOrStore();
const patientUuid = getPatientUuidFromStore();
const launchResultsDialog = (patientUuid: string, title: string, testUuid: string) => {
const dispose = showModal('timeline-results-modal', {
closeDeleteModal: () => dispose(),
Expand Down

0 comments on commit 7071e79

Please sign in to comment.