Skip to content

Commit

Permalink
EA-141: Fixed randomly failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
HelioStrike committed Mar 3, 2019
1 parent d68552f commit b05fd91
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
23 changes: 23 additions & 0 deletions api/src/main/java/org/openmrs/module/emrapi/adt/AdtService.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,29 @@ VisitDomainWrapper createRetrospectiveVisit(Patient patient, Location location,
*/
boolean hasVisitDuring(Patient patient, Location location, Date startDatetime, Date stopDatetime);

/**
* Gets all visits for the patient at the visit location associated with the specified location
* during the specified datetime range
*
* @param patient
* @param location
* @param startDatetime
* @param stopDatetime
* @return
*/
List<VisitDomainWrapper> getActiveVisits(Patient patient, Location location, Date startDatetime, Date stopDatetime);

/**
* Returns true/false whether or not the patient has any visits at the visit location associated with
* the specified location during the specified datetime range
*
* @param patient
* @param location
* @param startDatetime
* @param stopDatetime
* @return
*/
boolean hasActiveVisitDuring(Patient patient, Location location, Date startDatetime, Date stopDatetime);

/**
* @return all locations that are tagged to support admissions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,28 @@ public boolean hasVisitDuring(Patient patient, Location location, Date startDate
return visits == null || visits.size() == 0 ? false : true;
}

@Override
@Transactional(readOnly = true)
public List<VisitDomainWrapper> getActiveVisits(Patient patient, Location location, Date startDatetime, Date endDatetime) {

List<VisitDomainWrapper> visitDomainWrappers = new ArrayList<VisitDomainWrapper>();

for (Visit visit : visitService.getVisits(Collections.singletonList(emrApiProperties.getAtFacilityVisitType()),
Collections.singletonList(patient), Collections.singletonList(getLocationThatSupportsVisits(location)), null,
null, endDatetime, startDatetime, null, null, false, false)) {
visitDomainWrappers.add(wrap(visit));
}

return visitDomainWrappers;
}

@Override
@Transactional(readOnly = true)
public boolean hasActiveVisitDuring(Patient patient, Location location, Date startDatetime, Date stopDatetime) {
List<VisitDomainWrapper> visits = getActiveVisits(patient, location, startDatetime, stopDatetime);
return visits == null || visits.size() == 0 ? false : true;
}

@Override
public List<Location> getInpatientLocations() {
return locationService.getLocationsByTag(emrApiProperties.getSupportsAdmissionLocationTag());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ public void integrationTest_createRetrospectiveVisit() throws Exception {
}

@Test
@Ignore("Unignore after fixing EA-141")
public void test_getVisitsAndHasVisitDuring() throws Exception {

ContextSensitiveMetadataTestUtils.setupSupportsVisitLocationTag(locationService);
Expand Down Expand Up @@ -344,7 +343,7 @@ public void test_getVisitsAndHasVisitDuring() throws Exception {

service.ensureActiveVisit(patient, outpatientDepartment);
assertTrue(service.hasVisitDuring(patient, outpatientDepartment, now, futureDate));
assertFalse(service.hasVisitDuring(patient, outpatientDepartment, stopDate, now));
assertFalse(service.hasActiveVisitDuring(patient, outpatientDepartment, stopDate, now));

// now lets just add another retrospective visit to do a quick test of the getVisits method
startDate = new DateTime(2012, 1, 5, 0, 0, 0).toDate();
Expand Down

0 comments on commit b05fd91

Please sign in to comment.