Skip to content

Commit

Permalink
Merge pull request #867 from aehrc/fix/re-pop-encounter
Browse files Browse the repository at this point in the history
Fix/re pop encounter
  • Loading branch information
fongsean authored Jun 14, 2024
2 parents 2e5a096 + 02b3cf4 commit e224880
Show file tree
Hide file tree
Showing 25 changed files with 375 additions and 36 deletions.
12 changes: 12 additions & 0 deletions apps/smart-forms-app/e2e/prepop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,16 @@ test('pre-pop to test terminology resolving logic', async ({ page }) => {
.getByTestId('q-item-choice-select-answer-value-set-box')
.locator(`#${genderAvsContainedValueLinkId}`)
).toHaveValue('Female');

const medicalHistoryConditionValueLinkId = 'medical-history-condition';

const elements = await page.locator(`#${medicalHistoryConditionValueLinkId}`).all();
for (const element of elements) {
const inputValue = await element.inputValue();

// Test if the input values contains at least one alphabetic character
// If it's fully numeric, it means the valueCoding.code is pre-populated instead of valueCoding.display
// the logic in sdc-populate, automatically $lookup and assigns display to codings that lack them, which means that part is failing in this case
expect(/^\d+$/.test(inputValue)).toBeFalsy();
}
});
4 changes: 2 additions & 2 deletions apps/smart-forms-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"homepage": "https://github.com/aehrc/smart-forms#readme",
"dependencies": {
"@aehrc/sdc-assemble": "^1.2.0",
"@aehrc/sdc-populate": "^2.2.1",
"@aehrc/smart-forms-renderer": "^0.35.5",
"@aehrc/sdc-populate": "^2.2.2",
"@aehrc/smart-forms-renderer": "^0.35.6",
"@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 @@ -22,7 +22,7 @@ import cloneDeep from 'lodash.clonedeep';

interface RepopulateGridGroupProps {
qItem: QuestionnaireItem;
newQRItem: QuestionnaireResponseItem;
newQRItem?: QuestionnaireResponseItem;
oldQRItem?: QuestionnaireResponseItem;
}

Expand All @@ -34,7 +34,8 @@ function RepopulateGridGroup(props: RepopulateGridGroupProps) {
oldQRItem ??
cloneDeep({
...newQRItem,
item: newQRItem.item?.map((item) => ({
linkId: newQRItem?.linkId ?? '',
item: newQRItem?.item?.map((item) => ({
...item,
item: item.item?.map((subItem) => ({
...subItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { GroupTable } from '@aehrc/smart-forms-renderer';

interface RepopulateRepeatGroupProps {
qItem: QuestionnaireItem;
newQRItems: QuestionnaireResponseItem[];
newQRItems?: QuestionnaireResponseItem[];
oldQRItems?: QuestionnaireResponseItem[];
}

Expand Down Expand Up @@ -49,7 +49,7 @@ function RepopulateGroupTable(props: RepopulateRepeatGroupProps) {
</Typography>
<GroupTable
qItem={qItem}
qrItems={newQRItems}
qrItems={newQRItems ?? []}
groupCardElevation={1}
showMinimalView={true}
parentIsReadOnly={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import RepopulateGridGroup from './RepopulateGridGroup.tsx';

interface RepopulateItemSwitcherProps {
qItem: QuestionnaireItem;
newQRItem: QuestionnaireResponseItem;
newQRItem?: QuestionnaireResponseItem;
oldQRItem?: QuestionnaireResponseItem;
newQRItems: QuestionnaireResponseItem[];
newQRItems?: QuestionnaireResponseItem[];
oldQRItems?: QuestionnaireResponseItem[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import RepopulateItemSwitcher from './RepopulateItemSwitcher.tsx';
interface RepopulateListItemProps {
checkedIds: string[];
qItem: QuestionnaireItem;
newQRItem: QuestionnaireResponseItem;
newQRItem?: QuestionnaireResponseItem;
oldQRItem?: QuestionnaireResponseItem;
newQRItems: QuestionnaireResponseItem[];
newQRItems?: QuestionnaireResponseItem[];
oldQRItems?: QuestionnaireResponseItem[];
onCheckItem: () => void;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { RepeatGroup } from '@aehrc/smart-forms-renderer';

interface RepopulateRepeatGroupProps {
qItem: QuestionnaireItem;
newQRItems: QuestionnaireResponseItem[];
newQRItems?: QuestionnaireResponseItem[];
oldQRItems?: QuestionnaireResponseItem[];
}

Expand Down Expand Up @@ -49,7 +49,7 @@ function RepopulateRepeatGroup(props: RepopulateRepeatGroupProps) {
</Typography>
<RepeatGroup
qItem={qItem}
qrItems={newQRItems}
qrItems={newQRItems ?? []}
groupCardElevation={1}
showMinimalView={true}
parentIsReadOnly={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { RepeatItem } from '@aehrc/smart-forms-renderer';
interface RepopulateRepeatItemProps {
qItem: QuestionnaireItem;
oldQRItem?: QuestionnaireResponseItem;
newQRItem: QuestionnaireResponseItem;
newQRItem?: QuestionnaireResponseItem;
}

function RepopulateRepeatItem(props: RepopulateRepeatItemProps) {
Expand Down Expand Up @@ -53,7 +53,7 @@ function RepopulateRepeatItem(props: RepopulateRepeatItemProps) {
</Typography>
<RepeatItem
qItem={qItem}
qrItem={newQRItem}
qrItem={newQRItem ?? null}
groupCardElevation={1}
showMinimalView={true}
onQrItemChange={() => void 0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4';
interface RepopulateSingleItemProps {
qItem: QuestionnaireItem;
oldQRItem?: QuestionnaireResponseItem;
newQRItem: QuestionnaireResponseItem;
newQRItem?: QuestionnaireResponseItem;
}

function RepopulateSingleItem(props: RepopulateSingleItemProps) {
Expand Down Expand Up @@ -58,7 +58,7 @@ function RepopulateSingleItem(props: RepopulateSingleItemProps) {
</Typography>
<SingleItem
qItem={qItem}
qrItem={newQRItem}
qrItem={newQRItem ?? null}
isRepeated={true}
isTabled={false}
groupCardElevation={1}
Expand Down
22 changes: 17 additions & 5 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.2.1",
"version": "2.2.2",
"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
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ export function getCodeSystemLookupPromise(
terminologyCallback?: FetchResourceCallback,
terminologyRequestConfig?: any
) {
const query = `CodeSystem/$lookup?system=${coding.system}&code=${coding.code}`;
const key = `system=${coding.system}&code=${coding.code}`;
const query = `CodeSystem/$lookup?${key}`;

const lookupPromise = terminologyCallback
? terminologyCallback(query, terminologyRequestConfig)
: defaultTerminologyRequest(query);

codeSystemLookupPromiseMap[query] = {
codeSystemLookupPromiseMap[key] = {
promise: lookupPromise,
oldCoding: coding
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface ValueSetPromise {
}

export interface CodeSystemLookupPromise {
promise: Promise<Parameters<any>>;
promise: Promise<any>;
oldCoding: Coding;
newCoding?: Coding;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {
InitialExpression
} from '../interfaces/expressions.interface';
import type { Coding } from 'fhir/r4';
import type { LookupResponse } from '../api/lookupCodeSystem';
import { getCodeSystemLookupPromise, lookupResponseIsValid } from '../api/lookupCodeSystem';
import type { FetchResourceCallback } from '../interfaces';

Expand Down Expand Up @@ -89,8 +90,22 @@ export async function resolveLookupPromises(
continue;
}

const lookupResult = settledPromise.value;
if (!lookupResponseIsValid(lookupResult)) {
let lookupResult: LookupResponse | null = null;

// Get lookupResult from response (fhirClient scenario)
if (lookupResponseIsValid(settledPromise.value)) {
lookupResult = settledPromise.value;
}
// Fallback to get valueSet from response.data (axios scenario)
if (
!lookupResult &&
settledPromise.value.data &&
lookupResponseIsValid(settledPromise.value.data)
) {
lookupResult = settledPromise.value.data;
}

if (!lookupResult) {
continue;
}

Expand Down
6 changes: 4 additions & 2 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.35.5",
"version": "0.35.6",
"description": "FHIR Structured Data Captured (SDC) rendering engine for Smart Forms",
"main": "lib/index.js",
"scripts": {
Expand All @@ -27,7 +27,7 @@
},
"homepage": "https://github.com/aehrc/smart-forms#readme",
"dependencies": {
"@aehrc/sdc-populate": "^2.2.1",
"@aehrc/sdc-populate": "^2.2.2",
"@iconify/react": "^4.1.1",
"dayjs": "^1.11.10",
"deep-diff": "^1.0.2",
Expand All @@ -37,6 +37,8 @@
"js-base64": "^3.7.7",
"lodash.clonedeep": "^4.5.0",
"lodash.debounce": "^4.0.8",
"lodash.difference": "^4.5.0",
"lodash.intersection": "^4.4.0",
"nanoid": "^5.0.1",
"react-beautiful-dnd": "^13.1.1",
"react-dnd": "^16.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.
*/

/**
* InitialExpression interface
*
* @property expression - InitialExpression FHIRPath expression
*/
export interface InitialExpression {
expression: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { EnableWhenExpressions, EnableWhenItems } from './enableWhen.interf
import type { CalculatedExpression } from './calculatedExpression.interface';
import type { AnswerExpression } from './answerExpression.interface';
import type { Coding, QuestionnaireItemAnswerOption } from 'fhir/r4';
import type { InitialExpression } from './initialExpression.interface';

export interface QuestionnaireModel {
itemTypes: Record<string, string>;
Expand All @@ -31,6 +32,7 @@ export interface QuestionnaireModel {
enableWhenItems: EnableWhenItems;
enableWhenExpressions: EnableWhenExpressions;
calculatedExpressions: Record<string, CalculatedExpression[]>;
initialExpressions: Record<string, InitialExpression>;
answerExpressions: Record<string, AnswerExpression>;
answerOptions: Record<string, QuestionnaireItemAnswerOption[]>;
processedValueSetCodings: Record<string, Coding[]>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { mutateRepeatEnableWhenExpressionInstances } from '../utils/enableWhenEx
import { questionnaireResponseStore } from './questionnaireResponseStore';
import { createQuestionnaireResponseItemMap } from '../utils/questionnaireResponseStoreUtils/updatableResponseItems';
import { insertCompleteAnswerOptionsIntoQuestionnaire } from '../utils/questionnaireStoreUtils/insertAnswerOptions';
import type { InitialExpression } from '../interfaces/initialExpression.interface';

/**
* QuestionnaireStore properties and methods
Expand Down Expand Up @@ -100,6 +101,7 @@ export interface QuestionnaireStoreType {
enableWhenIsActivated: boolean;
enableWhenExpressions: EnableWhenExpressions;
calculatedExpressions: Record<string, CalculatedExpression[]>;
initialExpressions: Record<string, InitialExpression>;
answerExpressions: Record<string, AnswerExpression>;
processedValueSetCodings: Record<string, Coding[]>;
processedValueSetUrls: Record<string, string>;
Expand Down Expand Up @@ -156,6 +158,7 @@ export const questionnaireStore = createStore<QuestionnaireStoreType>()((set, ge
variables: { fhirPathVariables: {}, xFhirQueryVariables: {} },
launchContexts: {},
calculatedExpressions: {},
initialExpressions: {},
enableWhenExpressions: { singleExpressions: {}, repeatExpressions: {} },
answerExpressions: {},
enableWhenItems: { singleItems: {}, repeatItems: {} },
Expand Down Expand Up @@ -216,6 +219,7 @@ export const questionnaireStore = createStore<QuestionnaireStoreType>()((set, ge
enableWhenLinkedQuestions: initialEnableWhenLinkedQuestions,
enableWhenExpressions: initialEnableWhenExpressions,
calculatedExpressions: initialCalculatedExpressions,
initialExpressions: questionnaireModel.initialExpressions,
answerExpressions: questionnaireModel.answerExpressions,
processedValueSetCodings: questionnaireModel.processedValueSetCodings,
processedValueSetUrls: questionnaireModel.processedValueSetUrls,
Expand All @@ -235,6 +239,7 @@ export const questionnaireStore = createStore<QuestionnaireStoreType>()((set, ge
enableWhenLinkedQuestions: {},
enableWhenExpressions: { singleExpressions: {}, repeatExpressions: {} },
calculatedExpressions: {},
initialExpressions: {},
answerExpressions: {},
processedValueSetCodings: {},
processedValueSetUrls: {},
Expand Down
Loading

0 comments on commit e224880

Please sign in to comment.