-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cohort Definition Validation Feature API #1929
base: master
Are you sure you want to change the base?
Changes from 56 commits
5464709
6735945
f1203ec
704b5a2
8e4fc91
de445db
18319f8
b6d5b07
b82ef09
65028fc
7b02d10
45ffb5f
b2166a8
7b7ce8e
d769a68
b002dfe
348e67c
1326f9a
791e3f9
ba72b44
c695f24
1afa631
e5b1e2a
92271b4
3329bde
b8b61f4
734b8b3
47c6b31
37542bf
6bd6d66
abca93c
c880d3d
18a4d02
11f9df0
c793786
a0b4bd3
514673b
fed83bd
1bbf4dd
dd28f06
4f08ca2
c375503
d0dfb87
f0421a1
712c388
8854ba4
d58f51c
9c558ec
cecc37a
26eff09
075af89
cdca276
530fa59
2643f96
45057a4
aa9f441
41058f3
5a4905f
8814282
37d1c60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package org.ohdsi.webapi.annotation.annotation; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
|
||
import org.hibernate.annotations.GenericGenerator; | ||
import org.hibernate.annotations.Parameter; | ||
import org.ohdsi.webapi.annotation.set.QuestionSet; | ||
|
||
@Entity(name = "Annotation") | ||
@Table( | ||
name = "annotation" | ||
) | ||
public class Annotation { | ||
|
||
@Id | ||
@GenericGenerator( | ||
name="annotation_generator", | ||
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", | ||
parameters = { | ||
@Parameter(name="sequence_name",value="annotation_seq"), | ||
@Parameter(name="increment_size",value="1") | ||
} | ||
) | ||
@GeneratedValue(generator = "annotation_generator") | ||
@Column(name = "annotation_id") | ||
private int id; | ||
|
||
@Column(name = "subject_id") | ||
private int subjectId; | ||
|
||
@Column(name = "cohort_sample_id") | ||
private int cohortSampleId; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "question_set_id") | ||
private QuestionSet questionSet; | ||
|
||
//***** GETTERS/SETTERS ****** | ||
|
||
/** | ||
* @return the id | ||
*/ | ||
public int getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* @param id the id to set | ||
*/ | ||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
/** | ||
* @return the subjectId | ||
*/ | ||
public int getSubjectId() { | ||
return subjectId; | ||
} | ||
|
||
/** | ||
* @param subjectId the subjectId to set | ||
*/ | ||
public void setSubjectId(int subjectId) { | ||
this.subjectId = subjectId; | ||
} | ||
|
||
/** | ||
* @return the cohortId | ||
*/ | ||
public int getCohortSampleId() { | ||
return cohortSampleId; | ||
} | ||
|
||
/** | ||
* @param cohortSampleId the cohortId to set | ||
*/ | ||
public void setCohortSampleId(int cohortSampleId) { | ||
this.cohortSampleId = cohortSampleId; | ||
} | ||
|
||
/** | ||
* @return the set | ||
*/ | ||
public QuestionSet getQuestionSet() { | ||
return questionSet; | ||
} | ||
|
||
/** | ||
* @param set the set to set | ||
*/ | ||
public void setQuestionSet(QuestionSet questionSet) { | ||
this.questionSet = questionSet; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
package org.ohdsi.webapi.annotation.annotation; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.PathParam; | ||
import org.json.JSONObject; | ||
import org.json.JSONArray; | ||
import org.ohdsi.webapi.annotation.result.ResultService; | ||
import org.ohdsi.webapi.annotation.study.Study; | ||
import org.ohdsi.webapi.annotation.study.StudyService; | ||
import org.ohdsi.webapi.cohortdefinition.CohortDefinition; | ||
import org.ohdsi.webapi.cohortdefinition.CohortDefinitionRepository; | ||
import org.ohdsi.webapi.cohortsample.CohortSample; | ||
import org.ohdsi.webapi.cohortsample.CohortSampleRepository; | ||
import org.ohdsi.webapi.cohortsample.CohortSamplingService; | ||
import org.ohdsi.webapi.cohortsample.dto.SampleElementDTO; | ||
import org.ohdsi.webapi.source.Source; | ||
import org.ohdsi.webapi.source.SourceService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import org.ohdsi.webapi.annotation.set.QuestionSetRepository; | ||
import org.ohdsi.webapi.annotation.set.QuestionSet; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
|
||
@Path("annotations") | ||
@Component | ||
public class AnnotationController { | ||
|
||
@Autowired | ||
private StudyService studyService; | ||
|
||
@Autowired | ||
private ResultService resultService; | ||
|
||
@Autowired | ||
private CohortDefinitionRepository cohortDefinitionRepository; | ||
|
||
@Autowired | ||
private CohortSamplingService cohortSamplingService; | ||
|
||
@Autowired | ||
private CohortSampleRepository sampleRepository; | ||
|
||
@Autowired | ||
private AnnotationService annotationService; | ||
|
||
@Autowired | ||
private QuestionSetRepository questionSetRepository; | ||
|
||
@Autowired | ||
private SourceService sourceService; | ||
|
||
@GET | ||
@Path("/") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public List<AnnotationSummary> getAnnotations( | ||
@QueryParam("cohortSampleId") final int cohortSampleId, | ||
@QueryParam("subjectId") final int subjectId, | ||
@QueryParam("setId") final int setId | ||
) { | ||
List<Annotation> returnAnnotations; | ||
returnAnnotations = getFullAnnotations(cohortSampleId,subjectId,setId); | ||
List<AnnotationSummary> summaries = new ArrayList(); | ||
for(Annotation singleAnno : returnAnnotations){ | ||
// can we see about doing this in a more performant manner? | ||
AnnotationSummary tempAnnoSummary=new AnnotationSummary(singleAnno); | ||
summaries.add(tempAnnoSummary); | ||
} | ||
return summaries; | ||
} | ||
|
||
@GET | ||
@Path("/fullquestion") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public List<Annotation> getFullAnnotations( | ||
@QueryParam("cohortSampleId") final int cohortSampleId, | ||
@QueryParam("subjectId") final int subjectId, | ||
@QueryParam("setId") final int setId | ||
) { | ||
List<Annotation> returnAnnotations=null; | ||
if (cohortSampleId != 0 && subjectId != 0 && setId != 0) { | ||
System.out.println("made it into the search function"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to find and remove all |
||
returnAnnotations= annotationService.getAnnotationByCohortSampleIdAndBySubjectIdAndByQuestionSetId(cohortSampleId, subjectId, setId); | ||
} | ||
else if (cohortSampleId !=0 && setId!=0){ | ||
returnAnnotations= annotationService.getAnnotationByCohortSampleIdAndByQuestionSetId(cohortSampleId,setId); | ||
} | ||
else if(cohortSampleId!=0){ | ||
returnAnnotations= annotationService.getAnnotationsByCohortSampleId(cohortSampleId); | ||
} | ||
else if(setId !=0){ | ||
returnAnnotations= annotationService.getAnnotationsByQuestionSetId(setId); | ||
} | ||
else{ | ||
returnAnnotations=annotationService.getAnnotations(); | ||
} | ||
return returnAnnotations; | ||
} | ||
|
||
@POST | ||
@Path("/") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public void addResult(@RequestBody String payload) { | ||
System.out.println(payload); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't usually parse raw JSON text from the POST. Instead, you define a class that represents the data structure, and the service will automatically serialize the request body into the JSON form. In addition, we shouldn't leave 'System.out.println' in the sourcecode. Use a logger. |
||
JSONObject jsonpayload = new JSONObject(payload); | ||
System.out.println(jsonpayload); | ||
System.out.println(jsonpayload.get("results")); | ||
System.out.printf("cohortId: %s\n",jsonpayload.get("cohortId").toString()); | ||
System.out.printf("cohortSampleId: %s\n",jsonpayload.get("cohortSampleId").toString()); | ||
System.out.printf("subjectId: %s\n",jsonpayload.get("subjectId").toString()); | ||
System.out.printf("setId: %s\n",jsonpayload.get("setId").toString()); | ||
Annotation tempAnnotation = annotationService.getAnnotationsByAnnotationId(jsonpayload.getInt("id")); | ||
System.out.printf("annotationID:%d\n",tempAnnotation.getId()); | ||
JSONArray array = jsonpayload.getJSONArray("results"); | ||
Study study = studyService.getStudyByQuestionSetIdAndSampleId(jsonpayload.getInt("setId"),jsonpayload.getInt("cohortSampleId") ); | ||
resultService.insertResults(tempAnnotation,array,study); | ||
} | ||
|
||
@POST | ||
@Path("/sample") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public void addAnnotation(@RequestBody String payload) { | ||
JSONObject jsonpayload = new JSONObject(payload); | ||
int cohortSampleId = Integer.parseInt(jsonpayload.get("sampleId").toString()); | ||
CohortSample cohortSample =sampleRepository.findById(cohortSampleId); | ||
List<SampleElementDTO> temp = cohortSamplingService.getSample(cohortSampleId, false).getElements(); | ||
Study study = new Study(); | ||
int questionSetId = Integer.parseInt(jsonpayload.get("annotationSetId").toString()); | ||
QuestionSet questionSet = questionSetRepository.findById(questionSetId); | ||
study.setQuestionSet(questionSetRepository.findById(questionSetId)); | ||
study.setCohortSample(cohortSample); | ||
CohortDefinition cohortDefinition= cohortDefinitionRepository.findOneWithDetail(cohortSample.getCohortDefinitionId()); | ||
study.setCohortDefinition(cohortDefinition); | ||
Source source = sourceService.findBySourceKey(jsonpayload.get("sourceKey").toString()); | ||
study.setSource(source); | ||
studyService.addStudy(study); | ||
for (SampleElementDTO element : temp){ | ||
System.out.println("element"+element); | ||
System.out.println("element GetPersonID"+element.getPersonId()); | ||
Annotation annotation = new Annotation(); | ||
annotation.setSubjectId(Integer.parseInt(element.getPersonId())); | ||
annotation.setCohortSampleId(cohortSampleId); | ||
annotation.setQuestionSet(questionSet); | ||
annotationService.addAnnotation(annotation); | ||
} | ||
} | ||
|
||
@GET | ||
@Path("/{annotationID}") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Annotation getResults(@PathParam("annotationID") String annotationID) { | ||
int annotationIdInt=Integer.parseInt(annotationID); | ||
Annotation ourAnno =annotationService.getAnnotationsByAnnotationId(annotationIdInt); | ||
return ourAnno; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package org.ohdsi.webapi.annotation.annotation; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import org.ohdsi.webapi.annotation.result.ResultDto; | ||
|
||
public class AnnotationDto { | ||
|
||
private int id; | ||
private int subjectId; | ||
private int sampleId; | ||
private int annotationSetId; | ||
private String name; | ||
private Set<ResultDto> results = new HashSet(); | ||
|
||
//***** GETTERS/SETTERS ****** | ||
|
||
/** | ||
* @return the id | ||
*/ | ||
public int getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* @param id the id to set | ||
*/ | ||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
/** | ||
* @return the subjectId | ||
*/ | ||
public int getSubjectId() { | ||
return subjectId; | ||
} | ||
|
||
/** | ||
* @param subjectId the subjectId to set | ||
*/ | ||
public void setSubjectId(int subjectId) { | ||
this.subjectId = subjectId; | ||
} | ||
|
||
/** | ||
* @return the cohortId | ||
*/ | ||
public int getsampleId() { | ||
return sampleId; | ||
} | ||
|
||
/** | ||
* @param sampleId the cohortId to set | ||
*/ | ||
public void setsampleId(int sampleId) { | ||
this.sampleId = sampleId; | ||
} | ||
|
||
/** | ||
* @return the setId | ||
*/ | ||
public int getannotationSetId() { | ||
return annotationSetId; | ||
} | ||
|
||
/** | ||
* @param setId the setId to set | ||
*/ | ||
public void setannotationSetId(int setId) { | ||
this.annotationSetId = setId; | ||
} | ||
|
||
/** | ||
* @return the results | ||
*/ | ||
public Set<ResultDto> getResults() { | ||
return new HashSet<ResultDto>(results); | ||
} | ||
|
||
/** | ||
* @param results the results to set | ||
*/ | ||
protected void setResults(Set<ResultDto> results) { | ||
this.results = results; | ||
} | ||
|
||
/** | ||
* @return the sample name | ||
*/ | ||
public String getSampleName() { | ||
return name; | ||
} | ||
|
||
/** | ||
* @param name to the slected sample name | ||
*/ | ||
public void setSampleName(String name) { | ||
this.name = name; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.ohdsi.webapi.annotation.annotation; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import java.util.List; | ||
import java.util.Set; | ||
import org.ohdsi.webapi.annotation.annotation.Annotation; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface AnnotationRepository extends JpaRepository<Annotation, Integer> { | ||
|
||
public Set<Annotation> findOneByCohortSampleIdAndSubjectIdAndQuestionSetId(int cohortSampleId, int subjectId, int questionSetId); | ||
public List<Annotation> findByCohortSampleIdAndQuestionSetId(int cohortSampleId, int questionSetId); | ||
public List<Annotation> findByCohortSampleId(int cohortSampleId); | ||
public List<Annotation> findByQuestionSetId(int questionSetId); | ||
public Annotation findById(int annotation_id); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there a namespace 'annotation.annotation'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in this case- The overall functionality we're adding gets called "annotation", and inside that overall annotation idea we have the true Annotation package. Not sure what the best fix is here if it needs changed, but my take is that it's fine.