Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(refactor) Replace deprecated useSessionUser with useSession #661

Merged
merged 3 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import {
TimePicker,
} from 'carbon-components-react';
import { amPm, convertTime12to24, DefaultWorkspaceProps } from '@openmrs/esm-patient-common-lib';
import { useLocations, useSessionUser, showToast, showNotification, useLayoutType } from '@openmrs/esm-framework';
import { useLocations, useSession, showToast, showNotification, useLayoutType } from '@openmrs/esm-framework';
import { appointmentsSearchUrl, createAppointment, useAppointmentService } from './appointments.resource';
import styles from './appointments-form.scss';
import { AppointmentPayload } from '../types';
import styles from './appointments-form.scss';

const appointmentTypes = [{ name: 'Scheduled' }, { name: 'WalkIn' }];

Expand All @@ -26,7 +26,7 @@ const AppointmentsForm: React.FC<DefaultWorkspaceProps> = ({ patientUuid, closeW
const isTablet = useLayoutType() === 'tablet';
const { mutate } = useSWRConfig();
const locations = useLocations();
const session = useSessionUser();
const session = useSession();
const [appointmentNote, setAppointmentNote] = useState('');
const [selectedAppointmentType, setSelectedAppointmentType] = useState('');
const [selectedService, setSelectedService] = useState('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ jest.mock('@openmrs/esm-framework', () => {

return {
...originalModule,
showToast: jest.fn(),
useLocations: jest.fn().mockImplementation(() => mockLocations),
useSessionUser: jest.fn().mockImplementation(() => mockSessionDataResponse.data),
useSession: jest.fn().mockImplementation(() => mockSessionDataResponse.data),
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
showNotification,
showToast,
useLocations,
useSessionUser,
useSession,
ExtensionSlot,
NewVisitPayload,
toOmrsIsoString,
Expand All @@ -51,7 +51,7 @@ const StartVisitForm: React.FC<DefaultWorkspaceProps> = ({ patientUuid, closeWor
const { t } = useTranslation();
const isTablet = useLayoutType() === 'tablet';
const locations = useLocations();
const sessionUser = useSessionUser();
const sessionUser = useSession();
const config = useConfig() as ChartConfig;
const [contentSwitcherIndex, setContentSwitcherIndex] = useState(config.showRecommendedVisitTypeTab ? 0 : 1);
const [isMissingVisitType, setIsMissingVisitType] = useState(false);
Expand Down
4 changes: 2 additions & 2 deletions packages/esm-patient-common-lib/src/offline/visit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
QueueItemDescriptor,
queueSynchronizationItem,
useConnectivity,
useSessionUser,
useSession,
useVisit,
Visit,
} from '@openmrs/esm-framework';
Expand Down Expand Up @@ -67,7 +67,7 @@ export function useOfflineVisit(patientUuid: string): ReturnType<typeof useVisit
*/
export function useAutoCreatedOfflineVisit(patientUuid: string, offlineVisitTypeUuid: string) {
const isOnline = useConnectivity();
const location = useSessionUser()?.sessionLocation?.uuid;
const location = useSession()?.sessionLocation?.uuid;
const { currentVisit, isValidating, error, mutate } = useOfflineVisit(patientUuid);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
showNotification,
showToast,
useLayoutType,
useSessionUser,
useSession,
} from '@openmrs/esm-framework';
import {
Tile,
Expand All @@ -34,7 +34,7 @@ const searchTimeoutInMs = 500;
const ConditionsForm: React.FC<DefaultWorkspaceProps> = ({ closeWorkspace, patientUuid }) => {
const { t } = useTranslation();
const isTablet = useLayoutType() === 'tablet';
const session = useSessionUser();
const session = useSession();
const { mutate } = useSWRConfig();
const [clinicalStatus, setClinicalStatus] = React.useState('active');
const [endDate, setEndDate] = React.useState(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { SyntheticEvent, useEffect, useState } from 'react';
import styles from './immunizations-form.scss';
import { showNotification, showToast, useSessionUser, useVisit, useLayoutType } from '@openmrs/esm-framework';
import { showNotification, showToast, useSession, useVisit, useLayoutType } from '@openmrs/esm-framework';
import { useTranslation } from 'react-i18next';
import { savePatientImmunization } from './immunizations.resource';
import { mapToFHIRImmunizationResource } from './immunization-mapper';
Expand Down Expand Up @@ -53,7 +53,7 @@ const ImmunizationsForm: React.FC<DefaultWorkspaceProps> = ({ patientUuid, close
setFormState((state) => ({ ...state, [name]: value }));

const { t } = useTranslation();
const currentUser = useSessionUser();
const currentUser = useSession();
const { currentVisit } = useVisit(patientUuid);
const isTablet = useLayoutType() === 'tablet';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
showToast,
useConfig,
useLayoutType,
useSessionUser,
useSession,
} from '@openmrs/esm-framework';
import { convertToObsPayload } from './visit-note.util';
import { fetchDiagnosisByName, fetchLocationByUuid, fetchProviderByUuid, saveVisitNote } from './visit-notes.resource';
Expand All @@ -46,7 +46,7 @@ const encountersCustomRepresentation =
const VisitNotesForm: React.FC<DefaultWorkspaceProps> = ({ closeWorkspace, patientUuid }) => {
const { t } = useTranslation();
const isTablet = useLayoutType() === 'tablet';
const session = useSessionUser();
const session = useSession();
const { mutate } = useSWRConfig();
const config = useConfig() as ConfigObject;
const { clinicianEncounterRole, encounterNoteTextConceptUuid, encounterTypeUuid, formConceptUuid } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import userEvent from '@testing-library/user-event';
import { screen, render, waitFor } from '@testing-library/react';
import { of } from 'rxjs/internal/observable/of';
import { createErrorHandler, showNotification, showToast, useConfig, useSessionUser } from '@openmrs/esm-framework';
import { createErrorHandler, showNotification, showToast, useConfig, useSession } from '@openmrs/esm-framework';
import { fetchDiagnosisByName, fetchLocationByUuid, fetchProviderByUuid, saveVisitNote } from './visit-notes.resource';
import { ConfigMock } from '../../../../__mocks__/chart-widgets-config.mock';
import { mockPatient } from '../../../../__mocks__/patient.mock';
Expand All @@ -29,7 +29,7 @@ const mockSaveVisitNote = saveVisitNote as jest.Mock;
const mockShowNotification = showNotification as jest.Mock;
const mockShowToast = showToast as jest.Mock;
const mockUseConfig = useConfig as jest.Mock;
const mockUseSessionUser = useSessionUser as jest.Mock;
const mockUseSession = useSession as jest.Mock;

jest.mock('lodash-es/debounce', () => jest.fn((fn) => fn));

Expand Down Expand Up @@ -58,7 +58,7 @@ describe('Visit notes form: ', () => {
mockFetchProviderByUuid.mockResolvedValue(mockFetchProviderByUuidResponse);
mockFetchDiagnosisByName.mockReturnValue(of(diagnosisSearchResponse.results));
mockUseConfig.mockReturnValue(ConfigMock);
mockUseSessionUser.mockReturnValue(mockSessionDataResponse);
mockUseSession.mockReturnValue(mockSessionDataResponse);
});

it('renders the visit notes form with all the relevant fields and values', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
createErrorHandler,
showNotification,
showToast,
useSessionUser,
useSession,
useLocations,
useLayoutType,
} from '@openmrs/esm-framework';
Expand All @@ -35,7 +35,7 @@ import styles from './programs-form.scss';
const ProgramsForm: React.FC<DefaultWorkspaceProps> = ({ closeWorkspace, patientUuid }) => {
const { t } = useTranslation();
const isTablet = useLayoutType() === 'tablet';
const session = useSessionUser();
const session = useSession();
const availableLocations = useLocations();
const { mutate } = useSWRConfig();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import {
showNotification,
useConfig,
useLayoutType,
useSessionUser,
useSession,
} from '@openmrs/esm-framework';
import { DefaultWorkspaceProps, useVitalsConceptMetadata } from '@openmrs/esm-patient-common-lib';
import { Column, Grid, Row, Button, ButtonSet, Form } from 'carbon-components-react';
import { calculateBMI, isInNormalRange } from './vitals-biometrics-form.utils';
import { savePatientVitals } from '../vitals.resource';
import { ConfigObject } from '../../config-schema';
import styles from './vitals-biometrics-form.component.scss';
import VitalsBiometricInput from './vitals-biometrics-input.component';
import styles from './vitals-biometrics-form.component.scss';

export interface PatientVitalsAndBiometrics {
systolicBloodPressure: string;
Expand All @@ -34,7 +34,7 @@ export interface PatientVitalsAndBiometrics {
const VitalsAndBiometricForms: React.FC<DefaultWorkspaceProps> = ({ patientUuid, closeWorkspace }) => {
const { t } = useTranslation();
const isTablet = useLayoutType() === 'tablet';
const session = useSessionUser();
const session = useSession();
const config = useConfig() as ConfigObject;
const { cache, mutate }: { cache: any; mutate: Function } = useSWRConfig();
const { data: conceptUnits, conceptMetadata } = useVitalsConceptMetadata();
Expand Down
Loading