Example usage for org.hibernate.criterion Restrictions not

List of usage examples for org.hibernate.criterion Restrictions not

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions not.

Prototype

public static Criterion not(Criterion expression) 

Source Link

Document

Return the negation of an expression

Usage

From source file:org.openmrs.module.openconceptlab.ImportServiceImpl.java

License:Mozilla Public License

@Override
public Item getLastSuccessfulItemByUrl(String url) {
    Criteria criteria = getSession().createCriteria(Item.class);
    criteria.add(Restrictions.eq("hashedUrl", Item.hashUrl(url)));
    criteria.add(Restrictions.not(Restrictions.eq("state", ItemState.ERROR)));
    criteria.addOrder(Order.desc("itemId"));
    criteria.setMaxResults(1);/*from  www. j  ava2 s. c o  m*/

    Item item = ((Item) criteria.uniqueResult());
    if (item != null) {
        switch (item.getType()) {
        case MAPPING:
            ConceptMap map = getConceptMapByUuid(item.getUuid());
            if (map == null) {
                return null;
            }
            break;
        case CONCEPT:
            Concept concept = conceptService.getConceptByUuid(item.getUuid());
            if (concept == null) {
                return null;
            }
            break;
        default:
            throw new RuntimeException(
                    "Item with UUID=" + item.getUuid() + " couldn't be recognized as Concept or Mapping");
        }
    }
    return item;
}

From source file:org.openmrs.module.openconceptlab.UpdateServiceImpl.java

License:Mozilla Public License

@Override
public Item getLastSuccessfulItemByUrl(String url) {
    Criteria criteria = getSession().createCriteria(Item.class);
    criteria.add(Restrictions.eq("hashedUrl", Item.hashUrl(url)));
    criteria.add(Restrictions.not(Restrictions.eq("state", ItemState.ERROR)));
    criteria.addOrder(Order.desc("itemId"));
    criteria.setMaxResults(1);/*from  ww  w.  j a  va  2  s .  co m*/
    return (Item) criteria.uniqueResult();
}

From source file:org.openmrs.module.openhmis.inventory.api.impl.ItemDataServiceImpl.java

License:Open Source License

@Override
public List<Item> getItemsWithoutConcept(final List<Integer> excludedItemsIds, final Integer resultLimit) {
    return executeCriteria(Item.class, null, new Action1<Criteria>() {
        @Override/*  ww  w  . j a v  a  2 s . c o  m*/
        public void apply(Criteria criteria) {
            updateLocationUserCriteria(criteria);
            criteria.add(Restrictions.isNull(HibernateCriteriaConstants.CONCEPT))
                    .add(Restrictions.eq(HibernateCriteriaConstants.RETIRED, false))
                    .add(Restrictions.eq(HibernateCriteriaConstants.CONCEPT_ACCEPTED, false));
            if (excludedItemsIds != null && excludedItemsIds.size() > 0) {
                criteria.add(Restrictions
                        .not(Restrictions.in(HibernateCriteriaConstants.ID, excludedItemsIds.toArray())));
            }
            if (resultLimit != null && resultLimit > 0) {
                criteria.setMaxResults(resultLimit);
            }
        }
    }, getDefaultSort());
}

From source file:org.openmrs.module.patientaccesscontrol.api.db.hibernate.HibernatePatientAccessControlDAO.java

License:Open Source License

private Criteria createPatientCriteria(Collection<Integer> includePatients, Collection<Integer> excludePatients,
        Collection<Program> includePrograms, boolean includeProgramAlias, boolean orderByProgram) {
    Date now = new Date();
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ModulePatient.class, "patient");
    if (includeProgramAlias) {
        criteria.createAlias("patientPrograms", "pp", Criteria.LEFT_JOIN,
                Restrictions.conjunction().add(Restrictions.eq("pp.voided", false))
                        .add(Restrictions.or(Restrictions.isNull("pp.dateEnrolled"),
                                Restrictions.le("pp.dateEnrolled", now)))
                        .add(Restrictions.or(Restrictions.isNull("pp.dateCompleted"),
                                Restrictions.ge("pp.dateCompleted", now))))
                .createAlias("pp.program", "program", Criteria.LEFT_JOIN);
        if (orderByProgram) {
            criteria.addOrder(OrderNullsLast.asc("program.name"));
        }/*from w  w  w .j  a  v a 2 s  .c  o m*/

        if (includePrograms != null) {
            if (includePrograms.isEmpty()) {
                criteria.add(Restrictions.isNull("pp.program"));
            } else {
                criteria.add(Restrictions.or(Restrictions.isNull("pp.program"),
                        Restrictions.in("pp.program", includePrograms)));
            }
        }
    }

    if (includePatients != null) {
        criteria.add(Restrictions.in("patientId", includePatients));
    }

    if (excludePatients != null && !excludePatients.isEmpty()) {
        criteria.add(Restrictions.not(Restrictions.in("patientId", excludePatients)));
    }

    return criteria;
}

From source file:org.openmrs.module.radiology.report.HibernateRadiologyReportDAO.java

License:Mozilla Public License

/**
 * @see org.openmrs.module.radiology.report.RadiologyReportService#getActiveRadiologyReportByRadiologyOrder(RadiologyOrder)
 *///  w w w  . j a  va 2 s. c o  m
@Override
public RadiologyReport getActiveRadiologyReportByRadiologyOrder(RadiologyOrder radiologyOrder) {
    return (RadiologyReport) sessionFactory.getCurrentSession().createCriteria(RadiologyReport.class)
            .add(Restrictions.eq("radiologyOrder", radiologyOrder))
            .add(Restrictions.not(Restrictions.eq("reportStatus", RadiologyReportStatus.DISCONTINUED))).list()
            .get(0);
}

From source file:org.openmrs.module.radiology.report.HibernateRadiologyReportDAO.java

License:Mozilla Public License

/**
 * @see org.openmrs.module.radiology.report.RadiologyReportService#getRadiologyReports(RadiologyReportSearchCriteria)
 *//*from  ww  w .  ja v  a 2  s  .com*/
@SuppressWarnings("unchecked")
@Override
public List<RadiologyReport> getRadiologyReports(RadiologyReportSearchCriteria searchCriteria) {

    final Criteria crit = sessionFactory.getCurrentSession().createCriteria(RadiologyReport.class);

    if (!searchCriteria.getIncludeDiscontinued()) {
        crit.add(Restrictions.not(Restrictions.eq("reportStatus", RadiologyReportStatus.DISCONTINUED)));
    }
    if (searchCriteria.getFromDate() != null) {
        crit.add(Restrictions.ge("reportDate", searchCriteria.getFromDate()));
    }
    if (searchCriteria.getToDate() != null) {
        crit.add(Restrictions.le("reportDate", searchCriteria.getToDate()));
    }
    if (searchCriteria.getPrincipalResultsInterpreter() != null) {
        crit.add(Restrictions.eq("principalResultsInterpreter",
                searchCriteria.getPrincipalResultsInterpreter()));
    }
    if (searchCriteria.getStatus() != null) {
        crit.add(Restrictions.eq("reportStatus", searchCriteria.getStatus()));
    }

    crit.addOrder(Order.asc("reportDate"));
    return crit.list();
}

From source file:org.openmrs.module.registration.api.db.hibernate.HibernateRegistrationDAO.java

License:Open Source License

public int getNationalId(Integer patientId, String nationalId) {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(PersonAttribute.class);
    criteria.add(Restrictions.eq("attributeType.id", 20));
    criteria.add(Restrictions.eq("value", nationalId));
    criteria.add(Restrictions.eq("voided", false));
    criteria.add(Restrictions.not(Restrictions.eq("person.id", patientId)));
    List<PersonAttribute> list = criteria.list();
    if (list.size() > 0) {
        return 1;
    } else {/*  ww  w  .  ja  va  2s.c o  m*/
        return 0;
    }

}

From source file:org.openmrs.module.registration.api.db.hibernate.HibernateRegistrationDAO.java

License:Open Source License

public int getHealthId(Integer patientId, String healthId) {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(PersonAttribute.class);
    criteria.add(Restrictions.eq("attributeType.id", 24));
    criteria.add(Restrictions.eq("value", healthId));
    criteria.add(Restrictions.eq("voided", false));
    criteria.add(Restrictions.not(Restrictions.eq("person.id", patientId)));
    List<PersonAttribute> list = criteria.list();
    if (list.size() > 0) {
        return 1;
    } else {//from  ww w.j  a va 2s.  com
        return 0;
    }

}

From source file:org.openmrs.module.registration.api.db.hibernate.HibernateRegistrationDAO.java

License:Open Source License

public int getPassportNumber(Integer patientId, String passportNumber) {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(PersonAttribute.class);
    criteria.add(Restrictions.eq("attributeType.id", 38));
    criteria.add(Restrictions.eq("value", passportNumber));
    criteria.add(Restrictions.eq("voided", false));
    criteria.add(Restrictions.not(Restrictions.eq("person.id", patientId)));
    List<PersonAttribute> list = criteria.list();
    if (list.size() > 0) {
        return 1;
    } else {/*w  ww  .  j  a va2  s. co  m*/
        return 0;
    }

}

From source file:org.openmrs.module.sync.api.db.hibernate.HibernateSyncDAO.java

License:Open Source License

/**
 * @see org.openmrs.module.sync.api.db.SyncDAO#getSyncRecords(org.openmrs.module.sync.SyncRecordState[],
 *      boolean, java.lang.Integer, org.openmrs.module.sync.server.RemoteServer, java.lang.Integer)
 *//*ww  w  . jav  a2  s  . com*/
@SuppressWarnings("unchecked")
public List<SyncRecord> getSyncRecords(SyncRecordState[] states, boolean inverse, Integer maxSyncRecords,
        RemoteServer server, Integer firstRecordId) throws DAOException {
    if (maxSyncRecords == null) {
        maxSyncRecords = Integer.parseInt(SyncConstants.PROPERTY_NAME_MAX_RECORDS_DEFAULT);
    }

    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(SyncRecord.class, "s");

    String column = "s.state";

    if (server != null) {
        criteria = criteria.createCriteria("serverRecords", "sr");
        criteria.add(Restrictions.eq("sr.syncServer", server));
        column = "sr.state";
    }

    if (inverse)
        criteria.add(Restrictions.not(Restrictions.in(column, states)));
    else
        criteria.add(Restrictions.in(column, states));

    if (firstRecordId != null)
        criteria.add(Restrictions.ge("s.recordId", firstRecordId));

    criteria.addOrder(Order.asc("s.timestamp"));
    criteria.addOrder(Order.asc("s.recordId"));

    // if the user sets -1 as the max records, don't restrict the number of records downloaded/transferred
    if (maxSyncRecords > 0)
        criteria.setMaxResults(maxSyncRecords);

    return criteria.list();
}