Skip to content

Commit

Permalink
Fix lodash dependencies in renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
fongsean committed Sep 25, 2024
1 parent 4f94727 commit bdb8793
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 34 deletions.
4 changes: 0 additions & 4 deletions apps/smart-forms-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
"he": "^1.2.0",
"html-react-parser": "4.2.10",
"lodash.clonedeep": "^4.5.0",
"lodash.debounce": "^4.0.8",
"lodash.filter": "^4.6.0",
"material-ui-popup-state": "^5.1.2",
"moment": "^2.30.1",
"monaco-editor": "^0.47.0",
Expand Down Expand Up @@ -92,8 +90,6 @@
"@types/he": "^1.2.3",
"@types/jest": "^29.5.12",
"@types/lodash.clonedeep": "^4.5.9",
"@types/lodash.debounce": "^4.0.7",
"@types/lodash.filter": "^4.6.7",
"@types/node": "^22.5.0",
"@types/randomcolor": "^0.5.9",
"@types/react": "^18.2.37",
Expand Down
44 changes: 30 additions & 14 deletions package-lock.json

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

6 changes: 5 additions & 1 deletion packages/smart-forms-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"lodash.debounce": "^4.0.8",
"lodash.difference": "^4.5.0",
"lodash.intersection": "^4.4.0",
"lodash.isequal": "^4.5.0",
"nanoid": "^5.0.7",
"react-beautiful-dnd": "^13.1.1",
"react-dnd": "^16.0.1",
Expand Down Expand Up @@ -79,7 +80,10 @@
"@types/fhir": "^0.0.38",
"@types/jest": "^29.5.12",
"@types/lodash.clonedeep": "^4.5.9",
"@types/lodash.debounce": "^4.0.7",
"@types/lodash.debounce": "^4.0.9",
"@types/lodash.difference": "^4.5.9",
"@types/lodash.intersection": "^4.4.9",
"@types/lodash.isequal": "^4.5.8",
"@types/react": ">=17.0.0",
"@types/react-beautiful-dnd": "^13.1.7",
"@types/react-dom": ">=18.2.22",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import type {
QuestionnaireResponseItem,
QuestionnaireResponseItemAnswer
} from 'fhir/r4';
import _isEqual from 'lodash/isEqual';
import { emptyResponse } from './emptyResource';
import { createFhirPathContext } from './fhirpath';
import { getQrItemsIndex, mapQItemsIndex } from './mapItem';
import { updateQrItemsInGroup } from './qrItem';
import cloneDeep from 'lodash.clonedeep';
import dayjs from 'dayjs';
import { updateQuestionnaireResponse } from './genericRecursive';
import isEqual from 'lodash.isequal';

interface EvaluateInitialCalculatedExpressionsParams {
initialResponse: QuestionnaireResponse;
Expand All @@ -60,7 +60,7 @@ export function evaluateInitialCalculatedExpressions(

// Return early if initialResponse is empty or there are no calculated expressions to evaluate
if (
_isEqual(initialResponse, cloneDeep(emptyResponse)) ||
isEqual(initialResponse, cloneDeep(emptyResponse)) ||
Object.keys(calculatedExpressions).length === 0
) {
return {
Expand Down Expand Up @@ -93,7 +93,7 @@ export function evaluateInitialCalculatedExpressions(
);

// Only update calculatedExpressions if length of result array > 0
if (result.length > 0 && !_isEqual(calcExpression.value, result[0])) {
if (result.length > 0 && !isEqual(calcExpression.value, result[0])) {
calcExpression.value = result[0];
}
} catch (e) {
Expand Down Expand Up @@ -136,7 +136,7 @@ export function evaluateCalculatedExpressions(

// Update calculatedExpressions if length of result array > 0
// Only update when current calcExpression value is different from the result, otherwise it will result in an infinite loop as per issue #733
if (result.length > 0 && !_isEqual(calcExpression.value, result[0])) {
if (result.length > 0 && !isEqual(calcExpression.value, result[0])) {
isUpdated = true;
calcExpression.value = result[0];
}
Expand Down
6 changes: 3 additions & 3 deletions packages/smart-forms-renderer/src/utils/openChoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {
} from 'fhir/r4';
import { OpenChoiceItemControl } from '../interfaces/choice.enum';
import { isSpecificItemControl } from './itemControl';
import _isEqual from 'lodash/isEqual';
import isEqual from 'lodash.isequal';

/**
* Update open choice answer based on open label value
Expand Down Expand Up @@ -100,7 +100,7 @@ export function updateOpenLabelAnswer(

// Old open label answer equals to new open label answer
// This should not happen, but return oldQrItem
if (_isEqual(oldOpenLabelAnswer, newOpenLabelAnswer)) {
if (isEqual(oldOpenLabelAnswer, newOpenLabelAnswer)) {
return oldQrItem;
}

Expand All @@ -122,7 +122,7 @@ export function getOldOpenLabelAnswer(
options: QuestionnaireItemAnswerOption[]
): QuestionnaireResponseItemAnswer | null {
const openLabelAnswer = answers.find(
(answer) => !options.some((option) => _isEqual(option, answer))
(answer) => !options.some((option) => isEqual(option, answer))
);
return openLabelAnswer ?? null;
}
Expand Down
16 changes: 8 additions & 8 deletions packages/smart-forms-renderer/src/utils/repopulateItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import type {
QuestionnaireResponseItem
} from 'fhir/r4';
import type { Tabs } from '../interfaces/tab.interface';
import _isEqual from 'lodash/isEqual';
import _intersection from 'lodash/intersection';
import _difference from 'lodash/difference';
import { containsTabs, isTabContainer } from './tabs';
import { getShortText, isSpecificItemControl } from './itemControl';
import { getQrItemsIndex, mapQItemsIndex } from './mapItem';
Expand All @@ -34,6 +31,9 @@ import { questionnaireResponseStore, questionnaireStore } from '../stores';
import cloneDeep from 'lodash.clonedeep';
import { createQuestionnaireResponseItemMap } from './questionnaireResponseStoreUtils/updatableResponseItems';
import { getQuestionnaireItem, getSectionHeading } from './misc';
import difference from 'lodash.difference';
import intersection from 'lodash.intersection';
import isEqual from 'lodash.isequal';

/**
* ItemToRepopulate interface
Expand Down Expand Up @@ -99,11 +99,11 @@ export function generateItemsToRepopulate(populatedResponse: QuestionnaireRespon
// Get linkIds that are different between current QRItems and populated QRItems
// Doesn't work with repeat groups, but at the same time I'm not sure if it's needed, given you can't delete completely the first repeat group
const populatedResponseItemMap = createQuestionnaireResponseItemMap(populatedResponse);
const diffLinkIds = _difference(
const diffLinkIds = difference(
Object.keys(updatableResponseItems),
Object.keys(populatedResponseItemMap)
);
const diffLinkIdsWithInitialExpressions = _intersection(
const diffLinkIdsWithInitialExpressions = intersection(
Object.keys(initialExpressions),
diffLinkIds
);
Expand Down Expand Up @@ -468,7 +468,7 @@ function retrieveSingleOldQRItem(
return;
}

if (_isEqual(oldQRItem, newQRItem)) {
if (isEqual(oldQRItem, newQRItem)) {
delete itemsToRepopulate[qItem.linkId];
return;
}
Expand All @@ -490,7 +490,7 @@ function retrieveRepeatGroupOldQRItems(
return;
}

if (_isEqual(oldQRItems, newQRItems)) {
if (isEqual(oldQRItems, newQRItems)) {
delete itemsToRepopulate[qItem.linkId];
return;
}
Expand Down Expand Up @@ -535,7 +535,7 @@ function retrieveGridGroupOldQRItems(
continue;
}

if (_isEqual(oldGridChildQrItem, newGridChildQRItem)) {
if (isEqual(oldGridChildQrItem, newGridChildQRItem)) {
newGridChildQRItemMap.delete(gridChildQItem.linkId);
} else {
oldGridChildQRItems.push(oldGridChildQrItem);
Expand Down

0 comments on commit bdb8793

Please sign in to comment.