Skip to content

Commit

Permalink
Merge pull request #828 from aehrc/issue/827
Browse files Browse the repository at this point in the history
Issue/827
  • Loading branch information
fongsean authored May 31, 2024
2 parents 03cafbe + 6022e0b commit c8bdc0e
Show file tree
Hide file tree
Showing 29 changed files with 269 additions and 98 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ The default configuration is set to:
```
# Ontoserver endpoint for $expand operations
# To run your own Ontoserver instance, contact us at https://ontoserver.csiro.au/site/contact-us/ontoserver-contact-form/
VITE_ONTOSERVER_URL=https://r4.ontoserver.csiro.au/fhir
VITE_ONTOSERVER_URL=https://tx.ontoserver.csiro.au/fhir
# Questionnaire-hosting FHIR server
VITE_FORMS_SERVER_URL=https://smartforms.csiro.au/api/fhir
Expand Down
2 changes: 0 additions & 2 deletions apps/smart-forms-app/.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ VITE_LAUNCH_SCOPE=fhirUser online_access openid profile patient/Condition.rs pat
VITE_LAUNCH_CLIENT_ID=a57d90e3-5f69-4b92-aa2e-2992180863c1

VITE_IN_APP_POPULATE=true

VITE_SHOW_DEBUG_MODE=true
2 changes: 0 additions & 2 deletions apps/smart-forms-app/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ VITE_LAUNCH_SCOPE=fhirUser online_access openid profile patient/Condition.rs pat
VITE_LAUNCH_CLIENT_ID=a57d90e3-5f69-4b92-aa2e-2992180863c1

VITE_IN_APP_POPULATE=true

VITE_SHOW_DEBUG_MODE=false
4 changes: 2 additions & 2 deletions apps/smart-forms-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"homepage": "https://github.com/aehrc/smart-forms#readme",
"dependencies": {
"@aehrc/sdc-assemble": "^1.2.0",
"@aehrc/sdc-populate": "^2.0.3",
"@aehrc/smart-forms-renderer": "^0.32.2",
"@aehrc/sdc-populate": "^2.1.0",
"@aehrc/smart-forms-renderer": "^0.33.0",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@fontsource/material-icons": "^5.0.16",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import { StyledRoot } from '../../../../components/DebugFooter/DebugFooter.styles.ts';
import { Box, Typography } from '@mui/material';
import { FORMS_SERVER_ENDPOINT } from '../../../../utils/env.ts';
import useSmartClient from '../../../../hooks/useSmartClient.ts';
import { FORMS_SERVER_URL, LAUNCH_CLIENT_ID } from '../../../../globals.ts';

function DashboardDebugFooter() {
const { smartClient } = useSmartClient();
Expand All @@ -32,13 +32,10 @@ function DashboardDebugFooter() {
</Typography>
<Typography variant="overline">
{`Forms server: ${
FORMS_SERVER_ENDPOINT ??
'Undefined. Defaulting to https://smartforms.csiro.au/api/fhir'
FORMS_SERVER_URL ?? 'Undefined. Defaulting to https://smartforms.csiro.au/api/fhir'
}`}
</Typography>
<Typography variant="overline">
{`Client ID: ${import.meta.env.VITE_LAUNCH_CLIENT_ID}`}
</Typography>
<Typography variant="overline">{`Client ID: ${LAUNCH_CLIENT_ID}`}</Typography>
</Box>
</StyledRoot>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ import type Client from 'fhirclient/lib/Client';
import type { QuestionnaireListItem, ResponseListItem } from '../types/list.interface.ts';
import { HEADERS } from '../../../api/headers.ts';
import { nanoid } from 'nanoid';

const endpointUrl = import.meta.env.VITE_FORMS_SERVER_URL ?? 'https://smartforms.csiro.au/api/fhir';
import { FORMS_SERVER_URL } from '../../../globals.ts';

export function getFormsServerBundlePromise(queryUrl: string): Promise<Bundle> {
queryUrl = queryUrl.replace('|', '&version=');

return FHIR.client(endpointUrl).request({
return FHIR.client(FORMS_SERVER_URL).request({
url: queryUrl,
headers: HEADERS
});
Expand All @@ -45,7 +44,7 @@ export function getFormsServerBundlePromise(queryUrl: string): Promise<Bundle> {
export function getFormsServerAssembledBundlePromise(queryUrl: string): Promise<Bundle> {
queryUrl = queryUrl.replace('|', '&version=');

return FHIR.client(endpointUrl).request({
return FHIR.client(FORMS_SERVER_URL).request({
url: queryUrl,
headers: HEADERS
});
Expand All @@ -68,7 +67,7 @@ export function getFormsServerBundleOrQuestionnairePromise(
queryUrl = queryUrl.substring(0, queryUrl.lastIndexOf('-SMARTcopy')) + '';
}

return FHIR.client(endpointUrl).request({
return FHIR.client(FORMS_SERVER_URL).request({
url: queryUrl,
headers: HEADERS
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,44 @@
* limitations under the License.
*/

import { IS_IN_APP_POPULATE } from '../../../utils/env.ts';
import type { InputParameters, OutputParameters } from '@aehrc/sdc-populate';
import { isOutputParameters, populate } from '@aehrc/sdc-populate';
import type { RequestConfig } from '../utils/callback.ts';
import { fetchResourceCallback } from '../utils/callback.ts';
import { fetchResourceCallback, terminologyCallback } from '../utils/callback.ts';
import { HEADERS } from '../../../api/headers.ts';
import type Client from 'fhirclient/lib/Client';
import type { OperationOutcome } from 'fhir/r4';
import { IN_APP_POPULATE, TERMINOLOGY_SERVER_URL } from '../../../globals.ts';

export async function requestPopulate(
fhirClient: Client,
inputParameters: InputParameters
): Promise<OutputParameters | OperationOutcome> {
const requestConfig: RequestConfig = {
const fetchResourceRequestConfig: RequestConfig = {
clientEndpoint: fhirClient.state.serverUrl,
authToken: fhirClient.state.tokenResponse!.access_token!
};

const populatePromise: Promise<any> = IS_IN_APP_POPULATE
? populate(inputParameters, fetchResourceCallback, requestConfig)
const terminologyRequestConfig: RequestConfig = {
clientEndpoint: TERMINOLOGY_SERVER_URL
};

const populatePromise: Promise<any> = IN_APP_POPULATE
? populate(
inputParameters,
fetchResourceCallback,
fetchResourceRequestConfig,
terminologyCallback,
terminologyRequestConfig
)
: fhirClient.request({
url: 'Questionnaire/$populate',
method: 'POST',
body: JSON.stringify(inputParameters),
headers: {
...HEADERS,
'Content-Type': 'application/json',
Authorization: `Bearer ${requestConfig.authToken}`
Authorization: `Bearer ${fetchResourceRequestConfig.authToken}`
}
});

Expand Down
23 changes: 22 additions & 1 deletion apps/smart-forms-app/src/features/prepopulate/utils/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const ABSOLUTE_URL_REGEX = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/;

export interface RequestConfig {
clientEndpoint: string;
authToken: string;
authToken?: string;
}

export const fetchResourceCallback: FetchResourceCallback = (
Expand All @@ -47,3 +47,24 @@ export const fetchResourceCallback: FetchResourceCallback = (
headers: headers
});
};

export const terminologyCallback: FetchResourceCallback = (
query: string,
requestConfig: RequestConfig
) => {
let { clientEndpoint } = requestConfig;

const headers = {
Accept: 'application/json;charset=utf-8'
};

if (!clientEndpoint.endsWith('/')) {
clientEndpoint += '/';
}

const queryUrl = ABSOLUTE_URL_REGEX.test(query) ? query : clientEndpoint + query;

return axios.get(queryUrl, {
headers: headers
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import AccountTreeIcon from '@mui/icons-material/AccountTree';
import NotesIcon from '@mui/icons-material/Notes';
import DebugResponseView from './DebugResponseView.tsx';
import OpenInNewIcon from '@mui/icons-material/OpenInNew';

const endpointUrl = import.meta.env.VITE_FORMS_SERVER_URL ?? 'https://smartforms.csiro.au/api/fhir';
import { FORMS_SERVER_URL } from '../../../../globals.ts';

interface Props {
questionnaire: Questionnaire;
Expand Down Expand Up @@ -96,7 +95,7 @@ function DebugPanel(props: Props) {
{questionnaireSelected ? (
<Tooltip title="Open Questionnaire in new tab">
<a
href={endpointUrl + '/Questionnaire/' + questionnaire.id}
href={FORMS_SERVER_URL + '/Questionnaire/' + questionnaire.id}
target="_blank"
rel="noreferrer">
<IconButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useSearchParams } from 'react-router-dom';
import { oauth2 } from 'fhirclient';
import { useState } from 'react';
import LaunchView from './LaunchView.tsx';
import { LAUNCH_CLIENT_ID, LAUNCH_SCOPE } from '../../../globals.ts';

export type LaunchState = 'loading' | 'error' | 'success';

Expand All @@ -29,8 +30,8 @@ function Launch() {
const iss = searchParams.get('iss');
const launch = searchParams.get('launch');

const clientId = import.meta.env.VITE_LAUNCH_CLIENT_ID;
const scope = import.meta.env.VITE_LAUNCH_SCOPE;
const clientId = LAUNCH_CLIENT_ID;
const scope = LAUNCH_SCOPE;

if (iss && launch) {
// oauth2.authorize triggers a redirect to EHR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import type {
import type { fhirclient } from 'fhirclient/lib/types';
import * as FHIR from 'fhirclient';
import { HEADERS } from '../../../api/headers.ts';

const endpointUrl = import.meta.env.VITE_FORMS_SERVER_URL ?? 'https://smartforms.csiro.au/api/fhir';
import { FORMS_SERVER_URL } from '../../../globals.ts';

export async function readCommonLaunchContexts(
client: Client
Expand Down Expand Up @@ -117,7 +116,7 @@ export function readQuestionnaireContext(

canonical = canonical.replace('|', '&version=');

return FHIR.client(endpointUrl).request({
return FHIR.client(FORMS_SERVER_URL).request({
url: 'Questionnaire?url=' + canonical + '&_sort=_lastUpdated',
method: 'GET',
headers: HEADERS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function ResourceViewSwitcher(props: ResourceViewSwitcherProps) {
return (
<>
<Typography variant="subtitle2">
Defaults to https://r4.ontoserver.csiro.au if null
Defaults to https://tx.ontoserver.csiro.au if null
</Typography>
<pre>{JSON.stringify(state.terminologyServerUrl, null, 2)}</pre>
</>
Expand Down
26 changes: 26 additions & 0 deletions apps/smart-forms-app/src/globals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2024 Commonwealth Scientific and Industrial Research
* Organisation (CSIRO) ABN 41 687 119 230.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export const TERMINOLOGY_SERVER_URL =
import.meta.env.VITE_ONTOSERVER_URL ?? 'https://tx.ontoserver.csiro.au/fhir';
export const FORMS_SERVER_URL =
import.meta.env.VITE_FORMS_SERVER_URL ?? 'https://smartforms.csiro.au/api/fhir';
export const LAUNCH_SCOPE =
import.meta.env.VITE_LAUNCH_SCOPE ??
'fhirUser online_access openid profile patient/Condition.rs patient/Observation.rs launch patient/Encounter.rs patient/QuestionnaireResponse.cruds patient/Patient.rs';
export const LAUNCH_CLIENT_ID = import.meta.env.VITE_LAUNCH_CLIENT_ID ?? 'smart-forms-client-id';
export const IN_APP_POPULATE = import.meta.env.VITE_IN_APP_POPULATE ?? true;
7 changes: 3 additions & 4 deletions apps/smart-forms-app/src/utils/assemble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import { isInputParameters } from '@aehrc/sdc-assemble';
import * as FHIR from 'fhirclient';
import { HEADERS } from '../api/headers.ts';
import { getFormsServerAssembledBundlePromise } from '../features/dashboard/utils/dashboard.ts';

const endpointUrl = import.meta.env.VITE_FORMS_SERVER_URL ?? 'https://smartforms.csiro.au/api/fhir';
import { FORMS_SERVER_URL } from '../globals.ts';

export function assemblyIsRequired(questionnaire: Questionnaire): boolean {
return !!questionnaire.extension?.find(
Expand Down Expand Up @@ -49,7 +48,7 @@ export async function assembleQuestionnaire(
): Promise<Questionnaire | OperationOutcome> {
const parameters = defineAssembleParameters(questionnaire);
if (isInputParameters(parameters)) {
const outputAssembleParams = await FHIR.client(endpointUrl).request({
const outputAssembleParams = await FHIR.client(FORMS_SERVER_URL).request({
url: 'Questionnaire/$assemble',
method: 'POST',
body: JSON.stringify(parameters),
Expand All @@ -67,7 +66,7 @@ export async function assembleQuestionnaire(
}

export function updateAssembledQuestionnaire(questionnaire: Questionnaire) {
return FHIR.client(endpointUrl).request({
return FHIR.client(FORMS_SERVER_URL).request({
url: `Questionnaire/${questionnaire.id}`,
method: 'PUT',
body: JSON.stringify(questionnaire),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
> `const` **terminologyServerStore**: `StoreApi` \<[`TerminologyServerStoreType`](../interfaces/TerminologyServerStoreType.md)\>
Terminology server state management store. This is used for resolving valueSets externally.
Defaults to use https://r4.ontoserver.csiro.au/fhir.
Defaults to use https://tx.ontoserver.csiro.au/fhir.
This is the vanilla version of the store which can be used in non-React environments.

## See
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
> `const` **useTerminologyServerStore**: `StoreApi` \<[`TerminologyServerStoreType`](../interfaces/TerminologyServerStoreType.md)\> & `object`
Terminology server state management store. This is used for resolving valueSets externally.
Defaults to use https://r4.ontoserver.csiro.au/fhir.
Defaults to use https://tx.ontoserver.csiro.au/fhir.
This is the React version of the store which can be used as React hooks in React functional components.

## See
Expand Down
2 changes: 1 addition & 1 deletion documentation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"typecheck": "tsc"
},
"dependencies": {
"@aehrc/smart-forms-renderer": "^0.32.2",
"@aehrc/smart-forms-renderer": "^0.33.0",
"@docusaurus/core": "3.3.2",
"@docusaurus/preset-classic": "3.3.2",
"@docusaurus/theme-live-codeblock": "^3.3.2",
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/sdc-populate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aehrc/sdc-populate",
"version": "2.0.3",
"version": "2.1.0",
"description": "Performs the $populate operation from the HL7 FHIR SDC (Structured Data Capture) specification: http://hl7.org/fhir/uv/sdc",
"main": "lib/index.js",
"scripts": {
Expand Down
Loading

0 comments on commit c8bdc0e

Please sign in to comment.