| 115 | |
| 116 | Or run this script - Edit the parameters first |
| 117 | |
| 118 | {{{#!sql |
| 119 | |
| 120 | DECLARE @OntologyName VARCHAR(50), -- The name of the ontology, e.g. 'Onyx' |
| 121 | @Prefix VARCHAR(10), -- The prefic for the concept code, e.g. 'ONX' |
| 122 | @OntologyDescription VARCHAR(100), -- A nice description, e.g. 'BRICCS Onyx Questionnaire' |
| 123 | @OntologyBaseNode VARCHAR(50), -- The name of the base node of the tree within i2b2, e.g. 'Onyx' |
| 124 | @SourceSystem VARCHAR(50), -- The system from where the data came, e.g. 'BRICCS Onyx' |
| 125 | @MetaDatabaseName VARCHAR(50), -- The name of the Meta Database in which to create the Ontology, e.g. 'i2b2_b1_metadata' |
| 126 | @DataDatabaseName VARCHAR(50) -- The name of the Data Database in which to create the Ontology, e.g. 'i2b2_b1_data' |
| 127 | |
| 128 | SET @OntologyName = 'Test CiviCRM' |
| 129 | SET @Prefix = 'TestGenCV' |
| 130 | SET @OntologyDescription = 'TestGenvasc Study Details from CiviCRM' |
| 131 | SET @OntologyBaseNode = 'TestCiviCRM' |
| 132 | SET @SourceSystem = 'TestGenvasc CiviCRM' |
| 133 | SET @MetaDatabaseName = 'i2b2_b1_metadata' |
| 134 | SET @DataDatabaseName = 'i2b2_b1_data' |
| 135 | |
| 136 | ---------------------------------------------------------------- |
| 137 | -------------- T H E A C T U A L S C R I P T --------------- |
| 138 | ---------------------------------------------------------------- |
| 139 | |
| 140 | -- |
| 141 | -- CREATE ONTOLOGY TABLE |
| 142 | -- |
| 143 | |
| 144 | DECLARE @TCreateOntologyTable VARCHAR(MAX) |
| 145 | SET @TCreateOntologyTable = ' |
| 146 | USE ' + @MetaDatabaseName + '; |
| 147 | |
| 148 | CREATE TABLE ' + @OntologyName + ' |
| 149 | ( "C_HLEVEL" INT NOT NULL, |
| 150 | "C_FULLNAME" VARCHAR(700) NOT NULL, |
| 151 | "C_NAME" VARCHAR(2000) NOT NULL, |
| 152 | "C_SYNONYM_CD" CHAR(1) NOT NULL, |
| 153 | "C_VISUALATTRIBUTES" CHAR(3) NOT NULL, |
| 154 | "C_TOTALNUM" INT NULL, |
| 155 | "C_BASECODE" VARCHAR(50) NULL, |
| 156 | "C_METADATAXML" TEXT NULL, |
| 157 | "C_FACTTABLECOLUMN" VARCHAR(50) NOT NULL, |
| 158 | "C_TABLENAME" VARCHAR(50) NOT NULL, |
| 159 | "C_COLUMNNAME" VARCHAR(50) NOT NULL, |
| 160 | "C_COLUMNDATATYPE" VARCHAR(50) NOT NULL, |
| 161 | "C_OPERATOR" VARCHAR(10) NOT NULL, |
| 162 | "C_DIMCODE" VARCHAR(700) NOT NULL, |
| 163 | "C_COMMENT" TEXT NULL, |
| 164 | "C_TOOLTIP" VARCHAR(900) NULL, |
| 165 | "UPDATE_DATE" DATETIME NOT NULL, |
| 166 | "DOWNLOAD_DATE" DATETIME NULL, |
| 167 | "IMPORT_DATE" DATETIME NULL, |
| 168 | "SOURCESYSTEM_CD" VARCHAR(50) NULL, |
| 169 | "VALUETYPE_CD" VARCHAR(50) NULL |
| 170 | ) ;' |
| 171 | |
| 172 | EXEC (@TCreateOntologyTable); |
| 173 | |
| 174 | -- |
| 175 | -- CREATE SCHEME |
| 176 | -- |
| 177 | |
| 178 | DECLARE @TCreateScheme VARCHAR(MAX) |
| 179 | SET @TCreateScheme = ' |
| 180 | USE ' + @MetaDatabaseName + '; |
| 181 | |
| 182 | INSERT INTO SCHEMES(C_KEY, C_NAME, C_DESCRIPTION) |
| 183 | VALUES(''' + @Prefix + ':'', ''' + @Prefix + ''', ''' + @OntologyDescription + ''');' |
| 184 | |
| 185 | EXEC (@TCreateScheme); |
| 186 | |
| 187 | -- |
| 188 | -- CREATE TABLE ACCESS |
| 189 | -- |
| 190 | |
| 191 | DECLARE @TCreateTableAccess VARCHAR(MAX) |
| 192 | SET @TCreateTableAccess = ' |
| 193 | USE ' + @MetaDatabaseName + '; |
| 194 | |
| 195 | INSERT INTO TABLE_ACCESS(C_TABLE_CD, C_TABLE_NAME, C_HLEVEL, C_FULLNAME, C_NAME, C_SYNONYM_CD, C_VISUALATTRIBUTES, C_TOTALNUM, C_BASECODE, C_METADATAXML, C_FACTTABLECOLUMN, C_DIMTABLENAME, C_COLUMNNAME, C_COLUMNDATATYPE, C_OPERATOR, C_DIMCODE, C_COMMENT, C_TOOLTIP, C_ENTRY_DATE, C_CHANGE_DATE, C_STATUS_CD, C_PROTECTED_ACCESS, VALUETYPE_CD) |
| 196 | VALUES(''' + @OntologyName + ''', ''' + @OntologyName + ''', 0, ''\' + @OntologyBaseNode + '\'', ''' + @OntologyDescription + ''', ''N'', ''CA'', NULL, NULL, NULL, ''concept_cd'', ''concept_dimension'', ''concept_path'', ''T'', ''LIKE'', ''\' + @OntologyBaseNode + '\'', NULL, ''' + @OntologyDescription + ''', NULL, NULL, NULL, ''N'', NULL);'; |
| 197 | |
| 198 | EXEC (@TCreateTableAccess); |
| 199 | |
| 200 | -- |
| 201 | -- CREATE THE BASE FOR THE ONTOLOGY |
| 202 | -- |
| 203 | |
| 204 | DECLARE @OntologyID INT |
| 205 | |
| 206 | -- Create the Ontology |
| 207 | |
| 208 | INSERT INTO [i2b2ClinDataIntegration].[dbo].[Ontology] ([Name],[Prefix],[SourceSystem]) |
| 209 | VALUES ( |
| 210 | @OntologyName |
| 211 | ,@Prefix |
| 212 | ,@SourceSystem); |
| 213 | |
| 214 | SET @OntologyID = SCOPE_IDENTITY(); |
| 215 | |
| 216 | SELECT @OntologyID; |
| 217 | |
| 218 | -- Create the ontology base code |
| 219 | |
| 220 | INSERT INTO [i2b2ClinDataIntegration].[dbo].[OntologyCode] ([ParentID],[OntologyID],[Code],[Name],[OntologyNodeTypeCode],[OntologyNodeStatusCode],[Editable],[MetaDataTypeCode],[MetaUnits]) |
| 221 | VALUES ( |
| 222 | NULL |
| 223 | ,@OntologyID |
| 224 | ,1 |
| 225 | ,@OntologyBaseNode |
| 226 | ,'C' |
| 227 | ,'A' |
| 228 | ,0 |
| 229 | ,NULL |
| 230 | ,NULL |
| 231 | ); |
| 232 | |
| 233 | -- Insert the base code into the Ontology table |
| 234 | DECLARE @TCreateBaseInOntologyTable VARCHAR(MAX) |
| 235 | SET @TCreateBaseInOntologyTable = ' |
| 236 | USE ' + @MetaDatabaseName + '; |
| 237 | |
| 238 | INSERT INTO Onyxv2 |
| 239 | SELECT [C_HLEVEL] |
| 240 | ,[C_FULLNAME] |
| 241 | ,[C_NAME] |
| 242 | ,[C_SYNONYM_CD] |
| 243 | ,[C_VISUALATTRIBUTES] |
| 244 | ,[C_TOTALNUM] |
| 245 | ,[C_BASECODE] |
| 246 | ,[C_METADATAXML] |
| 247 | ,[C_FACTTABLECOLUMN] |
| 248 | ,[C_TABLENAME] |
| 249 | ,[C_COLUMNNAME] |
| 250 | ,[C_COLUMNDATATYPE] |
| 251 | ,[C_OPERATOR] |
| 252 | ,[C_DIMCODE] |
| 253 | ,[C_COMMENT] |
| 254 | ,[C_TOOLTIP] |
| 255 | ,[UPDATE_DATE] |
| 256 | ,[DOWNLOAD_DATE] |
| 257 | ,[IMPORT_DATE] |
| 258 | ,[SOURCESYSTEM_CD] |
| 259 | ,[VALUETYPE_CD] |
| 260 | FROM [i2b2ClinDataIntegration].[dbo].[i2b2Ontology] |
| 261 | WHERE OntologyID = ' + @OntologyID; |
| 262 | |
| 263 | EXEC (@TCreateBaseInOntologyTable); |
| 264 | |
| 265 | -- Insert the base code into the Concept Table |
| 266 | DECLARE @TCreateBaseConceptTable VARCHAR(MAX) |
| 267 | SET @TCreateBaseConceptTable = ' |
| 268 | USE ' + @DataDatabaseName + '; |
| 269 | |
| 270 | INSERT INTO concept_dimension |
| 271 | SELECT |
| 272 | [concept_path] |
| 273 | ,[concept_cd] |
| 274 | ,[name_char] |
| 275 | ,[concept_blob] |
| 276 | ,[update_date] |
| 277 | ,[download_date] |
| 278 | ,[import_date] |
| 279 | ,[sourcesystem_cd] |
| 280 | ,[UPLOAD_ID] |
| 281 | FROM [i2b2ClinDataIntegration].[dbo].[i2b2OntologyConceptCodes] |
| 282 | WHERE OntologyID = ' + @OntologyID |
| 283 | |
| 284 | EXEC (@TCreateBaseConceptTable); |
| 285 | |
| 286 | ---------------------------------------------------------------- |
| 287 | ------- E N D O F T H E A C T U A L S C R I P T -------- |
| 288 | ---------------------------------------------------------------- |
| 289 | |
| 290 | |
| 291 | }}} |