Example usage for org.hibernate Criteria add

List of usage examples for org.hibernate Criteria add

Introduction

In this page you can find the example usage for org.hibernate Criteria add.

Prototype

public Criteria add(Criterion criterion);

Source Link

Document

Add a Criterion restriction to constrain the results to be retrieved.

Usage

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

public GenderType getGenderType(String name) {
    Criteria criteria = getSession().createCriteria(GenderType.class);
    criteria.add(Restrictions.eq("name", name));
    GenderType genderType = new GenderType();
    List<GenderType> results = criteria.list();
    if (!results.isEmpty()) {
        genderType = (GenderType) results.get(0);
    }/* www.ja  v  a2s .  c  o  m*/
    return genderType;
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

public VitalStatus getVitalStatus(String name) {
    Criteria criteria = getSession().createCriteria(VitalStatus.class);
    criteria.add(Restrictions.eq("name", name));
    VitalStatus vitalStatus = new VitalStatus();
    List<VitalStatus> results = criteria.list();

    if (!results.isEmpty()) {
        vitalStatus = (VitalStatus) results.get(0);
    }// www  .j  a  v a2  s. c  o m
    return vitalStatus;
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

public TitleType getTitleType(String name) {
    Criteria criteria = getSession().createCriteria(TitleType.class);
    criteria.add(Restrictions.eq("name", name));
    TitleType titleType = new TitleType();
    List<TitleType> results = criteria.list();
    if (!results.isEmpty()) {
        titleType = (TitleType) results.get(0);
    }// ww w  .jav a 2s .  c  o m
    return titleType;
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

public MaritalStatus getMaritalStatus(String name) {
    Criteria criteria = getSession().createCriteria(MaritalStatus.class);
    criteria.add(Restrictions.eq("name", name));
    MaritalStatus maritalStatus = new MaritalStatus();
    List<MaritalStatus> results = criteria.list();
    if (!results.isEmpty()) {
        maritalStatus = (MaritalStatus) results.get(0);
    }//from w w w.  j  a va  2s .  c o m
    return maritalStatus;
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

public PersonContactMethod getPersonContactMethod(String name) {
    Criteria criteria = getSession().createCriteria(PersonContactMethod.class);
    criteria.add(Restrictions.eq("name", name));
    PersonContactMethod personContactMethod = new PersonContactMethod();
    List<PersonContactMethod> results = criteria.list();
    if (!results.isEmpty()) {
        personContactMethod = (PersonContactMethod) results.get(0);
    }/* w ww .  j  a va2 s .  c o m*/
    return personContactMethod;
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

private Criteria buildGeneralSubjectCriteria(SubjectVO subjectVO) {
    Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class);
    criteria.createAlias("person", "p");
    if (subjectVO.getLinkSubjectStudy().getStudy() != null) {
        criteria.add(Restrictions.eq("study.id", subjectVO.getLinkSubjectStudy().getStudy().getId()));
    } else {/*from www.ja v  a  2s  . c o  m*/
        criteria.add(Restrictions.in("study", subjectVO.getStudyList()));
        criteria.createAlias("study", "st");
        criteria.addOrder(Order.asc("st.name"));
    }
    if (subjectVO.getLinkSubjectStudy().getPerson() != null) {

        if (subjectVO.getLinkSubjectStudy().getPerson().getId() != null) {
            criteria.add(Restrictions.eq("p.id", subjectVO.getLinkSubjectStudy().getPerson().getId()));
        }

        if (subjectVO.getLinkSubjectStudy().getPerson().getFirstName() != null) {
            criteria.add(Restrictions.ilike("p.firstName",
                    subjectVO.getLinkSubjectStudy().getPerson().getFirstName(), MatchMode.ANYWHERE));
        }

        if (subjectVO.getLinkSubjectStudy().getPerson().getMiddleName() != null) {
            criteria.add(Restrictions.ilike("p.middleName",
                    subjectVO.getLinkSubjectStudy().getPerson().getMiddleName(), MatchMode.ANYWHERE));
        }

        if (subjectVO.getLinkSubjectStudy().getPerson().getLastName() != null) {
            /* old code pre George adding personlastname lookup criteria.add(Restrictions.ilike("p.lastName", subjectVO.getLinkSubjectStudy().getPerson().getLastName(), MatchMode.ANYWHERE));*/
            //log.info("Lastname: " + subjectVO.getLinkSubjectStudy().getPerson().getLastName());
            DetachedCriteria previousLastNames = DetachedCriteria.forClass(PersonLastnameHistory.class, "l")
                    .setProjection(Projections.property("l.lastName"))
                    .add(Restrictions.ilike("l.lastName",
                            subjectVO.getLinkSubjectStudy().getPerson().getLastName(), MatchMode.ANYWHERE))
                    .add(Restrictions.eqProperty("p.id", "l.person.id"));
            criteria.add(Restrictions.or(Restrictions.ilike("p.lastName",
                    subjectVO.getLinkSubjectStudy().getPerson().getLastName(), MatchMode.ANYWHERE),
                    Subqueries.exists(previousLastNames)));
        }

        if (subjectVO.getLinkSubjectStudy().getPerson().getDateOfBirth() != null) {
            criteria.add(Restrictions.eq("p.dateOfBirth",
                    subjectVO.getLinkSubjectStudy().getPerson().getDateOfBirth()));
        }

        if (subjectVO.getLinkSubjectStudy().getPerson().getGenderType() != null) {
            criteria.add(Restrictions.eq("p.genderType.id",
                    subjectVO.getLinkSubjectStudy().getPerson().getGenderType().getId()));
        }

        if (subjectVO.getLinkSubjectStudy().getPerson().getVitalStatus() != null) {
            criteria.add(Restrictions.eq("p.vitalStatus.id",
                    subjectVO.getLinkSubjectStudy().getPerson().getVitalStatus().getId()));
        }

        if (!subjectVO.getLinkSubjectStudy().getPerson().getOtherIDs().isEmpty()) {
            OtherID o = (OtherID) subjectVO.getLinkSubjectStudy().getPerson().getOtherIDs().toArray()[0];
            if (o != null && o.getOtherID() != null && !o.getOtherID().isEmpty()) {
                log.info("OtherID search");
                //               DetachedCriteria otherID = DetachedCriteria.forClass(OtherID.class, "O")
                //                     .setProjection(Projections.projectionList().add(Projections.property("O.otherID")))
                //                     .add(Restrictions.ilike("O.otherID", ((OtherID) subjectVO.getLinkSubjectStudy().getPerson().getOtherIDs().toArray()[0]).getOtherID(), MatchMode.EXACT))
                //                     .add(Restrictions.eqProperty("p.id", "O.person.id"));
                //               criteria.add(Subqueries.exists(otherID));
                criteria.createAlias("p.otherIDs", "o");
                criteria.add(Restrictions.ilike("o.otherID",
                        ((OtherID) subjectVO.getLinkSubjectStudy().getPerson().getOtherIDs().toArray()[0])
                                .getOtherID(),
                        MatchMode.ANYWHERE));
                criteria.setProjection(Projections.distinct(
                        Projections.projectionList().add(Projections.property("o.personid"), "lss.person.id")));
            }
        }
    }

    if (subjectVO.getLinkSubjectStudy().getSubjectUID() != null
            && subjectVO.getLinkSubjectStudy().getSubjectUID().length() > 0) {
        criteria.add(Restrictions.ilike("subjectUID", subjectVO.getLinkSubjectStudy().getSubjectUID(),
                MatchMode.ANYWHERE));
    }

    if (subjectVO.getLinkSubjectStudy().getSubjectStatus() != null) {
        criteria.add(Restrictions.eq("subjectStatus", subjectVO.getLinkSubjectStudy().getSubjectStatus()));
        SubjectStatus subjectStatus = getSubjectStatus("Archive");
        if (subjectStatus != null) {
            criteria.add(Restrictions.ne("subjectStatus", subjectStatus));
        }
    } else {
        SubjectStatus subjectStatus = getSubjectStatus("Archive");
        if (subjectStatus != null) {
            criteria.add(Restrictions.ne("subjectStatus", subjectStatus));
        }
    }
    if (subjectVO.getRelativeUIDs().size() > 0) {
        criteria.add(Restrictions.not(Restrictions.in("subjectUID", subjectVO.getRelativeUIDs().toArray())));
    }

    criteria.setProjection(Projections.distinct(Projections.projectionList().add(Projections.id())));

    criteria.addOrder(Order.asc("subjectUID"));
    return criteria;
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

public List<ConsentStatus> getRecordableConsentStatus() {
    Criteria criteria = getSession().createCriteria(ConsentStatus.class);
    criteria.add(Restrictions.not(Restrictions.ilike("name", "Not Consented", MatchMode.ANYWHERE)));
    return criteria.list();
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

/**
 * Look up a Person based on the supplied Long ID that represents a Person primary key. This id is the primary key of the Person table that can
 * represent a subject or contact./*from   w  ww  . jav a 2s  . com*/
 * 
 * @param personId
 * @return
 * @throws EntityNotFoundException
 * @throws ArkSystemException
 */
public Person getPerson(Long personId) throws EntityNotFoundException, ArkSystemException {

    Criteria personCriteria = getSession().createCriteria(Person.class);
    personCriteria.add(Restrictions.eq("id", personId));
    List<Person> listOfPerson = personCriteria.list();
    if (listOfPerson != null && listOfPerson.size() > 0) {
        return listOfPerson.get(0);
    } else {
        throw new EntityNotFoundException("The entity with id" + personId.toString() + " cannot be found.");
    }
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

public ArkFunctionType getArkFunctionType(String reportType) {
    Criteria criteria = getSession().createCriteria(ArkFunctionType.class);
    criteria.add(Restrictions.eq("name", reportType));
    criteria.setMaxResults(1);//  www .  j a  v a  2 s  .  com
    return (ArkFunctionType) criteria.uniqueResult();
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

public List<ArkFunction> getModuleFunction(ArkModule arkModule) {

    ArkFunctionType arkFunctionType = getArkFunctionType(Constants.ARK_FUNCTION_TYPE_NON_REPORT);

    Criteria criteria = getSession().createCriteria(ArkModuleFunction.class);
    criteria.createAlias("arkFunction", "aliasArkFunction");
    criteria.add(Restrictions.eq("arkModule", arkModule));
    // Pass in an instance that represents arkFunctionType non-report
    criteria.add(Restrictions.eq("aliasArkFunction.arkFunctionType", arkFunctionType));
    criteria.addOrder(Order.asc("functionSequence"));
    List<ArkModuleFunction> listOfArkModuleFunction = criteria.list();
    List<ArkFunction> arkFunctionList = new ArrayList<ArkFunction>();
    for (ArkModuleFunction arkModuleFunction : listOfArkModuleFunction) {
        arkFunctionList.add(arkModuleFunction.getArkFunction());
    }/*from  w  w w. j  a v a  2  s. c  o  m*/

    return arkFunctionList;
}