Skip to content

Commit

Permalink
- Fixed #1069 by adding support for Quantity Max and Min value extens…
Browse files Browse the repository at this point in the history
…ions.
  • Loading branch information
janadh committed Jan 10, 2025
1 parent 17d8b33 commit aa9f78c
Show file tree
Hide file tree
Showing 4 changed files with 301 additions and 10 deletions.
4 changes: 3 additions & 1 deletion apps/smart-forms-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true
"forceConsistentCasingInFileNames": true,
/* Debugging */
"sourceMap": true
},
"include": ["src", "cypress"],
"references": [{ "path": "./tsconfig.node.json" }]
Expand Down
29 changes: 28 additions & 1 deletion packages/smart-forms-renderer/src/hooks/useValidationFeedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import {
getMaxValueFeedback,
getMinValue,
getMinValueFeedback,
getMinQuantityValue,
getMinQuantityValueFeedback,
getMaxQuantityValue,
getMaxQuantityValueFeedback,
getRegexValidation
} from '../utils/itemControl';
import { structuredDataCapture } from 'fhir-sdc-helpers';
Expand All @@ -33,6 +37,8 @@ function useValidationFeedback(qItem: QuestionnaireItem, input: string): string
const maxDecimalPlaces = structuredDataCapture.getMaxDecimalPlaces(qItem);
const minValue = getMinValue(qItem);
const maxValue = getMaxValue(qItem);
const minQuantityValue = getMinQuantityValue(qItem);//gets the minQuantity value from the questionaire item

Check failure on line 40 in packages/smart-forms-renderer/src/hooks/useValidationFeedback.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `·`
const maxQuantityValue = getMaxQuantityValue(qItem);//gets the maxQuantity value from the questionaire item

Check failure on line 41 in packages/smart-forms-renderer/src/hooks/useValidationFeedback.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `·`

const invalidType = getInputInvalidType({
qItem,
Expand All @@ -42,12 +48,17 @@ function useValidationFeedback(qItem: QuestionnaireItem, input: string): string
maxLength,
maxDecimalPlaces,
minValue,
maxValue
maxValue,
minQuantityValue,// Min Quantity validation type

Check failure on line 52 in packages/smart-forms-renderer/src/hooks/useValidationFeedback.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `·`
maxQuantityValue// Max Quantity validation type

Check failure on line 53 in packages/smart-forms-renderer/src/hooks/useValidationFeedback.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `·`
});

if (!invalidType) {
return '';
}

Check failure on line 58 in packages/smart-forms-renderer/src/hooks/useValidationFeedback.ts

View workflow job for this annotation

GitHub Actions / Lint

Delete `⏎·`
else {
//invalid type exists, so we proceed
}

if (invalidType === ValidationResult.regex && regexValidation) {
return `Input should match the specified regex ${regexValidation.expression}`;
Expand Down Expand Up @@ -86,6 +97,22 @@ function useValidationFeedback(qItem: QuestionnaireItem, input: string): string
return maxValueFeedback ?? `Input exceeds permitted maximum value of ${maxValue}.`;
}

//Test min quantity
if (

Check failure on line 101 in packages/smart-forms-renderer/src/hooks/useValidationFeedback.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `⏎····invalidType·===·ValidationResult.minQuantityValue·&&⏎····(typeof·minQuantityValue·===·'number')⏎··` with `invalidType·===·ValidationResult.minQuantityValue·&&·typeof·minQuantityValue·===·'number'`
invalidType === ValidationResult.minQuantityValue &&
(typeof minQuantityValue === 'number')
) {
const minQuantityFeedback = getMinQuantityValueFeedback(qItem);//get the feedback for minquantity if it exists

Check failure on line 105 in packages/smart-forms-renderer/src/hooks/useValidationFeedback.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `·`
return minQuantityFeedback ?? `Input is lower than the expected minimum quantity value of ${minQuantityValue}.`;

Check failure on line 106 in packages/smart-forms-renderer/src/hooks/useValidationFeedback.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `minQuantityFeedback·??·`Input·is·lower·than·the·expected·minimum·quantity·value·of·${minQuantityValue}.`` with `(⏎······minQuantityFeedback·??⏎······`Input·is·lower·than·the·expected·minimum·quantity·value·of·${minQuantityValue}.`⏎····)`
}
//Test max quantity
if (

Check failure on line 109 in packages/smart-forms-renderer/src/hooks/useValidationFeedback.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `⏎····invalidType·===·ValidationResult.maxQuantityValue·&&⏎····(typeof·maxQuantityValue·===·'number')⏎··` with `invalidType·===·ValidationResult.maxQuantityValue·&&·typeof·maxQuantityValue·===·'number'`
invalidType === ValidationResult.maxQuantityValue &&
(typeof maxQuantityValue === 'number')
) {
const maxQuantityFeedback = getMaxQuantityValueFeedback(qItem);//get the feedback for maxquantity if it exists

Check failure on line 113 in packages/smart-forms-renderer/src/hooks/useValidationFeedback.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `·`
return maxQuantityFeedback ?? `Input exceeds permitted maximum quantity value of ${maxQuantityValue}.`;
}
return '';
}

Expand Down
105 changes: 104 additions & 1 deletion packages/smart-forms-renderer/src/utils/itemControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import type { Coding, Extension, QuestionnaireItem, QuestionnaireItemAnswerOption } from 'fhir/r4';
import type { Coding, Extension, Quantity, QuestionnaireItem, QuestionnaireItemAnswerOption } from 'fhir/r4';
import type { RegexValidation } from '../interfaces/regex.interface';
import { structuredDataCapture } from 'fhir-sdc-helpers';
import { default as htmlParse } from 'html-react-parser';
Expand Down Expand Up @@ -470,3 +470,106 @@ export function getMaxValueFeedback(qItem: QuestionnaireItem) {

return null;
}




/**
* Check if the item has a sdc-questionnaire-minQuantity and minQuantity extension
* @author Janardhan Vignarajan
* @export
* @param {QuestionnaireItem} qItem
* @return {*} {(number | undefined)}
*/
export function getMinQuantityValue(qItem: QuestionnaireItem) : number | undefined {
const itemControl = qItem.extension?.find(
(extension: Extension) =>
extension.url === 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-minQuantity'
);

if (itemControl && itemControl.valueQuantity) { //check if valueQuantity exists in the extension
if (itemControl.valueQuantity.value) {//check if valueQuantity.value exists in the extension
return itemControl.valueQuantity.value;
}
}
return undefined;
}


/**
* Check if the item has a sdc-questionnaire-minQuantity feedback extension
*
* @author Janardhan Vignarajan
* @export
* @param {QuestionnaireItem} qItem
* @return {*}
*/
export function getMinQuantityValueFeedback(qItem: QuestionnaireItem) {
const itemControl = qItem.extension?.find(
(extension: Extension) =>
extension.url === 'https://smartforms.csiro.au/ig/StructureDefinition/minQuantityValue-feedback'
);
if (itemControl) {
const extensionString = itemControl.valueString;
if (extensionString) {
return extensionString;
}
}

return null;
}



/**
* Check if the item has a sdc-questionnaire-maxQuantity extension
*
* @author Janardhan Vignarajan
* @export
* @param {QuestionnaireItem} qItem
* @return {*} {(number | undefined)}
*/
export function getMaxQuantityValue(qItem: QuestionnaireItem) : number | undefined {
const itemControl = qItem.extension?.find(
(extension: Extension) =>
extension.url === 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-maxQuantity'
);

if (itemControl && itemControl.valueQuantity) { //check if valueQuantity exists in the extension
if (itemControl.valueQuantity.value) {//check if valueQuantity.value exists in the extension
return itemControl.valueQuantity.value;
}
}
return undefined;
}


/**
* Check if the item has a sdc-questionnaire-maxQuantity Feedback extension
*
* @author Janardhan Vignarajan
* @export
* @param {QuestionnaireItem} qItem
* @return {*}
*/
export function getMaxQuantityValueFeedback(qItem: QuestionnaireItem) {
const itemControl = qItem.extension?.find(
(extension: Extension) =>
extension.url === 'https://smartforms.csiro.au/ig/StructureDefinition/maxQuantityValue-feedback'
);
if (itemControl) {
const extensionString = itemControl.valueString;
if (extensionString) {
return extensionString;
}
}

return null;
}






Loading

0 comments on commit aa9f78c

Please sign in to comment.