Skip to content

Commit

Permalink
(refactor) Refactor REST API calls to reuse restBaseUrl (#1168)
Browse files Browse the repository at this point in the history
This PR refactors some calls to the REST API to reuse the `restBaseUrl` variable.
  • Loading branch information
denniskigen authored Oct 2, 2024
1 parent 3ff1435 commit 1555681
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/apps/esm-login-app/src/login.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
fhirBaseUrl,
openmrsFetch,
refetchCurrentUser,
restBaseUrl,
type FetchResponse,
type Session,
useDebounce,
Expand Down Expand Up @@ -108,7 +109,7 @@ export function useLoginLocations(
export async function performLogin(username: string, password: string): Promise<{ data: Session }> {
const abortController = new AbortController();
const token = window.btoa(`${username}:${password}`);
const url = `/ws/rest/v1/session`;
const url = `${restBaseUrl}/session`;

return openmrsFetch(url, {
headers: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { openmrsFetch, queueSynchronizationItemFor } from '@openmrs/esm-framework/src/internal';
import { openmrsFetch, restBaseUrl, queueSynchronizationItemFor } from '@openmrs/esm-framework/src/internal';
import { userPropertyChange } from '../../constants';

export type PostUserProperties = (
Expand All @@ -12,7 +12,7 @@ export async function postUserPropertiesOnline(
userProperties: Record<string, string>,
abortController: AbortController,
): Promise<void> {
await openmrsFetch(`/ws/rest/v1/user/${userUuid}`, {
await openmrsFetch(`${restBaseUrl}/user/${userUuid}`, {
method: 'POST',
body: { userProperties },
headers: { 'Content-Type': 'application/json' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useMemo } from 'react';
import useSWR from 'swr';
import { type FetchResponse, openmrsFetch } from '@openmrs/esm-api';
import { type FetchResponse, openmrsFetch, restBaseUrl } from '@openmrs/esm-api';
import { type CohortMemberResponse } from './types';

export function usePatientListsForPatient(patientUuid: string) {
const customRepresentation = 'custom:(uuid,patient:ref,cohort:(uuid,name,startDate,endDate))';
const url = patientUuid ? `ws/rest/v1/cohortm/cohortmember?patient=${patientUuid}&v=${customRepresentation}` : null;
const url = patientUuid
? `${restBaseUrl}/cohortm/cohortmember?patient=${patientUuid}&v=${customRepresentation}`
: null;
const { data, isLoading } = useSWR<FetchResponse<CohortMemberResponse>, Error>(url, openmrsFetch);

const cohorts = data?.data?.results.map((ref) => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/** @module @category UI */
import React from 'react';
import { Tag } from '@carbon/react';
import { useConfig, usePrimaryIdentifierCode } from '@openmrs/esm-react-utils';
import React from 'react';
import styles from './patient-banner-patient-info.module.scss';
import { type StyleguideConfigObject } from '../../config-schema';
import styles from './patient-banner-patient-info.module.scss';

interface PatientBannerPatientIdentifierProps {
identifier: fhir.Identifier[] | undefined;
Expand Down

0 comments on commit 1555681

Please sign in to comment.