Commit ec4987b3 authored by Javi Corvi's avatar Javi Corvi
Browse files

Merge branch 'allevidence' of https://gitlab.bsc.es/inb/etransafe/pretox-rest-api into allevidence

parents 631948d5 1d03e12e
Pipeline #25854 passed with stage
in 2 seconds
......@@ -76,6 +76,12 @@ public class DocumentController {
return "true";
}
@RequestMapping("/documents/{id}/srFindingValidation/{srDomainId}/{status}")
public String setSRFindingValidation(@PathVariable(value="id") Long id, @PathVariable(value="srDomainId") Integer srDomainId, @PathVariable(value="status") String status) {
documentService.setValidationSRDomainFinding(id, srDomainId, status);
return "true";
}
@RequestMapping("/documents/{id}/findingValidation/{findingId}/{status}")
public String setFindingValidation(@PathVariable(value="id") Long id, @PathVariable(value="findingId") Integer findingId, @PathVariable(value="status") String status) {
documentService.setFindingValidation(id, findingId, status);
......@@ -88,15 +94,22 @@ public class DocumentController {
return snippet;
}
@RequestMapping("/documents/{id}/evidence/findings")
public String findAllFindingEvidence(@PathVariable(value="id") Long id) {
String snippet = documentService.findFindingsEvidenceByDocumentId(id);
return snippet;
}
@RequestMapping("/documents/{id}/evidence/all")
public String findAllEvidence(@PathVariable(value="id") Long id) {
String snippet = documentService.findFindingsEvidenceByDocumentId(id);
String snippet = documentService.findAllEvidenceByDocumentId(id);
return snippet;
}
@RequestMapping("/documents/{id}/evidence/sentences")
public String findSentencesEvidence(@PathVariable(value="id") Long id) {
String snippet = documentService.findSentencesEvidenceByDocumentId(id);
//String snippet = documentService.findAllEvidenceByDocumentId(id);
return snippet;
}
......
package es.bsc.inb.ades.rest.api.model;
import org.apache.tomcat.util.bcel.classfile.Constant;
import es.bsc.inb.ades.rest.api.util.Constants;
/**
* This class describes a finding in SR-Domain format.
* No textual evidence.
......@@ -40,8 +44,31 @@ public class SRDomainFinding implements Cloneable{
private String SRTRTEF="";
private String SRCOMNT="";
private Boolean export;
private Integer findingId;
private Integer srDomainId;
private String status="non_curated";
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getSrdomain_value() {
return SRDOMAIN_DESC + "(" + SRDOMAIN + ")";
if(Constants.SEND_DOMAIN_NAMES.get(SRDOMAIN)!=null) {
return Constants.SEND_DOMAIN_NAMES.get(SRDOMAIN) + "(" + SRDOMAIN + ")";
}else if(SRDOMAIN==null || SRDOMAIN.equals("")) {
return "";
}else {
return SRDOMAIN;
}
}
public String getSrfndg_value() {
......@@ -72,9 +99,7 @@ public class SRDomainFinding implements Cloneable{
return SRSPEC_DESC + "(" + SRSPEC + ")";
}
private Boolean export;
private Integer findingId;
private Integer srDomainId;
public String getSTUDYID() {
return STUDYID;
......
......@@ -30,12 +30,16 @@ public interface DocumentService {
String findFindingsEvidenceByDocumentId(Long id);
String findAllEvidenceByDocumentId(Long id);
String findSentencesEvidenceByDocumentId(Long id);
String findTextByDocumentId(Long id);
Boolean setExportSRDomainFinding(Long id, Integer findingId, Boolean export_srdomain);
Boolean setValidationSRDomainFinding(Long id, Integer srDomainFindingId,String status);
Boolean setFindingValidation(Long id, Integer findingId,String status);
Status moveDocument(Long id, Status status);
......
......@@ -128,8 +128,34 @@ public class DocumentServiceImpl implements DocumentService {
return false;
}
@Override
public Boolean setValidationSRDomainFinding(Long id, Integer srDomainFindingId, String status) {
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
SRDomainFinding srDomainFindingelected = null;
for (Annotation annotation : documentAnnotations.getRelevantSentences()) {
for (Finding finding : annotation.getFindings()) {
for (SRDomainFinding srDomainFinding : finding.getSrDomainFindings()) {
if(srDomainFinding.getSrDomainId().equals(srDomainFindingId)) {
srDomainFindingelected = srDomainFinding;
break;
}
}
}
}
if(srDomainFindingelected!=null) {
//https://stackoverflow.com/questions/47699646/updating-replacing-a-deeply-nested-object-in-mongodb-with-spring-data-mongodb
srDomainFindingelected.setStatus(status);
documentAnnotationsRepository.save(documentAnnotations);
createTracking(id, "admin", Action.ACCEPT, srDomainFindingelected.getTrackingSummary());
return true;
}
return false;
}
@Override
public Boolean setExportSRDomainFinding(Long id, Integer srDomainId,Boolean export_srdomainfinding) {
System.out.println("Entra:"+srDomainId);
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
SRDomainFinding sRDomainFindingSelected = null;
for (Annotation annotation : documentAnnotations.getRelevantSentences()) {
......@@ -189,10 +215,20 @@ public class DocumentServiceImpl implements DocumentService {
* Get Findings evidence from a document
*/
public String findFindingsEvidenceByDocumentId(Long id) {
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
Document document = this.findByDocumentId(id);
return this.generateAllFindingsEvidenceSnippet(document.getText(), documentAnnotations.getRelevantSentences());
}
/**
* Get Findings evidence from a document
*/
public String findAllEvidenceByDocumentId(Long id) {
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
Document document = this.findByDocumentId(id);
return this.generateAllEvidenceSnippet(document.getText(), documentAnnotations.getRelevantSentences());
}
/**
* Get relevant sentences evidence from a document
*/
......@@ -610,6 +646,98 @@ public class DocumentServiceImpl implements DocumentService {
int a = 1;
int r = 1;
for (Annotation sentenceAnnotation : sentences) {
JsonArray values_sentence = new JsonArray();
//values_sentence.add("T"+t);
values_sentence.add("S"+sentenceAnnotation.getId());
values_sentence.add("RELEVANT_SENTENCE");
JsonArray offste_sentence = new JsonArray();
JsonArray offste2_sentence = new JsonArray();
offste_sentence.add(sentenceAnnotation.getStartOffset());
offste_sentence.add(sentenceAnnotation.getEndOffset());
offste2_sentence.add(offste_sentence);
values_sentence.add(offste2_sentence);
entities.add(values_sentence);
t++;
if(sentenceAnnotation.getFindings()!=null) {
for (Finding findingSelected : sentenceAnnotation.getFindings()) {
List<Annotation> all = findingSelected.generateSortedAnnotationsAll();
String id_finding = "";
for (Annotation annotation : all) {
JsonArray values = new JsonArray();
String type = annotation.getFeature("ANNOTATION_TYPE");
//String id = "T"+t;
String id = "E"+annotation.getId();
//TODO source
// String source = annotation.getFeature("SOURCES");
// if(source!=null && !source.equals("")) {
// id = id + " - SOURCE: " + source;
// }
// values.add("T"+t+ " - SOURCE: " + source);
values.add(id);
values.add(type);
JsonArray offste = new JsonArray();
JsonArray offste2 = new JsonArray();
offste.add(annotation.getStartOffset());
offste.add(annotation.getEndOffset());
offste2.add(offste);
values.add(offste2);
entities.add(values);
if(type.equals("FINDING") || type.equals("STUDY_TESTCD") ) {
id_finding = "T"+t;
JsonArray values_a = new JsonArray();
values_a.add("A"+a);
values_a.add("Notorious");
values_a.add(id_finding);
attributes.add(values_a);
a++;
}else {
JsonArray values_r = new JsonArray();
values_r.add("R"+r);
values_r.add("Relation");
JsonArray values_r_e = new JsonArray();
JsonArray values_r_e_v = new JsonArray();
values_r_e_v.add("Entity");
values_r_e_v.add(id_finding);
values_r_e.add(values_r_e_v);
JsonArray values_r_e_v_2 = new JsonArray();
values_r_e_v_2.add("Subentity");
values_r_e_v_2.add("T"+t);
values_r_e.add(values_r_e_v_2);
values_r.add(values_r_e);
relations.add(values_r);
r++;
}
t++;
}
}
}
}
findings_evidence.add("entities", entities);
findings_evidence.add("attributes", attributes);
findings_evidence.add("relations", relations);
return gsonBuilder.toJson(findings_evidence).toString();
}
/**
* Generate the evidence of view all button.
* @param text
* @param findingSelected
* @return
*/
private String generateAllFindingsEvidenceSnippet(String text, List<Annotation> sentences) {
Gson gsonBuilder = new GsonBuilder().create();
JsonObject findings_evidence = new JsonObject();
findings_evidence.addProperty("text", text);
JsonArray entities = new JsonArray();
JsonArray attributes = new JsonArray();
JsonArray relations = new JsonArray();
int t = 1;
int a = 1;
int r = 1;
for (Annotation sentenceAnnotation : sentences) {
// JsonArray values_sentence = new JsonArray();
// values_sentence.add("T"+t);
// values_sentence.add("PRETOX_RELEVANT_SENTENCE");
......
package es.bsc.inb.ades.rest.api.util;
import java.util.HashMap;
import java.util.Map;
public class Constants {
public static int SLICE_START = 1000;
......@@ -7,4 +10,26 @@ public class Constants {
public static int POINTS_INT = 5;
public static String POINTS = ".....";
public static Map<String, String> SEND_DOMAIN_NAMES = new HashMap<String, String>(){{
put("LB", "Laboratory Test Results");
put("BW", "Body Weight");
put("BG", "Body Weight Gain");
put("CV", "Cardiovascular Domain");
put("CL", "Clinical");
put("DD", "Death Diagnosis");
put("EG", "ECG Test Results");
put("FM", "Fetal Measurements");
put("FW", "Food And Water");
put("FX", "Fetal Pathology Findings");
put("MA", "Macroscopic Findings");
put("MI", "Microscopic Findings");
put("OM", "Organ Measurements");
put("RE", "Respiratory Findings");
put("TF", "Tumor Findings");
put("VS", "Vital Signs");
}};
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment