use of gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method findObservedSubjectRole.
@Override
public ObservedSubjectRole findObservedSubjectRole(String templateName, String columnName) {
List<ObservedSubjectRole> list = new ArrayList<ObservedSubjectRole>();
// first grab observation template name
List<ObservationTemplate> otList = queryWithClass("from ObservationTemplateImpl where displayName = :templateName", "templateName", templateName);
for (ObservationTemplate ot : otList) {
List<ObservedSubjectRole> osrList = query2ParamsWithClass("from ObservedSubjectRoleImpl as osr where columnName = :columnName and " + "osr.observationTemplate = :ot", "columnName", columnName, "ot", ot);
for (ObservedSubjectRole o : osrList) {
list.add(o);
}
}
assert list.size() <= 1;
return (list.size() == 1) ? list.iterator().next() : null;
}
use of gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole in project nci-ctd2-dashboard by CBIIT.
the class ControlledVocabularyPerColumnFieldSetMapper method mapFieldSet.
public ControlledVocabulary mapFieldSet(FieldSet fieldSet) throws BindException {
String templateName = fieldSet.readString(TEMPLATE_NAME);
ObservationTemplate observationTemplate = observationTemplateNameMap.get(templateName);
if (observationTemplate == null)
return new ControlledVocabulary(null, null, null);
if (subjectRoleCache == null)
subjectRoleCache = new HashMap<String, SubjectRole>();
if (evidenceRoleCache == null)
evidenceRoleCache = new HashMap<String, EvidenceRole>();
String subject = fieldSet.readString(SUBJECT);
String evidence = fieldSet.readString(EVIDENCE);
if (subject.length() > 0) {
String subjectRoleStr = fieldSet.readString(ROLE);
SubjectRole subjectRole = subjectRoleCache.get(subjectRoleStr);
if (subjectRole == null) {
subjectRole = dashboardFactory.create(SubjectRole.class);
subjectRole.setDisplayName(subjectRoleStr);
subjectRoleCache.put(subjectRoleStr, subjectRole);
}
ObservedSubjectRole observedSubjectRole = dashboardFactory.create(ObservedSubjectRole.class);
observedSubjectRole.setSubjectRole(subjectRole);
observedSubjectRole.setColumnName(fieldSet.readString(COLUMN_NAME));
observedSubjectRole.setDisplayText(fieldSet.readString(DISPLAY_TEXT));
observedSubjectRole.setObservationTemplate(observationTemplate);
return new ControlledVocabulary(observationTemplate, subjectRole, observedSubjectRole);
} else if (evidence.length() > 0) {
String evidenceRoleStr = fieldSet.readString(ROLE);
EvidenceRole evidenceRole = evidenceRoleCache.get(evidenceRoleStr);
if (evidenceRole == null) {
evidenceRole = dashboardFactory.create(EvidenceRole.class);
evidenceRole.setDisplayName(evidenceRoleStr);
evidenceRoleCache.put(evidenceRoleStr, evidenceRole);
}
ObservedEvidenceRole observedEvidenceRole = dashboardFactory.create(ObservedEvidenceRole.class);
observedEvidenceRole.setEvidenceRole(evidenceRole);
observedEvidenceRole.setColumnName(fieldSet.readString(COLUMN_NAME));
observedEvidenceRole.setDisplayText(fieldSet.readString(DISPLAY_TEXT));
observedEvidenceRole.setObservationTemplate(observationTemplate);
observedEvidenceRole.setAttribute(getObservedEvidenceRoleAttribute(fieldSet.readString(MIME_TYPE), fieldSet.readString(NUMERIC_UNITS)));
return new ControlledVocabulary(observationTemplate, evidenceRole, observedEvidenceRole);
}
return new ControlledVocabulary(null, null, null);
}
use of gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole in project nci-ctd2-dashboard by CBIIT.
the class ObservationController method getBySubjectId.
private List<Observation> getBySubjectId(Integer subjectId, String role, Integer tier) {
Subject subject = dashboardDao.getEntityById(Subject.class, subjectId);
if (subject != null) {
Set<Observation> observations = new HashSet<Observation>();
for (ObservedSubject observedSubject : dashboardDao.findObservedSubjectBySubject(subject)) {
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)) {
observations.add(observedSubject.getObservation());
}
}
List<Observation> list = new ArrayList<Observation>(observations);
Collections.sort(list, new Comparator<Observation>() {
@Override
public int compare(Observation o1, Observation o2) {
Integer tier2 = o2.getSubmission().getObservationTemplate().getTier();
Integer tier1 = o1.getSubmission().getObservationTemplate().getTier();
return tier2 - tier1;
}
});
return list;
} else {
return new ArrayList<Observation>();
}
}
use of gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole in project nci-ctd2-dashboard by CBIIT.
the class SubjectResponse method createInstance.
private static SubjectResponse createInstance(final Subject subject, final Filter filter, DashboardDao dashboardDao) {
int[] tierCount = new int[3];
Set<Integer> set = new HashSet<Integer>();
for (ObservedSubject observedSubject : dashboardDao.findObservedSubjectBySubject(subject)) {
ObservedSubjectRole observedSubjectRole = observedSubject.getObservedSubjectRole();
String subjectRole = observedSubjectRole.getSubjectRole().getDisplayName();
if (filter.rolesIncluded.size() > 0 && !filter.rolesIncluded.contains(subjectRole))
continue;
ObservationTemplate observatinoTemplate = observedSubject.getObservation().getSubmission().getObservationTemplate();
Integer observationTier = observatinoTemplate.getTier();
String centerNameBrief = observatinoTemplate.getSubmissionCenter().getStableURL().substring(7);
if (filter.centerIncluded.size() > 0 && !filter.centerIncluded.contains(centerNameBrief))
continue;
if ((Arrays.asList(filter.tiersIncluded).contains(observationTier))) {
set.add(observedSubject.getObservation().getId());
tierCount[observationTier.intValue() - 1]++;
if (filter.limit > 0 && set.size() >= filter.limit) {
break;
}
}
}
List<ObservationItem> observations = dashboardDao.findObservationInfo(new ArrayList<Integer>(set));
Set<String> roles = new TreeSet<String>();
for (int i = 0; i < observations.size(); i++) {
for (SubjectItem sub : observations.get(i).subject_list) {
if (sub.getName().equals(subject.getDisplayName())) {
roles.add(sub.getRole());
break;
}
}
}
String[] uris = observations.stream().map(x -> x.uri).toArray(String[]::new);
SubjectResponse subjectResponse = new SubjectResponse(subject, uris, roles.toArray(new String[0]), tierCount);
return subjectResponse;
}
use of gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole 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