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>();
}
}
Aggregations