Skip to content

Commit

Permalink
Confguration refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ir4y committed Jun 18, 2024
1 parent 7de1056 commit 9324fa2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 23 deletions.
33 changes: 20 additions & 13 deletions shared/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
export const baseURL =
(window as any).BASE_URL === '{{BASE_URL}}'
? 'http://localhost:8080/'
: (window as any).BASE_URL;
export const juteURL =
(window as any).JUTE_URL === '{{JUTE_URL}}'
? 'http://localhost:8099/'
: (window as any).JUTE_URL;
const envs = {
baseURL: ['BASE_URL', 'http://localhost:8080'],
juteURL: ['JUTE_URL', 'http://localhost:8099'],
aiQuestionnaireBuilderUrl: ['AI_BUILDER_URL', 'http://localhost:3002'],
fhirpathMappingUrl: ['FHIRPATHMAPPING_URL', 'http://localhost:8091'],
fhirMappingLanguageUrl: ['FHIRMAPPING_URL','http://localhost:8084/matchboxv3/fhir']
}

export const aiQuestionnaireBuilderUrl = 'https://builder.emr.beda.software';
// export const aiQuestionnaireBuilderUrl = 'http://localhost:3002';
export const fhirpathMappingUrl = 'https://fhirpathmapper.emr.beda.software';
// export const fhirpathMappingUrl = 'http://localhost:8091';
export const fhirMappingLanguageUrl = 'http://localhost:8084/matchboxv3/fhir';
export const configuration:Record<keyof typeof envs,string> = {} as any;

const globalConfig = (window as any)

Object.keys(envs).forEach((key) => {
const [globalKey,defaultValue] = envs[key];
if(globalConfig[globalKey] == `{{${globalKey}}}`){
configuration[key] = defaultValue;
} else {
configuration[key] = globalConfig[globalKey];
}
})
console.log(configuration)
2 changes: 2 additions & 0 deletions web/src/services/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export function getAuthorizeUrl(clientId: string, state?: OAuthState) {
connection: { baseUrl },
} = getData();

console.log(baseUrl);

return `${baseUrl}/auth/authorize?client_id=${clientId}&response_type=token${stateStr}`;
}

Expand Down
6 changes: 3 additions & 3 deletions web/src/services/builder.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { service } from './fhir';

import { aiQuestionnaireBuilderUrl } from 'shared/src/constants';
import { configuration } from 'shared/src/constants';

import { getToken } from './auth';

export async function generateQuestionnaireService(prompt: string, questionnaire?: string) {
const appToken = getToken();

return await service<any>({
baseURL: aiQuestionnaireBuilderUrl,
baseURL: configuration.aiQuestionnaireBuilderUrl,
url: `/questionnaire`,
method: 'POST',
data: { prompt: prompt, questionnaire },
Expand All @@ -22,7 +22,7 @@ export async function generateMappingService(prompt: string, questionnaire: stri
const appToken = getToken();

return await service<any>({
baseURL: aiQuestionnaireBuilderUrl,
baseURL: configuration.aiQuestionnaireBuilderUrl,
url: `/mapper`,
method: 'POST',
data: { prompt: prompt, questionnaire },
Expand Down
4 changes: 2 additions & 2 deletions web/src/services/fhir.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { initServices } from '@beda.software/fhir-react';

import { baseURL } from 'shared/src/constants';
import { configuration } from 'shared/src/constants';

export const {
axiosInstance,
Expand All @@ -16,4 +16,4 @@ export const {
forceDeleteFHIRResource,
patchFHIRResource,
setInstanceBaseURL,
} = initServices(baseURL + '/fhir');
} = initServices(configuration.baseURL + '/fhir');
8 changes: 4 additions & 4 deletions web/src/services/fhirmapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { Bundle, QuestionnaireResponse, StructureMap } from 'fhir/r4b';

import { service } from './fhir';

import { fhirMappingLanguageUrl } from 'shared/src/constants';
import { configuration } from 'shared/src/constants';

const CONTENT_TYPE_FHIR_MAPPING = 'text/fhir-mapping';
const CONTENT_TYPE_FHIR_JSON = 'application/fhir+json';
const ACCEPT_FHIR_JSON = 'application/fhir+json';

export async function convert({ mapString }: { mapString: string }) {
return await service<StructureMap>({
baseURL: fhirMappingLanguageUrl,
baseURL: configuration.fhirMappingLanguageUrl,
url: `/StructureMap/$convert`,
method: 'POST',
data: mapString,
Expand All @@ -22,7 +22,7 @@ export async function convert({ mapString }: { mapString: string }) {

export async function createStructureMap({ structureMap }: { structureMap: StructureMap }) {
return await service<StructureMap>({
baseURL: fhirMappingLanguageUrl,
baseURL: configuration.fhirMappingLanguageUrl,
url: `/StructureMap`,
method: 'POST',
data: structureMap,
Expand All @@ -37,7 +37,7 @@ export async function transform({
questionnaireResponse: QuestionnaireResponse;
}) {
return await service<Bundle>({
baseURL: fhirMappingLanguageUrl,
baseURL: configuration.fhirMappingLanguageUrl,
url: `/StructureMap/$transform`,
method: 'POST',
data: questionnaireResponse,
Expand Down
3 changes: 2 additions & 1 deletion web/src/services/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { setInstanceBaseURL as setAidboxInstanceBaseURL } from 'aidbox-react/lib/services/instance';

import { baseURL, juteURL, fhirpathMappingUrl } from 'shared/src/constants';
import { configuration } from 'shared/src/constants';
const { baseURL, juteURL, fhirpathMappingUrl } = configuration;

setAidboxInstanceBaseURL(baseURL);

Expand Down

0 comments on commit 9324fa2

Please sign in to comment.