Skip to content

Commit d2c3504

Browse files
committed
Merge pull request #17 from OHDSI/cohortdef-jpa
Cohort Definition Persistence Implementation
2 parents c662573 + dc01d2b commit d2c3504

10 files changed

+493
-53
lines changed

src/main/java/org/ohdsi/webapi/Filter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void filter(final ContainerRequestContext requestContext, final Container
1818
cres.getHeaders().add("Access-Control-Allow-Origin", "*");
1919
cres.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization");
2020
cres.getHeaders().add("Access-Control-Allow-Credentials", "true");
21-
cres.getHeaders().add("Access-Control-Allow-Methods", "GET, POST");
21+
cres.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT");
2222
cres.getHeaders().add("Access-Control-Max-Age", "1209600");
2323
}
2424
}

src/main/java/org/ohdsi/webapi/cohortanalysis/CohortSummary.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import java.util.List;
44

5-
import org.ohdsi.webapi.model.CohortDefinition;
5+
import org.ohdsi.webapi.service.CohortDefinitionService.CohortDefinitionDTO;
66

77
public class CohortSummary {
88

9-
private CohortDefinition cohortDefinition;
9+
private CohortDefinitionDTO cohortDefinition;
1010

1111
private String totalPatients;
1212

@@ -23,14 +23,14 @@ public class CohortSummary {
2323
/**
2424
* @return the definition
2525
*/
26-
public CohortDefinition getCohortDefinition() {
26+
public CohortDefinitionDTO getCohortDefinition() {
2727
return cohortDefinition;
2828
}
2929

3030
/**
3131
* @param definition the definition to set
3232
*/
33-
public void setCohortDefinition(CohortDefinition definition) {
33+
public void setCohortDefinition(CohortDefinitionDTO definition) {
3434
this.cohortDefinition = definition;
3535
}
3636

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package org.ohdsi.webapi.cohortdefinition;
16+
17+
import java.io.Serializable;
18+
import java.util.Date;
19+
import javax.persistence.CascadeType;
20+
import javax.persistence.Column;
21+
import javax.persistence.Entity;
22+
import javax.persistence.EnumType;
23+
import javax.persistence.Enumerated;
24+
import javax.persistence.FetchType;
25+
import javax.persistence.GeneratedValue;
26+
import javax.persistence.Id;
27+
import javax.persistence.JoinColumn;
28+
import javax.persistence.NamedAttributeNode;
29+
import javax.persistence.NamedEntityGraph;
30+
import javax.persistence.NamedSubgraph;
31+
import javax.persistence.OneToOne;
32+
33+
/**
34+
* JPA Entity for Cohort Definitions
35+
* @author cknoll1
36+
*/
37+
@Entity(name = "cohort_definition")
38+
@NamedEntityGraph(
39+
name = "CohortDefinition.withDetail",
40+
attributeNodes = { @NamedAttributeNode(value = "details", subgraph = "detailsGraph") },
41+
subgraphs = {@NamedSubgraph(name = "detailsGraph", type = CohortDefinitionDetails.class, attributeNodes = { @NamedAttributeNode(value="expression")})}
42+
)
43+
public class CohortDefinition implements Serializable{
44+
45+
private static final long serialVersionUID = 1L;
46+
47+
@Id
48+
@GeneratedValue
49+
private Integer id;
50+
51+
private String name;
52+
53+
private String description;
54+
55+
@Enumerated(EnumType.STRING)
56+
@Column(name="expression_type")
57+
private ExpressionType expressionType;
58+
59+
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional=false, orphanRemoval = true)
60+
@JoinColumn(name="id")
61+
CohortDefinitionDetails details;
62+
63+
@Column(name="created_by")
64+
private String createdBy;
65+
66+
@Column(name="created_date")
67+
private Date createdDate;
68+
69+
@Column(name="modified_by")
70+
private String modifiedBy;
71+
72+
@Column(name="modified_date")
73+
private Date modifiedDate;
74+
75+
public Integer getId() {
76+
return id;
77+
}
78+
79+
public void setId(Integer id) {
80+
this.id = id;
81+
}
82+
83+
public String getName() {
84+
return name;
85+
}
86+
87+
public CohortDefinition setName(String name) {
88+
this.name = name;
89+
return this;
90+
}
91+
92+
public String getDescription() {
93+
return description;
94+
}
95+
96+
public CohortDefinition setDescription(String description) {
97+
this.description = description;
98+
return this;
99+
}
100+
101+
public ExpressionType getExpressionType() {
102+
return expressionType;
103+
}
104+
105+
public CohortDefinition setExpressionType(ExpressionType expressionType) {
106+
this.expressionType = expressionType;
107+
return this;
108+
}
109+
110+
public CohortDefinitionDetails getDetails() {
111+
return this.details;
112+
}
113+
114+
public CohortDefinition setDetails(CohortDefinitionDetails details) {
115+
this.details = details;
116+
return this;
117+
}
118+
119+
public String getCreatedBy() {
120+
return createdBy;
121+
}
122+
123+
public CohortDefinition setCreatedBy(String createdBy) {
124+
this.createdBy = createdBy;
125+
return this;
126+
}
127+
128+
public Date getCreatedDate() {
129+
return createdDate;
130+
}
131+
132+
public CohortDefinition setCreatedDate(Date createdDate) {
133+
this.createdDate = createdDate;
134+
return this;
135+
}
136+
137+
public String getModifiedBy() {
138+
return modifiedBy;
139+
}
140+
141+
public CohortDefinition setModifiedBy(String modifiedBy) {
142+
this.modifiedBy = modifiedBy;
143+
return this;
144+
}
145+
146+
public Date getModifiedDate() {
147+
return modifiedDate;
148+
}
149+
150+
public CohortDefinition setModifiedDate(Date modifiedDate) {
151+
this.modifiedDate = modifiedDate;
152+
return this;
153+
}
154+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package org.ohdsi.webapi.cohortdefinition;
16+
17+
import java.io.Serializable;
18+
import javax.persistence.Column;
19+
import javax.persistence.Entity;
20+
import javax.persistence.GeneratedValue;
21+
import javax.persistence.Id;
22+
import javax.persistence.JoinColumn;
23+
import javax.persistence.Lob;
24+
import javax.persistence.MapsId;
25+
import javax.persistence.OneToOne;
26+
import javax.persistence.PrimaryKeyJoinColumn;
27+
import org.hibernate.annotations.GenericGenerator;
28+
import org.hibernate.annotations.Parameter;
29+
30+
/**
31+
*
32+
* Stores the LOB/CLOB portion of the cohort definition expression.
33+
*/
34+
@Entity(name = "cohort_definition_details")
35+
public class CohortDefinitionDetails implements Serializable{
36+
37+
private static final long serialVersionUID = 1L;
38+
39+
@Id
40+
private Integer id;
41+
42+
@MapsId
43+
@OneToOne
44+
@JoinColumn(name="id")
45+
private CohortDefinition definition;
46+
47+
@Lob
48+
private String expression;
49+
50+
public String getExpression() {
51+
return expression;
52+
}
53+
54+
public CohortDefinitionDetails setExpression(String expression) {
55+
this.expression = expression;
56+
return this;
57+
}
58+
59+
public CohortDefinitionDetails setCohortDefinition(CohortDefinition definition) {
60+
this.definition = definition;
61+
return this;
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package org.ohdsi.webapi.cohortdefinition;
16+
17+
import java.io.Serializable;
18+
import org.springframework.data.domain.Page;
19+
import org.springframework.data.domain.Pageable;
20+
import org.springframework.data.jpa.repository.EntityGraph;
21+
import org.springframework.data.repository.CrudRepository;
22+
import org.springframework.data.repository.Repository;
23+
24+
/**
25+
*
26+
* @author cknoll1
27+
*/
28+
public interface CohortDefinitionRepository extends CrudRepository<CohortDefinition, Integer> {
29+
Page<CohortDefinition> findAll(Pageable pageable);
30+
31+
// Bug in hibernate, findById should use @EntityGraph, but details are not being feched. Workaround: mark details Fetch.EAGER,
32+
// but means findAll() will eager load definitions (what the @EntityGraph was supposed to solve)
33+
@EntityGraph(value = "CohortDefinition.withDetail", type = EntityGraph.EntityGraphType.LOAD)
34+
CohortDefinition findById(Integer id);
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package org.ohdsi.webapi.cohortdefinition;
16+
17+
/**
18+
*
19+
* @author cknoll1
20+
*/
21+
public enum ExpressionType
22+
{
23+
SIMPLE_EXPRESSION,
24+
CUSTOM_SQL
25+
}

0 commit comments

Comments
 (0)