Skip to content

Commit eb1b3d1

Browse files
committed
HTML-873: Encounter Date should validate that encounter datetime falls within Visit
1 parent eca7d69 commit eb1b3d1

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

api/src/main/java/org/openmrs/module/htmlformentry/element/EncounterDetailSubmissionElement.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,15 @@ protected void validateDateWidget(FormEntryContext context, DateWidget dateWidge
680680
if (OpenmrsUtil.compare((Date) date, new Date()) > 0) {
681681
throw new Exception("htmlformentry.error.cannotBeInFuture");
682682
}
683+
684+
if (context.getVisit() != null) {
685+
if (date.before(((Visit) context.getVisit()).getStartDatetime())) {
686+
throw new Exception("htmlformentry.error.cannotBeBeforeVisitStart");
687+
}
688+
if (((Visit) context.getVisit()).getStopDatetime() != null && date.after(((Visit) context.getVisit()).getStopDatetime())) {
689+
throw new Exception("htmlformentry.error.cannotBeAfterVisitStop");
690+
}
691+
}
683692
}
684693

685694
/**

api/src/main/resources/messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ htmlformentry.error.blockMultipleEncounterOnDate = This form has already
1717
htmlformentry.error.cannotBeInFuture = Cannot be in the future
1818
htmlformentry.error.cannotBeAfterEncounterDate = Cannot be after encounter date
1919
htmlformentry.error.cannotBeBeforeEncounterDate = Cannot be before encounter date
20+
htmlformentry.error.cannotBeBeforeVisitStart = Cannot be before visit start date
21+
htmlformentry.error.cannotBeAfterVisitStop = Cannot be after visit stop date
2022
htmlformentry.error.cannotChooseADrugHeader = Oops! You selected a drug header instead of a specific drug.
2123
htmlformentry.error.changedEncounterDate = Changing encounter date is not supported with workflow state
2224
htmlformentry.error.commentWithoutValue = Comment without value

0 commit comments

Comments
 (0)