Skip to content

Commit

Permalink
Remove new helper package to avoid over engineering
Browse files Browse the repository at this point in the history
  • Loading branch information
fongsean committed Dec 21, 2023
1 parent d5dd346 commit 0e81c5b
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 35 deletions.
9 changes: 2 additions & 7 deletions apps/smart-forms-app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ import svgr from 'vite-plugin-svgr';
export default defineConfig({
plugins: [react(), svgr()],
optimizeDeps: {
include: ['@aehrc/sdc-assemble', '@aehrc/sdc-populate', '@aehrc/fhir-questionnaire-helpers']
include: ['@aehrc/sdc-assemble', '@aehrc/sdc-populate']
},
build: {
commonjsOptions: {
include: [
/node_modules/,
'@aehrc/sdc-assemble',
'@aehrc/sdc-populate',
'@aehrc/fhir-questionnaire-helpers'
]
include: [/node_modules/, '@aehrc/sdc-assemble', '@aehrc/sdc-populate']
}
},
resolve: { preserveSymlinks: true }
Expand Down
6 changes: 2 additions & 4 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions packages/sdc-assemble/src/utils/fetchSubquestionnaires.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

import type { Bundle, OperationOutcome, Questionnaire } from 'fhir/r4';
import axios from 'axios';
import { createErrorOutcome } from './operationOutcome';
import type { FetchQuestionnaireCallback } from '../interfaces';

Expand All @@ -40,7 +39,7 @@ export async function fetchSubquestionnaires(

let resources: (Bundle | OperationOutcome)[] = [];
try {
const responses = await axios.all(promises);
const responses = await Promise.all(promises);
resources = responses.map((response) => response.data);
} catch (e) {
if (e instanceof Error) {
Expand Down
3 changes: 1 addition & 2 deletions packages/sdc-populate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aehrc/sdc-populate",
"version": "1.4.2",
"version": "1.4.3",
"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 All @@ -20,7 +20,6 @@
},
"homepage": "https://github.com/aehrc/smart-forms#readme",
"dependencies": {
"@aehrc/fhir-questionnaire-helpers": "^0.1.1",
"dayjs": "^1.11.10",
"fhir-sdc-helpers": "^0.1.0",
"fhirclient": "^2.5.2",
Expand Down
56 changes: 56 additions & 0 deletions packages/sdc-populate/src/utils/answerOption.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2023 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 { QuestionnaireItemAnswerOption, QuestionnaireResponseItemAnswer } from 'fhir/r4';

/**
* Find and return corresponding answerOption based on selected answer in form
*
* @author Sean Fong
*/
export function findInAnswerOptions(
options: QuestionnaireItemAnswerOption[],
str: string
): QuestionnaireResponseItemAnswer | undefined {
for (const option of options) {
if (option.valueCoding) {
if (str === option.valueCoding.code) {
return {
valueCoding: option.valueCoding
};
}
}

if (option.valueString) {
if (str === option.valueString) {
return {
valueString: option.valueString
};
}
}

if (option.valueInteger) {
if (str === option.valueInteger.toString()) {
return {
valueInteger: option.valueInteger
};
}
}
}

return;
}
2 changes: 1 addition & 1 deletion packages/sdc-populate/src/utils/constructResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import moment from 'moment';
import dayjs from 'dayjs';
import fhirpath from 'fhirpath';
import fhirpath_r4_model from 'fhirpath/fhir-context/r4';
import { findInAnswerOptions } from '@aehrc/fhir-questionnaire-helpers';
import { findInAnswerOptions } from './answerOption';

/**
* Constructs a questionnaireResponse recursively from a specified questionnaire, its subject and its initialExpressions
Expand Down
3 changes: 1 addition & 2 deletions packages/sdc-populate/src/utils/createFhirPathContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import type {
import { isContextParameter } from './typePredicates';
import fhirpath from 'fhirpath';
import type { Bundle, FhirResource, OperationOutcomeIssue, Questionnaire } from 'fhir/r4';
import axios from 'axios';
import { createWarningIssue } from './operationOutcome';
import type { FetchResourceCallback } from '../interfaces';

Expand Down Expand Up @@ -60,7 +59,7 @@ export async function createFhirPathContext(
// Resolve promises
try {
const promises: Promise<any>[] = referenceContextsTuple.map(([, promise]) => promise);
const responses = await axios.all(promises);
const responses = await Promise.all(promises);

const resources = responses.map((response) => response.data as FhirResource);
referenceContextsTuple = referenceContextsTuple.map((tuple, i) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdc-populate/src/utils/processValueSets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {
QuestionnaireResponseItemAnswer,
ValueSet
} from 'fhir/r4';
import type { ValueSetPromise } from '@aehrc/fhir-questionnaire-helpers';
import type { ValueSetPromise } from '../interfaces/expressions.interface';
import * as FHIR from 'fhirclient';

const ONTOSERVER_ENDPOINT = 'https://r4.ontoserver.csiro.au/fhir/';
Expand Down
3 changes: 1 addition & 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.10.6",
"version": "0.10.7",
"description": "FHIR Structured Data Captured (SDC) rendering engine for Smart Forms",
"main": "lib/index.js",
"scripts": {
Expand All @@ -24,7 +24,6 @@
},
"homepage": "https://github.com/aehrc/smart-forms#readme",
"dependencies": {
"@aehrc/fhir-questionnaire-helpers": "^0.1.1",
"@iconify/react": "^4.1.1",
"@types/fhir": "^0.0.38",
"dayjs": "^1.11.10",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import React from 'react';
import Grid from '@mui/material/Grid';
import type { ChoiceItemOrientation } from '../../../interfaces/choice.enum';
import type { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4';
import { getQrChoiceValue } from '../../../utils/choice';
import { findInAnswerOptions, getQrChoiceValue } from '../../../utils/choice';
import { createEmptyQrItem } from '../../../utils/qrItem';
import { FullWidthFormComponentBox } from '../../Box.styles';
import useRenderingExtensions from '../../../hooks/useRenderingExtensions';
Expand All @@ -32,7 +32,6 @@ import DisplayInstructions from '../DisplayItem/DisplayInstructions';
import LabelWrapper from '../ItemParts/ItemLabelWrapper';
import ChoiceRadioAnswerOptionFields from './ChoiceRadioAnswerOptionFields';
import useReadOnly from '../../../hooks/useReadOnly';
import { findInAnswerOptions } from '@aehrc/fhir-questionnaire-helpers';

interface ChoiceRadioAnswerOptionItemProps
extends PropsWithQrItemChangeHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import React from 'react';
import Grid from '@mui/material/Grid';

import type { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4';
import { getQrChoiceValue } from '../../../utils/choice';
import { findInAnswerOptions, getQrChoiceValue } from '../../../utils/choice';
import { createEmptyQrItem } from '../../../utils/qrItem';
import { FullWidthFormComponentBox } from '../../Box.styles';
import useRenderingExtensions from '../../../hooks/useRenderingExtensions';
Expand All @@ -33,7 +33,6 @@ import DisplayInstructions from '../DisplayItem/DisplayInstructions';
import LabelWrapper from '../ItemParts/ItemLabelWrapper';
import ChoiceSelectAnswerOptionFields from './ChoiceSelectAnswerOptionFields';
import useReadOnly from '../../../hooks/useReadOnly';
import { findInAnswerOptions } from '@aehrc/fhir-questionnaire-helpers';

interface ChoiceSelectAnswerOptionItemProps
extends PropsWithQrItemChangeHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { createEmptyQrItem } from '../../../utils/qrItem';
import { getOpenLabelText } from '../../../utils/itemControl';
import { getOldOpenLabelAnswer } from '../../../utils/openChoice';
import { FullWidthFormComponentBox } from '../../Box.styles';
import { getQrChoiceValue } from '../../../utils/choice';
import { findInAnswerOptions, getQrChoiceValue } from '../../../utils/choice';
import useRenderingExtensions from '../../../hooks/useRenderingExtensions';
import type {
PropsWithIsRepeatedAttribute,
Expand All @@ -34,7 +34,6 @@ import DisplayInstructions from '../DisplayItem/DisplayInstructions';
import LabelWrapper from '../ItemParts/ItemLabelWrapper';
import OpenChoiceRadioAnswerOptionFields from './OpenChoiceRadioAnswerOptionFields';
import useReadOnly from '../../../hooks/useReadOnly';
import { findInAnswerOptions } from '@aehrc/fhir-questionnaire-helpers';

interface OpenChoiceRadioAnswerOptionItemProps
extends PropsWithQrItemChangeHandler,
Expand Down
40 changes: 38 additions & 2 deletions packages/smart-forms-renderer/src/utils/choice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type {
Coding,
Extension,
Expand All @@ -25,7 +24,44 @@ import type {
} from 'fhir/r4';
import { ChoiceItemControl, ChoiceItemOrientation } from '../interfaces/choice.enum';
import { isSpecificItemControl } from './itemControl';
import { findInAnswerOptions } from '@aehrc/fhir-questionnaire-helpers';

/**
* Find and return corresponding answerOption based on selected answer in form
*
* @author Sean Fong
*/
export function findInAnswerOptions(
options: QuestionnaireItemAnswerOption[],
str: string
): QuestionnaireResponseItemAnswer | undefined {
for (const option of options) {
if (option.valueCoding) {
if (str === option.valueCoding.code) {
return {
valueCoding: option.valueCoding
};
}
}

if (option.valueString) {
if (str === option.valueString) {
return {
valueString: option.valueString
};
}
}

if (option.valueInteger) {
if (str === option.valueInteger.toString()) {
return {
valueInteger: option.valueInteger
};
}
}
}

return;
}

/**
* Get choice control type based on certain criteria in choice items
Expand Down
3 changes: 1 addition & 2 deletions packages/smart-forms-renderer/src/utils/openChoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import type {
} from 'fhir/r4';
import { CheckBoxOption, OpenChoiceItemControl } from '../interfaces/choice.enum';
import { isSpecificItemControl } from './itemControl';
import { findInAnswerValueSetCodings } from './choice';
import { findInAnswerOptions } from '@aehrc/fhir-questionnaire-helpers';
import { findInAnswerOptions, findInAnswerValueSetCodings } from './choice';

/**
* Update open-choice checkbox group answers based on checkbox changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import type { ValueSetPromise } from '@aehrc/fhir-questionnaire-helpers';
import type { ValueSetPromise } from '../../interfaces/valueSet.interface';
import { getValueSetCodings, getValueSetPromise } from '../valueSet';
import type { Coding, Questionnaire, ValueSet } from 'fhir/r4';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {
EnableWhenLinkedItem
} from '../../interfaces/enableWhen.interface';
import type { AnswerExpression } from '../../interfaces/answerExpression.interface';
import type { ValueSetPromise } from '@aehrc/fhir-questionnaire-helpers';
import type { ValueSetPromise } from '../../interfaces/valueSet.interface';
import { getAnswerExpression } from '../itemControl';
import { getTerminologyServerUrl, getValueSetPromise } from '../valueSet';
import type { Variables } from '../../interfaces/variables.interface';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
resolvePromises
} from '../valueSet';
import type { Variables } from '../../interfaces/variables.interface';
import type { ValueSetPromise } from '@aehrc/fhir-questionnaire-helpers';
import type { ValueSetPromise } from '../../interfaces/valueSet.interface';

export async function resolveValueSets(
variables: Variables,
Expand Down
2 changes: 1 addition & 1 deletion packages/smart-forms-renderer/src/utils/valueSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type {
import * as FHIR from 'fhirclient';
import type { FhirResourceString } from '../interfaces/populate.interface';
import type { VariableXFhirQuery } from '../interfaces/variables.interface';
import type { ValueSetPromise } from '@aehrc/fhir-questionnaire-helpers';
import type { ValueSetPromise } from '../interfaces/valueSet.interface';

const VALID_VALUE_SET_URL_REGEX =
/https?:\/\/(www\.)?[-\w@:%.+~#=]{2,256}\.[a-z]{2,4}\b([-@\w:%+.~#?&/=]*ValueSet[-@\w:%+.~#?&/=]*)/;
Expand Down

0 comments on commit 0e81c5b

Please sign in to comment.