use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method findSubjectsBySynonym.
@Override
public List<Subject> findSubjectsBySynonym(String synonym, boolean exact) {
Set<Subject> subjects = new HashSet<Subject>();
// First grab the synonyms
String query = "from SynonymImpl where displayName " + (exact ? " = :synonym" : "like concat('%', :synonym, '%')");
List<Synonym> synonymList = queryWithClass(query, "synonym", synonym);
for (Synonym o : synonymList) {
// Second: find subjects with the synonym
List<Subject> subjectList = queryWithClass("select o from SubjectImpl as o where :synonyms member of o.synonyms", "synonyms", o);
for (Subject o2 : subjectList) {
subjects.add(o2);
}
}
return new ArrayList<Subject>(subjects);
}
use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method getSubjectCounts.
@Override
public WordCloudEntry[] getSubjectCounts(Integer associatedSubject) {
String sqlForObservations = "SELECT DISTINCT observation_id FROM observed_subject WHERE subject_id=" + associatedSubject;
Session session = getSession();
@SuppressWarnings("unchecked") org.hibernate.query.Query<Integer> query3 = session.createNativeQuery(sqlForObservations);
List<Integer> observationIds = query3.getResultList();
// ID=0 is not any object
StringBuffer idList = new StringBuffer("0");
for (Integer observationId : observationIds) {
idList.append("," + observationId);
}
List<WordCloudEntry> list = new ArrayList<WordCloudEntry>();
String sql = "SELECT displayName, count(*) AS x, stableURL FROM observed_subject" + " JOIN dashboard_entity ON observed_subject.subject_id=dashboard_entity.id" + " JOIN subject ON observed_subject.subject_id=subject.id" + " WHERE subject.id!=" + associatedSubject + " AND observation_id IN (" + idList + ") GROUP BY subject.id ORDER BY x DESC LIMIT 250";
log.debug(sql);
@SuppressWarnings("unchecked") org.hibernate.query.Query<Object[]> query = session.createNativeQuery(sql);
for (Object[] obj : query.getResultList()) {
String subject = (String) obj[0];
String fullname = null;
if (subject.length() > ABBREVIATION_LENGTH_LIMIT) {
fullname = subject;
subject = shorternSubjectName(subject);
}
Integer count = ((BigInteger) obj[1]).intValue();
String url = (String) obj[2];
list.add(new WordCloudEntry(subject, count, url, fullname));
}
session.close();
return list.toArray(new WordCloudEntry[0]);
}
use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method summarizePerSubject.
private Summary summarizePerSubject(Class<? extends Subject> subjectClass, String label) {
String tableName = "";
Class<?> implClass = subjectClass.isInterface() ? dashboardFactory.getImplClass(subjectClass) : subjectClass;
java.lang.annotation.Annotation[] annotation = implClass.getAnnotationsByType(javax.persistence.Table.class);
if (annotation.length == 1) {
javax.persistence.Table table = (javax.persistence.Table) annotation[0];
tableName = table.name();
} else {
return new Summary("exception", 0, 0, 0, 0);
}
Session session = getSession();
@SuppressWarnings("unchecked") org.hibernate.query.Query<BigInteger> query = session.createNativeQuery("SELECT count(DISTINCT submission_id) FROM " + tableName + " JOIN observed_subject ON observed_subject.subject_id=" + tableName + ".id" + " JOIN observation ON observation.id=observed_subject.observation_id");
BigInteger submissions = query.getSingleResult();
String tierQuery = "SELECT tier, COUNT(DISTINCT observation_id) FROM " + tableName + " JOIN observed_subject ON observed_subject.subject_id=" + tableName + ".id" + " JOIN observation ON observation.id=observed_subject.observation_id" + " JOIN submission ON submission.id=observation.submission_id" + " JOIN observation_template ON observation_template.id=submission.observationTemplate_id" + " GROUP BY tier";
@SuppressWarnings("unchecked") org.hibernate.query.Query<Object[]> query2 = session.createNativeQuery(tierQuery);
int[] tierCount = new int[3];
List<Object[]> result = query2.list();
for (Object[] obj : result) {
Integer tier = (Integer) obj[0];
BigInteger count = (BigInteger) obj[1];
tierCount[tier - 1] = count.intValue();
}
session.close();
return new Summary(label, submissions.intValue(), tierCount[0], tierCount[1], tierCount[2]);
}
use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method prepareAPIData.
/*
* This is still necessary for API 2.0 because we need to access roles from
* subject.
*/
@SuppressWarnings("unchecked")
@Override
public void prepareAPIData() {
Session session = getSession();
session.beginTransaction();
session.createQuery("DELETE FROM EvidenceItem").executeUpdate();
session.createQuery("DELETE FROM SubjectItem").executeUpdate();
session.createQuery("DELETE FROM ObservationItem").executeUpdate();
org.hibernate.query.Query<Object[]> query0 = session.createNativeQuery("SELECT submission.id, observationSummary FROM observation_template JOIN submission ON observation_template.id=submission.observationTemplate_id");
List<Object[]> submissions = query0.list();
for (Object[] objs : submissions) {
Integer submission_id = (Integer) (objs[0]);
String observationSummary = (String) (objs[1]);
org.hibernate.query.Query<Object[]> query = session.createNativeQuery("SELECT id, stableURL FROM observation WHERE submission_id=" + submission_id);
List<Object[]> result = query.list();
for (Object[] obj : result) {
Integer id = (Integer) obj[0];
String uri = (String) obj[1];
List<EvidenceItem> evidences = createObservedEvidenceInfo(id);
List<SubjectItem> subjects = createObservedSubjectInfo(id);
ObservationItem obsv = new ObservationItem();
obsv.setId(id);
obsv.setSubmission_id(submission_id);
obsv.observation_summary = replaceValues(observationSummary, subjects, evidences);
obsv.evidence_list = evidences.toArray(new EvidenceItem[0]);
obsv.subject_list = subjects.toArray(new SubjectItem[0]);
session.save(obsv);
obsv.uri = uri;
}
}
session.getTransaction().commit();
session.close();
}
use of gov.nih.nci.ctd2.dashboard.model.Subject 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