Skip to content

Commit

Permalink
RA-950: Add LastVisit and EditVisit require an EndDate
Browse files Browse the repository at this point in the history
  • Loading branch information
reagan committed Feb 19, 2020
1 parent 5789acc commit f625180
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,30 @@ public Object create(@SpringBean("adtService") AdtService adtService,
@RequestParam(value = "stopDate", required = false) Date stopDate,
HttpServletRequest request, UiUtils ui) {

// if no stop date, set it to start date
if (stopDate == null) {
stopDate = startDate;
}

// set the startDate time component to the start of day
startDate = new DateTime(startDate).withTime(0,0,0,0).toDate();

// if stopDate is today, set stopDate to current datetime, otherwise set time component to end of date
if (stopDate != null){
if (new DateTime().withTime(0,0,0,0).equals(new DateTime(stopDate).withTime(0,0,0,0))) {
stopDate = new Date();
}
else {
stopDate = new DateTime(stopDate).withTime(23, 59, 59, 999).toDate();
}
}

try {

VisitDomainWrapper createdVisit = adtService.createRetrospectiveVisit(patient, location, startDate, stopDate);

request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE,
ui.message("coreapps.retrospectiveVisit.addedVisitMessage"));
request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");

return SimpleObject.create("success", true, "id", createdVisit.getVisit().getId().toString(), "uuid", createdVisit.getVisit().getUuid());
}

}
catch (ExistingVisitDuringTimePeriodException e) {

// if there are existing visit(s), return these existing visits
Expand All @@ -70,6 +69,7 @@ public Object create(@SpringBean("adtService") AdtService adtService,
}
}


return simpleVisits;
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ public SimpleObject setDuration(@SpringBean("visitService") VisitService visitSe
@RequestParam(value="stopDate", required = false) Date stopDate,
HttpServletRequest request, UiUtils ui) {


if (!isSameDay(startDate, visit.getStartDatetime())) {
visit.setStartDatetime(new DateTime(startDate).toDateMidnight().toDate());
}

if ( (stopDate!=null) && !isSameDay(stopDate, visit.getStopDatetime())) {
if(stopDate == null){

visit.setStopDatetime(null);

} else if (!isSameDay(stopDate, visit.getStopDatetime())) {

Date now = new DateTime().toDate();
if (isSameDay(stopDate, now)) {
visit.setStopDatetime(now);
Expand All @@ -54,15 +58,16 @@ public SimpleObject setDuration(@SpringBean("visitService") VisitService visitSe
.withMillisOfSecond(999)
.toDate());
}

}

visitService.saveVisit(visit);

request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, ui.message("coreapps.editVisitDate.visitSavedMessage"));
request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");

return SimpleObject.create("success", true, "search", "?patientId=" + visit.getPatient().getId() + "&visitId=" + visit.getId());

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
defaultDate: config.defaultStartDate
])}
</p>
<% if(config.defaultEndDate != null) { %>
<% if(config.visitEndDate != null) { %>
<p>
<label for="stopDate" class="required">
${ ui.message("coreapps.stopDate.label") }
Expand Down
18 changes: 16 additions & 2 deletions omod/src/main/webapp/fragments/patientdashboard/visitIncludes.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,28 @@
${ ui.message("coreapps.stopDate.label") }
</label>
${ ui.includeFragment("uicommons", "field/datetimepicker", [
<% if(activeVisits){ %>
${ ui.includeFragment("uicommons", "field/datetimepicker", [
id: "retrospectiveVisitStopDate",
formFieldName: "retrospectiveVisitStopDate",
label:"",
defaultDate: visitEndTime,
endDate: editDateFormat.format(visitEndTime),
useTime: false,
])}
])}
<% } else { %>
${ ui.includeFragment("uicommons", "field/datetimepicker", [
id: "noActiveVisitStopDate",
formFieldName: "retrospectiveVisitStopDate",
label:"",
defaultDate: null,
endDate: editDateFormat.format(visitEndTime),
useTime: false,
])}
<% } %>
</p>
<br><br>
Expand Down
3 changes: 2 additions & 1 deletion omod/src/main/webapp/fragments/patientdashboard/visits.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
startDateLowerLimit: (idx + 1 == visits.size || visits[idx + 1].stopDatetime == null) ? null : editDateFormat.format(org.apache.commons.lang.time.DateUtils.addDays(visits[idx + 1].stopDatetime, 1)),
startDateUpperLimit: wrapper.oldestEncounter == null && wrapper.stopDatetime == null ? editDateFormat.format(new Date()) : editDateFormat.format(wrapper.oldestEncounter == null ? wrapper.stopDatetime : wrapper.oldestEncounter.encounterDatetime),
defaultStartDate: wrapper.startDatetime,
defaultEndDate: wrapper.stopDatetime
defaultEndDate:idx == 0 ? null : wrapper.stopDatetime,
visitEndDate: wrapper.stopDatetime
]) }
${ ui.includeFragment("coreapps", "patientdashboard/editVisit", [
visit: wrapper.visit,
Expand Down
3 changes: 2 additions & 1 deletion omod/src/main/webapp/resources/scripts/custom/visits.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ visit.showEditVisitDateDialog = function(visitId) {
if (data.success) {
jq('#edit-visit-dates-dialog-form-' + visitId + ' .icon-spin').css('display', 'inline-block').parent().addClass('disabled');
// TODO Do we need to update this to specify return url, or is this link only going to ever be used from the old visits view?
data.patientId = visit.patientId;
window.location.search = data.search;
}
}
}
);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ public void test_shouldCreateNewRetrospectiveVisit_whenNoStopDateSpecified() thr

// should round to the time components to the start and end of the days, respectively
Date expectedStartDate = new DateTime(2012, 1, 1, 0, 0, 0, 0).toDate();
Date expectedStopDate = new DateTime(2012, 1, 1, 23, 59, 59, 999).toDate();

Visit visit = createVisit();

when(adtService.createRetrospectiveVisit(patient, location, expectedStartDate, expectedStopDate)).thenReturn(new VisitDomainWrapper(visit));
when(adtService.createRetrospectiveVisit(patient, location, expectedStartDate, null)).thenReturn(new VisitDomainWrapper(visit));

SimpleObject result = (SimpleObject) controller.create(adtService, patient, location, startDate, null, request, ui);

Expand All @@ -118,7 +117,7 @@ public void test_shouldReturnConflictingVisits() throws Exception {
Patient patient = new Patient();
Location location = new Location();
Date startDate = new DateTime(2012, 1, 1, 12, 12, 12).toDate();

Date stopDate = startDate;
// should round to the time components to the start and end of the days, respectively
Date expectedStartDate = new DateTime(2012, 1, 1, 0, 0, 0, 0).toDate();
Date expectedStopDate = new DateTime(2012, 1, 1, 23, 59, 59, 999).toDate();
Expand All @@ -135,7 +134,7 @@ public void test_shouldReturnConflictingVisits() throws Exception {

when(ui.format(any())).thenReturn("someDate");

List<SimpleObject> result = (List<SimpleObject>) controller.create(adtService, patient, location, startDate, null, request, ui);
List<SimpleObject> result = (List<SimpleObject>) controller.create(adtService, patient, location, startDate, stopDate, request, ui);

assertThat(result.size(), is(1));
assertThat(result.get(0).toJson(), is("{\"startDate\":\"someDate\",\"stopDate\":\"someDate\",\"id\":null,\"uuid\":\"" + conflictingVisit.getUuid() + "\"}"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void setUp() throws Exception {

controller = new VisitDatesFragmentController();
visitService = mock(VisitService.class);

request = mock(HttpServletRequest.class);
session = mock(HttpSession.class);
when(request.getSession()).thenReturn(session);
Expand Down Expand Up @@ -76,6 +76,25 @@ public void shouldSetVisitStartAndStopDates() throws Exception {
assertThat(actualVisit.getStopDatetime(), is(expectedStopDate));
}

@Test
public void shouldSetVisitStopDateAsNullIfStopDateIsNotSpecified() throws Exception {
Date startDate = (new DateTime(2013, 6, 24, 13, 1, 7)).toDate();
Date stopDate = null;

Date expectedStartDate = (new DateTime(2013, 6, 24, 0, 0, 0)).toDate();
Date expectedStopDate = null;

Visit visit = new Visit(1);
visit.setStartDatetime(new Date());
visit.setStopDatetime(new Date());
visit.setPatient(new Patient(1));

controller.setDuration(visitService, visit, startDate, stopDate, request, mock(UiUtils.class));

Visit actualVisit = savedVisit();
assertThat(actualVisit.getStartDatetime(), is(expectedStartDate));
assertThat(actualVisit.getStopDatetime(), is(expectedStopDate));
}
@Test
public void shouldNotChangeStartOrStopDatetimeIfSettingToSameDay() throws Exception {
Visit visit = new Visit(1);
Expand Down

0 comments on commit f625180

Please sign in to comment.