Search in sources :

Example 16 with VisitAttributeType

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");
}
Also used : VisitAttributeType(org.openmrs.VisitAttributeType) BindException(org.springframework.validation.BindException) Before(org.junit.Before)

Example 17 with VisitAttributeType

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;
}
Also used : Visit(org.openmrs.Visit) VisitAttributeType(org.openmrs.VisitAttributeType) Criteria(org.hibernate.Criteria) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

VisitAttributeType (org.openmrs.VisitAttributeType)17 Test (org.junit.Test)9 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)9 Visit (org.openmrs.Visit)7 VisitAttribute (org.openmrs.VisitAttribute)5 Date (java.util.Date)4 APIException (org.openmrs.api.APIException)3 BindException (org.springframework.validation.BindException)3 SimpleDateFormat (java.text.SimpleDateFormat)2 VisitType (org.openmrs.VisitType)2 PatientDomainWrapper (org.openmrs.module.emrapi.patient.PatientDomainWrapper)2 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)2 SimpleObject (org.openmrs.ui.framework.SimpleObject)2 ObjectResult (org.openmrs.ui.framework.fragment.action.ObjectResult)2 Transactional (org.springframework.transaction.annotation.Transactional)2 BindingResult (org.springframework.validation.BindingResult)2 Errors (org.springframework.validation.Errors)2 Criteria (org.hibernate.Criteria)1 Before (org.junit.Before)1 Patient (org.openmrs.Patient)1