use of gov.nih.nci.ctd2.dashboard.model.Observation in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method getOneObservationPerSubmissionByEcoCode.
@Override
public Map<Observation, BigInteger> getOneObservationPerSubmissionByEcoCode(String ecocode, int tier) {
String sql = "SELECT MIN(observation.id), COUNT(DISTINCT observation.id) FROM observation" + " JOIN submission ON observation.submission_id=submission.id" + " JOIN observation_template ON submission.observationTemplate_id=observation_template.id" + " WHERE ecocode LIKE '%" + ecocode + "%'";
if (tier > 0) {
sql += " AND tier=" + tier;
}
sql += " GROUP BY submission_id";
Session session = getSession();
@SuppressWarnings("unchecked") org.hibernate.query.Query<Object[]> query = session.createNativeQuery(sql);
List<Object[]> idList = query.list();
session.close();
Map<Observation, BigInteger> result = new HashMap<Observation, BigInteger>();
for (Object[] pair : idList) {
Observation observation = getEntityById(Observation.class, (Integer) pair[0]);
BigInteger count = (BigInteger) pair[1];
result.put(observation, count);
}
return result;
}
use of gov.nih.nci.ctd2.dashboard.model.Observation in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method getOneObservationPerSubmission.
@Override
public Map<Observation, BigInteger> getOneObservationPerSubmission(Integer subjectId) {
Session session = getSession();
@SuppressWarnings("unchecked") org.hibernate.query.Query<Object[]> query = session.createNativeQuery("SELECT MIN(observation_id), COUNT(DISTINCT observation_id) FROM observed_subject JOIN observation on observed_subject.observation_id=observation.id WHERE subject_id=" + subjectId + " GROUP BY submission_id");
List<Object[]> idList = query.list();
session.close();
Map<Observation, BigInteger> result = new HashMap<Observation, BigInteger>();
for (Object[] pair : idList) {
Observation observation = getEntityById(Observation.class, (Integer) pair[0]);
BigInteger count = (BigInteger) pair[1];
result.put(observation, count);
}
return result;
}
use of gov.nih.nci.ctd2.dashboard.model.Observation 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.Observation 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.Observation in project nci-ctd2-dashboard by CBIIT.
the class ObservationDataWriter method write.
public void write(List<? extends ObservationData> items) throws Exception {
// calls) (2) there is at least one observation in each call
if (items.size() == 0) {
// this might happen when some suject is rejected
log.debug("no item");
return;
}
final Submission submission = items.get(0).observation.getSubmission();
final String submissionName = submission.getDisplayName();
StableURL stableURL = new StableURL();
synchronized (submission) {
log.debug("[" + ++counter + "]SUBMISSION " + submissionName + ": " + items.size() + " observation(s)");
final String submissionCacheKey = submissionName + new SimpleDateFormat("yyyy.MM.dd").format(submission.getSubmissionDate()) + submission.getObservationTemplate().getDisplayName();
if (!submissionCache.contains(submissionCacheKey)) {
submission.setStableURL(stableURL.createURLWithPrefix("submission", submissionName));
dashboardDao.save(submission);
submissionCache.add(submissionCacheKey);
observationIndex.put(submissionName, 0);
}
}
List<Observation> observations = new ArrayList<Observation>();
List<Evidence> evidences = new ArrayList<Evidence>();
List<ObservedSubject> observedSubjects = new ArrayList<ObservedSubject>();
List<ObservedEvidence> observedEvidences = new ArrayList<ObservedEvidence>();
for (ObservationData observationData : items) {
Observation observation = observationData.observation;
int index = observationIndex.get(submissionName);
observation.setStableURL(stableURL.createURLWithPrefix("observation", submissionName) + "-" + index);
observations.add(observation);
observationIndex.put(submissionName, index + 1);
for (DashboardEntity e : observationData.evidence) {
evidences.add((Evidence) e);
}
for (DashboardEntity e : observationData.observedEntities) {
String className = e.getClass().getName();
switch(className) {
case "gov.nih.nci.ctd2.dashboard.impl.ObservedSubjectImpl":
observedSubjects.add((ObservedSubject) e);
break;
case "gov.nih.nci.ctd2.dashboard.impl.ObservedEvidenceImpl":
observedEvidences.add((ObservedEvidence) e);
break;
default:
log.error("unexpected type " + className);
}
}
}
// use a smaller batch size to prevent 'lock wait timeout'
int batchSize = 100;
log.debug("observations to write " + observations.size());
dashboardDao.batchSave(observations, batchSize);
log.debug("observedSubjects to write " + observedSubjects.size());
dashboardDao.batchSave(observedSubjects, batchSize);
log.debug("evidences to write " + evidences.size());
dashboardDao.batchSave(evidences, batchSize);
log.debug("observedEvidences to write " + observedEvidences.size());
dashboardDao.batchSave(observedEvidences, batchSize);
log.debug("ALL WRITTEN: " + submissionName);
}
Aggregations