use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method batchMerge.
@Override
public void batchMerge(Collection<? extends Subject> subjects) {
if (subjects == null || subjects.isEmpty())
return;
Session session = getSessionFactory().openSession();
session.beginTransaction();
for (Subject subject : subjects) {
session.merge(subject);
}
session.getTransaction().commit();
session.close();
}
use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method getSubmissionsForSubjectName.
/*
* get submissions if subject name is in some of four fields of its
* **Observation Template**: (1) DashboardEntityImpl.FIELD_DISPLAYNAME, (2)
* ObservationTemplateImpl.FIELD_DESCRIPTION, (3)
* ObservationTemplateImpl.FIELD_SUBMISSIONDESC, (4)
* ObservationTemplateImpl.FIELD_SUBMISSIONNAME
*/
@Override
public List<Submission> getSubmissionsForSubjectName(String subjectName) {
String sql = "SELECT submission.id from submission JOIN observation_template ON submission.observationTemplate_id=observation_template.id" + " JOIN dashboard_entity ON submission.id=dashboard_entity.id WHERE displayName LIKE :subjectName" + " OR description LIKE :subjectName OR submissionDescription LIKE :subjectName" + " OR submissionName LIKE :subjectName";
Session session = getSession();
@SuppressWarnings("unchecked") org.hibernate.query.Query<Integer> query = session.createNativeQuery(sql);
query.setParameter("subjectName", "%" + subjectName + "%");
List<Submission> list = new ArrayList<Submission>();
for (Integer id : query.getResultList()) {
Submission submission = getEntityById(Submission.class, id);
list.add(submission);
}
session.close();
return list;
}
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() {
List<WordCloudEntry> list = new ArrayList<WordCloudEntry>();
String sql = "SELECT displayName, numberOfObservations, stableURL FROM subject_with_summaries" + " JOIN subject ON subject_with_summaries.subject_id=subject.id" + " JOIN dashboard_entity ON subject.id=dashboard_entity.id" + " WHERE score>1 ORDER BY numberOfObservations DESC LIMIT 250";
Session session = getSession();
@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 = (Integer) obj[1];
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 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.Subject in project nci-ctd2-dashboard by CBIIT.
the class XrefDataWriter method write.
public void write(List<? extends XrefData> items) throws Exception {
Map<Integer, Subject> all = new HashMap<Integer, Subject>();
for (XrefData item : items) {
List<? extends Subject> subjects = item.subjects;
if (subjects == null || subjects.size() == 0) {
continue;
}
Xref xref = item.xref;
for (Subject subject : subjects) {
Integer subjectId = subject.getId();
Subject x = all.get(subjectId);
if (x == null) {
x = subject;
all.put(subjectId, x);
}
x.getXrefs().add(xref);
}
}
dashboardDao.batchMerge(all.values());
}
Aggregations