Search in sources :

Example 26 with Submission

use of gov.nih.nci.ctd2.dashboard.model.Submission in project nci-ctd2-dashboard by CBIIT.

the class ObservationController method onePerSubmissionBySubjectId.

private List<ObservationWithCount> onePerSubmissionBySubjectId(Integer subjectId, String role, Integer tier) {
    Subject subject = dashboardDao.getEntityById(Subject.class, subjectId);
    if (subject != null) {
        Map<Integer, Integer> submissionIds = new HashMap<Integer, Integer>();
        Map<Integer, Observation> observations = new HashMap<Integer, Observation>();
        for (ObservedSubject observedSubject : dashboardDao.findObservedSubjectBySubject(subject)) {
            Observation observation = observedSubject.getObservation();
            Submission submission = observation.getSubmission();
            Integer submissionId = submission.getId();
            ObservedSubjectRole observedSubjectRole = observedSubject.getObservedSubjectRole();
            String subjectRole = observedSubjectRole.getSubjectRole().getDisplayName();
            Integer observationTier = observedSubject.getObservation().getSubmission().getObservationTemplate().getTier();
            if ((role.equals("") || role.equals(subjectRole)) && (tier == 0 || tier == observationTier)) {
                if (!submissionIds.containsKey(submissionId)) {
                    submissionIds.put(submissionId, 1);
                    observations.put(submissionId, observation);
                } else {
                    submissionIds.put(submissionId, submissionIds.get(submissionId) + 1);
                }
            }
        }
        List<ObservationWithCount> list = new ArrayList<ObservationWithCount>();
        for (Integer submissionId : observations.keySet()) {
            Observation obs = observations.get(submissionId);
            Integer count = submissionIds.get(submissionId);
            list.add(new ObservationWithCount(obs, count));
        }
        Collections.sort(list, new Comparator<ObservationWithCount>() {

            @Override
            public int compare(ObservationWithCount o1, ObservationWithCount o2) {
                Integer tier2 = o2.observation.getSubmission().getObservationTemplate().getTier();
                Integer tier1 = o1.observation.getSubmission().getObservationTemplate().getTier();
                return tier2 - tier1;
            }
        });
        return list;
    } else {
        return new ArrayList<ObservationWithCount>();
    }
}
Also used : Submission(gov.nih.nci.ctd2.dashboard.model.Submission) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) BigInteger(java.math.BigInteger) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject)

Aggregations

Submission (gov.nih.nci.ctd2.dashboard.model.Submission)15 BigInteger (java.math.BigInteger)14 ArrayList (java.util.ArrayList)14 FullTextSession (org.hibernate.search.FullTextSession)13 Session (org.hibernate.Session)12 HttpHeaders (org.springframework.http.HttpHeaders)9 ResponseEntity (org.springframework.http.ResponseEntity)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 Observation (gov.nih.nci.ctd2.dashboard.model.Observation)8 Transactional (org.springframework.transaction.annotation.Transactional)8 ObservedSubject (gov.nih.nci.ctd2.dashboard.model.ObservedSubject)7 JSONSerializer (flexjson.JSONSerializer)6 ObservationTemplate (gov.nih.nci.ctd2.dashboard.model.ObservationTemplate)6 Subject (gov.nih.nci.ctd2.dashboard.model.Subject)6 Summary (gov.nih.nci.ctd2.dashboard.util.Summary)6 HashMap (java.util.HashMap)6 DashboardEntity (gov.nih.nci.ctd2.dashboard.model.DashboardEntity)5 ImplTransformer (gov.nih.nci.ctd2.dashboard.util.ImplTransformer)5 HashSet (java.util.HashSet)5 DashboardDao (gov.nih.nci.ctd2.dashboard.dao.DashboardDao)4