List of usage examples for org.hibernate Criteria createAlias
public Criteria createAlias(String associationPath, String alias) throws HibernateException;
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 w w w . j a 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<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()); }// w w w . j av a2s . c om return arkFunctionList; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public List<Study> getStudiesForUser(ArkUser arkUser, Study study) { Criteria criteria = getSession().createCriteria(ArkUserRole.class); criteria.createAlias("arkStudy", "arkStudy"); criteria.add(Restrictions.eq("arkUser", arkUser));// Represents the user // either who is // logged in or one // that is provided if (study.getId() != null) { criteria.add(Restrictions.eq("arkStudy.id", study.getId())); }// w ww . j a v a2 s. c o m if (study.getName() != null) { criteria.add(Restrictions.ilike("arkStudy.name", study.getName(), MatchMode.ANYWHERE)); } criteria.setProjection(Projections.distinct(Projections.property("study"))); List<Study> studies = (List<Study>) criteria.list(); return studies; }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public List<Study> getAssignedChildStudyListForPerson(Study study, Person person) { Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class); criteria.createAlias("study", "s"); criteria.add(Restrictions.eq("person", person)); criteria.add(Restrictions.eq("s.parentStudy", study)); criteria.add(Restrictions.ne("s.id", study.getId())); criteria.add(Restrictions.ne("subjectStatus", getSubjectStatus("Archive"))); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("study"), "study"); criteria.setProjection(projectionList); return criteria.list(); }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
private List<Long> applyConsentStatusFilters(DataExtractionVO allTheData, Search search, List<Long> idsToInclude) { //for(Long l : idsToInclude) { // log.info("including: " + l); //}//ww w . jav a2 s. c om boolean hasConsentFilters = false; if (search.getQueryFilters().isEmpty()) { return idsToInclude; } else { for (QueryFilter filter : search.getQueryFilters()) { if (filter.getConsentStatusField() != null) { hasConsentFilters = true; } } } Criteria filter = getSession().createCriteria(Consent.class, "c"); filter.add(Restrictions.eq("c.study.id", search.getStudy().getId())); filter.createAlias("c.linkSubjectStudy", "lss"); if (!idsToInclude.isEmpty()) { filter.add(Restrictions.in("lss.id", idsToInclude)); } filter.createAlias("c.studyComponentStatus", "cscs"); filter.createAlias("c.studyComp", "csc"); if (!hasConsentFilters) { for (QueryFilter qf : search.getQueryFilters()) { if (qf.getConsentStatusField() != null) { switch (qf.getOperator()) { case EQUAL: filter.add(Restrictions.eq(getConsentFilterFieldName(qf), qf.getValue())); break; case BETWEEN: filter.add(Restrictions.between(getConsentFilterFieldName(qf), qf.getValue(), qf.getSecondValue())); break; case GREATER_THAN: filter.add(Restrictions.gt(getConsentFilterFieldName(qf), qf.getValue())); break; case GREATER_THAN_OR_EQUAL: filter.add(Restrictions.ge(getConsentFilterFieldName(qf), qf.getValue())); break; case IS_EMPTY: filter.add(Restrictions.isEmpty(getConsentFilterFieldName(qf))); break; case IS_NOT_EMPTY: filter.add(Restrictions.isNotEmpty(getConsentFilterFieldName(qf))); break; case LESS_THAN: filter.add(Restrictions.lt(getConsentFilterFieldName(qf), qf.getValue())); break; case LESS_THAN_OR_EQUAL: filter.add(Restrictions.le(getConsentFilterFieldName(qf), qf.getValue())); break; case LIKE: filter.add(Restrictions.like(getConsentFilterFieldName(qf), qf.getValue(), MatchMode.ANYWHERE)); break; case NOT_EQUAL: filter.add(Restrictions.ne(getConsentFilterFieldName(qf), qf.getValue())); break; default: break; } } } } filter.setProjection( Projections.distinct(Projections.projectionList().add(Projections.property("lss.id")))); List<Long> consentStatusIDs = filter.list(); Collection<Consent> csData = Collections.EMPTY_LIST; if (!consentStatusIDs.isEmpty()) { Criteria consentData = getSession().createCriteria(Consent.class, "c"); consentData.add(Restrictions.eq("c.study.id", search.getStudy().getId())); consentData.createAlias("c.linkSubjectStudy", "lss"); consentData.add(Restrictions.in("lss.id", consentStatusIDs)); csData = consentData.list(); } HashMap<String, ExtractionVO> hashOfConsentStatusData = allTheData.getConsentStatusData(); ExtractionVO valuesForThisLss = new ExtractionVO(); HashMap<String, String> map = null; LinkSubjectStudy previousLss = null; int count = 0; //will try to order our results and can therefore just compare to last LSS and either add to or create new Extraction VO for (Consent data : csData) { if (previousLss == null) { map = new HashMap<String, String>(); previousLss = data.getLinkSubjectStudy(); count = 0; } else if (data.getLinkSubjectStudy().getId().equals(previousLss.getId())) { //then just put the data in count++; } else { //if its a new LSS finalize previous map, etc valuesForThisLss.setKeyValues(map); valuesForThisLss.setSubjectUid(previousLss.getSubjectUID()); hashOfConsentStatusData.put(previousLss.getSubjectUID(), valuesForThisLss); previousLss = data.getLinkSubjectStudy(); map = new HashMap<String, String>();//reset valuesForThisLss = new ExtractionVO(); count = 0; } if (data.getStudyComp().getName() != null) { map.put(count + "_Study Component Name", data.getStudyComp().getName()); } if (data.getStudyComponentStatus() != null) { map.put(count + "_Study Component Status", data.getStudyComponentStatus().getName()); } if (data.getConsentDate() != null) { map.put(count + "_Consent Date", data.getConsentDate().toString()); } if (data.getConsentedBy() != null) { map.put(count + "_Consented By", data.getConsentedBy()); } } //finalize the last entered key value sets/extraction VOs if (map != null && previousLss != null) { valuesForThisLss.setKeyValues(map); valuesForThisLss.setSubjectUid(previousLss.getSubjectUID()); hashOfConsentStatusData.put(previousLss.getSubjectUID(), valuesForThisLss); } //can probably now go ahead and add these to the dataVO...even though inevitable further filters may further axe this list or parts of it. allTheData.setConsentStatusData(hashOfConsentStatusData); if (hasConsentFilters) { return consentStatusIDs; } else { return idsToInclude; } }
From source file:au.org.theark.lims.model.dao.BioCollectionDao.java
License:Open Source License
/** * This count can be based on CustomFieldDisplay alone (i.e. does not need left join to BioCollectionCustomFieldData) *///from w w w.ja va2 s . com public long getBioCollectionCustomFieldDataCount(BioCollection bioCollectionCriteria, ArkFunction arkFunction) { Criteria criteria = getSession().createCriteria(CustomFieldDisplay.class); criteria.createAlias("customField", "cfield"); // criteria.add(Restrictions.eq("cfield.study", bioCollectionCriteria.getStudy())); // Added to allow child studies to inherit parent defined custom fields List studyList = new ArrayList(); studyList.add(bioCollectionCriteria.getStudy()); if (bioCollectionCriteria.getStudy().getParentStudy() != null && bioCollectionCriteria.getStudy().getParentStudy() != bioCollectionCriteria.getStudy()) { studyList.add(bioCollectionCriteria.getStudy().getParentStudy()); } criteria.add(Restrictions.in("cfield.study", studyList)); criteria.add(Restrictions.eq("cfield.arkFunction", arkFunction)); criteria.setProjection(Projections.rowCount()); return (Long) criteria.uniqueResult(); }
From source file:au.org.theark.lims.model.dao.BiospecimenDao.java
License:Open Source License
protected Criteria buildBiospecimenCriteria(LimsVO limsVo) { Criteria criteria = getSession().createCriteria(Biospecimen.class); Biospecimen biospecimen = limsVo.getBiospecimen(); criteria.createAlias("bioCollection", "bc"); criteria.createAlias("linkSubjectStudy", "lss"); // If study chosen, restrict otherwise restrict on users' studyList if (limsVo.getStudy() != null && limsVo.getStudy().getId() != null) { //if(limsVo.getStudy().isParentStudy()) { if (limsVo.getStudy().getParentStudy() != null && limsVo.getStudy().getParentStudy().getId() != null && limsVo.getStudy().getParentStudy().getId().equals(limsVo.getStudy().getId())) { // If parent study, show all children as well criteria.add(Restrictions.in("study", iStudyDao.getChildStudiesForStudy(limsVo.getStudy()))); } else {/*from w ww .ja v a2s. co m*/ criteria.add(Restrictions.eq("study", limsVo.getStudy())); } } else { criteria.add(Restrictions.in("study", limsVo.getStudyList())); criteria.createAlias("study", "st"); criteria.addOrder(Order.asc("st.name")); criteria.addOrder(Order.asc("lss.subjectUID")); criteria.addOrder(Order.asc("bc.biocollectionUid")); criteria.addOrder(Order.asc("biospecimenUid")); } // Restrict on linkSubjectStudy in the LimsVO (or biospecimen) if (limsVo.getLinkSubjectStudy() != null && limsVo.getLinkSubjectStudy().getId() != null) { criteria.add(Restrictions.eq("linkSubjectStudy", limsVo.getLinkSubjectStudy())); } else if (biospecimen.getLinkSubjectStudy() != null) { criteria.add(Restrictions.eq("linkSubjectStudy", biospecimen.getLinkSubjectStudy())); } if (limsVo.getLinkSubjectStudy() != null) { if (limsVo.getLinkSubjectStudy().getSubjectUID() != null) { criteria.add(Restrictions.ilike("lss.subjectUID", limsVo.getLinkSubjectStudy().getSubjectUID(), MatchMode.ANYWHERE)); } } if (limsVo.getBioCollection() != null && limsVo.getBioCollection().getBiocollectionUid() != null) { criteria.add(Restrictions.ilike("bc.biocollectionUid", limsVo.getBioCollection().getBiocollectionUid(), MatchMode.ANYWHERE)); } if (biospecimen.getId() != null) { criteria.add(Restrictions.eq("id", biospecimen.getId())); } if (biospecimen.getBiospecimenUid() != null) { criteria.add(Restrictions.ilike("biospecimenUid", biospecimen.getBiospecimenUid(), MatchMode.ANYWHERE)); } if (biospecimen.getSampleType() != null) { criteria.add(Restrictions.eq("sampleType", biospecimen.getSampleType())); } if (biospecimen.getSampleDate() != null) { criteria.add(Restrictions.eq("sampleDate", biospecimen.getSampleDate())); } if (biospecimen.getQtyCollected() != null) { criteria.add(Restrictions.eq("qtyCollected", biospecimen.getQtyCollected())); } return criteria; }
From source file:au.org.theark.lims.model.dao.BiospecimenDao.java
License:Open Source License
public long getBiospecimenCustomFieldDataCount(Biospecimen biospecimenCriteria, ArkFunction arkFunction) { Criteria criteria = getSession().createCriteria(CustomFieldDisplay.class); criteria.createAlias("customField", "cfield"); // Allow child studies to inherit parent defined custom fields List studyList = new ArrayList(); studyList.add(biospecimenCriteria.getStudy()); if (biospecimenCriteria.getStudy().getParentStudy() != null && biospecimenCriteria.getStudy().getParentStudy() != biospecimenCriteria.getStudy()) { studyList.add(biospecimenCriteria.getStudy().getParentStudy()); }//from w w w. j av a2 s . c o m criteria.add(Restrictions.in("cfield.study", studyList)); criteria.add(Restrictions.eq("cfield.arkFunction", arkFunction)); criteria.setProjection(Projections.rowCount()); return (Long) criteria.uniqueResult(); }
From source file:au.org.theark.lims.model.dao.LimsSubjectDao.java
License:Open Source License
private Criteria buildGeneralSubjectCriteria(LimsVO limsVo, List<Study> studyList) { Criteria criteria = getSession().createCriteria(LinkSubjectStudy.class); criteria.createAlias("person", "p"); criteria.add(Restrictions.in("study", studyList)); if (limsVo.getLinkSubjectStudy().getPerson() != null) { if (limsVo.getLinkSubjectStudy().getPerson().getId() != null) { criteria.add(Restrictions.eq("p.id", limsVo.getLinkSubjectStudy().getPerson().getId())); }//from ww w. jav a 2 s .c om if (limsVo.getLinkSubjectStudy().getPerson().getFirstName() != null) { criteria.add(Restrictions.ilike("p.firstName", limsVo.getLinkSubjectStudy().getPerson().getFirstName(), MatchMode.ANYWHERE)); } if (limsVo.getLinkSubjectStudy().getPerson().getMiddleName() != null) { criteria.add(Restrictions.ilike("p.middleName", limsVo.getLinkSubjectStudy().getPerson().getMiddleName(), MatchMode.ANYWHERE)); } if (limsVo.getLinkSubjectStudy().getPerson().getLastName() != null) { criteria.add(Restrictions.ilike("p.lastName", limsVo.getLinkSubjectStudy().getPerson().getLastName(), MatchMode.ANYWHERE)); } if (limsVo.getLinkSubjectStudy().getPerson().getDateOfBirth() != null) { criteria.add(Restrictions.eq("p.dateOfBirth", limsVo.getLinkSubjectStudy().getPerson().getDateOfBirth())); } if (limsVo.getLinkSubjectStudy().getPerson().getGenderType() != null) { criteria.add(Restrictions.eq("p.genderType.id", limsVo.getLinkSubjectStudy().getPerson().getGenderType().getId())); } if (limsVo.getLinkSubjectStudy().getPerson().getVitalStatus() != null) { criteria.add(Restrictions.eq("p.vitalStatus.id", limsVo.getLinkSubjectStudy().getPerson().getVitalStatus().getId())); } } if (limsVo.getLinkSubjectStudy().getSubjectUID() != null && limsVo.getLinkSubjectStudy().getSubjectUID().length() > 0) { criteria.add(Restrictions.ilike("subjectUID", limsVo.getLinkSubjectStudy().getSubjectUID(), MatchMode.ANYWHERE)); } if (limsVo.getLinkSubjectStudy().getSubjectStatus() != null) { criteria.add(Restrictions.eq("subjectStatus", limsVo.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)); } } criteria.addOrder(Order.asc("subjectUID")); return criteria; }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
public Long isCustomFieldUsed(PhenoDataSetData phenoData) { Long count = new Long("0"); PhenoDataSetField phenoDataSetField = phenoData.getPhenoDataSetFieldDisplay().getPhenoDataSetField(); Study study = phenoDataSetField.getStudy(); ArkFunction arkFunction = phenoDataSetField.getArkFunction(); Criteria criteria = getSession().createCriteria(PhenoDataSetData.class, "pd"); criteria.createAlias("pd.customFieldDisplay", "cfd"); criteria.createAlias("cfd.customField", "cf"); criteria.createAlias("cf.arkFunction", "aF"); criteria.createAlias("cf.study", "s"); criteria.add(Restrictions.eq("aF.id", arkFunction.getId())); criteria.add(Restrictions.eq("cfd.id", phenoData.getPhenoDataSetFieldDisplay().getId())); criteria.add(Restrictions.eq("s.id", study.getId())); count = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); return count; }