Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/aehrc/smart-forms
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Oct 9, 2024
2 parents 4163304 + fd52504 commit b263a9d
Show file tree
Hide file tree
Showing 27 changed files with 258 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ This log documents significant changes for the [@aehrc/smart-forms-renderer](htt
Changelog only includes changes from version 0.36.0 onwards.


## [0.44.0] - 2024-10-09
### Added
- Added support for the [preferredTerminologyServer](https://hl7.org/fhir/uv/sdc/STU3/StructureDefinition-sdc-questionnaire-preferredTerminologyServer.html) SDC extension.

## [0.43.1] - 2024-10-04
### Changed
- Completely removed persisting "iframe-resizer" dependencies as a follow-up to v0.43.0.
Expand Down
8 changes: 4 additions & 4 deletions apps/demo-renderer-app/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 apps/demo-renderer-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@aehrc/sdc-populate": "^2.3.1",
"@aehrc/smart-forms-renderer": "^0.43.1",
"@aehrc/smart-forms-renderer": "^0.44.0",
"@radix-ui/react-collapsible": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-switch": "^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/smart-forms-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dependencies": {
"@aehrc/sdc-assemble": "^1.3.1",
"@aehrc/sdc-populate": "^2.3.1",
"@aehrc/smart-forms-renderer": "^0.43.1",
"@aehrc/smart-forms-renderer": "^0.44.0",
"@emotion/react": "^11.13.0",
"@emotion/styled": "^11.13.0",
"@fontsource/material-icons": "^5.0.18",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import GenericStatePropertyPicker from './GenericStatePropertyPicker.tsx';
const questionnaireStoreStatePropertyNames: string[] = [
'sourceQuestionnaire',
'itemTypes',
'itemPreferredTerminologyServers',
'tabs',
'currentTabIndex',
'variables',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { useQuestionnaireStore } from '@aehrc/smart-forms-renderer';
function useShowQuestionnaireStoreProperty(selectedProperty: string) {
const sourceQuestionnaire = useQuestionnaireStore.use.sourceQuestionnaire();
const itemTypes = useQuestionnaireStore.use.itemTypes();
const itemPreferredTerminologyServers =
useQuestionnaireStore.use.itemPreferredTerminologyServers();
const tabs = useQuestionnaireStore.use.tabs();
const currentTabIndex = useQuestionnaireStore.use.currentTabIndex();
const variables = useQuestionnaireStore.use.variables();
Expand All @@ -42,6 +44,7 @@ function useShowQuestionnaireStoreProperty(selectedProperty: string) {
{
sourceQuestionnaire,
itemTypes,
itemPreferredTerminologyServers,
tabs,
currentTabIndex,
variables,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ LinkId of the currently focused item
***

### itemPreferredTerminologyServers

> **itemPreferredTerminologyServers**: `Record`\<`string`, `string`\>
Key-value pair of item types `Record<linkId, preferred terminology servers>`

***

### itemTypes

> **itemTypes**: `Record`\<`string`, `string`\>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ This is the React version of the store which can be used as React hooks in React

`Record`\<`string`, `InitialExpression`\>

### use.itemPreferredTerminologyServers()

> **itemPreferredTerminologyServers**: () => `Record`\<`string`, `string`\>
#### Returns

`Record`\<`string`, `string`\>

### use.itemTypes()

> **itemTypes**: () => `Record`\<`string`, `string`\>
Expand Down
16 changes: 14 additions & 2 deletions documentation/docs/sdc/terminology.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ The elements/extensions that fall under this category are:
- [answerValueSet](http://hl7.org/fhir/uv/sdc/behavior.html#answerValueSet)
- [answerExpression](http://hl7.org/fhir/uv/sdc/expressions.html#answerExpression)

There is also another extension that can be used to define the unit of a quantity item:
Other related extensions:

- [unitOption](https://hl7.org/fhir/uv/sdc/behavior.html#unitOption)
- [unitOption](https://hl7.org/fhir/uv/sdc/behavior.html#unitOption) - Provide selection choices for the unit of a quantity item
- [preferredTerminologyServer](https://build.fhir.org/ig/HL7/sdc/StructureDefinition-sdc-questionnaire-preferredTerminologyServer.html) - Specify the preferred terminology server to use for terminology requests

:::note

Expand Down Expand Up @@ -169,3 +170,14 @@ This can be used when the unit is not fixed, and allows the user to choose from
storyId="component-itemtype-quantity--quantity-unit-option-response"
initialHeight={280}
/>

### PreferredTerminologyServer

PreferredTerminologyServer is used to specify the preferred terminology server to use for terminology requests associated with the whole questionnaire or a particular group or question within the questionnaire (depending on where the extension appears).

#### Basic usage

<IframeContainer
storyId="component-sdc-other-extensions--preferred-terminology-server"
initialHeight={280}
/>
2 changes: 1 addition & 1 deletion documentation/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 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.43.1",
"@aehrc/smart-forms-renderer": "^0.44.0",
"@docusaurus/core": "^3.4.0",
"@docusaurus/preset-classic": "^3.4.0",
"@docusaurus/theme-live-codeblock": "^3.4.0",
Expand Down
6 changes: 3 additions & 3 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/smart-forms-renderer/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import '@fontsource/material-icons';
import { withThemeFromJSXProvider } from '@storybook/addon-styling';
import { createTheme } from '@mui/material/styles';
import { CssBaseline, ThemeProvider } from '@mui/material';
import './iframeResizerChild';
import '../src/stories/storybookWrappers/iframeResizerChild.js';

export const decorators = [
withThemeFromJSXProvider({
Expand Down
5 changes: 2 additions & 3 deletions packages/smart-forms-renderer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aehrc/smart-forms-renderer",
"version": "0.43.1",
"version": "0.44.0",
"description": "FHIR Structured Data Captured (SDC) rendering engine for Smart Forms",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -94,6 +94,5 @@
"ts-jest": "^29.1.1",
"tslib": "^2.6.3",
"typescript": "^5.2.2"
},
"sideEffects": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ function useTerminologyServerQuery(
searchTerm: string
): { options: Coding[]; loading: boolean; feedback?: { message: string; color: AlertColor } } {
const processedValueSetUrls = useQuestionnaireStore.use.processedValueSetUrls();
const itemPreferredTerminologyServers =
useQuestionnaireStore.use.itemPreferredTerminologyServers();
const defaultTerminologyServerUrl = useTerminologyServerStore.use.url();

let fullUrl = '';
Expand Down Expand Up @@ -61,7 +63,9 @@ function useTerminologyServerQuery(
}

// Perform query
const terminologyServerUrl = getTerminologyServerUrl(qItem) ?? defaultTerminologyServerUrl;
const preferredTerminologyServerUrl = itemPreferredTerminologyServers[qItem.linkId];
const terminologyServerUrl =
getTerminologyServerUrl(qItem) ?? preferredTerminologyServerUrl ?? defaultTerminologyServerUrl;
const { isFetching, error, data } = useQuery<ValueSet>(
['expandValueSet', fullUrl],
() => getValueSetPromise(fullUrl, terminologyServerUrl),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ function useValueSetCodings(qItem: QuestionnaireItem): {
const cachedValueSetCodings = useQuestionnaireStore.use.cachedValueSetCodings();
const addCodingToCache = useQuestionnaireStore.use.addCodingToCache();
const { xFhirQueryVariables } = useQuestionnaireStore.use.variables();
const itemPreferredTerminologyServers =
useQuestionnaireStore.use.itemPreferredTerminologyServers();

const defaultTerminologyServerUrl = useTerminologyServerStore.use.url();

Expand Down Expand Up @@ -138,7 +140,11 @@ function useValueSetCodings(qItem: QuestionnaireItem): {
const valueSetUrl = qItem.answerValueSet;
if (!valueSetUrl || codings.length > 0) return;

const terminologyServerUrl = getTerminologyServerUrl(qItem) ?? defaultTerminologyServerUrl;
const preferredTerminologyServerUrl = itemPreferredTerminologyServers[qItem.linkId];
const terminologyServerUrl =
getTerminologyServerUrl(qItem) ??
preferredTerminologyServerUrl ??
defaultTerminologyServerUrl;
const promise = getValueSetPromise(valueSetUrl, terminologyServerUrl);
if (promise) {
promise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type { InitialExpression } from './initialExpression.interface';

export interface QuestionnaireModel {
itemTypes: Record<string, string>;
itemPreferredTerminologyServers: Record<string, string>;
tabs: Tabs;
pages: Pages;
variables: Variables;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import type { InitialExpression } from '../interfaces/initialExpression.interfac
*
* @property sourceQuestionnaire - FHIR R4 Questionnaire to render
* @property itemTypes - Key-value pair of item types `Record<linkId, item.type>`
* @property itemPreferredTerminologyServers - Key-value pair of item types `Record<linkId, preferred terminology servers>`
* @property tabs - Key-value pair of tabs `Record<linkId, Tab>`
* @property currentTabIndex - Index of the current tab
* @property pages - Key-value pair of pages `Record<linkId, Page>`
Expand Down Expand Up @@ -96,6 +97,7 @@ import type { InitialExpression } from '../interfaces/initialExpression.interfac
export interface QuestionnaireStoreType {
sourceQuestionnaire: Questionnaire;
itemTypes: Record<string, string>;
itemPreferredTerminologyServers: Record<string, string>;
tabs: Tabs;
currentTabIndex: number;
pages: Pages;
Expand Down Expand Up @@ -161,6 +163,7 @@ export interface QuestionnaireStoreType {
export const questionnaireStore = createStore<QuestionnaireStoreType>()((set, get) => ({
sourceQuestionnaire: structuredClone(emptyQuestionnaire),
itemTypes: {},
itemPreferredTerminologyServers: {},
tabs: {},
currentTabIndex: 0,
pages: {},
Expand Down Expand Up @@ -223,6 +226,7 @@ export const questionnaireStore = createStore<QuestionnaireStoreType>()((set, ge
set({
sourceQuestionnaire: questionnaire,
itemTypes: questionnaireModel.itemTypes,
itemPreferredTerminologyServers: questionnaireModel.itemPreferredTerminologyServers,
tabs: questionnaireModel.tabs,
currentTabIndex: firstVisibleTab,
pages: questionnaireModel.pages,
Expand All @@ -245,6 +249,7 @@ export const questionnaireStore = createStore<QuestionnaireStoreType>()((set, ge
set({
sourceQuestionnaire: structuredClone(emptyQuestionnaire),
itemTypes: {},
itemPreferredTerminologyServers: {},
tabs: {},
currentTabIndex: 0,
pages: {},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.
*/

import type { Questionnaire } from 'fhir/r4';

export const qPreferredTerminologyServer: Questionnaire = {
resourceType: 'Questionnaire',
id: 'PreferredTerminologyServer',
name: 'PreferredTerminologyServer',
title: 'Preferred Terminology Server',
version: '0.1.0',
status: 'draft',
publisher: 'AEHRC CSIRO',
date: '2024-10-08',
url: 'https://smartforms.csiro.au/docs/terminology/preferred-terminology-server',
extension: [
{
url: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-preferredTerminologyServer',
valueUrl: 'https://sqlonfhir-r4.azurewebsites.net/fhir'
}
],
item: [
{
linkId: 'notes',
_text: {
extension: [
{
url: 'http://hl7.org/fhir/StructureDefinition/rendering-xhtml',
valueString:
'<div xmlns="http://www.w3.org/1999/xhtml">\r\n <p style="font-size:0.875em"> PreferredTerminologyServer is set as <strong>https://sqlonfhir-r4.azurewebsites.net/fhir</strong> for the entire questionnaire.</p><p style="font-size:0.875em">Developer note: Use <strong>Inspect > Network</strong> to see the request.</p></div>'
}
]
},
text: 'PreferredTerminologyServer is set as https://sqlonfhir-r4.azurewebsites.net/fhir for the entire questionnaire. Use Inspect > Network to see the request.',
type: 'display',
repeats: false
},
{
linkId: 'languages',
text: 'Languages',
type: 'choice',
answerValueSet: 'http://hl7.org/fhir/ValueSet/languages'
}
]
};
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ export * from './QBehaviorValueConstraints';
export * from './QItemControlDisplay';
export * from './QItemControlGroup';
export * from './QItemControlQuestion';
export * from './QTerminologyControl';
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.
*/

import type { Meta, StoryObj } from '@storybook/react';
import BuildFormWrapperForStorybook from '../storybookWrappers/BuildFormWrapperForStorybook';
import { qPreferredTerminologyServer } from '../assets/questionnaires';

// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
const meta = {
title: 'Component/SDC/Other Extensions',
component: BuildFormWrapperForStorybook,
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs
tags: []
} satisfies Meta<typeof BuildFormWrapperForStorybook>;

export default meta;
type Story = StoryObj<typeof meta>;

// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args

export const PreferredTerminologyServer: Story = {
args: {
questionnaire: qPreferredTerminologyServer
}
};
Loading

0 comments on commit b263a9d

Please sign in to comment.