use of gov.nih.nci.ctd2.dashboard.model.Observation in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method getObservationsForSubmissionAndEcoCode.
@Override
public List<Observation> getObservationsForSubmissionAndEcoCode(Integer submissionId, String ecocode) {
String sql = "SELECT observation.id FROM observation" + " JOIN submission ON observation.submission_id=submission.id" + " JOIN observation_template ON submission.observationTemplate_id=observation_template.id" + " WHERE submission.id=" + submissionId + " AND ecocode LIKE '%" + ecocode + "%'";
Session session = getSession();
@SuppressWarnings("unchecked") org.hibernate.query.Query<Integer> query = session.createNativeQuery(sql);
List<Integer> idList = query.list();
List<Observation> list = new ArrayList<Observation>();
for (Integer id : idList) {
Observation observation = getEntityById(Observation.class, id);
list.add(observation);
}
session.close();
return list;
}
use of gov.nih.nci.ctd2.dashboard.model.Observation in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method ecoCode2ObservationURIsAndTiers.
@Override
public ObservationURIsAndTiers ecoCode2ObservationURIsAndTiers(String ecoCode) {
Session session = getSession();
@SuppressWarnings("unchecked") org.hibernate.query.Query<Object[]> ecocodeQuery = session.createNativeQuery("SELECT ecocode, id, tier FROM observation_template WHERE LENGTH(ecocode)>0");
List<Object[]> ecocodeResult = ecocodeQuery.list();
List<String> observationURIs = new ArrayList<String>();
int tier1 = 0, tier2 = 0, tier3 = 0;
for (Object[] array : ecocodeResult) {
String allcodes = (String) array[0];
Integer templateId = (Integer) array[1];
Integer tier = (Integer) array[2];
String[] ecocodes = allcodes.split("\\|");
if (Arrays.asList(ecocodes).contains(ecoCode)) {
String sql = "SELECT observation.stableURL FROM observation" + " JOIN submission ON observation.submission_id=submission.id" + " WHERE submission.observationTemplate_id=" + templateId;
@SuppressWarnings("unchecked") org.hibernate.query.Query<String> query = session.createNativeQuery(sql);
List<String> uris = query.list();
observationURIs.addAll(uris);
switch(tier) {
case 1:
tier1++;
break;
case 2:
tier2++;
break;
case 3:
tier3++;
break;
default:
log.error("unknow tier number " + tier);
}
}
}
session.close();
return new ObservationURIsAndTiers(observationURIs.toArray(new String[0]), tier1, tier2, tier3);
}
use of gov.nih.nci.ctd2.dashboard.model.Observation 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.Observation 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.Observation in project nci-ctd2-dashboard by CBIIT.
the class ObservationController method getOneObservationsPerSubmissionByECOTerm.
@Transactional
@RequestMapping(value = "onePerSubmissionByEcoTerm", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> getOneObservationsPerSubmissionByECOTerm(@RequestParam("ecocode") String ecocode, @RequestParam(value = "tier", required = false, defaultValue = "0") Integer tier) {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
Map<Observation, BigInteger> observationAndCount = dashboardDao.getOneObservationPerSubmissionByEcoCode(ecocode, tier);
List<ObservationWithCount> list = new ArrayList<ObservationWithCount>();
for (Observation observation : observationAndCount.keySet()) {
list.add(new ObservationWithCount(observation, observationAndCount.get(observation).intValue()));
}
JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
return new ResponseEntity<String>(jsonSerializer.serialize(list), headers, HttpStatus.OK);
}
Aggregations