@Override
 public boolean visitsOverlap(Visit v1, Visit v2) {
   Location where1 = v1.getLocation();
   Location where2 = v2.getLocation();
   if ((where1 == null && where2 == null)
       || isSameOrAncestor(where1, where2)
       || isSameOrAncestor(where2, where1)) {
     // "same" location, so check if date ranges overlap (assuming startDatetime is never null)
     return (OpenmrsUtil.compareWithNullAsLatest(v1.getStartDatetime(), v2.getStopDatetime()) <= 0)
         && (OpenmrsUtil.compareWithNullAsLatest(v2.getStartDatetime(), v1.getStopDatetime())
             <= 0);
   }
   return false;
 }
 /**
  * @param visit
  * @param location
  * @param when
  * @return true if when falls in the visits timespan AND location is within visit.location
  */
 @Override
 public boolean isSuitableVisit(Visit visit, Location location, Date when) {
   if (OpenmrsUtil.compare(when, visit.getStartDatetime()) < 0) {
     return false;
   }
   if (OpenmrsUtil.compareWithNullAsLatest(when, visit.getStopDatetime()) > 0) {
     return false;
   }
   return isSameOrAncestor(visit.getLocation(), location);
 }