-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathConditionEra.java
More file actions
131 lines (104 loc) · 4.12 KB
/
Copy pathConditionEra.java
File metadata and controls
131 lines (104 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
*
* Copyright 2017 Observational Health Data Sciences and Informatics
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Authors: Christopher Knoll
*
*/
package org.ohdsi.circe.cohortdefinition;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.lang3.StringUtils;
import org.ohdsi.circe.cohortdefinition.builders.BuilderOptions;
import org.ohdsi.circe.cohortdefinition.builders.ColumnFieldData;
import org.ohdsi.circe.cohortdefinition.builders.ColumnFieldDataType;
import org.ohdsi.circe.vocabulary.Concept;
/**
*
* @author cknoll1
*/
public class ConditionEra extends Criteria {
@JsonProperty("CodesetId")
public Integer codesetId;
@JsonProperty("First")
public Boolean first;
@JsonProperty("EraStartDate")
public DateRange eraStartDate;
@JsonProperty("EraEndDate")
public DateRange eraEndDate;
@JsonProperty("OccurrenceCount")
public NumericRange occurrenceCount;
@JsonProperty("EraLength")
public NumericRange eraLength;
@JsonProperty("AgeAtStart")
public NumericRange ageAtStart;
@JsonProperty("AgeAtEnd")
public NumericRange ageAtEnd;
@JsonProperty("Gender")
public Concept[] gender;
@Override
public String accept(IGetCriteriaSqlDispatcher dispatcher, BuilderOptions options) {
return dispatcher.getCriteriaSql(this, options);
}
@Override
public List<ColumnFieldData> getSelectedField(Boolean retainCohortCovariates) {
List<ColumnFieldData> selectCols = new ArrayList<>();
if (retainCohortCovariates) {
if (occurrenceCount != null) {
selectCols.add(new ColumnFieldData("condition_occurrence_count", ColumnFieldDataType.INTEGER));
}
}
return selectCols;
}
@Override
public String embedWindowedCriteriaQuery(String query, Map<String, ColumnFieldData> mapDistinctField) {
List<String> selectCols = new ArrayList<>();
List<String> groupCols = new ArrayList<>();
for (Entry<String, ColumnFieldData> entry : mapDistinctField.entrySet()) {
if (entry.getKey().equals("condition_occurrence_count") && occurrenceCount != null) {
selectCols.add(", cc.condition_occurrence_count");
groupCols.add(", cc.condition_occurrence_count");
} else {
selectCols.add(", CAST(null as " + entry.getValue().getDataType().getType() + ") " + entry.getKey());
}
}
query = StringUtils.replace(query, "@additionColumnscc", StringUtils.join(selectCols, ""));
query = StringUtils.replace(query, "@additionGroupColumnscc", StringUtils.join(groupCols, ""));
return query;
}
@Override
public String embedWindowedCriteriaQueryP(String query) {
ArrayList<String> selectColsA = new ArrayList<>();
if (occurrenceCount != null) {
selectColsA.add(", A.condition_occurrence_count");
}
query = StringUtils.replace(query, "@p.additionColumns", StringUtils.join(selectColsA, ""));
return query;
}
@Override
public String embedWrapCriteriaQuery(String query, List<String> selectColsPE, BuilderOptions options) {
ArrayList<String> selectCols = new ArrayList<>();
if(!options.isPrimaryCriteria()){
if (occurrenceCount != null) {
selectCols.add(", Q.condition_occurrence_count");
selectColsPE.add(", PE.condition_occurrence_count");
}
}
query = StringUtils.replace(query, "@QAdditionalColumnsInclusionN", StringUtils.join(selectCols, ""));
return query;
}
}