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 usages of '/ws/rest/v1/' with restBaseUrl #54

Merged
merged 1 commit into from
Feb 28, 2024
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,4 @@
"@carbon/react": "1.14.0"
},
"packageManager": "[email protected]"
}
}
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 useSWR from "swr";

export interface EncounterResponse {
Expand Down Expand Up @@ -276,7 +276,7 @@ export interface Encounter {
}

export function useGetEncounterById(encounterUuid: string) {
const apiUrl = `/ws/rest/v1/encounter/${encounterUuid}?v=full`;
const apiUrl = `${restBaseUrl}/encounter/${encounterUuid}?v=full`;
const { data, error, isLoading } = useSWR<{ data: EncounterResponse }, Error>(
apiUrl,
openmrsFetch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { formatDate, openmrsFetch, useConfig } from "@openmrs/esm-framework";
import {
formatDate,
openmrsFetch,
restBaseUrl,
useConfig,
} from "@openmrs/esm-framework";
import useSWR from "swr";

export interface LaboratoryResponse {
Expand Down Expand Up @@ -461,7 +466,7 @@ export function usePatientLaboratoryOrders(filter: LaboratoryOrderFilter) {
const config = useConfig();
const { laboratoryEncounterTypeUuid } = config;

const apiUrl = `/ws/rest/v1/encounter?patient=${filter.patientUuid}&encounterType=${laboratoryEncounterTypeUuid}&v=${filter.v}&totalCount=true`;
const apiUrl = `${restBaseUrl}/encounter?patient=${filter.patientUuid}&encounterType=${laboratoryEncounterTypeUuid}&v=${filter.v}&totalCount=true`;
const { data, error, isLoading } = useSWR<
{ data: LaboratoryResponse },
Error
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 { ObsMetaInfo } from "@openmrs/esm-patient-common-lib";

import useSWR from "swr";
Expand Down Expand Up @@ -161,7 +161,7 @@ export function assessValue(
}

export function useGetConceptById(conceptUuid: string) {
const apiUrl = `/ws/rest/v1/concept/${conceptUuid}?v=full`;
const apiUrl = `${restBaseUrl}/concept/${conceptUuid}?v=full`;
const { data, error, isLoading } = useSWR<{ data: ConceptResponse }, Error>(
apiUrl,
openmrsFetch
Expand All @@ -176,7 +176,7 @@ export function useGetConceptById(conceptUuid: string) {
export async function GetPatientByUuid(uuid: string) {
const abortController = new AbortController();

return openmrsFetch(`/ws/rest/v1/patient/${uuid}`, {
return openmrsFetch(`${restBaseUrl}/patient/${uuid}`, {
headers: {
"Content-Type": "application/json",
},
Expand Down
9 changes: 7 additions & 2 deletions src/patient-chart/results-summary/results/results.resource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { FetchResponse, openmrsFetch, useConfig } from "@openmrs/esm-framework";
import {
FetchResponse,
openmrsFetch,
restBaseUrl,
useConfig,
} from "@openmrs/esm-framework";
import useSWR from "swr";

export interface LabTestResultResponse {
Expand Down Expand Up @@ -36,7 +41,7 @@ export interface Link {
}

export function useGetLabEncounterTests(encounterUuid: string) {
const apiUrl = `/ws/rest/v1/encountertestresults?encounterUuid=${encounterUuid}`;
const apiUrl = `${restBaseUrl}/encountertestresults?encounterUuid=${encounterUuid}`;

const { data, error, isLoading } = useSWR<
{ data: LabTestResultResponse },
Expand Down
19 changes: 12 additions & 7 deletions src/queue-list/lab-dialogs/add-to-worklist-dialog.resource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { FetchResponse, openmrsFetch, useConfig } from "@openmrs/esm-framework";
import {
FetchResponse,
openmrsFetch,
restBaseUrl,
useConfig,
} from "@openmrs/esm-framework";
import { useMemo } from "react";
import useSWR from "swr";
import useSWRImmutable from "swr/immutable";
Expand Down Expand Up @@ -83,7 +88,7 @@ export interface ParentLocation {

// get queue rooms
export function useQueueRoomLocations(currentQueueLocation: string) {
const apiUrl = `/ws/rest/v1/location/${currentQueueLocation}?v=full`;
const apiUrl = `${restBaseUrl}/location/${currentQueueLocation}?v=full`;
const { data, error, isLoading } = useSWR<{ data: QueueRoomsResponse }>(
apiUrl,
openmrsFetch
Expand All @@ -106,7 +111,7 @@ export function useQueueRoomLocations(currentQueueLocation: string) {
export function useReferralLocations() {
const config = useConfig();
const { laboratoryReferalDestinationUuid } = config;
const apiUrl = `/ws/rest/v1/concept/${laboratoryReferalDestinationUuid}`;
const apiUrl = `${restBaseUrl}/concept/${laboratoryReferalDestinationUuid}`;
const { data, error, isLoading } = useSWRImmutable<FetchResponse>(
apiUrl,
openmrsFetch
Expand All @@ -123,7 +128,7 @@ export function useSpecimenTypes() {
const config = useConfig();
const { laboratorySpecimenTypeConcept } = config;

const apiUrl = `/ws/rest/v1/concept/${laboratorySpecimenTypeConcept}`;
const apiUrl = `${restBaseUrl}/concept/${laboratorySpecimenTypeConcept}`;
const { data, error, isLoading } = useSWRImmutable<FetchResponse>(
apiUrl,
openmrsFetch
Expand All @@ -147,7 +152,7 @@ export function useSpecimenTypes() {
// generate specimen id
export async function GenerateSpecimenId(uuid: string) {
const abortController = new AbortController();
return openmrsFetch(`/ws/rest/v1/generatesampleId?uuid=${uuid}`, {
return openmrsFetch(`${restBaseUrl}/generatesampleId?uuid=${uuid}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand All @@ -159,7 +164,7 @@ export async function GenerateSpecimenId(uuid: string) {
// update Order
export async function UpdateOrder(uuid: string, body: any) {
const abortController = new AbortController();
return openmrsFetch(`/ws/rest/v1/accessionorder/${uuid}`, {
return openmrsFetch(`${restBaseUrl}/accessionorder/${uuid}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -171,7 +176,7 @@ export async function UpdateOrder(uuid: string, body: any) {

export async function GetOrderByUuid(uuid: string) {
const abortController = new AbortController();
return openmrsFetch(`/ws/rest/v1/order/${uuid}`, {
return openmrsFetch(`${restBaseUrl}/order/${uuid}`, {
headers: {
"Content-Type": "application/json",
},
Expand Down
9 changes: 7 additions & 2 deletions src/queue-list/lab-tests/lab-tests.resource.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { FetchResponse, openmrsFetch, useConfig } from "@openmrs/esm-framework";
import {
FetchResponse,
openmrsFetch,
restBaseUrl,
useConfig,
} from "@openmrs/esm-framework";
import useSWR from "swr";
import { EncounterResponse } from "../../patient-chart/laboratory-item/view-laboratory-item.resource";
export function useGetLabOrders(encounterUuid: string) {
const apiUrl = `/ws/rest/v1/encounter/${encounterUuid}?v=full`;
const apiUrl = `${restBaseUrl}/encounter/${encounterUuid}?v=full`;

const { data, error, isLoading } = useSWR<{ data: EncounterResponse }, Error>(
apiUrl,
Expand Down
9 changes: 7 additions & 2 deletions src/queue-list/laboratory-patient-list.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { PatientQueue, UuidDisplay } from "../types/patient-queues";
import dayjs from "dayjs";
import useSWR from "swr";

import { formatDate, openmrsFetch, parseDate } from "@openmrs/esm-framework";
import {
formatDate,
openmrsFetch,
parseDate,
restBaseUrl,
} from "@openmrs/esm-framework";

export interface MappedPatientQueueEntry {
id: string;
Expand All @@ -29,7 +34,7 @@ export function usePatientQueuesList(
currentQueueRoomLocationUuid: string,
status: string
) {
const apiUrl = `/ws/rest/v1/patientqueue?v=full&room=${currentQueueRoomLocationUuid}&status=${status}`;
const apiUrl = `${restBaseUrl}/patientqueue?v=full&room=${currentQueueRoomLocationUuid}&status=${status}`;
return usePatientQueueRequest(apiUrl);
}

Expand Down
9 changes: 7 additions & 2 deletions src/reject-order/reject-order-dialog.resource.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { FetchResponse, openmrsFetch, useConfig } from "@openmrs/esm-framework";
import {
FetchResponse,
openmrsFetch,
restBaseUrl,
useConfig,
} from "@openmrs/esm-framework";

export async function RejectOrder(uuid: string, body: any) {
const abortController = new AbortController();

return openmrsFetch(`/ws/rest/v1/order/${uuid}/fulfillerdetails/`, {
return openmrsFetch(`${restBaseUrl}/order/${uuid}/fulfillerdetails/`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
12 changes: 6 additions & 6 deletions src/results/result-form.resource.ts
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 useSWR from "swr";

export interface ConceptResponse {
Expand Down Expand Up @@ -305,7 +305,7 @@ export interface ObPayload {
// get order concept
export async function GetOrderConceptByUuid(uuid: string) {
const abortController = new AbortController();
return openmrsFetch(`/ws/rest/v1/concept/${uuid}?v=full`, {
return openmrsFetch(`${restBaseUrl}/concept/${uuid}?v=full`, {
headers: {
"Content-Type": "application/json",
},
Expand All @@ -314,7 +314,7 @@ export async function GetOrderConceptByUuid(uuid: string) {
}

export function useGetOrderConceptByUuid(uuid: string) {
const apiUrl = `/ws/rest/v1/concept/${uuid}?v=custom:(uuid,display,name,datatype,set,answers,hiNormal,hiAbsolute,hiCritical,lowNormal,lowAbsolute,lowCritical,units,setMembers:(uuid,display,answers,datatype,hiNormal,hiAbsolute,hiCritical,lowNormal,lowAbsolute,lowCritical,units))`;
const apiUrl = `${restBaseUrl}/concept/${uuid}?v=custom:(uuid,display,name,datatype,set,answers,hiNormal,hiAbsolute,hiCritical,lowNormal,lowAbsolute,lowCritical,units,setMembers:(uuid,display,answers,datatype,hiNormal,hiAbsolute,hiCritical,lowNormal,lowAbsolute,lowCritical,units))`;

const { data, error, isLoading, isValidating, mutate } = useSWR<
{ data: ConceptResponse },
Expand All @@ -331,7 +331,7 @@ export function useGetOrderConceptByUuid(uuid: string) {

export async function UpdateEncounter(uuid: string, payload: any) {
const abortController = new AbortController();
return openmrsFetch(`/ws/rest/v1/encounter/${uuid}`, {
return openmrsFetch(`${restBaseUrl}/encounter/${uuid}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -348,7 +348,7 @@ export async function UpdateOrderResult(
orderPayload: any
) {
const abortController = new AbortController();
const updateOrderCall = await openmrsFetch(`/ws/rest/v1/order`, {
const updateOrderCall = await openmrsFetch(`${restBaseUrl}/order`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -358,7 +358,7 @@ export async function UpdateOrderResult(
});

if (updateOrderCall.status === 201) {
return await openmrsFetch(`/ws/rest/v1/encounter/${encounterUuid}`, {
return await openmrsFetch(`${restBaseUrl}/encounter/${encounterUuid}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
9 changes: 7 additions & 2 deletions src/review-list/dialog/review-item.resource.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { FetchResponse, openmrsFetch, useConfig } from "@openmrs/esm-framework";
import {
FetchResponse,
openmrsFetch,
restBaseUrl,
useConfig,
} from "@openmrs/esm-framework";

export async function ApproverOrder(body: any) {
const abortController = new AbortController();

return openmrsFetch(`/ws/rest/v1/approveorder`, {
return openmrsFetch(`${restBaseUrl}/approveorder`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
13 changes: 9 additions & 4 deletions src/summary-tiles/laboratory-summary.resource.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import useSWR from "swr";
import useSWRImmutable from "swr/immutable";
import { FetchResponse, openmrsFetch } from "@openmrs/esm-framework";
import {
FetchResponse,
openmrsFetch,
restBaseUrl,
} from "@openmrs/esm-framework";

import { Result } from "../work-list/work-list.resource";

export function useMetrics() {
Expand All @@ -11,7 +16,7 @@ export function useMetrics() {
completed: 6,
};
const { data, error } = useSWR<{ data: { results: {} } }, Error>(
`/ws/rest/v1/queue?`,
`${restBaseUrl}/queue?`,
openmrsFetch
);

Expand All @@ -24,7 +29,7 @@ export function useMetrics() {

export function useServices() {
const serviceConceptSetUuid = "330c0ec6-0ac7-4b86-9c70-29d76f0ae20a";
const apiUrl = `/ws/rest/v1/concept/${serviceConceptSetUuid}`;
const apiUrl = `${restBaseUrl}/concept/${serviceConceptSetUuid}`;
const { data } = useSWRImmutable<FetchResponse>(apiUrl, openmrsFetch);

return {
Expand All @@ -36,7 +41,7 @@ export function useServices() {

// worklist
export function useLabTestsStats(fulfillerStatus: string) {
const apiUrl = `/ws/rest/v1/order?orderTypes=52a447d3-a64a-11e3-9aeb-50e549534c5e&isStopped=false&fulfillerStatus=${fulfillerStatus}&v=full
const apiUrl = `${restBaseUrl}/order?orderTypes=52a447d3-a64a-11e3-9aeb-50e549534c5e&isStopped=false&fulfillerStatus=${fulfillerStatus}&v=full
`;
const { data, error, isLoading } = useSWR<
{ data: { results: Array<Result> } },
Expand Down
4 changes: 2 additions & 2 deletions src/utils/functions.ts
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 useSWR from "swr";

export const trimVisitNumber = (visitNumber: string) => {
Expand Down Expand Up @@ -233,7 +233,7 @@ export interface Creator {
}

export function useGetPatientByUuid(uuid: string) {
const apiUrl = `/ws/rest/v1/patient/${uuid}?v=full`;
const apiUrl = `${restBaseUrl}/patient/${uuid}?v=full`;
const { data, error, isLoading } = useSWR<{ data: PatientResource }, Error>(
apiUrl,
openmrsFetch
Expand Down
4 changes: 2 additions & 2 deletions src/work-list/work-list.resource.ts
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 useSWR from "swr";

export interface Result {
Expand Down Expand Up @@ -120,7 +120,7 @@ export function useGetOrdersWorklist(
activatedOnOrAfterDate: string,
fulfillerStatus: string
) {
const apiUrl = `/ws/rest/v1/order?orderTypes=52a447d3-a64a-11e3-9aeb-50e549534c5e&activatedOnOrAfterDate=${activatedOnOrAfterDate}&isStopped=false&fulfillerStatus=${fulfillerStatus}&v=full
const apiUrl = `${restBaseUrl}/order?orderTypes=52a447d3-a64a-11e3-9aeb-50e549534c5e&activatedOnOrAfterDate=${activatedOnOrAfterDate}&isStopped=false&fulfillerStatus=${fulfillerStatus}&v=full
`;

const { data, error, isLoading } = useSWR<
Expand Down
Loading