Skip to content

Commit

Permalink
(refactor) Replace usages of /ws/rest/v1 with restBaseUrl (#71)
Browse files Browse the repository at this point in the history
Replace usages of '/ws/rest/v1/' with restBaseUrl

Co-authored-by: jwnasambu <wamalwa1844.com>
  • Loading branch information
jwnasambu authored Mar 4, 2024
1 parent cffcba8 commit 7ab9079
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 26 deletions.
14 changes: 9 additions & 5 deletions src/cohort-builder.resources.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -13,7 +17,7 @@ interface SearchResults {

export const search = async (searchParams: SearchParams) => {
const searchResults: FetchResponse<SearchResults> = await openmrsFetch(
"/ws/rest/v1/reportingrest/adhocquery?v=full",
`${restBaseUrl}/reportingrest/adhocquery?v=full`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
Expand All @@ -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) => {
Expand All @@ -49,7 +53,7 @@ export const useLocations = () => {

export const getDataSet = async (queryID: string) => {
const results: FetchResponse<SearchResults> = await openmrsFetch(
`/ws/rest/v1/reportingrest/dataSet/${queryID}`,
`${restBaseUrl}/reportingrest/dataSet/${queryID}`,
{
method: "GET",
}
Expand All @@ -67,7 +71,7 @@ export const getDataSet = async (queryID: string) => {

export const getCohortMembers = async (cohortId: string) => {
const results: FetchResponse<SearchResults> = await openmrsFetch(
`/ws/rest/v1/cohort/${cohortId}/member?v=full`,
`${restBaseUrl}/cohort/${cohortId}/member?v=full`,
{
method: "GET",
}
Expand Down
10 changes: 7 additions & 3 deletions src/components/saved-cohorts/saved-cohorts.resources.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { FetchResponse, openmrsFetch } from "@openmrs/esm-framework";
import {
FetchResponse,
openmrsFetch,
restBaseUrl,
} from "@openmrs/esm-framework";

import { Cohort, DefinitionDataRow } from "../../types";

Expand All @@ -7,7 +11,7 @@ import { Cohort, DefinitionDataRow } from "../../types";
*/
export async function getCohorts(): Promise<DefinitionDataRow[]> {
const response: FetchResponse<{ results: Cohort[] }> = await openmrsFetch(
"/ws/rest/v1/cohort?v=full",
`${restBaseUrl}/cohort?v=full`,
{
method: "GET",
}
Expand All @@ -30,7 +34,7 @@ export async function getCohorts(): Promise<DefinitionDataRow[]> {

export const onDeleteCohort = async (cohort: string) => {
const result: FetchResponse = await openmrsFetch(
`/ws/rest/v1/cohort/${cohort}`,
`${restBaseUrl}/cohort/${cohort}`,
{
method: "DELETE",
}
Expand Down
10 changes: 7 additions & 3 deletions src/components/saved-queries/saved-queries.resources.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { FetchResponse, openmrsFetch } from "@openmrs/esm-framework";
import {
FetchResponse,
openmrsFetch,
restBaseUrl,
} from "@openmrs/esm-framework";

import { Response, DefinitionDataRow } from "../../types";

Expand All @@ -7,7 +11,7 @@ import { Response, DefinitionDataRow } from "../../types";
*/
export async function getQueries(): Promise<DefinitionDataRow[]> {
const response: FetchResponse<{ results: Response[] }> = await openmrsFetch(
"/ws/rest/v1/reportingrest/dataSetDefinition?v=full",
`${restBaseUrl}/reportingrest/dataSetDefinition?v=full`,
{
method: "GET",
}
Expand All @@ -30,7 +34,7 @@ export async function getQueries(): Promise<DefinitionDataRow[]> {

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",
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { FetchResponse, openmrsFetch } from "@openmrs/esm-framework";
import {
FetchResponse,
openmrsFetch,
restBaseUrl,
} from "@openmrs/esm-framework";

import { Concept, DataType } from "../../../types";

Expand All @@ -22,7 +26,7 @@ interface Description {
*/
export async function getConcepts(conceptName: String): Promise<Concept[]> {
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",
});

Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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[] = [];
Expand All @@ -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[] = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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) => {
Expand All @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { FetchResponse, openmrsFetch } from "@openmrs/esm-framework";
import {
FetchResponse,
openmrsFetch,
restBaseUrl,
} from "@openmrs/esm-framework";

import { Cohort, Query } from "../../../types";

Expand All @@ -9,7 +13,7 @@ import { Cohort, Query } from "../../../types";
export async function createCohort(
cohort: Cohort
): Promise<FetchResponse<Cohort>> {
return await openmrsFetch("/ws/rest/v1/cohort", {
return await openmrsFetch(`${restBaseUrl}/cohort`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: cohort,
Expand All @@ -21,7 +25,7 @@ export async function createCohort(
* @param query
*/
export async function createQuery(query: Query): Promise<FetchResponse<Query>> {
return await openmrsFetch("/ws/rest/v1/reportingrest/adhocdataset", {
return await openmrsFetch(`${restBaseUrl}/reportingrest/adhocdataset`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: query,
Expand Down

0 comments on commit 7ab9079

Please sign in to comment.