Skip to content

Commit

Permalink
Merge pull request #53 from EyeSeeTea/feat/hide-stage-datastore-rule
Browse files Browse the repository at this point in the history
feat: hide program stage based on datastore survey rule
  • Loading branch information
MiquelAdell authored May 22, 2024
2 parents 1e0bbb9 + 76f99af commit 1e44a33
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/domain/entities/AMRSurveyModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type SURVEY_TYPE = "NationalSurvey" | "HospitalSurvey" | "SupranationalSu

type UserGroups = { captureAccess: NamedRef[]; readAccess: NamedRef[]; adminAccess: NamedRef[] };

type SurveyRuleType = "HIDEFIELD" | "HIDESECTION";
type SurveyRuleType = "HIDEFIELD" | "HIDESECTION" | "HIDESTAGE";

type Rule = {
id: Id;
Expand Down
26 changes: 26 additions & 0 deletions src/domain/entities/Questionnaire/Questionnaire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ export class Questionnaire {
const updatedStages = questionnaire.stages.map(stage => {
return {
...stage,
isVisible: !surveyRule.rules.find(rule =>
rule.toHide?.find(ruleStage => ruleStage === stage.id)
),
sections: stage.sections.map(section => {
const currentSectionRule = surveyRule.rules.find(rule =>
rule.toHide?.find(de => de === section.code)
Expand Down Expand Up @@ -208,6 +211,29 @@ export class Questionnaire {
updatedStages
);

const hideEntityQuestionRule = surveyRule.rules.find(
rule =>
rule.type === "HIDEFIELD" &&
rule.toHide.find(id =>
updatedQuestionnaire.entity?.questions.find(q => q.id === id)
)
);
if (hideEntityQuestionRule && questionnaire.entity) {
const updatedEntityQuestions: Question[] = questionnaire.entity.questions.map(
question => {
return {
...question,
isVisible: hideEntityQuestionRule.toHide.find(id => id === question.id)
? false
: true,
};
}
);

const updatedEntity = { ...questionnaire.entity, questions: updatedEntityQuestions };
return Questionnaire.updateQuestionnaireEntity(updatedQuestionnaire, updatedEntity);
}

return updatedQuestionnaire;
}

Expand Down

0 comments on commit 1e44a33

Please sign in to comment.