Skip to content

Commit

Permalink
Remove empty QR.item array and tweak initialise QR logic to not gener…
Browse files Browse the repository at this point in the history
…ate dummy empty items
  • Loading branch information
fongsean committed Jun 21, 2024
1 parent 09ece41 commit 04a5798
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
13 changes: 3 additions & 10 deletions packages/smart-forms-renderer/src/utils/initialise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,9 @@ export function initialiseQuestionnaireResponse(
if (firstTopLevelItem && !questionnaireResponse.item) {
const initialItems = readItemInitialValues(questionnaire);

questionnaireResponse.item =
initialItems && initialItems.length > 0
? initialItems
: [
{
linkId: firstTopLevelItem.linkId,
text: firstTopLevelItem.text,
item: []
}
];
if (initialItems && initialItems.length > 0) {
questionnaireResponse.item = initialItems;
}
}

if (!questionnaireResponse.questionnaire) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
} from 'fhir/r4';
import type { EnableWhenExpressions, EnableWhenItems } from '../interfaces/enableWhen.interface';
import { isHiddenByEnableWhen } from './qItem';
import cloneDeep from 'lodash.clonedeep';

interface removeEmptyAnswersParams {
questionnaire: Questionnaire;
Expand Down Expand Up @@ -54,7 +55,9 @@ export function removeEmptyAnswers(params: removeEmptyAnswersParams): Questionna
!topLevelQRItems ||
topLevelQRItems.length === 0
) {
return questionnaireResponse;
const updatedQuestionnaireResponse = cloneDeep(questionnaireResponse);
delete updatedQuestionnaireResponse.item;
return updatedQuestionnaireResponse;
}

topLevelQRItems.forEach((qrItem, i) => {
Expand Down

0 comments on commit 04a5798

Please sign in to comment.