Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 801b47d

Browse files
author
Maxim Moinat
committed
replace default database parameters with server values
1 parent a4b6065 commit 801b47d

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

js/components/cohort-comparison-manager.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,6 @@ define(['jquery', 'knockout', 'text!./cohort-comparison-manager.html', 'lodash',
933933
// R code transform
934934
rCodeRaw = rCodeRaw.replace(/true/g, 'TRUE').replace(/false/g, 'FALSE');
935935

936-
// TODO: replace also databasename, cdm schema, results schema, cohort table
937936
// TODO: replace save to file by display inline
938937
var exporter = new RNotebookExport();
939938
var notebookJson = exporter.createNotebook(rCodeRaw);

js/modules/jupyter/RNotebookExport.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,34 @@ define(function (require, exports) {
3434
self.n_code_cells = 0;
3535
self.n_markdown_cells = 0;
3636

37+
// Parameters to replace
38+
self.dbServer = "localhost/ohdsi";
39+
self.dbUser = "demo";
40+
self.cdmDatabaseSchema = "cdm5";
41+
self.resultsDatabaseSchema = "webapi";
42+
self.exposureTable = "cohort";
43+
self.outcomeTable = "cohort";
44+
self.outputDirectory = "./";
45+
self.target = "T";
46+
self.comparator = "C";
47+
48+
// Patterns to replace
49+
self.parameters = {
50+
'localhost/ohdsi': self.dbServer,
51+
'joe': self.dbUser,
52+
'supersecret': self.dbUser,
53+
'my_cdm_data': self.cdmDatabaseSchema,
54+
'my_results|(exposure|outcome)_database_schema': self.resultsDatabaseSchema,
55+
'exposure_table': self.exposureTable,
56+
'outcome_table': self.outcomeTable,
57+
'<insert your directory here>': self.outputDirectory,
58+
'Target': self.target,
59+
'Comparator': self.comparator
60+
};
61+
3762
self.createNotebook = function(rawR) {
3863
var notebook = self.copyShallow(self.notebookBase);
64+
rawR = self.replaceParameters(rawR);
3965
notebook.cells = self.createCells(rawR);
4066
return notebook;
4167
};
@@ -119,6 +145,19 @@ define(function (require, exports) {
119145
return cellContent.trim();
120146
};
121147

148+
self.replaceParameters = function(string) {
149+
var regex;
150+
for (var key in self.parameters) {
151+
// check if the property/key is defined in the object itself, not in parent
152+
if (!self.parameters.hasOwnProperty(key)) {
153+
continue;
154+
}
155+
regex = new RegExp('"(' + key + ')"','g');
156+
string = string.replace(regex, '"' + self.parameters[key] + '"');
157+
}
158+
return string;
159+
};
160+
122161
self.copyShallow = function(object) {
123162
return JSON.parse(JSON.stringify(object));
124163
};

0 commit comments

Comments
 (0)