Example usage for org.hibernate Query list

List of usage examples for org.hibernate Query list

Introduction

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

Prototype

List<R> list();

Source Link

Document

Return the query results as a List.

Usage

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

License:Open Source License

public List<CustomFieldDisplay> getSelectedBiospecimenCustomFieldDisplaysForSearch(Search search) {
    String queryString = "select cfds.customFieldDisplay " + " from CustomFieldDisplaySearch cfds "
            + " where cfds.search=:search "
            + " and cfds.customFieldDisplay.customField.arkFunction=:arkFunction";
    Query query = getSession().createQuery(queryString);
    query.setParameter("search", search);
    query.setParameter("arkFunction", getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_BIOSPECIMEN));
    return query.list();
}

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

License:Open Source License

public List<CustomFieldDisplay> getAllSelectedCustomFieldDisplaysForSearch(Search search) {
    String queryString = "select cfds.customFieldDisplay " + " from CustomFieldDisplaySearch cfds "
            + " where cfds.search=:search ";
    Query query = getSession().createQuery(queryString);
    query.setParameter("search", search);
    return query.list();
}

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

License:Open Source License

public List<CustomFieldDisplay> getSelectedBiocollectionCustomFieldDisplaysForSearch(Search search) {
    String queryString = "select cfds.customFieldDisplay " + " from CustomFieldDisplaySearch cfds "
            + " where cfds.search=:search "
            + " and cfds.customFieldDisplay.customField.arkFunction=:arkFunction";
    Query query = getSession().createQuery(queryString);
    query.setParameter("search", search);
    //query.setParameter("arkFunction", getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_LIMS_COLLECTION));
    query.setParameter("arkFunction", getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_LIMS_CUSTOM_FIELD));
    return query.list();
}

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

License:Open Source License

private Collection<String> getBiospecimenUIDsNotMatchingTheseBiospecimenIdsOrSubjectIds(Study study,
        Collection<String> biospecimenUIDs, List<Long> biospecimenIds, List<Long> biocollectionIds,
        List<Long> subjectIds) {

    Query query = null;
    //if there is nothing to start with get out of here.
    if (biospecimenUIDs.isEmpty()) {
        return new ArrayList<String>();
    }/*from  w ww. ja  v a  2  s . co  m*/

    //if there is nothing to reduce the list by...return original list.
    if (biospecimenIds.isEmpty() || subjectIds.isEmpty() || biocollectionIds.isEmpty()) {
        return biospecimenUIDs;
    } else {
        String queryString = " select distinct biospecimen.biospecimenUid " + " from Biospecimen biospecimen "
                + " where " + " ( "
                + (biospecimenIds.isEmpty() ? "" : " biospecimen.id not in (:biospecidList) or ")
                + (biocollectionIds.isEmpty() ? ""
                        : " biospecimen.bioCollection.id not in (:biocollectionIds) or ")
                + (subjectIds.isEmpty() ? "" : " biospecimen.linkSubjectStudy.id not in (:subjectIdList)  ")
                + " ) " + " and biospecimen.biospecimenUid in (:uidList) " + " and biospecimen.study =:study ";
        query = getSession().createQuery(queryString);
        if (!biospecimenIds.isEmpty())
            query.setParameterList("biospecidList", biospecimenIds);
        if (!biocollectionIds.isEmpty())
            query.setParameterList("biocollectionIds", biocollectionIds);
        if (!subjectIds.isEmpty())
            query.setParameterList("subjectIdList", subjectIds);
        query.setParameter("study", study);
        query.setParameterList("uidList", biospecimenUIDs);
        return query.list();
    }
}

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

License:Open Source License

private Collection<String> getBioCollectionUIDsNotMatchingTheseBioCollectionIdsOrSubjectIds(Study study,
        Collection<String> bioCollectionUIDs, List<Long> bioCollectionIds, List<Long> subjectIds,
        List<Long> biospecimenIds, List<QueryFilter> biospecimenFilters) {

    Query query = null;
    //      Query query2 = null;
    //if there is nothing to start with get out of here.
    if (bioCollectionUIDs.isEmpty()) {
        return new ArrayList<String>();
    }/*from  w  w  w. ja v a  2  s  .  c  o  m*/

    //if there is nothing to reduce the list by...return original list.
    if ((bioCollectionIds.isEmpty() && subjectIds.isEmpty())) {
        return bioCollectionUIDs;
    } else {
        List<Long> subjectIdsNew = new ArrayList<Long>();
        //add a dummy value=0 to get rid of ".QuerySyntaxException: unexpected end of subtree" due to empty list.
        subjectIds.add(new Long(0));
        String queryString = " select distinct bioCollection.biocollectionUid "
                + " from BioCollection bioCollection " + " where (" + " bioCollection.id not in (:idList) or "
                + " bioCollection.linkSubjectStudy.id not in (:subjectIdList) ) and "
                + " bioCollection.biocollectionUid in (:uidList) " + " and bioCollection.study =:study ";
        query = getSession().createQuery(queryString);
        if (!bioCollectionIds.isEmpty())
            query.setParameterList("idList", bioCollectionIds);
        if (!subjectIds.isEmpty())
            query.setParameterList("subjectIdList", subjectIds);
        else {
            query.setParameterList("subjectIdList", subjectIdsNew);
        }
        query.setParameter("study", study);
        query.setParameterList("uidList", bioCollectionUIDs);
        log.info("Query String: " + query.getQueryString());
        List<String> collectionsToDelete = query.list();

        if (biospecimenIds.isEmpty()) {
            //if all biospecimens WERE filtered, then all biocollections deleted
            if (!biospecimenFilters.isEmpty()) {
                return bioCollectionUIDs;
            } else {
                //there were no biospec filters...continue as usual
                return collectionsToDelete;
            }
        } else {
            if (!bioCollectionUIDs.isEmpty() && !subjectIds.isEmpty()) {

                if (!biospecimenFilters.isEmpty()) {
                    List<String> biocollectionsCorrespondingOurFilteredBiospecimens = getBiocollectionUIDsForTheseBiospecimens(
                            biospecimenIds, collectionsToDelete, study);
                    for (String biocollectionUid : bioCollectionUIDs) {
                        if (!biocollectionsCorrespondingOurFilteredBiospecimens.contains(biocollectionUid)) {
                            collectionsToDelete.add(biocollectionUid);
                        }
                    }
                }
            }
        }
        return collectionsToDelete;
    }

}

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

License:Open Source License

/**
 * /*from w  ww .  jav  a 2 s.  c  o m*/
 * @param biospecimenIds 
 * @param collectionsToExclude DO NOT RETURN ANY OF THESE
 * @return
 */
private List<String> getBiocollectionUIDsForTheseBiospecimens(List<Long> biospecimenIds,
        List<String> collectionsToExclude, Study study) {
    if (biospecimenIds == null) {
        return new ArrayList<String>();
    } else {
        Query query2 = null;
        String queryString2 = "Select distinct biospecimen.bioCollection.biocollectionUid  "
                + " from  Biospecimen biospecimen " + " where " + " biospecimen.id in (:biospecimenIds)  "
                + "  and biospecimen.study =:study  ";
        query2 = getSession().createQuery(queryString2);
        query2.setParameterList("biospecimenIds", biospecimenIds);
        query2.setParameter("study", study);

        return query2.list();
    }

}

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

License:Open Source License

private List<Long> applyDemographicFilters(Search search) {
    List subjectUIDs = new ArrayList<Long>();

    String addressJoinFilters = getAddressFilters(search);

    String personFilters = getPersonFilters(search, "");
    String lssAndPersonFilters = getLSSFilters(search, personFilters);

    String otherIDFilters = getOtherIDFilters(search);

    List<Long> subjectList = getSubjectIdsforSearch(search);

    /**/*from   www. j  a  v  a  2  s .  c  om*/
     * note that this is ID not subject_uid being selected
     */
    String queryString = "select distinct lss.id from LinkSubjectStudy lss " + addressJoinFilters
            + otherIDFilters
            //TODO also add filters for phone and address 
            + " where lss.study.id = " + search.getStudy().getId()
            //TODO once we have confidence in entire methodology of including sub studies             + (search.getStudy().getParentStudy()==null?"":(" or lss.study.id = " + search.getStudy().getParentStudy() ) ) 
            + lssAndPersonFilters + " and lss.subjectStatus.name != 'Archive'";

    Query query = null;
    if (subjectList.isEmpty()) {
        query = getSession().createQuery(queryString);
    } else {
        queryString = queryString + " and lss.id in (:subjectIdList) ";
        query = getSession().createQuery(queryString);
        query.setParameterList("subjectIdList", subjectList);
    }

    subjectUIDs = query.list();
    log.info("size=" + subjectUIDs.size());

    return subjectUIDs;
}

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

License:Open Source License

/**
 * @param allTheData - reference to the object containing our data collected so far, this is to be updated as we continue our refinement.
 * @param search /*from w  w w.  j a  v  a2s. c  om*/
 * @param idsToInclude - the constantly refined list of ID's passed from the previous extraction step
 * 
 * @return the updated list of uids that are still left after the filtering.
 */
private List<Long> applySubjectCustomFilters(DataExtractionVO allTheData, Search search,
        List<Long> idsToInclude) {

    if (idsToInclude != null && !idsToInclude.isEmpty()) {
        String queryToFilterSubjectIDs = getSubjectCustomFieldQuery(search);
        Collection<CustomFieldDisplay> cfdsToReturn = getSelectedSubjectCustomFieldDisplaysForSearch(search);

        log.info("about to APPLY subjectcustom filters.  UIDs size =" + idsToInclude.size() + " query string = "
                + queryToFilterSubjectIDs + " cfd to return size = " + cfdsToReturn.size());
        if (!queryToFilterSubjectIDs.isEmpty()) {
            Query query = getSession().createQuery(queryToFilterSubjectIDs);
            query.setParameterList("idList", idsToInclude);
            List<Long> returnedSubjectIds = query.list();
            idsToInclude.clear();
            for (Long id : returnedSubjectIds) {
                idsToInclude.add(id);
            }
            log.info("rows returned = " + idsToInclude.size());
        } else {
            log.info("there were no subject custom data filters, therefore don't run filter query");
        }
    } else {
        log.info("there are no id's to filter.  therefore won't run filtering query");
    }

    Collection<CustomFieldDisplay> customFieldToGet = getSelectedSubjectCustomFieldDisplaysForSearch(search);

    /* We have the list of subjects, and therefore the list of subjectcustomdata - now bring back all the custom data rows IF they have any data they need */
    if (idsToInclude != null && !idsToInclude.isEmpty() && !customFieldToGet.isEmpty()) {
        String queryString = "select data from SubjectCustomFieldData data  "
                + " left join fetch data.linkSubjectStudy "
                + " left join fetch data.customFieldDisplay custFieldDisplay "
                + " left join fetch custFieldDisplay.customField custField "
                + " where data.linkSubjectStudy.id in (:idList) "
                + " and data.customFieldDisplay in (:customFieldsList)" + " order by data.linkSubjectStudy ";
        Query query2 = getSession().createQuery(queryString);
        query2.setParameterList("idList", idsToInclude);
        query2.setParameterList("customFieldsList", customFieldToGet);

        List<SubjectCustomFieldData> scfData = query2.list();
        HashMap<String, ExtractionVO> hashOfSubjectsWithTheirSubjectCustomData = allTheData
                .getSubjectCustomData();

        ExtractionVO valuesForThisLss = new ExtractionVO();
        HashMap<String, String> map = null;
        LinkSubjectStudy previousLss = null;
        //will try to order our results and can therefore just compare to last LSS and either add to or create new Extraction VO
        for (SubjectCustomFieldData data : scfData) {
            /*            log.info("\t\tprev='" + ((previousLss==null)?"null":previousLss.getSubjectUID()) + "\tsub='" + data.getLinkSubjectStudy().getSubjectUID() + "\terr=" + data.getErrorDataValue() + "\tdate=" + data.getDateDataValue() + "\tnum=" + data.getNumberDataValue() + "\tstr=" + data.getTextDataValue() );*/

            if (previousLss == null) {
                map = new HashMap<String, String>();
                previousLss = data.getLinkSubjectStudy();
            } else if (data.getLinkSubjectStudy().getId().equals(previousLss.getId())) {
                //then just put the data in
            } else { //if its a new LSS finalize previous map, etc
                valuesForThisLss.setKeyValues(map);
                valuesForThisLss.setSubjectUid(previousLss.getSubjectUID());
                hashOfSubjectsWithTheirSubjectCustomData.put(previousLss.getSubjectUID(), valuesForThisLss);
                previousLss = data.getLinkSubjectStudy();
                map = new HashMap<String, String>();//reset
                valuesForThisLss = new ExtractionVO();
            }

            //if any error value, then just use that - though, yet again I really question the acceptance of error data
            if (data.getErrorDataValue() != null && !data.getErrorDataValue().isEmpty()) {
                map.put(data.getCustomFieldDisplay().getCustomField().getName(), data.getErrorDataValue());
            } else {
                // Determine field type and assign key value accordingly
                if (data.getCustomFieldDisplay().getCustomField().getFieldType().getName()
                        .equalsIgnoreCase(Constants.FIELD_TYPE_DATE)) {
                    map.put(data.getCustomFieldDisplay().getCustomField().getName(),
                            data.getDateDataValue().toString());
                } else if (data.getCustomFieldDisplay().getCustomField().getFieldType().getName()
                        .equalsIgnoreCase(Constants.FIELD_TYPE_NUMBER)) {
                    map.put(data.getCustomFieldDisplay().getCustomField().getName(),
                            data.getNumberDataValue().toString());
                } else if (data.getCustomFieldDisplay().getCustomField().getFieldType().getName()
                        .equalsIgnoreCase(Constants.FIELD_TYPE_CHARACTER)) {
                    map.put(data.getCustomFieldDisplay().getCustomField().getName(), data.getTextDataValue());
                }
            }
        }

        //finalize the last entered key value sets/extraction VOs
        if (map != null && previousLss != null) {
            valuesForThisLss.setKeyValues(map);
            valuesForThisLss.setSubjectUid(previousLss.getSubjectUID());
            hashOfSubjectsWithTheirSubjectCustomData.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.setSubjectCustomData(hashOfSubjectsWithTheirSubjectCustomData);
    }

    return idsToInclude;
}

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

License:Open Source License

/**
 * @param allTheData - reference to the object containing our data collected so far, this is to be updated as we continue our refinement.
 * @param search // ww  w . j a  v  a2s  .c  o m
 * @param biospecimenIdsToInclude - the constantly refined list of ID's passed from the previous extraction step
 * 
 * @return the updated list of uids that are still left after the filtering.
 */
private List<Long> applyBiospecimenCustomFilters(DataExtractionVO allTheData, Search search,
        List<Long> idsToInclude, List<Long> biospecimenIdsAfterFiltering) {
    //      List<Long> biospecimenIdsToInclude = new ArrayList<Long>();
    if (idsToInclude != null && !idsToInclude.isEmpty() && biospecimenIdsAfterFiltering != null
            && !biospecimenIdsAfterFiltering.isEmpty()) {
        String queryToFilterBiospecimenIDs = getBiospecimenDataCustomFieldIdQuery(search);

        //Collection<CustomFieldDisplay> cfdsToReturn = getSelectedBiospecimenCustomFieldDisplaysForSearch(search);
        //log.info("about to APPLY subject  filters.  UIDs size =" + idsToInclude.size() + " query string = " + queryToFilterSubjectIDs + " cfd to return size = " + cfdsToReturn.size());
        if (!queryToFilterBiospecimenIDs.isEmpty()) {
            Query query = getSession().createQuery(queryToFilterBiospecimenIDs);
            query.setParameterList("idList", biospecimenIdsAfterFiltering);//TODO ASAP...this should be biospecimen list and not subjuid list now
            List<Long> biopecimenIds = query.list();
            biospecimenIdsAfterFiltering.clear();

            for (Long id : biopecimenIds) {
                biospecimenIdsAfterFiltering.add(id);
            }

            log.info("rows returned = " + biospecimenIdsAfterFiltering.size());
            if (biospecimenIdsAfterFiltering.isEmpty()) {
                idsToInclude.clear();
            } else {
                List<Long> subjectListIds = getSubjectIdsForBiospecimenIds(biospecimenIdsAfterFiltering);
                idsToInclude.clear();
                for (Long id : subjectListIds) {
                    idsToInclude.add(id);
                }
            }
        } else {
            log.info("there were no biospecimen custom data filters, therefore don't run filter query");
        }
    } else {
        log.info("there are no id's to filter.  therefore won't run filtering query");
    }

    Collection<CustomFieldDisplay> customFieldToGet = getSelectedBiospecimenCustomFieldDisplaysForSearch(
            search);
    /* We have the list of biospecimens, and therefore the list of biospecimen custom data - now bring back all the custom data rows IF they have any data they need */
    if (biospecimenIdsAfterFiltering != null && !biospecimenIdsAfterFiltering.isEmpty()
            && !customFieldToGet.isEmpty()) {
        String queryString = "select data from BiospecimenCustomFieldData data  "
                + " left join fetch data.biospecimen "
                + " left join fetch data.customFieldDisplay custFieldDisplay "
                + " left join fetch custFieldDisplay.customField custField "
                + " where data.biospecimen.id in (:biospecimenIdsToInclude)"
                + " and data.customFieldDisplay in (:customFieldsList)" + " order by data.biospecimen.id ";
        Query query2 = getSession().createQuery(queryString);
        query2.setParameterList("biospecimenIdsToInclude", biospecimenIdsAfterFiltering);
        query2.setParameterList("customFieldsList", customFieldToGet);

        List<BiospecimenCustomFieldData> scfData = query2.list();
        HashMap<String, ExtractionVO> hashOfBiospecimensWithTheirBiospecimenCustomData = allTheData
                .getBiospecimenCustomData();

        ExtractionVO valuesForThisBiospecimen = new ExtractionVO();
        HashMap<String, String> map = null;
        String previousBiospecimenUid = null;
        String previousSubjectUid = null;
        //will try to order our results and can therefore just compare to last LSS and either add to or create new Extraction VO
        for (BiospecimenCustomFieldData data : scfData) {

            if (previousBiospecimenUid == null) {
                map = new HashMap<String, String>();
                previousBiospecimenUid = data.getBiospecimen().getBiospecimenUid();
                previousSubjectUid = data.getBiospecimen().getLinkSubjectStudy().getSubjectUID();
            } else if (data.getBiospecimen().getBiospecimenUid().equals(previousBiospecimenUid)) {
                //then just put the data in
            } else { //if its a new LSS finalize previous map, etc
                valuesForThisBiospecimen.setKeyValues(map);
                valuesForThisBiospecimen.setSubjectUid(previousSubjectUid);
                hashOfBiospecimensWithTheirBiospecimenCustomData.put(previousBiospecimenUid,
                        valuesForThisBiospecimen);
                previousBiospecimenUid = data.getBiospecimen().getBiospecimenUid();
                map = new HashMap<String, String>();//reset
                valuesForThisBiospecimen = new ExtractionVO();
                previousSubjectUid = data.getBiospecimen().getLinkSubjectStudy().getSubjectUID();
            }

            //if any error value, then just use that - though, yet again I really question the acceptance of error data
            if (data.getErrorDataValue() != null && !data.getErrorDataValue().isEmpty()) {
                map.put(data.getCustomFieldDisplay().getCustomField().getName(), data.getErrorDataValue());
            } else {
                // Determine field type and assign key value accordingly
                if (data.getCustomFieldDisplay().getCustomField().getFieldType().getName()
                        .equalsIgnoreCase(Constants.FIELD_TYPE_DATE)) {
                    map.put(data.getCustomFieldDisplay().getCustomField().getName(),
                            data.getDateDataValue().toString());
                }
                if (data.getCustomFieldDisplay().getCustomField().getFieldType().getName()
                        .equalsIgnoreCase(Constants.FIELD_TYPE_NUMBER)) {
                    map.put(data.getCustomFieldDisplay().getCustomField().getName(),
                            data.getNumberDataValue().toString());
                }
                if (data.getCustomFieldDisplay().getCustomField().getFieldType().getName()
                        .equalsIgnoreCase(Constants.FIELD_TYPE_CHARACTER)) {
                    map.put(data.getCustomFieldDisplay().getCustomField().getName(), data.getTextDataValue());
                }
            }
        }

        //finalize the last entered key value sets/extraction VOs
        if (map != null && previousBiospecimenUid != null) {
            valuesForThisBiospecimen.setSubjectUid(previousSubjectUid);
            valuesForThisBiospecimen.setKeyValues(map);
            hashOfBiospecimensWithTheirBiospecimenCustomData.put(previousBiospecimenUid,
                    valuesForThisBiospecimen);
        }

        //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.setBiospecimenCustomData(hashOfBiospecimensWithTheirBiospecimenCustomData);
    }
    return idsToInclude;
}

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

License:Open Source License

/**
 * @param allTheData - reference to the object containing our data collected so far, this is to be updated as we continue our refinement.
 * @param search //  w  ww.j av a  2  s.  com
 * @param bioCollectionIdsToInclude - the constantly refined list of ID's passed from the previous extraction step
 * 
 * @return the updated list of uids that are still left after the filtering.
 */
private List<Long> applyBioCollectionCustomFilters(DataExtractionVO allTheData, Search search,
        List<Long> idsToInclude, List<Long> bioCollectionIdsAfterFiltering) {

    if (idsToInclude != null && !idsToInclude.isEmpty() && !bioCollectionIdsAfterFiltering.isEmpty()) {
        String queryToFilterBioCollectionIDs = getBioCollectionDataCustomFieldIdQuery(search);

        //Collection<CustomFieldDisplay> cfdsToReturn = getSelectedBioCollectionCustomFieldDisplaysForSearch(search);
        //log.info("about to APPLY subject  filters.  UIDs size =" + idsToInclude.size() + " query string = " + queryToFilterSubjectIDs + " cfd to return size = " + cfdsToReturn.size());
        if (!queryToFilterBioCollectionIDs.isEmpty()) {
            Query query = getSession().createQuery(queryToFilterBioCollectionIDs);
            query.setParameterList("idList", bioCollectionIdsAfterFiltering);//TODO ASAP...this should be bioCollection list and not subjuid list now
            //bioCollectionIdsAfterFiltering = query.list();    
            log.info("rows returned = " + bioCollectionIdsAfterFiltering.size());
            List<Long> bioCollList = query.list();
            //bioCollectionIdsAfterFiltering = new ArrayList<Long>(bioCollectionIdsAfterFiltering);
            bioCollectionIdsAfterFiltering.clear();
            for (Object id : bioCollList) {
                bioCollectionIdsAfterFiltering.add((Long) id);
            }

            if (bioCollectionIdsAfterFiltering.isEmpty()) {
                idsToInclude.clear();
            } else {
                List<Long> subjectIdsToInclude = getSubjectIdsForBioCollectionIds(
                        bioCollectionIdsAfterFiltering);
                idsToInclude.clear();
                for (Long id : subjectIdsToInclude) {
                    idsToInclude.add(id);
                }

            }
        } else {
            log.info("there were no biocol custom data filters, therefore don't run filter query");
        }
    } else {
        log.info("there are no id's to filter.  therefore won't run filtering query");
    }

    Collection<CustomFieldDisplay> customFieldToGet = getSelectedBiocollectionCustomFieldDisplaysForSearch(
            search);
    /* We have the list of bioCollections, and therefore the list of bioCollection custom data - now bring back all the custom data rows IF they have any data they need */
    if (bioCollectionIdsAfterFiltering != null && !bioCollectionIdsAfterFiltering.isEmpty()
            && !customFieldToGet.isEmpty()) {
        String queryString = "select data from BioCollectionCustomFieldData data  "
                + " left join fetch data.bioCollection "
                + " left join fetch data.customFieldDisplay custFieldDisplay "
                + " left join fetch custFieldDisplay.customField custField "
                + " where data.bioCollection.id in (:bioCollectionIdsToInclude)"
                + " and data.customFieldDisplay in (:customFieldsList)" + " order by data.bioCollection.id ";
        Query query2 = getSession().createQuery(queryString);
        query2.setParameterList("bioCollectionIdsToInclude", bioCollectionIdsAfterFiltering);
        query2.setParameterList("customFieldsList", customFieldToGet);

        List<BioCollectionCustomFieldData> scfData = query2.list();
        HashMap<String, ExtractionVO> hashOfBioCollectionsWithTheirBioCollectionCustomData = allTheData
                .getBiocollectionCustomData();

        ExtractionVO valuesForThisBiocollection = new ExtractionVO();
        HashMap<String, String> map = null;
        String previousBioCollectionUid = null;
        String previousSubjectUid = null;
        //will try to order our results and can therefore just compare to last LSS and either add to or create new Extraction VO
        for (BioCollectionCustomFieldData data : scfData) {

            if (previousBioCollectionUid == null) {
                map = new HashMap<String, String>();
                previousBioCollectionUid = data.getBioCollection().getBiocollectionUid();
                previousSubjectUid = data.getBioCollection().getLinkSubjectStudy().getSubjectUID();
            } else if (data.getBioCollection().getBiocollectionUid().equals(previousBioCollectionUid)) {
                //then just put the data in
            } else { //if its a new LSS finalize previous map, etc
                valuesForThisBiocollection.setKeyValues(map);
                hashOfBioCollectionsWithTheirBioCollectionCustomData.put(previousBioCollectionUid,
                        valuesForThisBiocollection);

                map = new HashMap<String, String>();//reset
                valuesForThisBiocollection = new ExtractionVO();
                previousBioCollectionUid = data.getBioCollection().getBiocollectionUid();
                previousSubjectUid = data.getBioCollection().getLinkSubjectStudy().getSubjectUID();
            }

            //if any error value, then just use that - though, yet again I really question the acceptance of error data
            if (data.getErrorDataValue() != null && !data.getErrorDataValue().isEmpty()) {
                map.put(data.getCustomFieldDisplay().getCustomField().getName(), data.getErrorDataValue());
            } else {
                // Determine field type and assign key value accordingly
                if (data.getCustomFieldDisplay().getCustomField().getFieldType().getName()
                        .equalsIgnoreCase(Constants.FIELD_TYPE_DATE)) {
                    map.put(data.getCustomFieldDisplay().getCustomField().getName(),
                            data.getDateDataValue().toString());
                }
                if (data.getCustomFieldDisplay().getCustomField().getFieldType().getName()
                        .equalsIgnoreCase(Constants.FIELD_TYPE_NUMBER)) {
                    map.put(data.getCustomFieldDisplay().getCustomField().getName(),
                            data.getNumberDataValue().toString());
                }
                if (data.getCustomFieldDisplay().getCustomField().getFieldType().getName()
                        .equalsIgnoreCase(Constants.FIELD_TYPE_CHARACTER)) {
                    map.put(data.getCustomFieldDisplay().getCustomField().getName(), data.getTextDataValue());
                }
            }
        }

        //finalize the last entered key value sets/extraction VOs
        if (map != null && previousBioCollectionUid != null) {
            valuesForThisBiocollection.setSubjectUid(previousSubjectUid);
            valuesForThisBiocollection.setKeyValues(map);
            hashOfBioCollectionsWithTheirBioCollectionCustomData.put(previousBioCollectionUid,
                    valuesForThisBiocollection);
        }

        //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.setBiocollectionCustomData(hashOfBioCollectionsWithTheirBioCollectionCustomData);
    }
    return idsToInclude;
}