Search in sources :

Example 6 with Observation

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;
}
Also used : HashMap(java.util.HashMap) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) BigInteger(java.math.BigInteger) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Example 7 with Observation

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;
}
Also used : HashMap(java.util.HashMap) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) BigInteger(java.math.BigInteger) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Example 8 with Observation

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;
}
Also used : BigInteger(java.math.BigInteger) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) ArrayList(java.util.ArrayList) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Example 9 with Observation

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;
}
Also used : ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) ArrayList(java.util.ArrayList) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate)

Example 10 with Observation

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);
}
Also used : ObservedEvidence(gov.nih.nci.ctd2.dashboard.model.ObservedEvidence) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) StableURL(gov.nih.nci.ctd2.dashboard.util.StableURL) ArrayList(java.util.ArrayList) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) Evidence(gov.nih.nci.ctd2.dashboard.model.Evidence) ObservedEvidence(gov.nih.nci.ctd2.dashboard.model.ObservedEvidence) SimpleDateFormat(java.text.SimpleDateFormat) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject)

Aggregations

BigInteger (java.math.BigInteger)18 ArrayList (java.util.ArrayList)16 Observation (gov.nih.nci.ctd2.dashboard.model.Observation)14 Session (org.hibernate.Session)13 FullTextSession (org.hibernate.search.FullTextSession)13 Submission (gov.nih.nci.ctd2.dashboard.model.Submission)8 HashMap (java.util.HashMap)8 ObservedSubject (gov.nih.nci.ctd2.dashboard.model.ObservedSubject)7 Subject (gov.nih.nci.ctd2.dashboard.model.Subject)7 HashSet (java.util.HashSet)7 Transactional (org.springframework.transaction.annotation.Transactional)7 JSONSerializer (flexjson.JSONSerializer)6 ObservationTemplate (gov.nih.nci.ctd2.dashboard.model.ObservationTemplate)6 ImplTransformer (gov.nih.nci.ctd2.dashboard.util.ImplTransformer)6 Summary (gov.nih.nci.ctd2.dashboard.util.Summary)6 HttpHeaders (org.springframework.http.HttpHeaders)6 ResponseEntity (org.springframework.http.ResponseEntity)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ObservedSubjectRole (gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole)5 DateTransformer (gov.nih.nci.ctd2.dashboard.util.DateTransformer)5