generated from databricks-industry-solutions/industry-solutions-blueprints
-
Notifications
You must be signed in to change notification settings - Fork 12
/
2-omop531-cdm-setup.sql
992 lines (802 loc) · 21.3 KB
/
2-omop531-cdm-setup.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
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
-- Databricks notebook source
-- MAGIC %md
-- MAGIC You may find this series of notebooks at https://github.com/databricks-industry-solutions/omop-cdm. For more information about this solution accelerator, visit https://www.databricks.com/blog/2021/07/19/unlocking-the-power-of-health-data-with-a-modern-data-lakehouse.html.
-- COMMAND ----------
-- MAGIC %md
-- MAGIC # Create OMOP 5.3.1 Lakehouse
-- MAGIC This notebook contains DDLs for OMOP5.3.1 tables, as described [here](https://ohdsi.github.io/CommonDataModel/cdm531.html)
-- MAGIC
-- MAGIC <img src="https://ohdsi.github.io/TheBookOfOhdsi/images/CommonDataModel/cdmDiagram.png" width=30%\>
-- MAGIC
-- MAGIC *OMOP CDM v5.3.1 14June2018*
-- MAGIC
-- MAGIC These tables are cathgorized into the following groups:
-- MAGIC
-- MAGIC - **Clinical Data Tables (CDT):** PERSON,OBSERVATION_PERIOD,VISIT_OCCURRENCE,VISIT_DETAIL,CONDITION_OCCURRENCE,DRUG_EXPOSURE,PROCEDURE_OCCURRENCE,DEVICE_EXPOSURE,MEASUREMENT,OBSERVATION,DEATH,NOTE,NOTE_NLP,SPECIMEN,FACT_RELATIONSHIP
-- MAGIC
-- MAGIC - **Health System Data Tables (HSDT)**: LOCATION,CARE_SITE,PROVIDER
-- MAGIC
-- MAGIC - **Health Economics Data Tables (HEDT)**: PAYER_PLAN_PERIOD,COST
-- MAGIC
-- MAGIC - **Standardized Derived Elements (SDE)**: DRUG_ERA,DOSE_ERA,CONDITION_ERA
-- MAGIC
-- MAGIC - **Metadata Tables (MT)**:
-- MAGIC METADATA,CDM_SOURCE
-- MAGIC
-- MAGIC - **Vocabulary Tables (VT)**:
-- MAGIC CONCEPT,VOCABULARY,DOMAIN,CONCEPT_CLASS,CONCEPT_RELATIONSHIP,RELATIONSHIP,CONCEPT_SYNONYM,CONCEPT_ANCESTOR,SOURCE_TO_CONCEPT_MAP,DRUG_STRENGTH,COHORT_DEFINITION,ATTRIBUTE_DEFINITION
-- COMMAND ----------
-- DBTITLE 1,initial configurations
-- MAGIC %python
-- MAGIC import json
-- MAGIC
-- MAGIC project_name='omop-cdm-100K'
-- MAGIC omop_version="OMOP531"
-- MAGIC
-- MAGIC with open(f'/tmp/{project_name}_configs.json','r') as f:
-- MAGIC paths = json.load(f)
-- MAGIC base_path = paths['base_path']
-- MAGIC delta_path = paths['delta_path']
-- MAGIC
-- MAGIC delta_bronze_path = f'{delta_path}/bronze'
-- MAGIC delta_silver_path = f'{delta_path}/silver/{omop_version}'
-- MAGIC
-- MAGIC print(f"{omop_version} database tables will be stored in {delta_silver_path}")
-- COMMAND ----------
-- DBTITLE 0,Drop Existing Database
-- MAGIC %python
-- MAGIC sql(f"DROP DATABASE IF EXISTS {omop_version} CASCADE;")
-- MAGIC sql(f"CREATE DATABASE IF NOT EXISTS {omop_version} LOCATION '{delta_silver_path}'")
-- MAGIC sql(f"USE {omop_version};")
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ## Create OMOP 5.3.1 Tables
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ### Standardized Vocabularies
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### CONCEPT
-- COMMAND ----------
CREATE
OR REPLACE TABLE CONCEPT (
CONCEPT_ID LONG,
CONCEPT_NAME STRING,
DOMAIN_ID STRING,
VOCABULARY_ID STRING,
CONCEPT_CLASS_ID STRING,
STANDARD_CONCEPT STRING,
CONCEPT_CODE STRING,
VALID_START_DATE DATE,
VALID_END_DATE DATE,
INVALID_REASON STRING
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### VOCABULARY
-- COMMAND ----------
CREATE
OR REPLACE TABLE VOCABULARY (
VOCABULARY_ID STRING,
VOCABULARY_NAME STRING,
VOCABULARY_REFERENCE STRING,
VOCABULARY_VERSION STRING,
VOCABULARY_CONCEPT_ID LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### DOMAIN
-- COMMAND ----------
CREATE
OR REPLACE TABLE DOMAIN (
DOMAIN_ID STRING,
DOMAIN_NAME STRING,
DOMAIN_CONCEPT_ID LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### CONCEPT_CLASS
-- COMMAND ----------
CREATE
OR REPLACE TABLE CONCEPT_CLASS (
CONCEPT_CLASS_ID STRING,
CONCEPT_CLASS_NAME STRING,
CONCEPT_CLASS_CONCEPT_ID LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### CONCEPT_RELATIONSHIP
-- COMMAND ----------
CREATE
OR REPLACE TABLE CONCEPT_RELATIONSHIP (
CONCEPT_ID_1 LONG,
CONCEPT_ID_2 LONG,
RELATIONSHIP_ID STRING,
VALID_START_DATE DATE,
VALID_END_DATE DATE,
INVALID_REASON STRING
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### RELATIONSHIP
-- COMMAND ----------
CREATE
OR REPLACE TABLE RELATIONSHIP (
RELATIONSHIP_ID STRING,
RELATIONSHIP_NAME STRING,
IS_HIERARCHICAL STRING,
DEFINES_ANCESTRY STRING,
REVERSE_RELATIONSHIP_ID STRING,
RELATIONSHIP_CONCEPT_ID LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### CONCEPT_SYNONYM
-- COMMAND ----------
CREATE
OR REPLACE TABLE CONCEPT_SYNONYM (
CONCEPT_ID LONG,
CONCEPT_SYNONYM_NAME STRING,
LANGUAGE_CONCEPT_ID LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### CONCEPT_ANCESTOR
-- COMMAND ----------
CREATE
OR REPLACE TABLE CONCEPT_ANCESTOR (
ANCESTOR_CONCEPT_ID LONG,
DESCENDANT_CONCEPT_ID LONG,
MIN_LEVELS_OF_SEPARATION LONG,
MAX_LEVELS_OF_SEPARATION LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### SOURCE_TO_CONCEPT_MAP
-- COMMAND ----------
CREATE
OR REPLACE TABLE SOURCE_TO_CONCEPT_MAP (
SOURCE_CODE STRING,
SOURCE_CONCEPT_ID LONG,
SOURCE_VOCABULARY_ID STRING,
SOURCE_CODE_DESCRIPTION STRING,
TARGET_CONCEPT_ID LONG,
TARGET_VOCABULARY_ID STRING,
VALID_START_DATE DATE,
VALID_END_DATE DATE,
INVALID_REASON STRING
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### DRUG_STRENGTH
-- COMMAND ----------
CREATE
OR REPLACE TABLE DRUG_STRENGTH (
DRUG_CONCEPT_ID LONG,
INGREDIENT_CONCEPT_ID LONG,
AMOUNT_VALUE DOUBLE,
AMOUNT_UNIT_CONCEPT_ID LONG,
NUMERATOR_VALUE DOUBLE,
NUMERATOR_UNIT_CONCEPT_ID LONG,
DENOMINATOR_VALUE DOUBLE,
DENOMINATOR_UNIT_CONCEPT_ID LONG,
BOX_SIZE LONG,
VALID_START_DATE DATE,
VALID_END_DATE DATE,
INVALID_REASON STRING
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### ATTRIBUTE_DEFINITION
-- COMMAND ----------
CREATE
OR REPLACE TABLE ATTRIBUTE_DEFINITION (
ATTRIBUTE_DEFINITION_ID LONG,
ATTRIBUTE_NAME STRING,
ATTRIBUTE_DESCRIPTION STRING,
ATTRIBUTE_TYPE_CONCEPT_ID LONG,
ATTRIBUTE_SYNTAX STRING
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ### Standardized metadata
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### CDM_SOURCE
-- COMMAND ----------
CREATE
OR REPLACE TABLE CDM_SOURCE (
CDM_SOURCE_NAME STRING,
CDM_SOURCE_ABBREVIATION STRING,
CDM_HOLDER STRING,
SOURCE_DESCRIPTION STRING,
SOURCE_DOCUMENTATION_REFERENCE STRING,
CDM_ETL_REFERENCE STRING,
SOURCE_RELEASE_DATE DATE,
CDM_RELEASE_DATE DATE,
CDM_VERSION STRING,
VOCABULARY_VERSION STRING
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### METADATA
-- COMMAND ----------
CREATE
OR REPLACE TABLE METADATA (
METADATA_CONCEPT_ID LONG,
METADATA_TYPE_CONCEPT_ID LONG,
NAME STRING,
VALUE_AS_STRING STRING,
VALUE_AS_CONCEPT_ID LONG,
METADATA_DATE DATE,
METADATA_DATETIME TIMESTAMP
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ### Standardized clinical data
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### PERSON
-- COMMAND ----------
--ZORDER BY (PERSON_ID)
CREATE
OR REPLACE TABLE PERSON (
PERSON_ID LONG,
GENDER_CONCEPT_ID LONG,
YEAR_OF_BIRTH LONG,
MONTH_OF_BIRTH LONG,
DAY_OF_BIRTH LONG,
BIRTH_DATETIME TIMESTAMP,
RACE_CONCEPT_ID LONG,
ETHNICITY_CONCEPT_ID LONG,
LOCATION_ID LONG,
PROVIDER_ID LONG,
CARE_SITE_ID LONG,
PERSON_SOURCE_VALUE STRING,
GENDER_SOURCE_VALUE STRING,
GENDER_SOURCE_CONCEPT_ID LONG,
RACE_SOURCE_VALUE STRING,
RACE_SOURCE_CONCEPT_ID LONG,
ETHNICITY_SOURCE_VALUE STRING,
ETHNICITY_SOURCE_CONCEPT_ID LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### OBSERVATION_PERIOD
-- COMMAND ----------
--ZORDER BY (PERSON_ID)
CREATE
OR REPLACE TABLE OBSERVATION_PERIOD (
OBSERVATION_PERIOD_ID LONG,
PERSON_ID LONG,
OBSERVATION_PERIOD_START_DATE DATE,
OBSERVATION_PERIOD_END_DATE DATE,
PERIOD_TYPE_CONCEPT_ID LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### VISIT_OCCURRENCE
-- COMMAND ----------
CREATE
OR REPLACE TABLE VISIT_OCCURRENCE (
VISIT_OCCURRENCE_ID LONG,
PERSON_ID LONG,
VISIT_CONCEPT_ID LONG,
VISIT_START_DATE DATE,
VISIT_START_DATETIME TIMESTAMP,
VISIT_END_DATE DATE,
VISIT_END_DATETIME TIMESTAMP,
VISIT_TYPE_CONCEPT_ID LONG,
PROVIDER_ID LONG,
CARE_SITE_ID LONG,
VISIT_SOURCE_VALUE STRING,
VISIT_SOURCE_CONCEPT_ID LONG,
ADMITTING_SOURCE_CONCEPT_ID LONG,
ADMITTING_SOURCE_VALUE STRING,
DISCHARGE_TO_CONCEPT_ID LONG,
DISCHARGE_TO_SOURCE_VALUE STRING,
PRECEDING_VISIT_OCCURRENCE_ID LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### VISIT_DETAIL
-- COMMAND ----------
CREATE
OR REPLACE TABLE VISIT_DETAIL (
VISIT_DETAIL_ID LONG,
PERSON_ID LONG,
VISIT_DETAIL_CONCEPT_ID LONG,
VISIT_DETAIL_START_DATE DATE,
VISIT_DETAIL_START_DATETIME TIMESTAMP,
VISIT_DETAIL_END_DATE DATE,
VISIT_DETAIL_END_DATETIME TIMESTAMP,
VISIT_DEATIL_TYPE_CONCEPT_ID LONG,
PROVIDER_ID LONG,
CARE_SITE_ID LONG,
ADMITTING_SOURCE_CONCEPT_ID LONG,
DISCHARGE_TO_CONCEPT_ID LONG,
PRECEDING_VISIT_DETAIL_ID LONG,
VISIT_DETAIL_SOURCE_VALUE STRING,
VISIT_DEATIL_SOURCE_CONCEPT_ID LONG,
ADMITTING_SOURCE_VALUE STRING,
DISCHARGE_TO_SOURCE_VALUE STRING,
VISIT_DETAIL_PARENT_ID LONG,
VISIT_OCCURRENCE_ID LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### CONDITION_OCCURRENCE
-- COMMAND ----------
CREATE
OR REPLACE TABLE CONDITION_OCCURRENCE (
CONDITION_OCCURRENCE_ID LONG,
PERSON_ID LONG,
CONDITION_CONCEPT_ID LONG,
CONDITION_START_DATE DATE,
CONDITION_START_DATETIME TIMESTAMP,
CONDITION_END_DATE DATE,
CONDITION_END_DATETIME TIMESTAMP,
CONDITION_TYPE_CONCEPT_ID LONG,
STOP_REASON STRING,
PROVIDER_ID LONG,
VISIT_OCCURRENCE_ID LONG,
VISIT_DETAIL_ID LONG,
CONDITION_SOURCE_VALUE STRING,
CONDITION_SOURCE_CONCEPT_ID LONG,
CONDITION_STATUS_SOURCE_VALUE STRING,
CONDITION_STATUS_CONCEPT_ID LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### DRUG_EXPOSURE
-- COMMAND ----------
CREATE
OR REPLACE TABLE DRUG_EXPOSURE (
DRUG_EXPOSURE_ID LONG,
PERSON_ID LONG,
DRUG_CONCEPT_ID LONG,
DRUG_EXPOSURE_START_DATE DATE,
DRUG_EXPOSURE_START_DATETIME TIMESTAMP,
DRUG_EXPOSURE_END_DATE DATE,
DRUG_EXPOSURE_END_DATETIME TIMESTAMP,
VERBATIM_END_DATE DATE,
DRUG_TYPE_CONCEPT_ID LONG,
STOP_REASON STRING,
REFILLS LONG,
QUANTITY DOUBLE,
DAYS_SUPPLY LONG,
SIG STRING,
ROUTE_CONCEPT_ID LONG,
LOT_NUMBER STRING,
PROVIDER_ID LONG,
VISIT_OCCURRENCE_ID LONG,
VISIT_DETAIL_ID LONG,
DRUG_SOURCE_VALUE STRING,
DRUG_SOURCE_CONCEPT_ID LONG,
ROUTE_SOURCE_VALUE STRING,
DOSE_UNIT_SOURCE_VALUE STRING
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### PROCEDURE_OCCURRENCE
-- COMMAND ----------
CREATE
OR REPLACE TABLE PROCEDURE_OCCURRENCE (
PROCEDURE_OCCURRENCE_ID LONG,
PERSON_ID LONG,
PROCEDURE_CONCEPT_ID LONG,
PROCEDURE_DATE DATE,
PROCEDURE_DATETIME TIMESTAMP,
PROCEDURE_TYPE_CONCEPT_ID LONG,
MODIFIER_CONCEPT_ID LONG,
QUANTITY LONG,
PROVIDER_ID LONG,
VISIT_OCCURRENCE_ID LONG,
VISIT_DETAIL_ID LONG,
PROCEDURE_SOURCE_VALUE STRING,
PROCEDURE_SOURCE_CONCEPT_ID LONG,
MODIFIER_SOURCE_VALUE STRING
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### DEVICE_EXPOSURE
-- COMMAND ----------
CREATE
OR REPLACE TABLE DEVICE_EXPOSURE (
DEVICE_EXPOSURE_ID LONG,
PERSON_ID LONG,
DEVICE_CONCEPT_ID LONG,
DEVICE_EXPOSURE_START_DATE DATE,
DEVICE_EXPOSURE_START_DATETIME TIMESTAMP,
DEVICE_EXPOSURE_END_DATE DATE,
DEVICE_EXPOSURE_END_DATETIME TIMESTAMP,
DEVICE_TYPE_CONCEPT_ID LONG,
UNIQUE_DEVICE_ID STRING,
QUANTITY LONG,
PROVIDER_ID LONG,
VISIT_OCCURRENCE_ID LONG,
VISIT_DETAIL_ID LONG,
DEVICE_SOURCE_VALUE STRING,
DEVICE_SOURCE_CONCEPT_ID LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### MEASUREMENT
-- COMMAND ----------
CREATE
OR REPLACE TABLE MEASUREMENT (
MEASUREMENT_ID LONG,
PERSON_ID LONG,
MEASUREMENT_CONCEPT_ID LONG,
MEASUREMENT_DATE DATE,
MEASUREMENT_DATETIME TIMESTAMP,
MEASUREMENT_TIME STRING,
MEASUREMENT_TYPE_CONCEPT_ID LONG,
OPERATOR_CONCEPT_ID LONG,
VALUE_AS_NUMBER DOUBLE,
VALUE_AS_CONCEPT_ID LONG,
UNIT_CONCEPT_ID LONG,
RANGE_LOW DOUBLE,
RANGE_HIGH DOUBLE,
PROVIDER_ID LONG,
VISIT_OCCURRENCE_ID LONG,
VISIT_DETAIL_ID LONG,
MEASUREMENT_SOURCE_VALUE STRING,
MEASUREMENT_SOURCE_CONCEPT_ID LONG,
UNIT_SOURCE_VALUE STRING,
VALUE_SOURCE_VALUE STRING
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### NOTE
-- COMMAND ----------
CREATE
OR REPLACE TABLE NOTE (
NOTE_ID LONG,
PERSON_ID LONG,
NOTE_DATE DATE,
NOTE_DATETIME TIMESTAMP,
NOTE_TYPE_CONCEPT_ID LONG,
NOTE_CLASS_CONCEPT_ID LONG,
NOTE_TITLE STRING,
NOTE_TEXT STRING,
ENCODING_CONCEPT_ID LONG,
LANGUAGE_CONCEPT_ID LONG,
PROVIDER_ID LONG,
VISIT_OCCURRENCE_ID LONG,
VISIT_DETAIL_ID LONG,
NOTE_SOURCE_VALUE STRING
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ##### NOTE_NLP
-- COMMAND ----------
CREATE
OR REPLACE TABLE NOTE_NLP (
NOTE_NLP_ID LONG,
NOTE_ID LONG,
SECTION_CONCEPT_ID LONG,
SNIPPET STRING,
OFFSET STRING,
LEXICAL_VARIANT STRING,
NOTE_NLP_CONCEPT_ID LONG,
NOTE_NLP_SOURCE_CONCEPT_ID LONG,
NLP_SYSTEM STRING,
NLP_DATE DATE,
NLP_DATETIME TIMESTAMP,
TERM_EXISTS STRING,
TERM_TEMPORAL STRING,
TERM_MODIFIERS STRING
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ##### OBSERVATION
-- COMMAND ----------
CREATE
OR REPLACE TABLE OBSERVATION (
OBSERVATION_ID LONG,
PERSON_ID LONG,
OBSERVATION_CONCEPT_ID LONG,
OBSERVATION_DATE DATE,
OBSERVATION_DATETIME TIMESTAMP,
OBSERVATION_TYPE_CONCEPT_ID LONG,
VALUE_AS_NUMBER DOUBLE,
VALUE_AS_STRING STRING,
VALUE_AS_CONCEPT_ID LONG,
QUALIFIER_CONCEPT_ID LONG,
UNIT_CONCEPT_ID LONG,
PROVIDER_ID LONG,
VISIT_OCCURRENCE_ID LONG,
VISIT_DETAIL_ID LONG,
OBSERVATION_SOURCE_VALUE STRING,
OBSERVATION_SOURCE_CONCEPT_ID LONG,
UNIT_SOURCE_VALUE STRING,
QUALIFIER_SOURCE_VALUE STRING
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ##### SPECIMEN
-- COMMAND ----------
CREATE
OR REPLACE TABLE SPECIMEN (
SPECIMEN_ID LONG,
PERSON_ID LONG,
SPECIMEN_CONCEPT_ID LONG,
SPECIMEN_TYPE_CONCEPT_ID LONG,
SPECIMEN_DATE DATE,
SPECIMEN_DATETIME TIMESTAMP,
QUANTITY DOUBLE,
UNIT_CONCEPT_ID LONG,
ANATOMIC_SITE_CONCEPT_ID LONG,
DISEASE_STATUS_CONCEPT_ID LONG,
SPECIMEN_SOURCE_ID STRING,
SPECIMEN_SOURCE_VALUE STRING,
UNIT_SOURCE_VALUE STRING,
ANATOMIC_SITE_SOURCE_VALUE STRING,
DISEASE_STATUS_SOURCE_VALUE STRING
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ##### FACT_RELATIONSHIP
-- COMMAND ----------
CREATE
OR REPLACE TABLE FACT_RELATIONSHIP (
DOMAIN_CONCEPT_ID_1 LONG,
FACT_ID_1 LONG,
DOMAIN_CONCEPT_ID_2 LONG,
FACT_ID_2 LONG,
RELATIONSHIP_CONCEPT_ID LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ##### DEATH
-- COMMAND ----------
CREATE
OR REPLACE TABLE DEATH (
PERSON_ID LONG,
DEATH_DATE DATE,
DEATH_DATETIME TIMESTAMP,
DEATH_TYPE_CONCEPT_ID LONG,
CAUSE_CONCEPT_ID LONG,
CAUSE_SOURCE_VALUE STRING,
CAUSE_SOURCE_CONCEPT_ID LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ### Standardized health system data
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### LOCATION
-- COMMAND ----------
CREATE
OR REPLACE TABLE LOCATION (
LOCATION_ID LONG,
ADDRESS_1 STRING,
ADDRESS_2 STRING,
CITY STRING,
STATE STRING,
ZIP STRING,
COUNTY STRING,
LOCATION_SOURCE_VALUE STRING
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### CARE_SITE
-- COMMAND ----------
CREATE
OR REPLACE TABLE CARE_SITE (
CARE_SITE_ID LONG,
CARE_SITE_NAME STRING,
PLACE_OF_SERVICE_CONCEPT_ID LONG,
LOCATION_ID LONG,
CARE_SITE_SOURCE_VALUE STRING,
PLACE_OF_SERVICE_SOURCE_VALUE STRING
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### PROVIDER
-- COMMAND ----------
CREATE
OR REPLACE TABLE PROVIDER (
PROVIDER_ID LONG,
PROVIDER_NAME STRING,
NPI STRING,
DEA STRING,
SPECIALTY_CONCEPT_ID LONG,
CARE_SITE_ID LONG,
YEAR_OF_BIRTH LONG,
GENDER_CONCEPT_ID LONG,
PROVIDER_SOURCE_VALUE STRING,
SPECIALTY_SOURCE_VALUE STRING,
SPECIALTY_SOURCE_CONCEPT_ID LONG,
GENDER_SOURCE_VALUE STRING,
GENDER_SOURCE_CONCEPT_ID LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ### Standardized health economics
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### PAYER_PLAN_PERIOD
-- COMMAND ----------
CREATE
OR REPLACE TABLE PAYER_PLAN_PERIOD (
PAYER_PLAN_PERIOD_ID LONG,
PERSON_ID LONG,
PAYER_PLAN_PERIOD_START_DATE DATE,
PAYER_PLAN_PERIOD_END_DATE DATE,
PAYER_CONCEPT_ID LONG,
PAYER_SOURCE_VALUE STRING,
PAYER_SOURCE_CONCEPT_ID LONG,
PLAN_CONCEPT_ID LONG,
PLAN_SOURCE_VALUE STRING,
PLAN_SOURCE_CONCEPT_ID LONG,
SPONSOR_CONCEPT_ID LONG,
SPONSOR_SOURCE_VALUE STRING,
SPONSOR_SOURCE_CONCEPT_ID LONG,
FAMILY_SOURCE_VALUE STRING,
STOP_REASON_CONCEPT_ID LONG,
STOP_REASON_SOURCE_VALUE STRING,
STOP_REASON_SOURCE_CONCEPT_ID LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### COST
-- COMMAND ----------
CREATE
OR REPLACE TABLE COST (
COST_ID LONG,
COST_EVENT_ID LONG,
COST_DOMAIN_ID STRING,
COST_TYPE_CONCEPT_ID LONG,
CURRENCY_CONCEPT_ID LONG,
TOTAL_CHARGE DOUBLE,
TOTAL_COST DOUBLE,
TOTAL_PAID DOUBLE,
PAID_BY_PAYER DOUBLE,
PAID_BY_PATIENT DOUBLE,
PAID_PATIENT_COPAY DOUBLE,
PAID_PATIENT_COINSURANCE DOUBLE,
PAID_PATIENT_DEDUCTIBLE DOUBLE,
PAID_BY_PRIMARY DOUBLE,
PAID_INGREDIENT_COST DOUBLE,
PAID_DISPENSING_FEE DOUBLE,
PAYER_PLAN_PERIOD_ID LONG,
AMOUNT_ALLOWED DOUBLE,
REVENUE_CODE_CONCEPT_ID LONG,
REVENUE_CODE_SOURCE_VALUE STRING,
DRG_CONCEPT_ID LONG,
DRG_SOURCE_VALUE STRING
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ### Standardized derived elements
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### Condition_era
-- COMMAND ----------
CREATE
OR REPLACE TABLE CONDITION_ERA (
CONDITION_ERA_ID LONG,
PERSON_ID LONG,
CONDITION_CONCEPT_ID LONG,
CONDITION_ERA_START_DATE DATE,
CONDITION_ERA_END_DATE DATE,
CONDITION_OCCURRENCE_COUNT LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### Drug_era
-- COMMAND ----------
CREATE
OR REPLACE TABLE DRUG_ERA (
DRUG_ERA_ID LONG,
PERSON_ID LONG,
DRUG_CONCEPT_ID LONG,
DRUG_ERA_START_DATE DATE,
DRUG_ERA_END_DATE DATE,
DRUG_EXPOSURE_COUNT LONG,
GAP_DAYS LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### Dose_era
-- COMMAND ----------
CREATE
OR REPLACE TABLE DOSE_ERA (
DOSE_ERA_ID LONG,
PERSON_ID LONG,
DRUG_CONCEPT_ID LONG,
UNIT_CONCEPT_ID LONG,
DOSE_VALUE DOUBLE,
DOSE_ERA_START_DATE DATE,
DOSE_ERA_END_DATE DATE
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC #### Results schema
-- COMMAND ----------
-- MAGIC %md
-- MAGIC sql(f"DROP DATABASE IF EXISTS {omop_version}Results CASCADE;")
-- MAGIC sql(f"CREATE DATABASE IF NOT EXISTS {omop_version}Results LOCATION '{delta_path}'")
-- MAGIC sql(f"USE {omop_version}Results;")
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ##### cohort
-- COMMAND ----------
CREATE
OR REPLACE TABLE cohort (
cohort_definition_id LONG,
subject_id LONG,
cohort_start_date DATE,
cohort_end_date DATE
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ##### Cohort_definition
-- COMMAND ----------
CREATE
OR REPLACE TABLE cohort_definition (
cohort_definition_id LONG,
cohort_definition_name STRING,
cohort_definition_description STRING,
definition_type_concept_id LONG,
cohort_definition_syntax STRING,
subject_concept_id LONG,
cohort_initiation_date DATE
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ##### COHORT_ATTRIBUTE
-- COMMAND ----------
CREATE
OR REPLACE TABLE COHORT_ATTRIBUTE (
COHORT_DEFINITION_ID LONG,
SUBJECT_ID LONG,
COHORT_START_DATE DATE,
COHORT_END_DATE DATE,
ATTRIBUTE_DEFINITION_ID LONG,
VALUE_AS_NUMBER DOUBLE,
VALUE_AS_CONCEPT_ID LONG
) USING DELTA;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ## Check OMOP 5.3.1 Metadata Version
-- COMMAND ----------
INSERT INTO METADATA
VALUES
(
0,
0,
'OHDSI OMOP CDM Version',
'5.3.1',
0,
CURRENT_DATE(),
CURRENT_TIMESTAMP()
);
-- COMMAND ----------
SELECT
metadata_concept_id,
metadata_type_concept_id,
name,
value_as_string,
value_as_concept_id,
metadata_date,
metadata_datetime
FROM
metadata;
-- COMMAND ----------
-- MAGIC %md
-- MAGIC ### Update Metadata
-- COMMAND ----------
-- MAGIC %md
-- MAGIC Copyright / License info of the notebook. Copyright Databricks, Inc. [2021]. The source in this notebook is provided subject to the [Databricks License](https://databricks.com/db-license-source). All included or referenced third party libraries are subject to the licenses set forth below.
-- MAGIC
-- MAGIC |Library Name|Library License|Library License URL|Library Source URL|
-- MAGIC | :-: | :-:| :-: | :-:|
-- MAGIC |Smolder |Apache-2.0 License| https://github.com/databrickslabs/smolder | https://github.com/databrickslabs/smolder/blob/master/LICENSE|
-- MAGIC |Synthea|Apache License 2.0|https://github.com/synthetichealth/synthea/blob/master/LICENSE| https://github.com/synthetichealth/synthea|
-- MAGIC | OHDSI/CommonDataModel| Apache License 2.0 | https://github.com/OHDSI/CommonDataModel/blob/master/LICENSE | https://github.com/OHDSI/CommonDataModel |
-- MAGIC | OHDSI/ETL-Synthea| Apache License 2.0 | https://github.com/OHDSI/ETL-Synthea/blob/master/LICENSE | https://github.com/OHDSI/ETL-Synthea |
-- MAGIC |OHDSI/OMOP-Queries|||https://github.com/OHDSI/OMOP-Queries|
-- MAGIC |The Book of OHDSI | Creative Commons Zero v1.0 Universal license.|https://ohdsi.github.io/TheBookOfOhdsi/index.html#license|https://ohdsi.github.io/TheBookOfOhdsi/|