Skip to content

Commit 1e55d21

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

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import org.apache.commons.lang.StringEscapeUtils;
55
import org.apache.commons.logging.Log;
66
import org.apache.commons.logging.LogFactory;
7+
import org.codehaus.jackson.map.ext.JodaDeserializers;
8+
import org.joda.time.DateMidnight;
9+
import org.joda.time.DateTime;
10+
import org.joda.time.LocalTime;
711
import org.openmrs.Encounter;
812
import org.openmrs.EncounterType;
913
import org.openmrs.Location;
@@ -682,9 +686,17 @@ protected void validateDateWidget(FormEntryContext context, DateWidget dateWidge
682686
}
683687

684688
if (context.getVisit() != null) {
685-
if (date.before(((Visit) context.getVisit()).getStartDatetime())) {
686-
throw new Exception("htmlformentry.error.cannotBeBeforeVisitStart");
689+
// if the date is at midnight, just compare date components, on the assumption that HFE-UI will adjust as needed
690+
if (new DateTime(date).getMillisOfDay() == 0) {
691+
if (new DateTime(date).isBefore((new DateTime(((Visit) context.getVisit()).getStartDatetime()).withTimeAtStartOfDay()))) {
692+
throw new Exception("htmlformentry.error.cannotBeBeforeVisitStart");
693+
}
694+
} else {
695+
if (date.before(((Visit) context.getVisit()).getStartDatetime())) {
696+
throw new Exception("htmlformentry.error.cannotBeBeforeVisitStart");
697+
}
687698
}
699+
688700
if (((Visit) context.getVisit()).getStopDatetime() != null && date.after(((Visit) context.getVisit()).getStopDatetime())) {
689701
throw new Exception("htmlformentry.error.cannotBeAfterVisitStop");
690702
}

0 commit comments

Comments
 (0)