From 7ab9079cc6c7437d75dab1d2447324b3a59068c7 Mon Sep 17 00:00:00 2001 From: jwnasambu <33891016+jwnasambu@users.noreply.github.com> Date: Mon, 4 Mar 2024 11:44:11 +0300 Subject: [PATCH] (refactor) Replace usages of /ws/rest/v1 with restBaseUrl (#71) Replace usages of '/ws/rest/v1/' with restBaseUrl Co-authored-by: jwnasambu --- src/cohort-builder.resources.ts | 14 +++++++++----- .../saved-cohorts/saved-cohorts.resources.ts | 10 +++++++--- .../saved-queries/saved-queries.resources.ts | 10 +++++++--- .../search-concept/search-concept.resource.ts | 8 ++++++-- .../search-by-drug-orders.resources.ts | 6 +++--- .../search-by-encounters.resources.ts | 6 +++--- .../search-by-enrollments.resources.ts | 4 ++-- .../search-by-person-attributes.resource.ts | 4 ++-- .../search-history-options.resources.ts | 10 +++++++--- 9 files changed, 46 insertions(+), 26 deletions(-) diff --git a/src/cohort-builder.resources.ts b/src/cohort-builder.resources.ts index 0c5974e..61d580d 100644 --- a/src/cohort-builder.resources.ts +++ b/src/cohort-builder.resources.ts @@ -1,4 +1,8 @@ -import { openmrsFetch, FetchResponse } from "@openmrs/esm-framework"; +import { + openmrsFetch, + FetchResponse, + restBaseUrl, +} from "@openmrs/esm-framework"; import useSWRImmutable from "swr/immutable"; import { Patient, SearchParams, DropdownValue, Response } from "./types"; @@ -13,7 +17,7 @@ interface SearchResults { export const search = async (searchParams: SearchParams) => { const searchResults: FetchResponse = await openmrsFetch( - "/ws/rest/v1/reportingrest/adhocquery?v=full", + `${restBaseUrl}/reportingrest/adhocquery?v=full`, { method: "POST", headers: { "Content-Type": "application/json" }, @@ -29,7 +33,7 @@ export const search = async (searchParams: SearchParams) => { export const useLocations = () => { const { data, error } = useSWRImmutable<{ data: { results: Response[] }; - }>("/ws/rest/v1/location", openmrsFetch); + }>(`${restBaseUrl}/location`, openmrsFetch); const locations: DropdownValue[] = []; data?.data.results.map((location: Response, index: number) => { @@ -49,7 +53,7 @@ export const useLocations = () => { export const getDataSet = async (queryID: string) => { const results: FetchResponse = await openmrsFetch( - `/ws/rest/v1/reportingrest/dataSet/${queryID}`, + `${restBaseUrl}/reportingrest/dataSet/${queryID}`, { method: "GET", } @@ -67,7 +71,7 @@ export const getDataSet = async (queryID: string) => { export const getCohortMembers = async (cohortId: string) => { const results: FetchResponse = await openmrsFetch( - `/ws/rest/v1/cohort/${cohortId}/member?v=full`, + `${restBaseUrl}/cohort/${cohortId}/member?v=full`, { method: "GET", } diff --git a/src/components/saved-cohorts/saved-cohorts.resources.ts b/src/components/saved-cohorts/saved-cohorts.resources.ts index a8280aa..41916f0 100644 --- a/src/components/saved-cohorts/saved-cohorts.resources.ts +++ b/src/components/saved-cohorts/saved-cohorts.resources.ts @@ -1,4 +1,8 @@ -import { FetchResponse, openmrsFetch } from "@openmrs/esm-framework"; +import { + FetchResponse, + openmrsFetch, + restBaseUrl, +} from "@openmrs/esm-framework"; import { Cohort, DefinitionDataRow } from "../../types"; @@ -7,7 +11,7 @@ import { Cohort, DefinitionDataRow } from "../../types"; */ export async function getCohorts(): Promise { const response: FetchResponse<{ results: Cohort[] }> = await openmrsFetch( - "/ws/rest/v1/cohort?v=full", + `${restBaseUrl}/cohort?v=full`, { method: "GET", } @@ -30,7 +34,7 @@ export async function getCohorts(): Promise { export const onDeleteCohort = async (cohort: string) => { const result: FetchResponse = await openmrsFetch( - `/ws/rest/v1/cohort/${cohort}`, + `${restBaseUrl}/cohort/${cohort}`, { method: "DELETE", } diff --git a/src/components/saved-queries/saved-queries.resources.ts b/src/components/saved-queries/saved-queries.resources.ts index ff6cb27..8dddf6e 100644 --- a/src/components/saved-queries/saved-queries.resources.ts +++ b/src/components/saved-queries/saved-queries.resources.ts @@ -1,4 +1,8 @@ -import { FetchResponse, openmrsFetch } from "@openmrs/esm-framework"; +import { + FetchResponse, + openmrsFetch, + restBaseUrl, +} from "@openmrs/esm-framework"; import { Response, DefinitionDataRow } from "../../types"; @@ -7,7 +11,7 @@ import { Response, DefinitionDataRow } from "../../types"; */ export async function getQueries(): Promise { const response: FetchResponse<{ results: Response[] }> = await openmrsFetch( - "/ws/rest/v1/reportingrest/dataSetDefinition?v=full", + `${restBaseUrl}/reportingrest/dataSetDefinition?v=full`, { method: "GET", } @@ -30,7 +34,7 @@ export async function getQueries(): Promise { export const deleteDataSet = async (queryID: string) => { const dataset: FetchResponse = await openmrsFetch( - `/ws/rest/v1/reportingrest/adhocdataset/${queryID}?purge=true`, + `${restBaseUrl}/reportingrest/adhocdataset/${queryID}?purge=true`, { method: "DELETE", } diff --git a/src/components/search-by-concepts/search-concept/search-concept.resource.ts b/src/components/search-by-concepts/search-concept/search-concept.resource.ts index 479453e..115050e 100644 --- a/src/components/search-by-concepts/search-concept/search-concept.resource.ts +++ b/src/components/search-by-concepts/search-concept/search-concept.resource.ts @@ -1,4 +1,8 @@ -import { FetchResponse, openmrsFetch } from "@openmrs/esm-framework"; +import { + FetchResponse, + openmrsFetch, + restBaseUrl, +} from "@openmrs/esm-framework"; import { Concept, DataType } from "../../../types"; @@ -22,7 +26,7 @@ interface Description { */ export async function getConcepts(conceptName: String): Promise { const searchResult: FetchResponse<{ results: ConceptResponse[] }> = - await openmrsFetch(`/ws/rest/v1/concept?v=full&q=${conceptName}`, { + await openmrsFetch(`${restBaseUrl}/concept?v=full&q=${conceptName}`, { method: "GET", }); diff --git a/src/components/search-by-drug-orders/search-by-drug-orders.resources.ts b/src/components/search-by-drug-orders/search-by-drug-orders.resources.ts index 642c90a..69bdaa0 100644 --- a/src/components/search-by-drug-orders/search-by-drug-orders.resources.ts +++ b/src/components/search-by-drug-orders/search-by-drug-orders.resources.ts @@ -1,6 +1,6 @@ import { useMemo } from "react"; -import { openmrsFetch } from "@openmrs/esm-framework"; +import { openmrsFetch, restBaseUrl } from "@openmrs/esm-framework"; import useSWRImmutable from "swr/immutable"; import { DropdownValue, Response } from "../../types"; @@ -11,7 +11,7 @@ import { DropdownValue, Response } from "../../types"; export function useDrugs() { const { data, error } = useSWRImmutable<{ data: { results: Response[] }; - }>("/ws/rest/v1/drug", openmrsFetch); + }>(`${restBaseUrl}/drug`, openmrsFetch); const results = useMemo(() => { const drugs: DropdownValue[] = []; @@ -38,7 +38,7 @@ export function useDrugs() { export function useCareSettings() { const { data, error } = useSWRImmutable<{ data: { results: Response[] }; - }>("/ws/rest/v1/caresetting", openmrsFetch); + }>(`${restBaseUrl}/caresetting`, openmrsFetch); const results = useMemo(() => { const careSettings: DropdownValue[] = []; diff --git a/src/components/search-by-encounters/search-by-encounters.resources.ts b/src/components/search-by-encounters/search-by-encounters.resources.ts index b2722ae..f210750 100644 --- a/src/components/search-by-encounters/search-by-encounters.resources.ts +++ b/src/components/search-by-encounters/search-by-encounters.resources.ts @@ -1,4 +1,4 @@ -import { openmrsFetch } from "@openmrs/esm-framework"; +import { openmrsFetch, restBaseUrl } from "@openmrs/esm-framework"; import useSWRImmutable from "swr/immutable"; import { DropdownValue, Response } from "../../types"; @@ -9,7 +9,7 @@ import { DropdownValue, Response } from "../../types"; export const useForms = () => { const { data, error } = useSWRImmutable<{ data: { results: Response[] }; - }>("/ws/rest/v1/form", openmrsFetch); + }>(`${restBaseUrl}/form`, openmrsFetch); const forms: DropdownValue[] = []; data?.data.results.map((form: Response, index: number) => { @@ -33,7 +33,7 @@ export const useForms = () => { export const useEncounterTypes = () => { const { data, error } = useSWRImmutable<{ data: { results: Response[] }; - }>("/ws/rest/v1/encountertype", openmrsFetch); + }>(`${restBaseUrl}/encountertype`, openmrsFetch); const encounterTypes: DropdownValue[] = []; data?.data.results.map((encounterType: Response, index: number) => { diff --git a/src/components/search-by-enrollments/search-by-enrollments.resources.ts b/src/components/search-by-enrollments/search-by-enrollments.resources.ts index d58003d..81d2e7a 100644 --- a/src/components/search-by-enrollments/search-by-enrollments.resources.ts +++ b/src/components/search-by-enrollments/search-by-enrollments.resources.ts @@ -1,4 +1,4 @@ -import { openmrsFetch } from "@openmrs/esm-framework"; +import { openmrsFetch, restBaseUrl } from "@openmrs/esm-framework"; import useSWRImmutable from "swr/immutable"; import { DropdownValue, Response } from "../../types"; @@ -13,7 +13,7 @@ interface ProgramsResponse extends Response { export function usePrograms() { const { data, error } = useSWRImmutable<{ data: { results: ProgramsResponse[] }; - }>("/ws/rest/v1/program", openmrsFetch); + }>(`${restBaseUrl}/program`, openmrsFetch); const programs: DropdownValue[] = []; data?.data.results.map((program: ProgramsResponse, index: number) => { diff --git a/src/components/search-by-person-attributes/search-by-person-attributes.resource.ts b/src/components/search-by-person-attributes/search-by-person-attributes.resource.ts index 5938850..2fceaa4 100644 --- a/src/components/search-by-person-attributes/search-by-person-attributes.resource.ts +++ b/src/components/search-by-person-attributes/search-by-person-attributes.resource.ts @@ -1,4 +1,4 @@ -import { openmrsFetch } from "@openmrs/esm-framework"; +import { openmrsFetch, restBaseUrl } from "@openmrs/esm-framework"; import useSWRImmutable from "swr/immutable"; import { DropdownValue, Response } from "../../types"; @@ -9,7 +9,7 @@ import { DropdownValue, Response } from "../../types"; export function usePersonAttributes() { const { data, error } = useSWRImmutable<{ data: { results: Response[] }; - }>("/ws/rest/v1/personattributetype", openmrsFetch); + }>(`${restBaseUrl}/personattributetype`, openmrsFetch); const personAttributes: DropdownValue[] = []; data?.data.results.map((personAttribute: Response, index: number) => { diff --git a/src/components/search-history/search-history-options/search-history-options.resources.ts b/src/components/search-history/search-history-options/search-history-options.resources.ts index 112a09d..1d847eb 100644 --- a/src/components/search-history/search-history-options/search-history-options.resources.ts +++ b/src/components/search-history/search-history-options/search-history-options.resources.ts @@ -1,4 +1,8 @@ -import { FetchResponse, openmrsFetch } from "@openmrs/esm-framework"; +import { + FetchResponse, + openmrsFetch, + restBaseUrl, +} from "@openmrs/esm-framework"; import { Cohort, Query } from "../../../types"; @@ -9,7 +13,7 @@ import { Cohort, Query } from "../../../types"; export async function createCohort( cohort: Cohort ): Promise> { - return await openmrsFetch("/ws/rest/v1/cohort", { + return await openmrsFetch(`${restBaseUrl}/cohort`, { method: "POST", headers: { "Content-Type": "application/json" }, body: cohort, @@ -21,7 +25,7 @@ export async function createCohort( * @param query */ export async function createQuery(query: Query): Promise> { - return await openmrsFetch("/ws/rest/v1/reportingrest/adhocdataset", { + return await openmrsFetch(`${restBaseUrl}/reportingrest/adhocdataset`, { method: "POST", headers: { "Content-Type": "application/json" }, body: query,