Skip to content

Commit

Permalink
#1430 | Throw rule failure if visits are scheduled without earliestVi…
Browse files Browse the repository at this point in the history
…sitDateTime

Return empty array instead of pre-existing visits if error occurs during visit schedule rule execution
Check for null before converting toISTDate
  • Loading branch information
1t5j0y committed Jun 17, 2024
1 parent a326c38 commit e29d825
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
14 changes: 7 additions & 7 deletions packages/openchs-android/package-lock.json

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

19 changes: 16 additions & 3 deletions packages/openchs-android/src/service/RuleEvaluationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,10 @@ class RuleEvaluationService extends BaseService {
params: _.merge({visitSchedule: scheduledVisits, entity, entityContext, services: this.services}, this.getCommonParams()),
imports: getImports()
});
this.checkIfScheduledVisitsAreValid(nextVisits);
return nextVisits;
} catch (e) {
General.logDebug("Rule-Failure", `New enrolment decision failed for form: ${form.uuid}`);
General.logDebug("Rule-Failure", `Visit Schedule failed for form: ${form.uuid}`);
this.saveFailedRules(e, form.uuid, this.getIndividualUUID(entity, entityName));
}
} else {
Expand All @@ -476,9 +477,21 @@ class RuleEvaluationService extends BaseService {
return this.runRuleAndSaveFailure(rule, entityName, entity, schedule, visitScheduleConfig, null, entityContext);
}, scheduledVisits);
General.logDebug("RuleEvaluationService - Next Visits", nextVisits);
return nextVisits;
try {
this.checkIfScheduledVisitsAreValid(nextVisits);
return nextVisits;
} catch(e) {
General.logDebug("Rule-Failure", `Visit Schedule (old) failed for form: ${form.uuid}`);
this.saveFailedRules(e, form.uuid, this.getIndividualUUID(entity, entityName));
}
}
return defaultVisitSchedule;
}

checkIfScheduledVisitsAreValid(nextVisits) {
if (nextVisits.map(visit => _.isNil(visit.earliestVisitDateTime)).length > 0) {
throw new Error("Visit(s) scheduled without earliestVisitDateTime");
}
return scheduledVisits;
}

getChecklists(entity, entityName, defaultChecklists = []) {
Expand Down
2 changes: 1 addition & 1 deletion packages/openchs-android/src/utility/General.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class General {
}

static toISTDate(x) {
if (x.toString().includes("18:30:00"))
if (x && x.toString().includes("18:30:00"))
return moment(x).add(330, "m").toDate();
return x;
}
Expand Down

0 comments on commit e29d825

Please sign in to comment.