Example usage for org.hibernate Criteria addOrder

List of usage examples for org.hibernate Criteria addOrder

Introduction

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

Prototype

public Criteria addOrder(Order order);

Source Link

Document

Add an Order ordering to the result set.

Usage

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

@Override
public List<PhenoDataSetFieldDisplay> getPhenoDataSetFieldDisplayForPhenoDataSetFieldGroupOrderByPhenoDataSetCategory(
        PhenoDataSetGroup phenoDataSetGroup) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetFieldDisplay.class);
    criteria.add(Restrictions.eq("phenoDataSetGroup", phenoDataSetGroup));
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("phenoDataSetGroup"), "phenoDataSetGroup");
    projectionList.add(Projections.groupProperty("phenoDataSetCategory"), "phenoDataSetCategory");
    projectionList.add(Projections.groupProperty("parentPhenoDataSetCategory"), "parentPhenoDataSetCategory");
    projectionList.add(Projections.groupProperty("phenoDataSetCategoryOrderNumber"),
            "phenoDataSetCategoryOrderNumber");
    criteria.setProjection(projectionList);
    criteria.addOrder(Order.asc("phenoDataSetCategoryOrderNumber"));
    criteria.setResultTransformer(Transformers.aliasToBean(PhenoDataSetFieldDisplay.class));
    return (List<PhenoDataSetFieldDisplay>) criteria.list();
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

@Override
public List<PhenoDataSetField> getPhenoDataSetFieldsLinkedToPhenoDataSetFieldGroupAndPhenoDataSetCategory(
        PhenoDataSetGroup phenoDataSetGroupCriteria, PhenoDataSetCategory phenoDataSetCategory) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetFieldDisplay.class);
    criteria.add(Restrictions.eq("phenoDataSetGroup", phenoDataSetGroupCriteria));
    criteria.add(Restrictions.eq("phenoDataSetCategory", phenoDataSetCategory));
    criteria.add(Restrictions.isNotNull("phenoDataSetField"));
    criteria.addOrder(Order.asc("phenoDataSetFiledOrderNumber"));
    List<PhenoDataSetFieldDisplay> phenoDataSetFieldDisplays = (List<PhenoDataSetFieldDisplay>) criteria.list();
    List<PhenoDataSetField> phenoDataSetFields = new ArrayList<PhenoDataSetField>();
    for (PhenoDataSetFieldDisplay phenoDataSetFieldDisplay : phenoDataSetFieldDisplays) {
        phenoDataSetFields.add(phenoDataSetFieldDisplay.getPhenoDataSetField());
    }//from www.  j a va2 s.  c  o  m
    return phenoDataSetFields;
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

@Override
public List<PhenoDataSetField> getAllPhenoDataSetFieldsLinkedToPhenoDataSetFieldGroup(
        PhenoDataSetGroup phenoDataSetGroupCriteria) {
    Criteria criteria = getSession().createCriteria(PhenoDataSetFieldDisplay.class);
    criteria.add(Restrictions.eq("phenoDataSetGroup", phenoDataSetGroupCriteria));
    criteria.add(Restrictions.isNotNull("phenoDataSetField"));
    criteria.addOrder(Order.asc("phenoDataSetCategoryOrderNumber"))
            .addOrder(Order.asc("phenoDataSetFiledOrderNumber"));
    List<PhenoDataSetFieldDisplay> phenoDataSetFieldDisplays = (List<PhenoDataSetFieldDisplay>) criteria.list();
    List<PhenoDataSetField> phenoDataSetFields = new ArrayList<PhenoDataSetField>();
    for (PhenoDataSetFieldDisplay phenoDataSetFieldDisplay : phenoDataSetFieldDisplays) {
        phenoDataSetFields.add(phenoDataSetFieldDisplay.getPhenoDataSetField());
    }//from   w  w w . j a  va2 s.c  om
    return phenoDataSetFields;
}

From source file:au.org.theark.report.model.dao.ReportDao.java

License:Open Source License

public List<LinkSubjectStudy> getStudyLevelConsentDetailsList(ConsentDetailsReportVO cdrVO) {
    Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class);

    // Add study in context to criteria first (linkSubjectStudy on the VO should never be null)
    criteria.add(Restrictions.eq(Constants.LINKSUBJECTSTUDY_STUDY, cdrVO.getLinkSubjectStudy().getStudy()));
    if (cdrVO.getLinkSubjectStudy().getSubjectUID() != null) {
        criteria.add(Restrictions.ilike(Constants.LINKSUBJECTSTUDY_SUBJECTUID,
                cdrVO.getLinkSubjectStudy().getSubjectUID(), MatchMode.ANYWHERE));
    }//ww  w. j a va2s. com
    if (cdrVO.getLinkSubjectStudy().getSubjectStatus() != null) {
        criteria.add(Restrictions.eq(Constants.LINKSUBJECTSTUDY_SUBJECTSTATUS,
                cdrVO.getLinkSubjectStudy().getSubjectStatus()));
    }

    // we are dealing with study-level consent
    if (cdrVO.getConsentStatus() != null) {
        if (cdrVO.getConsentStatus().getName().equals(Constants.NOT_CONSENTED)) {
            // Special-case: Treat the null FK for consentStatus as "Not Consented"
            criteria.add(Restrictions.or(
                    Restrictions.eq(Constants.LINKSUBJECTSTUDY_CONSENTSTATUS, cdrVO.getConsentStatus()),
                    Restrictions.isNull(Constants.LINKSUBJECTSTUDY_CONSENTSTATUS)));
        } else {
            criteria.add(Restrictions.eq(Constants.LINKSUBJECTSTUDY_CONSENTSTATUS, cdrVO.getConsentStatus()));
        }
    }
    if (cdrVO.getConsentDate() != null) {
        criteria.add(Restrictions.eq(Constants.LINKSUBJECTSTUDY_CONSENTDATE, cdrVO.getConsentDate()));
    }
    criteria.addOrder(Order.asc("consentStatus")); // although MySQL causes NULLs to come first
    criteria.addOrder(Order.asc("subjectUID"));

    return (List<LinkSubjectStudy>) criteria.list();
}

From source file:au.org.theark.report.model.dao.ReportDao.java

License:Open Source License

public List<ConsentDetailsDataRow> getStudyLevelConsentDetailsDataRowList(ConsentDetailsReportVO cdrVO) {
    List<ConsentDetailsDataRow> resultList = new ArrayList<ConsentDetailsDataRow>(0);

    Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class, "lss");
    // Add study in context to criteria first (linkSubjectStudy on the VO should never be null)
    criteria.add(// w ww  .  jav a  2  s.  com
            Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_STUDY, cdrVO.getLinkSubjectStudy().getStudy()));
    if (cdrVO.getLinkSubjectStudy().getSubjectUID() != null) {
        criteria.add(Restrictions.ilike("lss." + Constants.LINKSUBJECTSTUDY_SUBJECTUID,
                cdrVO.getLinkSubjectStudy().getSubjectUID(), MatchMode.ANYWHERE));
    }
    if (cdrVO.getLinkSubjectStudy().getSubjectStatus() != null) {
        criteria.add(Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_SUBJECTSTATUS,
                cdrVO.getLinkSubjectStudy().getSubjectStatus()));
    }

    // we are dealing with study-level consent
    if (cdrVO.getConsentStatus() != null) {
        if (cdrVO.getConsentStatus().getName().equals(Constants.NOT_CONSENTED)) {
            // Special-case: Treat the null FK for consentStatus as "Not Consented"
            criteria.add(Restrictions.or(
                    Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_CONSENTSTATUS,
                            cdrVO.getConsentStatus()),
                    Restrictions.isNull(Constants.LINKSUBJECTSTUDY_CONSENTSTATUS)));
        } else {
            criteria.add(Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_CONSENTSTATUS,
                    cdrVO.getConsentStatus()));
        }
    }
    if (cdrVO.getConsentDate() != null) {
        criteria.add(Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_CONSENTDATE, cdrVO.getConsentDate()));
    }

    criteria.createAlias("lss.consentStatus", "cs", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("lss.subjectStatus", "ss");
    criteria.createAlias("lss.person", "p");
    criteria.createAlias("lss.person.genderType", "genderType");

    // Restrict any addresses to the preferred mailing address
    //Criteria addressCriteria = 
    criteria.createAlias("lss.person.addresses", "a", JoinType.LEFT_OUTER_JOIN);
    //      addressCriteria.setMaxResults(1);
    //      addressCriteria.add(Restrictions.or(Restrictions.or(Restrictions.eq("a.preferredMailingAddress", true), Restrictions.isNull("a.preferredMailingAddress"),Restrictions.eq("a.preferredMailingAddress", false))));

    criteria.createAlias("lss.person.addresses.country", "c", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("lss.person.addresses.state", "state", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("lss.person.phones", "phone", JoinType.LEFT_OUTER_JOIN);

    //TODO: Get work phone returned as well
    //Criteria phoneCriteria = 
    criteria.createAlias("lss.person.phones.phoneType", "phoneType", JoinType.LEFT_OUTER_JOIN);/*.add(
                                                                                               Restrictions.or(Restrictions.eq("phoneType.name", "Home"),
                                                                                               (
                                                                                               Restrictions.or(Restrictions.or(Restrictions.eq("phoneType.name", "Home"),
                                                                                               Restrictions.isNull("phoneType.name"),Restrictions.eq("phoneType.name", "Mobile")))
                                                                                                       
                                                                                               )
                                                                                               )
                                                                                               ));*/
    //phoneCriteria.setMaxResults(1);
    criteria.createAlias("lss.person.titleType", "title");

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("lss.subjectUID"), "subjectUID");
    projectionList.add(Projections.property("cs.name"), "consentStatus");
    projectionList.add(Projections.property("ss.name"), "subjectStatus");
    projectionList.add(Projections.property("title.name"), "title");
    projectionList.add(Projections.property("p.firstName"), "firstName");
    projectionList.add(Projections.property("p.lastName"), "lastName");
    projectionList.add(Projections.property("a.streetAddress"), "streetAddress");
    projectionList.add(Projections.property("a.city"), "suburb");
    projectionList.add(Projections.property("a.postCode"), "postcode");
    projectionList.add(Projections.property("state.name"), "state");
    projectionList.add(Projections.property("c.name"), "country");
    projectionList.add(Projections.property("phone.phoneNumber"), "homePhone");
    projectionList.add(Projections.property("p.preferredEmail"), "email");
    projectionList.add(Projections.property("genderType.name"), "sex");
    projectionList.add(Projections.property("lss.consentDate"), "consentDate");

    criteria.setProjection(projectionList); // only return fields required for report

    criteria.addOrder(Order.asc("lss.consentStatus")); // although MySQL causes NULLs to come first
    criteria.addOrder(Order.asc("lss.subjectUID"));

    criteria.setResultTransformer(Transformers.aliasToBean(ConsentDetailsDataRow.class));
    resultList = (criteria.list());

    return resultList;
}

From source file:au.org.theark.report.model.dao.ReportDao.java

License:Open Source License

public List<ConsentDetailsDataRow> getStudyLevelConsentOtherIDDetailsDataRowList(ConsentDetailsReportVO cdrVO) {
    List<ConsentDetailsDataRow> resultList = new ArrayList<ConsentDetailsDataRow>(0);

    Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class, "lss");
    // Add study in context to criteria first (linkSubjectStudy on the VO should never be null)
    criteria.add(//ww w .  j  a va  2  s .c  om
            Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_STUDY, cdrVO.getLinkSubjectStudy().getStudy()));
    if (cdrVO.getLinkSubjectStudy().getSubjectUID() != null) {
        criteria.add(Restrictions.ilike("lss." + Constants.LINKSUBJECTSTUDY_SUBJECTUID,
                cdrVO.getLinkSubjectStudy().getSubjectUID(), MatchMode.ANYWHERE));
    }
    if (cdrVO.getLinkSubjectStudy().getSubjectStatus() != null) {
        criteria.add(Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_SUBJECTSTATUS,
                cdrVO.getLinkSubjectStudy().getSubjectStatus()));
    }

    // we are dealing with study-level consent
    if (cdrVO.getConsentStatus() != null) {
        if (cdrVO.getConsentStatus().getName().equals(Constants.NOT_CONSENTED)) {
            // Special-case: Treat the null FK for consentStatus as "Not Consented"
            criteria.add(Restrictions.or(
                    Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_CONSENTSTATUS,
                            cdrVO.getConsentStatus()),
                    Restrictions.isNull(Constants.LINKSUBJECTSTUDY_CONSENTSTATUS)));
        } else {
            criteria.add(Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_CONSENTSTATUS,
                    cdrVO.getConsentStatus()));
        }
    }
    if (cdrVO.getConsentDate() != null) {
        criteria.add(Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_CONSENTDATE, cdrVO.getConsentDate()));
    }

    criteria.createAlias("lss.consentStatus", "cs", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("lss.subjectStatus", "ss");
    criteria.createAlias("lss.person", "p");
    criteria.createAlias("lss.person.genderType", "genderType");

    // Restrict any addresses to the preferred mailing address
    //Criteria addressCriteria = 
    criteria.createAlias("lss.person.addresses", "a", JoinType.LEFT_OUTER_JOIN);
    //      addressCriteria.setMaxResults(1);
    //      addressCriteria.add(Restrictions.or(Restrictions.or(Restrictions.eq("a.preferredMailingAddress", true), Restrictions.isNull("a.preferredMailingAddress"),Restrictions.eq("a.preferredMailingAddress", false))));

    criteria.createAlias("lss.person.addresses.country", "c", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("lss.person.addresses.state", "state", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("lss.person.phones", "phone", JoinType.LEFT_OUTER_JOIN);

    //TODO: Get work phone returned as well
    //Criteria phoneCriteria = 
    criteria.createAlias("lss.person.phones.phoneType", "phoneType", JoinType.LEFT_OUTER_JOIN);/*.add(
                                                                                               Restrictions.or(Restrictions.eq("phoneType.name", "Home"),
                                                                                               (
                                                                                               Restrictions.or(Restrictions.or(Restrictions.eq("phoneType.name", "Home"),
                                                                                               Restrictions.isNull("phoneType.name"),Restrictions.eq("phoneType.name", "Mobile")))
                                                                                                       
                                                                                               )
                                                                                               )
                                                                                               ));*/
    //phoneCriteria.setMaxResults(1);
    criteria.createAlias("lss.person.titleType", "title");

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("lss.subjectUID"), "subjectUID");
    projectionList.add(Projections.property("cs.name"), "consentStatus");
    projectionList.add(Projections.property("ss.name"), "subjectStatus");
    projectionList.add(Projections.property("title.name"), "title");
    projectionList.add(Projections.property("p.firstName"), "firstName");
    projectionList.add(Projections.property("p.lastName"), "lastName");
    projectionList.add(Projections.property("a.streetAddress"), "streetAddress");
    projectionList.add(Projections.property("a.city"), "suburb");
    projectionList.add(Projections.property("a.postCode"), "postcode");
    projectionList.add(Projections.property("state.name"), "state");
    projectionList.add(Projections.property("c.name"), "country");
    projectionList.add(Projections.property("phone.phoneNumber"), "homePhone");
    projectionList.add(Projections.property("p.preferredEmail"), "email");
    projectionList.add(Projections.property("genderType.name"), "sex");
    projectionList.add(Projections.property("lss.consentDate"), "consentDate");

    criteria.setProjection(projectionList); // only return fields required for report

    criteria.addOrder(Order.asc("lss.consentStatus")); // although MySQL causes NULLs to come first
    criteria.addOrder(Order.asc("lss.subjectUID"));

    criteria.setResultTransformer(Transformers.aliasToBean(ConsentDetailsDataRow.class));
    resultList = (criteria.list());

    //removing duplicate entries from resultList

    List<ConsentDetailsDataRow> uniqueResults = new ArrayList();

    Iterator<ConsentDetailsDataRow> iterator = resultList.iterator();

    while (iterator.hasNext()) {
        ConsentDetailsDataRow o = iterator.next();
        if (!uniqueResults.contains(o))
            uniqueResults.add(o);
    }

    resultList.clear();
    resultList.addAll(uniqueResults);

    for (int j = 0; j < resultList.size(); j++) {
        ConsentDetailsDataRow c = resultList.get(j);
        if (c.getOtherID() == null && c.getOtherIDSource() == null) {
            List<OtherID> otherIDs = null;
            try {
                otherIDs = iArkCommonService.getOtherIDs(iArkCommonService
                        .getSubjectByUID(c.getSubjectUID(), cdrVO.getLinkSubjectStudy().getStudy())
                        .getPerson());
                if (otherIDs.size() >= 1) {
                    c.setOtherID(otherIDs.get(0).getOtherID());
                    c.setOtherIDSource(otherIDs.get(0).getOtherID_Source());
                }
                if (otherIDs.size() > 1) {
                    for (int i = 1; i < otherIDs.size(); i++) {
                        OtherID o = otherIDs.get(i);
                        ConsentDetailsDataRow clone = new ConsentDetailsDataRow(c.getSubjectUID(),
                                o.getOtherID_Source(), o.getOtherID(), null, null, null, null, null, null, null,
                                null, null, null, null, null, null, null, null);
                        resultList.add(clone);
                    }
                }
            } catch (EntityNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    return resultList;
}

From source file:au.org.theark.report.model.dao.ReportDao.java

License:Open Source License

public List<ConsentDetailsDataRow> getStudyCompConsentList(ConsentDetailsReportVO cdrVO) {
    // NB: There should only ever be one Consent record for a particular Subject for a particular StudyComp

    List<ConsentDetailsDataRow> results = new ArrayList<ConsentDetailsDataRow>();
    Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class, "lss");
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("lss." + "subjectUID"), "subjectUID");

    criteria.add(//from  ww w.  j a v a  2  s.c  o  m
            Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_STUDY, cdrVO.getLinkSubjectStudy().getStudy()));
    if (cdrVO.getLinkSubjectStudy().getSubjectUID() != null) {
        criteria.add(Restrictions.ilike("lss." + Constants.LINKSUBJECTSTUDY_SUBJECTUID,
                cdrVO.getLinkSubjectStudy().getSubjectUID(), MatchMode.ANYWHERE));
    }
    if (cdrVO.getLinkSubjectStudy().getSubjectStatus() != null) {
        criteria.add(Restrictions.eq("lss." + Constants.LINKSUBJECTSTUDY_SUBJECTSTATUS,
                cdrVO.getLinkSubjectStudy().getSubjectStatus()));
    }

    if (cdrVO.getConsentDate() != null) {
        // NB: constraint on consentDate or consentStatus automatically removes "Not Consented" state
        // So LinkSubjectStudy inner join to Consent ok for populated consentDate
        criteria.createAlias("lss." + Constants.LINKSUBJECTSTUDY_CONSENT, "c");
        criteria.createAlias("c." + Constants.CONSENT_CONSENTSTATUS, "cs");
        // constrain on studyComp
        criteria.add(Restrictions.eq("c." + Constants.CONSENT_STUDYCOMP, cdrVO.getStudyComp()));
        // constrain on consentDate
        criteria.add(Restrictions.eq("c." + Constants.CONSENT_CONSENTDATE, cdrVO.getConsentDate()));
        // ConsentStatus is optional for this query...
        if (cdrVO.getConsentStatus() != null) {
            criteria.add(Restrictions.eq("c." + Constants.CONSENT_CONSENTSTATUS, cdrVO.getConsentStatus()));
        }
        projectionList.add(Projections.property("cs.name"), "consentStatus");
        projectionList.add(Projections.property("c." + Constants.CONSENT_CONSENTDATE), "consentDate");

    } else if (cdrVO.getConsentStatus() != null) {
        if (cdrVO.getConsentStatus().getName().equals(Constants.NOT_CONSENTED)) {
            // Need to handle "Not Consented" status differently (since it doesn't have a Consent record)
            // Helpful website: http://www.cereslogic.com/pages/2008/09/22/hibernate-criteria-subqueries-exists/

            // Build subquery to find all Consent records for a Study Comp
            DetachedCriteria consentCriteria = DetachedCriteria.forClass(Consent.class, "c");
            // Constrain on StudyComponent
            consentCriteria.add(Restrictions.eq("c." + Constants.CONSENT_STUDYCOMP, cdrVO.getStudyComp()));
            // Just in case "Not Consented" is erroneously entered into a row in the Consent table
            // consentCriteria.add(Restrictions.ne("c." + Constants.CONSENT_CONSENTSTATUS, cdrVO.getConsentStatus()));
            // Join LinkSubjectStudy and Consent on ID FK
            consentCriteria.add(Property.forName("c.linkSubjectStudy.id").eqProperty("lss." + "id"));
            criteria.add(Subqueries.notExists(consentCriteria.setProjection(Projections.property("c.id"))));

            // If Consent records follows design for "Not Consented", then:
            // - consentStatus and consentDate are not populated
        } else {
            // NB: constraint on consentDate or consentStatus automatically removes "Not Consented" state
            // So LinkSubjectStudy inner join to Consent ok for all recordable consentStatus
            criteria.createAlias("lss." + Constants.LINKSUBJECTSTUDY_CONSENT, "c");
            criteria.createAlias("c." + Constants.CONSENT_CONSENTSTATUS, "cs");
            // Constrain on StudyComponent
            criteria.add(Restrictions.eq("c." + Constants.CONSENT_STUDYCOMP, cdrVO.getStudyComp()));
            // ConsentStatus is NOT optional for this query!
            criteria.add(Restrictions.eq("c." + Constants.CONSENT_CONSENTSTATUS, cdrVO.getConsentStatus()));
            if (cdrVO.getConsentDate() != null) {
                criteria.add(Restrictions.eq("c." + Constants.CONSENT_CONSENTDATE, cdrVO.getConsentDate()));
            }
            projectionList.add(Projections.property("cs.name"), "consentStatus");
            projectionList.add(Projections.property("c." + Constants.CONSENT_CONSENTDATE), "consentDate");
        }
    } else {
        // Should not attempt to run this query with no consentDate nor consentStatus criteria provided
        log.error(
                "reportDao.getStudyCompConsentList(..) is missing consentDate or consentStatus parameters in the VO");
        return null;
    }

    criteria.addOrder(Order.asc("lss." + "subjectUID"));
    criteria.setProjection(projectionList);
    criteria.setResultTransformer(Transformers.aliasToBean(ConsentDetailsDataRow.class));
    // This gives a list of subjects matching the specific studyComp and consentStatus
    results = criteria.list();

    return results;
}

From source file:au.org.theark.report.model.dao.ReportDao.java

License:Open Source License

public List<LinkSubjectStudy> getSubjects(ConsentDetailsReportVO cdrVO) {
    Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class);
    criteria.add(Restrictions.eq(Constants.LINKSUBJECTSTUDY_STUDY, cdrVO.getLinkSubjectStudy().getStudy()));
    if (cdrVO.getLinkSubjectStudy().getSubjectUID() != null) {
        criteria.add(Restrictions.ilike(Constants.LINKSUBJECTSTUDY_SUBJECTUID,
                cdrVO.getLinkSubjectStudy().getSubjectUID(), MatchMode.ANYWHERE));
    }//from www  .  java 2  s.c o  m
    if (cdrVO.getLinkSubjectStudy().getSubjectStatus() != null) {
        criteria.add(Restrictions.eq(Constants.LINKSUBJECTSTUDY_SUBJECTSTATUS,
                cdrVO.getLinkSubjectStudy().getSubjectStatus()));
    }
    criteria.addOrder(Order.asc("subjectUID"));
    List<LinkSubjectStudy> results = criteria.list();
    return results;
}

From source file:au.org.theark.report.model.dao.ReportDao.java

License:Open Source License

public List<FieldDetailsDataRow> getPhenoFieldDetailsList(FieldDetailsReportVO fdrVO) {
    List<FieldDetailsDataRow> results = new ArrayList<FieldDetailsDataRow>();
    Criteria criteria = getSession().createCriteria(PhenoDataSetCollection.class, "fpc");
    criteria.createAlias("phenoCollection", "pc"); // Inner join to Field
    criteria.createAlias("field", "f"); // Inner join to Field
    criteria.createAlias("f.fieldType", "ft"); // Inner join to FieldType
    criteria.add(Restrictions.eq("study", fdrVO.getStudy()));
    if (fdrVO.getPhenoCollection() != null) {
        criteria.add(Restrictions.eq("phenoCollection", fdrVO.getPhenoCollection()));
    }//from ww w .j  a  v  a 2  s.c  o  m
    if (fdrVO.getFieldDataAvailable()) {
        DetachedCriteria fieldDataCriteria = DetachedCriteria.forClass(PhenoDataSetData.class, "fd");
        // Join FieldPhenoCollection and FieldData on ID FK
        fieldDataCriteria.add(Property.forName("f.id").eqProperty("fd." + "field.id"));
        fieldDataCriteria.add(Property.forName("pc.id").eqProperty("fd." + "collection.id"));
        criteria.add(Subqueries.exists(fieldDataCriteria.setProjection(Projections.property("fd.id"))));
    }
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("pc.name"), "collection");
    projectionList.add(Projections.property("f.name"), "fieldName");
    projectionList.add(Projections.property("f.description"), "description");
    projectionList.add(Projections.property("f.minValue"), "minValue");
    projectionList.add(Projections.property("f.maxValue"), "maxValue");
    projectionList.add(Projections.property("f.encodedValues"), "encodedValues");
    projectionList.add(Projections.property("f.missingValue"), "missingValue");
    projectionList.add(Projections.property("f.units"), "units");
    projectionList.add(Projections.property("ft.name"), "type");
    criteria.setProjection(projectionList); // only return fields required for report
    criteria.setResultTransformer(Transformers.aliasToBean(FieldDetailsDataRow.class));
    criteria.addOrder(Order.asc("pc.id"));
    criteria.addOrder(Order.asc("f.name"));
    results = criteria.list();

    return results;
}

From source file:au.org.theark.report.model.dao.ReportDao.java

License:Open Source License

public List<CustomFieldDetailsDataRow> getPhenoCustomFieldDetailsList(CustomFieldDetailsReportVO fdrVO) {
    List<CustomFieldDetailsDataRow> results = new ArrayList<CustomFieldDetailsDataRow>();
    if (fdrVO.getCustomFieldDisplay() != null) {
        /*/*from  w ww .ja va  2  s.  c om*/
         * Following query returns customFields whether or not they are 
         * associated with a customFieldGroups (via customFieldDisplay)
         */
        Criteria criteria = getSession().createCriteria(CustomField.class, "cf");
        criteria.createAlias("customFieldDisplay", "cfd", JoinType.LEFT_OUTER_JOIN); // Left join to CustomFieldDisplay
        criteria.createAlias("cfd.customFieldGroup", "cfg", JoinType.LEFT_OUTER_JOIN); // Left join to CustomFieldGroup
        criteria.createAlias("fieldType", "ft", JoinType.LEFT_OUTER_JOIN); // Left join to FieldType
        criteria.createAlias("unitType", "ut", JoinType.LEFT_OUTER_JOIN); // Left join to UnitType
        criteria.add(Restrictions.eq("cf.study", fdrVO.getStudy()));
        ArkFunction function = iArkCommonService
                .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_PHENO_COLLECTION);
        criteria.add(Restrictions.eq("cf.arkFunction", function));

        if (fdrVO.getCustomFieldDisplay().getCustomFieldGroup() != null) {
            criteria.add(
                    Restrictions.eq("cfg.id", fdrVO.getCustomFieldDisplay().getCustomFieldGroup().getId()));
        }
        if (fdrVO.getFieldDataAvailable()) {
            DetachedCriteria fieldDataCriteria = DetachedCriteria.forClass(PhenoDataSetData.class, "pd");
            // Join CustomFieldDisplay and PhenoData on ID FK
            fieldDataCriteria.add(Property.forName("cfd.id").eqProperty("pd." + "customFieldDisplay.id"));
            criteria.add(Subqueries
                    .exists(fieldDataCriteria.setProjection(Projections.property("pd.customFieldDisplay"))));
        }

        ProjectionList projectionList = Projections.projectionList();
        projectionList.add(Projections.property("cfg.name"), "questionnaire");
        projectionList.add(Projections.property("cf.name"), "fieldName");
        projectionList.add(Projections.property("cf.description"), "description");
        projectionList.add(Projections.property("cf.minValue"), "minValue");
        projectionList.add(Projections.property("cf.maxValue"), "maxValue");
        projectionList.add(Projections.property("cf.encodedValues"), "encodedValues");
        projectionList.add(Projections.property("cf.missingValue"), "missingValue");
        projectionList.add(Projections.property("ut.name"), "units");
        projectionList.add(Projections.property("ft.name"), "type");

        criteria.setProjection(projectionList); // only return fields required for report
        criteria.setResultTransformer(Transformers.aliasToBean(CustomFieldDetailsDataRow.class));
        criteria.addOrder(Order.asc("cfg.id"));
        criteria.addOrder(Order.asc("cfd.sequence"));
        results = criteria.list();
    }

    return results;
}