Example usage for org.hibernate Criteria list

List of usage examples for org.hibernate Criteria list

Introduction

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

Prototype

public List list() throws HibernateException;

Source Link

Document

Get the results.

Usage

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

License:Open Source License

public Map<String, Long> getStudyCompConsentCounts(Study study, StudyComp studyComp) {
    Map<String, Long> statusMap = new HashMap<String, Long>();

    Criteria criteria = getSession().createCriteria(Consent.class);
    criteria.add(Restrictions.eq("study", study));
    criteria.add(Restrictions.eq("studyComp", studyComp));
    ProjectionList projectionList = Projections.projectionList();
    criteria.createAlias("consentStatus", "consentStatusAlias");
    projectionList.add(Projections.groupProperty("consentStatusAlias.name"));
    projectionList.add(Projections.rowCount());
    criteria.setProjection(projectionList);
    List results = criteria.list();
    if ((results != null) && (results.size() > 0)) {
        for (Object r : results) {
            Object[] obj = (Object[]) r;
            String statusName = (String) obj[0];
            statusMap.put(statusName, (Long) obj[1]);
        }//from ww w  .ja  v  a 2 s .c  om
    } else {
        statusMap.put("(none found)", new Long(0));
    }
    return statusMap;
}

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

License:Open Source License

public List<ReportTemplate> getReportsForUser(ArkUser arkUser, Study study) {
    Criteria criteria = getSession().createCriteria(ReportTemplate.class, "rt");
    Collection<ArkModule> modules = iArkCommonService.getArkModulesLinkedWithStudy(study);
    /*//from   w  w  w . j a  v  a2  s. co  m
     * TODO : Filter reports based on security criteria For now we will implement security upon the selection of a report
     * 
     * // The following is not yet designed to work with super admins // criteria.add(Restrictions.eq("arkUser", arkUser)); DetachedCriteria
     * functionCriteria = DetachedCriteria.forClass(ArkRolePolicyTemplate.class, "arpt"); // Join FieldPhenoCollection and FieldData on ID FK
     * functionCriteria.add(Property.forName("rt.module").eqProperty("arpt." + "arkModule"));
     * functionCriteria.add(Property.forName("rt.function").eqProperty("arpt." + "arkFunction")); criteria.createAlias("arpt." + "arkFunction",
     * "aFn"); ArkFunction reportArkFnType = getArkFunctionByName(RoleConstants.REPORT_FUNCTION_TYPE);
     * functionCriteria.add(Restrictions.eq("aFn.arkFunctionType", reportArkFnType));
     * criteria.add(Subqueries.exists(functionCriteria.setProjection(Projections.property("arpt.id"))));
     */
    if (modules.size() > 0)
        criteria.add(Restrictions.in("module", modules));

    List<ReportTemplate> reportsAvailListing = criteria.list();

    return reportsAvailListing;
}

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

License:Open Source License

public List<ReportOutputFormat> getOutputFormats() {
    Criteria criteria = getSession().createCriteria(ReportOutputFormat.class);
    List<ReportOutputFormat> outputFormats = criteria.list();

    return outputFormats;
}

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));
    }/*  w  ww  . j a  v a2s . c  o  m*/
    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(/*from   ww  w.ja va 2s  .  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  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()));
    }

    // 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(/* w  w  w.j  a  v a2  s.co 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));
    }// w w w .j  a v a 2s.  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<PhenoDataSetCollection> getPhenoCollectionList(Study study) {
    List<PhenoDataSetCollection> results = null;
    Criteria criteria = getSession().createCriteria(PhenoDataSetCollection.class);
    criteria.add(Restrictions.eq("study", study));
    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  w w  w .  java 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;
}