Skip to content

Commit

Permalink
HTML-844 - Encounter fails to save if entered at the same time as vis…
Browse files Browse the repository at this point in the history
…it but hideSeconds is set to true (#304)
  • Loading branch information
mseaton authored Aug 13, 2024
1 parent 52fd5c6 commit c0b5a61
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -704,7 +705,11 @@ public Collection<FormSubmissionError> validateSubmission(FormEntryContext conte
}

validateDateWidget(context, zonedDateTimeWidget, submission);
context.setPendingEncounterDatetime(zonedDateTimeWidget.getValue(context, submission));
Date pendingEncounterDatetime = zonedDateTimeWidget.getValue(context, submission);
if (zonedDateTimeWidget.getHideSeconds()) {
pendingEncounterDatetime = adjustEncounterDate(pendingEncounterDatetime, (Visit) context.getVisit());
}
context.setPendingEncounterDatetime(pendingEncounterDatetime);
}
}
catch (Exception ex) {
Expand Down Expand Up @@ -807,7 +812,10 @@ public void handleSubmission(FormEntrySession session, HttpServletRequest submis
}
}
if (zonedDateTimeWidget != null) {
Date dateTime = (Date) zonedDateTimeWidget.getValue(session.getContext(), submission);
Date dateTime = zonedDateTimeWidget.getValue(session.getContext(), submission);
if (zonedDateTimeWidget.getHideSeconds()) {
dateTime = adjustEncounterDate(dateTime, (Visit) session.getContext().getVisit());
}
Encounter e = session.getSubmissionActions().getCurrentEncounter();
e.setEncounterDatetime(dateTime);
}
Expand Down Expand Up @@ -867,4 +875,20 @@ public static Set<Location> getAllVisitsAndChildLocations(Set<Location> visitLoc
return locations;
}

/**
* This method checks whether the encounter date matches the visit start date down to the minute If
* it does but is after the visit start date (i.e. the seconds are in the future), then it returns
* the visit start date, otherwise it returns the given encounter date.
*/
private Date adjustEncounterDate(Date encounterDate, Visit visit) {
if (encounterDate != null && visit != null && visit.getStartDatetime() != null) {
DateFormat dfToMinutes = new SimpleDateFormat("yyyy-MM-dd-HH-mm");
if (dfToMinutes.format(encounterDate).equals(dfToMinutes.format(visit.getStartDatetime()))) {
if (encounterDate.before(visit.getStartDatetime())) {
return visit.getStartDatetime();
}
}
}
return encounterDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,7 @@ public void setHideSeconds(boolean hideSeconds) {
timeWidget.setHideSeconds(hideSeconds);
}

public boolean getHideSeconds() {
return timeWidget.getHideSeconds();
}
}

0 comments on commit c0b5a61

Please sign in to comment.