-
Notifications
You must be signed in to change notification settings - Fork 0
/
OMOP CDM ddl - PostgreSQL.sql
702 lines (545 loc) · 19.1 KB
/
OMOP CDM ddl - PostgreSQL.sql
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
/*********************************************************************************
# Copyright 2014-6 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.
********************************************************************************/
/************************
####### # # ####### ###### ##### ###### # # ####### #####
# # ## ## # # # # # # # # ## ## # # # # #
# # # # # # # # # # # # # # # # # # # # #
# # # # # # # ###### # # # # # # # # ###### #####
# # # # # # # # # # # # # # # ### #
# # # # # # # # # # # # # # # # # ### #
####### # # ####### # ##### ###### # # ## ##### ### #######
script to create OMOP common data model, version 5.2 for PostgreSQL database
last revised: 14 July 2017
Authors: Patrick Ryan, Christian Reich
*************************/
/************************
Standardized vocabulary
************************/
CREATE TABLE concept (
concept_id INTEGER NOT NULL,
concept_name VARCHAR(255) NOT NULL,
domain_id VARCHAR(20) NOT NULL,
vocabulary_id VARCHAR(20) NOT NULL,
concept_class_id VARCHAR(20) NOT NULL,
standard_concept VARCHAR(1) NULL,
concept_code VARCHAR(50) NOT NULL,
valid_start_date DATE NOT NULL,
valid_end_date DATE NOT NULL,
invalid_reason VARCHAR(1) NULL
)
;
CREATE TABLE vocabulary (
vocabulary_id VARCHAR(20) NOT NULL,
vocabulary_name VARCHAR(255) NOT NULL,
vocabulary_reference VARCHAR(255) NULL,
vocabulary_version VARCHAR(255) NULL,
vocabulary_concept_id INTEGER NOT NULL
)
;
CREATE TABLE domain (
domain_id VARCHAR(20) NOT NULL,
domain_name VARCHAR(255) NOT NULL,
domain_concept_id INTEGER NOT NULL
)
;
CREATE TABLE concept_class (
concept_class_id VARCHAR(20) NOT NULL,
concept_class_name VARCHAR(255) NOT NULL,
concept_class_concept_id INTEGER NOT NULL
)
;
CREATE TABLE concept_relationship (
concept_id_1 INTEGER NOT NULL,
concept_id_2 INTEGER NOT NULL,
relationship_id VARCHAR(20) NOT NULL,
valid_start_date DATE NOT NULL,
valid_end_date DATE NOT NULL,
invalid_reason VARCHAR(1) NULL)
;
CREATE TABLE relationship (
relationship_id VARCHAR(20) NOT NULL,
relationship_name VARCHAR(255) NOT NULL,
is_hierarchical VARCHAR(1) NOT NULL,
defines_ancestry VARCHAR(1) NOT NULL,
reverse_relationship_id VARCHAR(20) NOT NULL,
relationship_concept_id INTEGER NOT NULL
)
;
CREATE TABLE concept_synonym (
concept_id INTEGER NOT NULL,
concept_synonym_name VARCHAR(1000) NOT NULL,
language_concept_id INTEGER NOT NULL
)
;
CREATE TABLE concept_ancestor (
ancestor_concept_id INTEGER NOT NULL,
descendant_concept_id INTEGER NOT NULL,
min_levels_of_separation INTEGER NOT NULL,
max_levels_of_separation INTEGER NOT NULL
)
;
CREATE TABLE source_to_concept_map (
source_code VARCHAR(50) NOT NULL,
source_concept_id INTEGER NOT NULL,
source_vocabulary_id VARCHAR(20) NOT NULL,
source_code_description VARCHAR(255) NULL,
target_concept_id INTEGER NOT NULL,
target_vocabulary_id VARCHAR(20) NOT NULL,
valid_start_date DATE NOT NULL,
valid_end_date DATE NOT NULL,
invalid_reason VARCHAR(1) NULL
)
;
CREATE TABLE drug_strength (
drug_concept_id INTEGER NOT NULL,
ingredient_concept_id INTEGER NOT NULL,
amount_value NUMERIC NULL,
amount_unit_concept_id INTEGER NULL,
numerator_value NUMERIC NULL,
numerator_unit_concept_id INTEGER NULL,
denominator_value NUMERIC NULL,
denominator_unit_concept_id INTEGER NULL,
box_size INTEGER NULL,
valid_start_date DATE NOT NULL,
valid_end_date DATE NOT NULL,
invalid_reason VARCHAR(1) NULL
)
;
CREATE TABLE cohort_definition (
cohort_definition_id INTEGER NOT NULL,
cohort_definition_name VARCHAR(255) NOT NULL,
cohort_definition_description TEXT NULL,
definition_type_concept_id INTEGER NOT NULL,
cohort_definition_syntax TEXT NULL,
subject_concept_id INTEGER NOT NULL,
cohort_initiation_date DATE NULL
)
;
CREATE TABLE attribute_definition (
attribute_definition_id INTEGER NOT NULL,
attribute_name VARCHAR(255) NOT NULL,
attribute_description TEXT NULL,
attribute_type_concept_id INTEGER NOT NULL,
attribute_syntax TEXT NULL
)
;
/**************************
Standardized meta-data
***************************/
CREATE TABLE cdm_source
(
cdm_source_name VARCHAR(255) NOT NULL,
cdm_source_abbreviation VARCHAR(25) NULL,
cdm_holder VARCHAR(255) NULL,
source_description TEXT NULL,
source_documentation_reference VARCHAR(255) NULL,
cdm_etl_reference VARCHAR(255) NULL,
source_release_date DATE NULL,
cdm_release_date DATE NULL,
cdm_version VARCHAR(10) NULL,
vocabulary_version VARCHAR(20) NULL
)
;
/************************
Standardized clinical data
************************/
CREATE TABLE person
(
person_id INTEGER NOT NULL ,
gender_concept_id INTEGER NOT NULL ,
year_of_birth INTEGER NOT NULL ,
month_of_birth INTEGER NULL,
day_of_birth INTEGER NULL,
birth_datetime TIMESTAMP NULL,
race_concept_id INTEGER NOT NULL,
ethnicity_concept_id INTEGER NOT NULL,
location_id INTEGER NULL,
provider_id INTEGER NULL,
care_site_id INTEGER NULL,
person_source_value VARCHAR(50) NULL,
gender_source_value VARCHAR(50) NULL,
gender_source_concept_id INTEGER NULL,
race_source_value VARCHAR(50) NULL,
race_source_concept_id INTEGER NULL,
ethnicity_source_value VARCHAR(50) NULL,
ethnicity_source_concept_id INTEGER NULL
)
;
CREATE TABLE observation_period
(
observation_period_id INTEGER NOT NULL ,
person_id INTEGER NOT NULL ,
observation_period_start_date DATE NOT NULL ,
observation_period_end_date DATE NOT NULL ,
period_type_concept_id INTEGER NOT NULL
)
;
CREATE TABLE specimen
(
specimen_id INTEGER NOT NULL ,
person_id INTEGER NOT NULL ,
specimen_concept_id INTEGER NOT NULL ,
specimen_type_concept_id INTEGER NOT NULL ,
specimen_date DATE NOT NULL ,
specimen_datetime TIMESTAMP NULL ,
quantity NUMERIC NULL ,
unit_concept_id INTEGER NULL ,
anatomic_site_concept_id INTEGER NULL ,
disease_status_concept_id INTEGER NULL ,
specimen_source_id VARCHAR(50) NULL ,
specimen_source_value VARCHAR(50) NULL ,
unit_source_value VARCHAR(50) NULL ,
anatomic_site_source_value VARCHAR(50) NULL ,
disease_status_source_value VARCHAR(50) NULL
)
;
CREATE TABLE death
(
person_id INTEGER NOT NULL ,
death_date DATE NOT NULL ,
death_datetime TIMESTAMP NULL ,
death_type_concept_id INTEGER NOT NULL ,
cause_concept_id INTEGER NULL ,
cause_source_value VARCHAR(50) NULL,
cause_source_concept_id INTEGER NULL
)
;
CREATE TABLE visit_occurrence
(
visit_occurrence_id INTEGER NOT NULL ,
person_id INTEGER NOT NULL ,
visit_concept_id INTEGER NOT NULL ,
visit_start_date DATE NOT NULL ,
visit_start_datetime TIMESTAMP NULL ,
visit_end_date DATE NOT NULL ,
visit_end_datetime TIMESTAMP NULL ,
visit_type_concept_id INTEGER NOT NULL ,
provider_id INTEGER NULL,
care_site_id INTEGER NULL,
visit_source_value VARCHAR(50) NULL,
visit_source_concept_id INTEGER NULL ,
admitting_source_concept_id INTEGER NULL ,
admitting_source_value VARCHAR(50) NULL ,
discharge_to_concept_id INTEGER NULL ,
discharge_to_source_value VARCHAR(50) NULL ,
preceding_visit_occurrence_id INTEGER NULL
)
;
CREATE TABLE procedure_occurrence
(
procedure_occurrence_id INTEGER NOT NULL ,
person_id INTEGER NOT NULL ,
procedure_concept_id INTEGER NOT NULL ,
procedure_date DATE NOT NULL ,
procedure_datetime TIMESTAMP NOT NULL ,
procedure_type_concept_id INTEGER NOT NULL ,
modifier_concept_id INTEGER NULL ,
quantity INTEGER NULL ,
provider_id INTEGER NULL ,
visit_occurrence_id INTEGER NULL ,
procedure_source_value VARCHAR(50) NULL ,
procedure_source_concept_id INTEGER NULL ,
qualifier_source_value VARCHAR(50) NULL
)
;
CREATE TABLE drug_exposure
(
drug_exposure_id INTEGER NOT NULL ,
person_id INTEGER NOT NULL ,
drug_concept_id INTEGER NOT NULL ,
drug_exposure_start_date DATE NOT NULL ,
drug_exposure_start_datetime TIMESTAMP NOT NULL ,
drug_exposure_end_date DATE NOT NULL ,
drug_exposure_end_datetime TIMESTAMP NULL ,
verbatim_end_date DATE NULL ,
drug_type_concept_id INTEGER NOT NULL ,
stop_reason VARCHAR(20) NULL ,
refills INTEGER NULL ,
quantity NUMERIC NULL ,
days_supply INTEGER NULL ,
sig TEXT NULL ,
route_concept_id INTEGER NULL ,
lot_number VARCHAR(50) NULL ,
provider_id INTEGER NULL ,
visit_occurrence_id INTEGER NULL ,
drug_source_value VARCHAR(50) NULL ,
drug_source_concept_id INTEGER NULL ,
route_source_value VARCHAR(50) NULL ,
dose_unit_source_value VARCHAR(50) NULL
)
;
CREATE TABLE device_exposure
(
device_exposure_id INTEGER NOT NULL ,
person_id INTEGER NOT NULL ,
device_concept_id INTEGER NOT NULL ,
device_exposure_start_date DATE NOT NULL ,
device_exposure_start_datetime TIMESTAMP NOT NULL ,
device_exposure_end_date DATE NULL ,
device_exposure_end_datetime TIMESTAMP NULL ,
device_type_concept_id INTEGER NOT NULL ,
unique_device_id VARCHAR(50) NULL ,
quantity INTEGER NULL ,
provider_id INTEGER NULL ,
visit_occurrence_id INTEGER NULL ,
device_source_value VARCHAR(100) NULL ,
device_source_concept_id INTEGER NULL
)
;
CREATE TABLE condition_occurrence
(
condition_occurrence_id INTEGER NOT NULL ,
person_id INTEGER NOT NULL ,
condition_concept_id INTEGER NOT NULL ,
condition_start_date DATE NOT NULL ,
condition_start_datetime TIMESTAMP NOT NULL ,
condition_end_date DATE NULL ,
condition_end_datetime TIMESTAMP NULL ,
condition_type_concept_id INTEGER NOT NULL ,
stop_reason VARCHAR(20) NULL ,
provider_id INTEGER NULL ,
visit_occurrence_id INTEGER NULL ,
condition_source_value VARCHAR(50) NULL ,
condition_source_concept_id INTEGER NULL ,
condition_status_source_value VARCHAR(50) NULL ,
condition_status_concept_id INTEGER NULL
)
;
CREATE TABLE measurement
(
measurement_id INTEGER NOT NULL ,
person_id INTEGER NOT NULL ,
measurement_concept_id INTEGER NOT NULL ,
measurement_date DATE NOT NULL ,
measurement_datetime TIMESTAMP NULL ,
measurement_type_concept_id INTEGER NOT NULL ,
operator_concept_id INTEGER NULL ,
value_as_number NUMERIC NULL ,
value_as_concept_id INTEGER NULL ,
unit_concept_id INTEGER NULL ,
range_low NUMERIC NULL ,
range_high NUMERIC NULL ,
provider_id INTEGER NULL ,
visit_occurrence_id INTEGER NULL ,
measurement_source_value VARCHAR(50) NULL ,
measurement_source_concept_id INTEGER NULL ,
unit_source_value VARCHAR(50) NULL ,
value_source_value VARCHAR(50) NULL
)
;
CREATE TABLE note
(
note_id INTEGER NOT NULL ,
person_id INTEGER NOT NULL ,
note_date DATE NOT NULL ,
note_datetime TIMESTAMP NULL ,
note_type_concept_id INTEGER NOT NULL ,
note_class_concept_id INTEGER NOT NULL ,
note_title VARCHAR(250) NULL ,
note_text TEXT NOT NULL ,
encoding_concept_id INTEGER NOT NULL ,
language_concept_id INTEGER NOT NULL ,
provider_id INTEGER NULL ,
visit_occurrence_id INTEGER NULL ,
note_source_value VARCHAR(50) NULL
)
;
/*This table is new in CDM v5.2*/
CREATE TABLE note_nlp
(
note_nlp_id BIGINT NOT NULL ,
note_id INTEGER NOT NULL ,
section_concept_id INTEGER NULL ,
snippet VARCHAR(250) NULL ,
"offset" VARCHAR(250) NULL ,
lexical_variant VARCHAR(250) NOT NULL ,
note_nlp_concept_id INTEGER NULL ,
note_nlp_source_concept_id INTEGER NULL ,
nlp_system VARCHAR(250) NULL ,
nlp_date DATE NOT NULL ,
nlp_datetime TIMESTAMP NULL ,
term_exists VARCHAR(1) NULL ,
term_temporal VARCHAR(50) NULL ,
term_modifiers VARCHAR(2000) NULL
)
;
CREATE TABLE observation
(
observation_id INTEGER NOT NULL ,
person_id INTEGER NOT NULL ,
observation_concept_id INTEGER NOT NULL ,
observation_date DATE NOT NULL ,
observation_datetime TIMESTAMP NULL ,
observation_type_concept_id INTEGER NOT NULL ,
value_as_number NUMERIC NULL ,
value_as_string VARCHAR(60) NULL ,
value_as_concept_id INTEGER NULL ,
qualifier_concept_id INTEGER NULL ,
unit_concept_id INTEGER NULL ,
provider_id INTEGER NULL ,
visit_occurrence_id INTEGER NULL ,
observation_source_value VARCHAR(50) NULL ,
observation_source_concept_id INTEGER NULL ,
unit_source_value VARCHAR(50) NULL ,
qualifier_source_value VARCHAR(50) NULL
)
;
CREATE TABLE fact_relationship
(
domain_concept_id_1 INTEGER NOT NULL ,
fact_id_1 INTEGER NOT NULL ,
domain_concept_id_2 INTEGER NOT NULL ,
fact_id_2 INTEGER NOT NULL ,
relationship_concept_id INTEGER NOT NULL
)
;
/************************
Standardized health system data
************************/
CREATE TABLE location
(
location_id INTEGER NOT NULL ,
address_1 VARCHAR(50) NULL ,
address_2 VARCHAR(50) NULL ,
city VARCHAR(50) NULL ,
state VARCHAR(2) NULL ,
zip VARCHAR(9) NULL ,
county VARCHAR(20) NULL ,
location_source_value VARCHAR(50) NULL
)
;
CREATE TABLE care_site
(
care_site_id INTEGER NOT NULL ,
care_site_name VARCHAR(255) NULL ,
place_of_service_concept_id INTEGER NULL ,
location_id INTEGER NULL ,
care_site_source_value VARCHAR(50) NULL ,
place_of_service_source_value VARCHAR(50) NULL
)
;
CREATE TABLE provider
(
provider_id INTEGER NOT NULL ,
provider_name VARCHAR(255) NULL ,
NPI VARCHAR(20) NULL ,
DEA VARCHAR(20) NULL ,
specialty_concept_id INTEGER NULL ,
care_site_id INTEGER NULL ,
year_of_birth INTEGER NULL ,
gender_concept_id INTEGER NULL ,
provider_source_value VARCHAR(50) NULL ,
specialty_source_value VARCHAR(50) NULL ,
specialty_source_concept_id INTEGER NULL ,
gender_source_value VARCHAR(50) NULL ,
gender_source_concept_id INTEGER NULL
)
;
/************************
Standardized health economics
************************/
CREATE TABLE payer_plan_period
(
payer_plan_period_id INTEGER NOT NULL ,
person_id INTEGER NOT NULL ,
payer_plan_period_start_date DATE NOT NULL ,
payer_plan_period_end_date DATE NOT NULL ,
payer_source_value VARCHAR (50) NULL ,
plan_source_value VARCHAR (50) NULL ,
family_source_value VARCHAR (50) NULL
)
;
CREATE TABLE cost
(
cost_id INTEGER NOT NULL ,
cost_event_id INTEGER NOT NULL ,
cost_domain_id VARCHAR(20) NOT NULL ,
cost_type_concept_id INTEGER NOT NULL ,
currency_concept_id INTEGER NULL ,
total_charge NUMERIC NULL ,
total_cost NUMERIC NULL ,
total_paid NUMERIC NULL ,
paid_by_payer NUMERIC NULL ,
paid_by_patient NUMERIC NULL ,
paid_patient_copay NUMERIC NULL ,
paid_patient_coinsurance NUMERIC NULL ,
paid_patient_deductible NUMERIC NULL ,
paid_by_primary NUMERIC NULL ,
paid_ingredient_cost NUMERIC NULL ,
paid_dispensing_fee NUMERIC NULL ,
payer_plan_period_id INTEGER NULL ,
amount_allowed NUMERIC NULL ,
revenue_code_concept_id INTEGER NULL ,
reveue_code_source_value VARCHAR(50) NULL ,
drg_concept_id INTEGER NULL,
drg_source_value VARCHAR(3) NULL
)
;
/************************
Standardized derived elements
************************/
CREATE TABLE cohort
(
cohort_definition_id INTEGER NOT NULL ,
subject_id INTEGER NOT NULL ,
cohort_start_date DATE NOT NULL ,
cohort_end_date DATE NOT NULL
)
;
CREATE TABLE cohort_attribute
(
cohort_definition_id INTEGER NOT NULL ,
cohort_start_date DATE NOT NULL ,
cohort_end_date DATE NOT NULL ,
subject_id INTEGER NOT NULL ,
attribute_definition_id INTEGER NOT NULL ,
value_as_number NUMERIC NULL ,
value_as_concept_id INTEGER NULL
)
;
CREATE TABLE drug_era
(
drug_era_id INTEGER NOT NULL ,
person_id INTEGER NOT NULL ,
drug_concept_id INTEGER NOT NULL ,
drug_era_start_date DATE NOT NULL ,
drug_era_end_date DATE NOT NULL ,
drug_exposure_count INTEGER NULL ,
gap_days INTEGER NULL
)
;
CREATE TABLE dose_era
(
dose_era_id INTEGER NOT NULL ,
person_id INTEGER NOT NULL ,
drug_concept_id INTEGER NOT NULL ,
unit_concept_id INTEGER NOT NULL ,
dose_value NUMERIC NOT NULL ,
dose_era_start_date DATE NOT NULL ,
dose_era_end_date DATE NOT NULL
)
;
CREATE TABLE condition_era
(
condition_era_id INTEGER NOT NULL ,
person_id INTEGER NOT NULL ,
condition_concept_id INTEGER NOT NULL ,
condition_era_start_date DATE NOT NULL ,
condition_era_end_date DATE NOT NULL ,
condition_occurrence_count INTEGER NULL
)
;