-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathCohortDefinition.js
More file actions
210 lines (184 loc) · 5.83 KB
/
Copy pathCohortDefinition.js
File metadata and controls
210 lines (184 loc) · 5.83 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
define(function (require, exports) {
var $ = require('jquery');
var ko = require('knockout');
var config = require('appConfig');
var authApi = require('services/AuthAPI');
const httpService = require('services/http');
function pruneJSON(key, value) {
if (value === 0 || value) {
return value;
} else {
return
}
}
function getCohortDefinitionList() {
var promise = $.ajax({
url: config.webAPIRoot + 'cohortdefinition/',
error: authApi.handleAccessDenied
});
return promise;
}
async function saveCohortDefinition(definition) {
return authApi.executeWithRefresh($.ajax({
url: config.webAPIRoot + 'cohortdefinition/' + (definition.id || ""),
method: definition.id ? 'PUT' : 'POST',
contentType: 'application/json',
data: JSON.stringify(definition),
error: function(error) {
console.log("Error: " + error);
authApi.handleAccessDenied(error);
}
}));
}
async function copyCohortDefinition(id) {
return authApi.executeWithRefresh($.ajax({
url: config.webAPIRoot + 'cohortdefinition/' + (id || "") +"/copy",
method: 'GET',
contentType: 'application/json',
error: function (error) {
console.log("Error: " + error);
authApi.handleAccessDenied(error);
}
}));
}
function deleteCohortDefinition(id) {
var deletePromise = $.ajax({
url: config.webAPIRoot + 'cohortdefinition/' + (id || ""),
method: 'DELETE'
});
return deletePromise;
}
async function getCohortDefinition(id) {
return authApi.executeWithRefresh(httpService
.doGet(config.webAPIRoot + 'cohortdefinition/' + id)
.then(res => {
const cohortDef = res.data;
cohortDef.expression = JSON.parse(cohortDef.expression);
return cohortDef;
}).catch(error => {
console.log("Error: " + error);
authApi.handleAccessDenied(error);
}));
}
function exists(name, id) {
return httpService
.doGet(`${config.webAPIRoot}cohortdefinition/${id}/exists?name=${name}`)
.then(res => res.data);
}
function getSql(expression, options) {
var getSqlPromise = $.ajax({
url: config.webAPIRoot + 'cohortdefinition/sql',
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({
expression: expression,
options: options
}),
error: function (error) {
console.log("Error: " + error);
authApi.handleAccessDenied(error);
}
});
return getSqlPromise;
}
function translateSql(sql, dialect) {
return httpService.doPost(config.webAPIRoot + 'sqlrender/translate', ko.toJS({
SQL: sql,
targetdialect: dialect
}))
.catch(error => console.log("Error: " + error));
}
function generate(cohortDefinitionId, sourceKey, retainCohortCovariates) {
return httpService.doGet(`${config.webAPIRoot}cohortdefinition/${cohortDefinitionId}/generate/${sourceKey}?retainCohortCovariates=${retainCohortCovariates}`);
}
function cancelGenerate(cohortDefinitionId, sourceKey) {
return $.ajax({
url: config.webAPIRoot + 'cohortdefinition/' + (cohortDefinitionId || '-1') + '/cancel/' + sourceKey,
error: authApi.handleAccessDenied,
});
}
function getInfo(cohortDefinitionId) {
var infoPromise = $.ajax({
url: config.webAPIRoot + 'cohortdefinition/' + (cohortDefinitionId || '-1') + '/info',
error: function (error) {
console.log("Error: " + error);
authApi.handleAccessDenied(error);
}
});
return infoPromise;
}
function getReport(cohortDefinitionId, sourceKey, modeId) {
var reportPromise = $.ajax({
url: `${config.webAPIRoot}cohortdefinition/${(cohortDefinitionId || '-1')}/report/${sourceKey}?mode=${modeId || 0}`,
error: function (error) {
console.log("Error: " + error);
authApi.handleAccessDenied(error);
}
});
return reportPromise;
}
function runDiagnostics(expression) {
return httpService.doPost(config.webAPIRoot + 'cohortdefinition/checkV2', expression)
.then(res => res.data);
}
function getCohortCount(sourceKey, cohortDefinitionId) {
return httpService.doGet(config.api.url + 'cohortresults/' + sourceKey + '/' + cohortDefinitionId + '/distinctPersonCount')
.then(({ data }) => data);
}
function getCohortAnalyses(cohortJob) {
return httpService.doPost(config.api.url + 'cohortanalysis', cohortJob);
}
function getCohortPrintFriendly(cohortExpression) {
return httpService.plainTextService.doPost(config.webAPIRoot + 'cohortdefinition/printfriendly/cohort?format=html', cohortExpression);
}
function getVersions(cohortDefinitionId) {
return httpService.doGet(`${config.webAPIRoot}cohortdefinition/${cohortDefinitionId}/version/`)
.then(({ data }) => data);
}
function getVersion(cohortDefinitionId, versionNumber) {
return httpService.doGet(`${config.webAPIRoot}cohortdefinition/${cohortDefinitionId}/version/${versionNumber}`)
.then(res => {
const cohortDef = res.data.entityDTO;
cohortDef.expression = JSON.parse(cohortDef.expression);
cohortDef.versionDef = res.data.versionDTO;
return cohortDef;
}).catch(error => {
console.log("Error: " + error);
authApi.handleAccessDenied(error);
});
}
function copyVersion(cohortDefinitionId, versionNumber) {
return authApi.executeWithRefresh(httpService
.doPut(`${config.webAPIRoot}cohortdefinition/${cohortDefinitionId}/version/${versionNumber}/createAsset`)
.then(({ data }) => data));
}
function updateVersion(version) {
return httpService.doPut(`${config.webAPIRoot}cohortdefinition/${version.assetId}/version/${version.version}`, {
comment: version.comment,
archived: version.archived
}).then(({ data }) => data);
}
var api = {
getCohortDefinitionList,
saveCohortDefinition,
copyCohortDefinition,
deleteCohortDefinition,
getCohortDefinition,
getSql,
translateSql,
generate,
getInfo,
getReport,
runDiagnostics,
cancelGenerate,
getCohortCount,
getCohortAnalyses,
exists: exists,
getCohortPrintFriendly,
getVersions,
getVersion,
updateVersion,
copyVersion
};
return api;
});