use of org.openmrs.VisitAttributeType in project openmrs-core by openmrs.
the class BaseAttributeTypeValidatorTest method before.
@Before
public void before() {
validator = new CustomVisitAttributeTypeValidator();
attributeType = new VisitAttributeType();
errors = new BindException(attributeType, "attributeType");
}
use of org.openmrs.VisitAttributeType in project openmrs-core by openmrs.
the class HibernateVisitDAO method getVisits.
/**
* @see org.openmrs.api.db.VisitDAO#getVisits(java.util.Collection, java.util.Collection,
* java.util.Collection, java.util.Collection, java.util.Date, java.util.Date,
* java.util.Date, java.util.Date, java.util.Map, boolean, boolean)
*/
@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
public List<Visit> getVisits(Collection<VisitType> visitTypes, Collection<Patient> patients, Collection<Location> locations, Collection<Concept> indications, Date minStartDatetime, Date maxStartDatetime, Date minEndDatetime, Date maxEndDatetime, final Map<VisitAttributeType, String> serializedAttributeValues, boolean includeInactive, boolean includeVoided) throws DAOException {
Criteria criteria = getCurrentSession().createCriteria(Visit.class);
if (visitTypes != null) {
criteria.add(Restrictions.in("visitType", visitTypes));
}
if (patients != null) {
criteria.add(Restrictions.in("patient", patients));
}
if (locations != null) {
criteria.add(Restrictions.in("location", locations));
}
if (indications != null) {
criteria.add(Restrictions.in("indication", indications));
}
if (minStartDatetime != null) {
criteria.add(Restrictions.ge("startDatetime", minStartDatetime));
}
if (maxStartDatetime != null) {
criteria.add(Restrictions.le("startDatetime", maxStartDatetime));
}
// active visits have null end date, so it doesn't make sense to search against it if include inactive is set to false
if (!includeInactive) {
// the user only asked for currently active visits, so stop time needs to be null or after right now
criteria.add(Restrictions.or(Restrictions.isNull("stopDatetime"), Restrictions.gt("stopDatetime", new Date())));
} else {
if (minEndDatetime != null) {
criteria.add(Restrictions.or(Restrictions.isNull("stopDatetime"), Restrictions.ge("stopDatetime", minEndDatetime)));
}
if (maxEndDatetime != null) {
criteria.add(Restrictions.le("stopDatetime", maxEndDatetime));
}
}
if (!includeVoided) {
criteria.add(Restrictions.eq("voided", false));
}
criteria.addOrder(Order.desc("startDatetime"));
criteria.addOrder(Order.desc("visitId"));
List<Visit> visits = criteria.list();
if (serializedAttributeValues != null) {
CollectionUtils.filter(visits, new AttributeMatcherPredicate<Visit, VisitAttributeType>(serializedAttributeValues));
}
return visits;
}
Aggregations