Skip to content

Commit

Permalink
fix: apply survey rule then program rule
Browse files Browse the repository at this point in the history
  • Loading branch information
9sneha-n committed Aug 13, 2024
1 parent 398aee9 commit 05953e4
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/domain/usecases/ApplyInitialRulesToSurveyUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ export class ApplyInitialRulesToSurveyUseCase {
currentPPSSurveyForm: Id | undefined,
currentPrevalenceSurveyForm: Id | undefined
): Questionnaire {
let updatedQuestionnaire: Questionnaire;
//1. Apply program rules defined in metadata
updatedQuestionnaire =
Questionnaire.applyProgramRulesOnQuestionnaireInitialLoad(questionnaire);

//2. Apply survey rules defined in the datastore

const currentParentId =
module?.name === "PPS" ? currentPPSSurveyForm : currentPrevalenceSurveyForm;

Expand All @@ -31,20 +24,28 @@ export class ApplyInitialRulesToSurveyUseCase {
rule => rule.surveyId === currentParentId
)?.antibioticBlacklist;

if (currentFormRule) {
updatedQuestionnaire = Questionnaire.applySurveyRulesOnQuestionnaireInitialLoad(
updatedQuestionnaire,
currentFormRule
);
}

if (currentSurveyAntibioticBlacklist) {
updatedQuestionnaire = Questionnaire.applyAntibioticsBlacklist(
updatedQuestionnaire,
currentSurveyAntibioticBlacklist
//1. Apply survey rules defined in the datastore
const surveyRuleUpdatedQuestionnaire = currentFormRule
? Questionnaire.applySurveyRulesOnQuestionnaireInitialLoad(
questionnaire,
currentFormRule
)
: questionnaire;

//2. Apply antibiotic blacklist rules defined in the datastore
const antibioticBlacklistUpdatedQuestionnaire = currentSurveyAntibioticBlacklist
? Questionnaire.applyAntibioticsBlacklist(
surveyRuleUpdatedQuestionnaire,
currentSurveyAntibioticBlacklist
)
: surveyRuleUpdatedQuestionnaire;

//3. Apply program rules defined in metadata
const programRuleUpdatedQuestionnaire =
Questionnaire.applyProgramRulesOnQuestionnaireInitialLoad(
antibioticBlacklistUpdatedQuestionnaire
);
}

return updatedQuestionnaire;
return programRuleUpdatedQuestionnaire;
}
}

0 comments on commit 05953e4

Please sign in to comment.