Skip to content

Commit

Permalink
Explicitly check some types for undefined instead of using falsy expr…
Browse files Browse the repository at this point in the history
…ession
  • Loading branch information
fongsean committed Sep 11, 2024
1 parent 527b745 commit 2ffb86f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/smart-forms-renderer/src/hooks/useDateValidation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function useDateValidation(input: string, parseFail: boolean = false): string |
}

const matches = input.split('/');
if (!matches[0] || !matches[1] || !matches[2]) {
if (matches[0] === undefined || matches[1] === undefined || matches[2] === undefined) {
return 'Input is an invalid date.';
}

Expand All @@ -58,7 +58,7 @@ function useDateValidation(input: string, parseFail: boolean = false): string |
}

const matches = input.split('/');
if (!matches[0] || !matches[1]) {
if (matches[0] === undefined || matches[1] === undefined) {
return 'Input is an invalid date.';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function useQuantityCalculatedExpression(
const ucumValueSet = 'http://hl7.org/fhir/ValueSet/ucum-units';
const ucumSystem = 'http://unitsofmeasure.org';

if (!value || !unitCodeFormatted) {
if (value === undefined || unitCodeFormatted === undefined) {
onChangeByCalcExpressionNull();
return;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/smart-forms-renderer/src/tests/initial.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ test('item.initial is properly pre-filled into QuestionnaireResponse', () => {
const outputResponse = initialiseQuestionnaireResponse(qInitialValueSample);

expect(outputResponse?.item?.[0]).toBeTruthy();
expect(outputResponse?.item?.[0].item?.[0]).toBeTruthy();
expect(outputResponse?.item?.[0].item?.[0].item?.[0]).toBeTruthy();
expect(outputResponse?.item?.[0].item?.[0].item?.[0].item?.[0].answer?.[0]).toStrictEqual({
expect(outputResponse?.item?.[0]?.item?.[0]).toBeTruthy();
expect(outputResponse?.item?.[0]?.item?.[0]?.item?.[0]).toBeTruthy();
expect(outputResponse?.item?.[0]?.item?.[0]?.item?.[0]?.item?.[0]?.answer?.[0]).toStrictEqual({
valueCoding: {
system: 'http://snomed.info/sct',
code: '373066001'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function evaluateEnableWhenSingleExpressions(
const enableWhenSingleExpression = enableWhenSingleExpressions[linkId];
const initialValue = enableWhenSingleExpression?.isEnabled;
const expression = enableWhenSingleExpression?.expression;
if (!enableWhenSingleExpression || !expression) {
if (!enableWhenSingleExpression || expression === undefined) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/smart-forms-renderer/src/utils/mapItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function getQrItemsIndex(

// Assign either a qrItem array or a single qrItem based on whether it is a repeatGroup or not
let isRepeatGroup = false;
if (qItemIndex) {
if (typeof qItemIndex === 'number') {
const qItemAtIndex = qItems[qItemIndex];
if (qItemAtIndex) {
isRepeatGroup = isRepeatItemAndNotCheckbox(qItemAtIndex) && qItemAtIndex.type === 'group';
Expand Down
8 changes: 4 additions & 4 deletions packages/smart-forms-renderer/src/utils/qrItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ export function updateQrItemsInGroup(
}

const newQrItemIndex = qItemsIndexMap[newQrItem.linkId];
if (!newQrItemIndex) {
if (newQrItemIndex === undefined) {
return;
}

// Get actual sequence index of qrItem within qrGroup
for (let i = 0; i < qrItemsRealIndexArr.length; i++) {
const currentRealIndex = qrItemsRealIndexArr[i];
if (!currentRealIndex) {
if (currentRealIndex === undefined) {
continue;
}

Expand Down Expand Up @@ -164,13 +164,13 @@ export function updateQrItemsInGroup(

// Get actual sequence index of qrItems within qrGroup
const newQrItemIndex = qItemsIndexMap[newQrRepeatGroup.linkId];
if (!newQrItemIndex) {
if (newQrItemIndex === undefined) {
return;
}

for (let i = 0; i < qrItemsRealIndexArr.length; i++) {
const currentRealIndex = qrItemsRealIndexArr[i];
if (!currentRealIndex) {
if (currentRealIndex === undefined) {
continue;
}

Expand Down

0 comments on commit 2ffb86f

Please sign in to comment.