-
Notifications
You must be signed in to change notification settings - Fork 0
/
OMOP_5_4_declarative.py
1971 lines (1821 loc) · 245 KB
/
OMOP_5_4_declarative.py
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
993
994
995
996
997
998
999
1000
from typing import List, Optional
from sqlalchemy import Date, DateTime, ForeignKeyConstraint, Index, Integer, Numeric, PrimaryKeyConstraint, String, Text
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
import datetime
import decimal
class Base(DeclarativeBase):
pass
class Cohort(Base):
__tablename__ = 'cohort'
__table_args__ = (
{'comment': 'DESC: The COHORT table contains records of subjects that satisfy '
'a given set of criteria for a duration of time. The definition of '
'the cohort is contained within the COHORT_DEFINITION table. It is '
'listed as part of the RESULTS schema because it is a table that '
'users of the database as well as tools such as ATLAS need to be '
'able to write to. The CDM and Vocabulary tables are all read-only '
'so it is suggested that the COHORT and COHORT_DEFINTION tables '
'are kept in a separate schema to alleviate confusion. | ETL '
'CONVENTIONS: Cohorts typically include patients diagnosed with a '
'specific condition, patients exposed to a particular drug, but '
'can also be Providers who have performed a specific Procedure. '
'Cohort records must have a Start Date and an End Date, but the '
'End Date may be set to Start Date or could have an applied censor '
'date using the Observation Period Start Date. Cohort records must '
'contain a Subject Id, which can refer to the Person, Provider, '
'Visit record or Care Site though they are most often Person Ids. '
'The Cohort Definition will define the type of subject through the '
'subject concept id. A subject can belong (or not belong) to a '
'cohort at any moment in time. A subject can only have one record '
'in the cohort table for any moment of time, i.e. it is not '
'possible for a person to contain multiple records indicating '
'cohort membership that are overlapping in time'}
)
__mapper_args__ = {"primary_key": ['cohort_definition_id', 'subject_id', 'cohort_start_date', 'cohort_end_date']}
cohort_definition_id: Mapped[int] = mapped_column(Integer, )
subject_id: Mapped[int] = mapped_column(Integer, )
cohort_start_date: Mapped[datetime.date] = mapped_column(Date, )
cohort_end_date: Mapped[datetime.date] = mapped_column(Date, )
class Concept(Base):
__tablename__ = 'concept'
__table_args__ = (
ForeignKeyConstraint(['concept_class_id'], ['concept_class.concept_class_id'], name='fpk_concept_concept_class_id'),
ForeignKeyConstraint(['domain_id'], ['domain.domain_id'], name='fpk_concept_domain_id'),
ForeignKeyConstraint(['vocabulary_id'], ['vocabulary.vocabulary_id'], name='fpk_concept_vocabulary_id'),
PrimaryKeyConstraint('concept_id', name='xpk_concept'),
Index('idx_concept_class_id', 'concept_class_id'),
Index('idx_concept_code', 'concept_code'),
Index('idx_concept_concept_id', 'concept_id'),
Index('idx_concept_domain_id', 'domain_id'),
Index('idx_concept_vocabluary_id', 'vocabulary_id'),
{'comment': 'DESC: The Standardized Vocabularies contains records, or '
'Concepts, that uniquely identify each fundamental unit of meaning '
'used to express clinical information in all domain tables of the '
'CDM. Concepts are derived from vocabularies, which represent '
'clinical information across a domain (e.g. conditions, drugs, '
'procedures) through the use of codes and associated descriptions. '
'Some Concepts are designated Standard Concepts, meaning these '
'Concepts can be used as normative expressions of a clinical '
'entity within the OMOP Common Data Model and within standardized '
'analytics. Each Standard Concept belongs to one domain, which '
'defines the location where the Concept would be expected to occur '
'within data tables of the CDM.\n'
'\n'
'Concepts can represent broad categories (like "Cardiovascular '
'disease"), detailed clinical elements ("Myocardial infarction of '
'the anterolateral wall") or modifying characteristics and '
'attributes that define Concepts at various levels of detail '
'(severity of a disease, associated morphology, etc.).\n'
'\n'
'Records in the Standardized Vocabularies tables are derived from '
'national or international vocabularies such as SNOMED-CT, RxNorm, '
'and LOINC, or custom Concepts defined to cover various aspects of '
'observational data analysis. '}
)
concept_id: Mapped[int] = mapped_column(Integer, primary_key=True, comment='USER GUIDANCE: A unique identifier for each Concept across all domains.')
concept_name: Mapped[str] = mapped_column(String(255), comment='USER GUIDANCE: An unambiguous, meaningful and descriptive name for the Concept.')
domain_id: Mapped[str] = mapped_column(String(20), comment='USER GUIDANCE: A foreign key to the [DOMAIN](https://ohdsi.github.io/CommonDataModel/cdm531.html#domain) table the Concept belongs to.')
vocabulary_id: Mapped[str] = mapped_column(String(20), comment='USER GUIDANCE: A foreign key to the [VOCABULARY](https://ohdsi.github.io/CommonDataModel/cdm531.html#vocabulary)\ntable indicating from which source the\nConcept has been adapted.')
concept_class_id: Mapped[str] = mapped_column(String(20), comment='USER GUIDANCE: The attribute or concept class of the\nConcept. Examples are "Clinical Drug",\n"Ingredient", "Clinical Finding" etc.')
concept_code: Mapped[str] = mapped_column(String(50), comment='USER GUIDANCE: The concept code represents the identifier\nof the Concept in the source vocabulary,\nsuch as SNOMED-CT concept IDs,\nRxNorm RXCUIs etc. Note that concept\ncodes are not unique across vocabularies.')
valid_start_date: Mapped[datetime.date] = mapped_column(Date, comment='USER GUIDANCE: The date when the Concept was first\nrecorded. The default value is\n1-Jan-1970, meaning, the Concept has no\n(known) date of inception.')
valid_end_date: Mapped[datetime.date] = mapped_column(Date, comment='USER GUIDANCE: The date when the Concept became\ninvalid because it was deleted or\nsuperseded (updated) by a new concept.\nThe default value is 31-Dec-2099,\nmeaning, the Concept is valid until it\nbecomes deprecated.')
standard_concept: Mapped[Optional[str]] = mapped_column(String(1), comment='USER GUIDANCE: This flag determines where a Concept is\na Standard Concept, i.e. is used in the\ndata, a Classification Concept, or a\nnon-standard Source Concept. The\nallowable values are "S" (Standard\nConcept) and "C" (Classification\nConcept), otherwise the content is NULL.')
invalid_reason: Mapped[Optional[str]] = mapped_column(String(1), comment='USER GUIDANCE: Reason the Concept was invalidated.\nPossible values are D (deleted), U\n(replaced with an update) or NULL when\nvalid_end_date has the default value.')
concept_class: Mapped['ConceptClass'] = relationship('ConceptClass', foreign_keys=[concept_class_id], back_populates='concept')
domain: Mapped['Domain'] = relationship('Domain', foreign_keys=[domain_id], back_populates='concept')
vocabulary: Mapped['Vocabulary'] = relationship('Vocabulary', foreign_keys=[vocabulary_id], back_populates='concept')
concept_classes: Mapped[List['ConceptClass']] = relationship('ConceptClass', foreign_keys='[ConceptClass.concept_class_concept_id]', back_populates='concept_class_concept')
class ConceptClass(Base):
__tablename__ = 'concept_class'
__table_args__ = (
ForeignKeyConstraint(['concept_class_concept_id'], ['concept.concept_id'], name='fpk_concept_class_concept_class_concept_id'),
PrimaryKeyConstraint('concept_class_id', name='xpk_concept_class'),
Index('idx_concept_class_class_id', 'concept_class_id'),
{'comment': 'DESC: The CONCEPT_CLASS table is a reference table, which '
'includes a list of the classifications used to differentiate '
'Concepts within a given Vocabulary. This reference table is '
'populated with a single record for each Concept Class.'}
)
concept_class_id: Mapped[str] = mapped_column(String(20), primary_key=True, comment='USER GUIDANCE: A unique key for each class.')
concept_class_name: Mapped[str] = mapped_column(String(255), comment='USER GUIDANCE: The name describing the Concept Class, e.g.\nClinical Finding, Ingredient, etc.')
concept_class_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: A Concept that represents the Concept Class.')
concepts: Mapped[List['Concept']] = relationship('Concept', foreign_keys='[Concept.concept_class_id]', back_populates='concept_class')
concept_class_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[concept_class_concept_id])
class Domain(Base):
__tablename__ = 'domain'
__table_args__ = (
ForeignKeyConstraint(['domain_concept_id'], ['concept.concept_id'], name='fpk_domain_domain_concept_id'),
PrimaryKeyConstraint('domain_id', name='xpk_domain'),
Index('idx_domain_domain_id', 'domain_id'),
{'comment': 'DESC: The DOMAIN table includes a list of OMOP-defined Domains '
'the Concepts of the Standardized Vocabularies can belong to. A '
'Domain defines the set of allowable Concepts for the standardized '
'fields in the CDM tables. For example, the "Condition" Domain '
'contains Concepts that describe a condition of a patient, and '
'these Concepts can only be stored in the condition_concept_id '
'field of the CONDITION_OCCURRENCE and CONDITION_ERA tables. This '
'reference table is populated with a single record for each Domain '
'and includes a descriptive name for the Domain.'}
)
domain_id: Mapped[str] = mapped_column(String(20), primary_key=True, comment='USER GUIDANCE: A unique key for each domain.')
domain_name: Mapped[str] = mapped_column(String(255), comment='USER GUIDANCE: The name describing the Domain, e.g.\nCondition, Procedure, Measurement\netc.')
domain_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: A Concept representing the Domain Concept the DOMAIN record belongs to.')
concept: Mapped[List['Concept']] = relationship('Concept', foreign_keys='[Concept.domain_id]', back_populates='domain')
domain_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[domain_concept_id])
cost: Mapped[List['Cost']] = relationship('Cost', back_populates='cost_domain')
class Vocabulary(Base):
__tablename__ = 'vocabulary'
__table_args__ = (
ForeignKeyConstraint(['vocabulary_concept_id'], ['concept.concept_id'], name='fpk_vocabulary_vocabulary_concept_id'),
PrimaryKeyConstraint('vocabulary_id', name='xpk_vocabulary'),
Index('idx_vocabulary_vocabulary_id', 'vocabulary_id'),
{'comment': 'DESC: The VOCABULARY table includes a list of the Vocabularies '
'collected from various sources or created de novo by the OMOP '
'community. This reference table is populated with a single record '
'for each Vocabulary source and includes a descriptive name and '
'other associated attributes for the Vocabulary.'}
)
vocabulary_id: Mapped[str] = mapped_column(String(20), primary_key=True, comment='USER GUIDANCE: A unique identifier for each Vocabulary, such\nas ICD9CM, SNOMED, Visit.')
vocabulary_name: Mapped[str] = mapped_column(String(255), comment='USER GUIDANCE: The name describing the vocabulary, for\nexample, International Classification of\nDiseases, Ninth Revision, Clinical\nModification, Volume 1 and 2 (NCHS) etc.')
vocabulary_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: A Concept that represents the Vocabulary the VOCABULARY record belongs to.')
vocabulary_reference: Mapped[Optional[str]] = mapped_column(String(255), comment='USER GUIDANCE: External reference to documentation or\navailable download of the about the\nvocabulary.')
vocabulary_version: Mapped[Optional[str]] = mapped_column(String(255), comment='USER GUIDANCE: Version of the Vocabulary as indicated in\nthe source.')
concept: Mapped[List['Concept']] = relationship('Concept', foreign_keys='[Concept.vocabulary_id]', back_populates='vocabulary')
vocabulary_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[vocabulary_concept_id])
source_to_concept_map: Mapped[List['SourceToConceptMap']] = relationship('SourceToConceptMap', back_populates='target_vocabulary')
class CdmSource(Base):
__tablename__ = 'cdm_source'
__table_args__ = (
ForeignKeyConstraint(['cdm_version_concept_id'], ['concept.concept_id'], name='fpk_cdm_source_cdm_version_concept_id'),
{'comment': 'DESC: The CDM_SOURCE table contains detail about the source '
'database and the process used to transform the data into the OMOP '
'Common Data Model.'}
)
__mapper_args__ = {"primary_key": ['cdm_source_abbreviation', 'cdm_holder', 'cdm_version_concept_id', 'vocabulary_version']}
cdm_source_name: Mapped[str] = mapped_column(String(255), comment='USER GUIDANCE: The name of the CDM instance.')
cdm_source_abbreviation: Mapped[str] = mapped_column(String(25), comment='USER GUIDANCE: The abbreviation of the CDM instance.')
cdm_holder: Mapped[str] = mapped_column(String(255), comment='USER GUIDANCE: The holder of the CDM instance.')
source_release_date: Mapped[datetime.date] = mapped_column(Date, comment='USER GUIDANCE: The release date of the source data.')
cdm_release_date: Mapped[datetime.date] = mapped_column(Date, comment='USER GUIDANCE: The release data of the CDM instance.')
cdm_version_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: The Concept Id representing the version of the CDM. | ETLCONVENTIONS: You can find all concepts that represent the CDM versions using the query: SELECT * FROM CONCEPT WHERE VOCABULARY_ID = "CDM" AND CONCEPT_CLASS = "CDM"')
vocabulary_version: Mapped[str] = mapped_column(String(20), comment=' | ETLCONVENTIONS: You can find the version of your Vocabulary using the query: SELECT vocabulary_version from vocabulary where vocabulary_id = "None"')
source_description: Mapped[Optional[str]] = mapped_column(Text, comment='USER GUIDANCE: The description of the CDM instance.')
source_documentation_reference: Mapped[Optional[str]] = mapped_column(String(255))
cdm_etl_reference: Mapped[Optional[str]] = mapped_column(String(255), comment=' | ETLCONVENTIONS: Put the link to the CDM version used.')
cdm_version: Mapped[Optional[str]] = mapped_column(String(10))
cdm_version_concept: Mapped['Concept'] = relationship('Concept')
class CohortDefinition(Base):
__tablename__ = 'cohort_definition'
__table_args__ = (
ForeignKeyConstraint(['definition_type_concept_id'], ['concept.concept_id'], name='fpk_cohort_definition_definition_type_concept_id'),
ForeignKeyConstraint(['subject_concept_id'], ['concept.concept_id'], name='fpk_cohort_definition_subject_concept_id'),
{'comment': 'DESC: The COHORT_DEFINITION table contains records defining a '
'Cohort derived from the data through the associated description '
'and syntax and upon instantiation (execution of the algorithm) '
'placed into the COHORT table. Cohorts are a set of subjects that '
'satisfy a given combination of inclusion criteria for a duration '
'of time. The COHORT_DEFINITION table provides a standardized '
'structure for maintaining the rules governing the inclusion of a '
'subject into a cohort, and can store operational programming code '
'to instantiate the cohort within the OMOP Common Data Model.'}
)
__mapper_args__ = {"primary_key": ['cohort_definition_id', 'definition_type_concept_id', 'subject_concept_id']}
cohort_definition_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: This is the identifier given to the cohort, usually by the ATLAS application')
cohort_definition_name: Mapped[str] = mapped_column(String(255), comment='USER GUIDANCE: A short description of the cohort')
definition_type_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: Type defining what kind of Cohort Definition the record represents and how the syntax may be executed.')
subject_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: This field contains a Concept that represents the domain of the subjects that are members of the cohort (e.g., Person, Provider, Visit).')
cohort_definition_description: Mapped[Optional[str]] = mapped_column(Text, comment='USER GUIDANCE: A complete description of the cohort.')
cohort_definition_syntax: Mapped[Optional[str]] = mapped_column(Text, comment='USER GUIDANCE: Syntax or code to operationalize the Cohort Definition.')
cohort_initiation_date: Mapped[Optional[datetime.date]] = mapped_column(Date, comment='USER GUIDANCE: A date to indicate when the Cohort was initiated in the COHORT table.')
definition_type_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[definition_type_concept_id])
subject_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[subject_concept_id])
class ConceptAncestor(Base):
__tablename__ = 'concept_ancestor'
__table_args__ = (
ForeignKeyConstraint(['ancestor_concept_id'], ['concept.concept_id'], name='fpk_concept_ancestor_ancestor_concept_id'),
ForeignKeyConstraint(['descendant_concept_id'], ['concept.concept_id'], name='fpk_concept_ancestor_descendant_concept_id'),
Index('idx_concept_ancestor_id_1', 'ancestor_concept_id'),
Index('idx_concept_ancestor_id_2', 'descendant_concept_id'),
{'comment': 'DESC: The CONCEPT_ANCESTOR table is designed to simplify '
'observational analysis by providing the complete hierarchical '
'relationships between Concepts. Only direct parent-child '
'relationships between Concepts are stored in the '
'CONCEPT_RELATIONSHIP table. To determine higher level ancestry '
'connections, all individual direct relationships would have to be '
'navigated at analysis time. The CONCEPT_ANCESTOR table includes '
'records for all parent-child relationships, as well as '
'grandparent-grandchild relationships and those of any other level '
'of lineage. Using the CONCEPT_ANCESTOR table allows for querying '
'for all descendants of a hierarchical concept. For example, drug '
'ingredients and drug products are all descendants of a drug class '
'ancestor.\n'
'\n'
'This table is entirely derived from the CONCEPT, '
'CONCEPT_RELATIONSHIP and RELATIONSHIP tables.'}
)
__mapper_args__ = {"primary_key": ['ancestor_concept_id', 'descendant_concept_id', 'min_levels_of_separation', 'max_levels_of_separation']}
ancestor_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: The Concept Id for the higher-level concept\nthat forms the ancestor in the relationship.')
descendant_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: The Concept Id for the lower-level concept\nthat forms the descendant in the\nrelationship.')
min_levels_of_separation: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: The minimum separation in number of\nlevels of hierarchy between ancestor and\ndescendant concepts. This is an attribute\nthat is used to simplify hierarchic analysis.')
max_levels_of_separation: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: The maximum separation in number of\nlevels of hierarchy between ancestor and\ndescendant concepts. This is an attribute\nthat is used to simplify hierarchic analysis.')
ancestor_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[ancestor_concept_id])
descendant_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[descendant_concept_id])
class ConceptSynonym(Base):
__tablename__ = 'concept_synonym'
__table_args__ = (
ForeignKeyConstraint(['concept_id'], ['concept.concept_id'], name='fpk_concept_synonym_concept_id'),
ForeignKeyConstraint(['language_concept_id'], ['concept.concept_id'], name='fpk_concept_synonym_language_concept_id'),
Index('idx_concept_synonym_id', 'concept_id'),
{'comment': 'DESC: The CONCEPT_SYNONYM table is used to store alternate names '
'and descriptions for Concepts.'}
)
__mapper_args__ = {"primary_key": ['concept_id', 'concept_synonym_name', 'language_concept_id']}
concept_id: Mapped[int] = mapped_column(Integer, )
concept_synonym_name: Mapped[str] = mapped_column(String(1000), )
language_concept_id: Mapped[int] = mapped_column(Integer, )
concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[concept_id])
language_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[language_concept_id])
class Cost(Base):
__tablename__ = 'cost'
__table_args__ = (
ForeignKeyConstraint(['cost_domain_id'], ['domain.domain_id'], name='fpk_cost_cost_domain_id'),
ForeignKeyConstraint(['cost_type_concept_id'], ['concept.concept_id'], name='fpk_cost_cost_type_concept_id'),
ForeignKeyConstraint(['currency_concept_id'], ['concept.concept_id'], name='fpk_cost_currency_concept_id'),
ForeignKeyConstraint(['drg_concept_id'], ['concept.concept_id'], name='fpk_cost_drg_concept_id'),
ForeignKeyConstraint(['revenue_code_concept_id'], ['concept.concept_id'], name='fpk_cost_revenue_code_concept_id'),
PrimaryKeyConstraint('cost_id', name='xpk_cost'),
Index('idx_cost_event_id', 'cost_event_id'),
{'comment': 'DESC: The COST table captures records containing the cost of any '
'medical event recorded in one of the OMOP clinical event tables '
'such as DRUG_EXPOSURE, PROCEDURE_OCCURRENCE, VISIT_OCCURRENCE, '
'VISIT_DETAIL, DEVICE_OCCURRENCE, OBSERVATION or MEASUREMENT.\n'
'\n'
'Each record in the cost table account for the amount of money '
'transacted for the clinical event. So, the COST table may be used '
'to represent both receivables (charges) and payments (paid), each '
'transaction type represented by its COST_CONCEPT_ID. The '
'COST_TYPE_CONCEPT_ID field will use concepts in the Standardized '
'Vocabularies to designate the source (provenance) of the cost '
'data. A reference to the health plan information in the '
'PAYER_PLAN_PERIOD table is stored in the record for information '
'used for the adjudication system to determine the persons benefit '
'for the clinical event. | USER GUIDANCE: When dealing with '
'summary costs, the cost of the goods or services the provider '
'provides is often not known directly, but derived from the '
'hospital charges multiplied by an average cost-to-charge ratio. | '
'ETL CONVENTIONS: One cost record is generated for each response '
'by a payer. In a claims databases, the payment and payment terms '
'reported by the payer for the goods or services billed will '
'generate one cost record. If the source data has payment '
'information for more than one payer (i.e. primary insurance and '
'secondary insurance payment for one entity), then a cost record '
'is created for each reporting payer. Therefore, it is possible '
'for one procedure to have multiple cost records for each payer, '
'but typically it contains one or no record per entity. Payer '
'reimbursement cost records will be identified by using the '
'PAYER_PLAN_ID field. Drug costs are composed of ingredient cost '
'(the amount charged by the wholesale distributor or '
'manufacturer), the dispensing fee (the amount charged by the '
'pharmacy and the sales tax).'}
)
cost_id: Mapped[int] = mapped_column(Integer, primary_key=True)
cost_event_id: Mapped[int] = mapped_column(Integer)
cost_domain_id: Mapped[str] = mapped_column(String(20))
cost_type_concept_id: Mapped[int] = mapped_column(Integer)
currency_concept_id: Mapped[Optional[int]] = mapped_column(Integer)
total_charge: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric)
total_cost: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric)
total_paid: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric)
paid_by_payer: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric)
paid_by_patient: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric)
paid_patient_copay: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric)
paid_patient_coinsurance: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric)
paid_patient_deductible: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric)
paid_by_primary: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric)
paid_ingredient_cost: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric)
paid_dispensing_fee: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric)
payer_plan_period_id: Mapped[Optional[int]] = mapped_column(Integer)
amount_allowed: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric)
revenue_code_concept_id: Mapped[Optional[int]] = mapped_column(Integer)
revenue_code_source_value: Mapped[Optional[str]] = mapped_column(String(50), comment='USER GUIDANCE: Revenue codes are a method to charge for a class of procedures and conditions in the U.S. hospital system.')
drg_concept_id: Mapped[Optional[int]] = mapped_column(Integer)
drg_source_value: Mapped[Optional[str]] = mapped_column(String(3), comment='USER GUIDANCE: Diagnosis Related Groups are US codes used to classify hospital cases into one of approximately 500 groups. ')
cost_domain: Mapped['Domain'] = relationship('Domain', back_populates='cost')
cost_type_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[cost_type_concept_id])
currency_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[currency_concept_id])
drg_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[drg_concept_id])
revenue_code_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[revenue_code_concept_id])
class DrugStrength(Base):
__tablename__ = 'drug_strength'
__table_args__ = (
ForeignKeyConstraint(['amount_unit_concept_id'], ['concept.concept_id'], name='fpk_drug_strength_amount_unit_concept_id'),
ForeignKeyConstraint(['denominator_unit_concept_id'], ['concept.concept_id'], name='fpk_drug_strength_denominator_unit_concept_id'),
ForeignKeyConstraint(['drug_concept_id'], ['concept.concept_id'], name='fpk_drug_strength_drug_concept_id'),
ForeignKeyConstraint(['ingredient_concept_id'], ['concept.concept_id'], name='fpk_drug_strength_ingredient_concept_id'),
ForeignKeyConstraint(['numerator_unit_concept_id'], ['concept.concept_id'], name='fpk_drug_strength_numerator_unit_concept_id'),
Index('idx_drug_strength_id_1', 'drug_concept_id'),
Index('idx_drug_strength_id_2', 'ingredient_concept_id'),
{'comment': 'DESC: The DRUG_STRENGTH table contains structured content about '
'the amount or concentration and associated units of a specific '
'ingredient contained within a particular drug product. This table '
'is supplemental information to support standardized analysis of '
'drug utilization.'}
)
__mapper_args__ = {"primary_key": ['drug_concept_id', 'ingredient_concept_id']}
drug_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: The Concept representing the Branded Drug or Clinical Drug Product.')
ingredient_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: The Concept representing the active ingredient contained within the drug product. | ETLCONVENTIONS: Combination Drugs will have more than one record in this table, one for each active Ingredient.')
valid_start_date: Mapped[datetime.date] = mapped_column(Date, comment='USER GUIDANCE: The date when the Concept was first\nrecorded. The default value is\n1-Jan-1970.')
valid_end_date: Mapped[datetime.date] = mapped_column(Date, comment='USER GUIDANCE: The date when then Concept became invalid.')
amount_value: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric, comment='USER GUIDANCE: The numeric value or the amount of active ingredient contained within the drug product.')
amount_unit_concept_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: The Concept representing the Unit of measure for the amount of active ingredient contained within the drug product. ')
numerator_value: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric, comment='USER GUIDANCE: The concentration of the active ingredient contained within the drug product.')
numerator_unit_concept_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: The Concept representing the Unit of measure for the concentration of active ingredient.')
denominator_value: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric, comment='USER GUIDANCE: The amount of total liquid (or other divisible product, such as ointment, gel, spray, etc.).')
denominator_unit_concept_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: The Concept representing the denominator unit for the concentration of active ingredient.')
box_size: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: The number of units of Clinical Branded Drug or Quantified Clinical or Branded Drug contained in a box as dispensed to the patient.')
invalid_reason: Mapped[Optional[str]] = mapped_column(String(1), comment='USER GUIDANCE: Reason the concept was invalidated. Possible values are D (deleted), U (replaced with an update) or NULL when valid_end_date has the default value.')
amount_unit_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[amount_unit_concept_id])
denominator_unit_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[denominator_unit_concept_id])
drug_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[drug_concept_id])
ingredient_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[ingredient_concept_id])
numerator_unit_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[numerator_unit_concept_id])
class FactRelationship(Base):
__tablename__ = 'fact_relationship'
__table_args__ = (
ForeignKeyConstraint(['domain_concept_id_1'], ['concept.concept_id'], name='fpk_fact_relationship_domain_concept_id_1'),
ForeignKeyConstraint(['domain_concept_id_2'], ['concept.concept_id'], name='fpk_fact_relationship_domain_concept_id_2'),
ForeignKeyConstraint(['relationship_concept_id'], ['concept.concept_id'], name='fpk_fact_relationship_relationship_concept_id'),
Index('idx_fact_relationship_id1', 'domain_concept_id_1'),
Index('idx_fact_relationship_id2', 'domain_concept_id_2'),
Index('idx_fact_relationship_id3', 'relationship_concept_id'),
{'comment': 'DESC: The FACT_RELATIONSHIP table contains records about the '
'relationships between facts stored as records in any table of the '
'CDM. Relationships can be defined between facts from the same '
'domain, or different domains. Examples of Fact Relationships '
'include: [Person '
'relationships](https://athena.ohdsi.org/search-terms/terms?domain=Relationship&standardConcept=Standard&page=2&pageSize=15&query=) '
'(parent-child), care site relationships (hierarchical '
'organizational structure of facilities within a health system), '
'indication relationship (between drug exposures and associated '
'conditions), usage relationships (of devices during the course of '
'an associated procedure), or facts derived from one another '
'(measurements derived from an associated specimen). | ETL '
'CONVENTIONS: All relationships are directional, and each '
'relationship is represented twice symmetrically within the '
'FACT_RELATIONSHIP table. For example, two persons if person_id = '
'1 is the mother of person_id = 2 two records are in the '
'FACT_RELATIONSHIP table (all strings in fact concept_id records '
'in the Concept table:\n'
'- Person, 1, Person, 2, parent of\n'
'- Person, 2, Person, 1, child of'}
)
__mapper_args__ = {"primary_key": ['domain_concept_id_1', 'fact_id_1', 'domain_concept_id_2', 'fact_id_2', 'relationship_concept_id']}
domain_concept_id_1: Mapped[int] = mapped_column(Integer, )
fact_id_1: Mapped[int] = mapped_column(Integer, )
domain_concept_id_2: Mapped[int] = mapped_column(Integer, )
fact_id_2: Mapped[int] = mapped_column(Integer, )
relationship_concept_id: Mapped[int] = mapped_column(Integer, )
domain_concept_1: Mapped['Concept'] = relationship('Concept', foreign_keys=[domain_concept_id_1])
domain_concept_2: Mapped['Concept'] = relationship('Concept', foreign_keys=[domain_concept_id_2])
relationship_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[relationship_concept_id])
class Location(Base):
__tablename__ = 'location'
__table_args__ = (
ForeignKeyConstraint(['country_concept_id'], ['concept.concept_id'], name='fpk_location_country_concept_id'),
PrimaryKeyConstraint('location_id', name='xpk_location'),
Index('idx_location_id_1', 'location_id'),
{'comment': 'DESC: The LOCATION table represents a generic way to capture '
'physical location or address information of Persons and Care '
'Sites. | USER GUIDANCE: The current iteration of the LOCATION '
'table is US centric. Until a major release to correct this, '
'certain fields can be used to represent different international '
'values. <br><br> - STATE can also be used for province or '
'district<br>- ZIP is also the postal code or postcode <br>- '
'COUNTY can also be used to represent region | ETL CONVENTIONS: '
'Each address or Location is unique and is present only once in '
'the table. Locations do not contain names, such as the name of a '
'hospital. In order to construct a full address that can be used '
'in the postal service, the address information from the Location '
'needs to be combined with information from the Care Site.'}
)
location_id: Mapped[int] = mapped_column(Integer, primary_key=True, comment='USER GUIDANCE: The unique key given to a unique Location. | ETLCONVENTIONS: Each instance of a Location in the source data should be assigned this unique key.')
address_1: Mapped[Optional[str]] = mapped_column(String(50), comment='USER GUIDANCE: This is the first line of the address.')
address_2: Mapped[Optional[str]] = mapped_column(String(50), comment='USER GUIDANCE: This is the second line of the address')
city: Mapped[Optional[str]] = mapped_column(String(50))
state: Mapped[Optional[str]] = mapped_column(String(2))
zip: Mapped[Optional[str]] = mapped_column(String(9), comment=' | ETLCONVENTIONS: Zip codes are handled as strings of up to 9 characters length. For US addresses, these represent either a 3-digit abbreviated Zip code as provided by many sources for patient protection reasons, the full 5-digit Zip or the 9-digit (ZIP + 4) codes. Unless for specific reasons analytical methods should expect and utilize only the first 3 digits. For international addresses, different rules apply.')
county: Mapped[Optional[str]] = mapped_column(String(20))
location_source_value: Mapped[Optional[str]] = mapped_column(String(50), comment=' | ETLCONVENTIONS: Put the verbatim value for the location here, as it shows up in the source. ')
country_concept_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: The Concept Id representing the country. Values should conform to the [Geography](https://athena.ohdsi.org/search-terms/terms?domain=Geography&standardConcept=Standard&page=1&pageSize=15&query=&boosts) domain. ')
country_source_value: Mapped[Optional[str]] = mapped_column(String(80), comment='USER GUIDANCE: The name of the country.')
latitude: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric, comment=' | ETLCONVENTIONS: Must be between -90 and 90.')
longitude: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric, comment=' | ETLCONVENTIONS: Must be between -180 and 180.')
country_concept: Mapped['Concept'] = relationship('Concept')
care_site: Mapped[List['CareSite']] = relationship('CareSite', back_populates='location')
person: Mapped[List['Person']] = relationship('Person', back_populates='location')
class Metadata(Base):
__tablename__ = 'metadata'
__table_args__ = (
ForeignKeyConstraint(['metadata_concept_id'], ['concept.concept_id'], name='fpk_metadata_metadata_concept_id'),
ForeignKeyConstraint(['metadata_type_concept_id'], ['concept.concept_id'], name='fpk_metadata_metadata_type_concept_id'),
ForeignKeyConstraint(['value_as_concept_id'], ['concept.concept_id'], name='fpk_metadata_value_as_concept_id'),
PrimaryKeyConstraint('metadata_id', name='xpk_metadata'),
Index('idx_metadata_concept_id_1', 'metadata_concept_id'),
{'comment': 'DESC: The METADATA table contains metadata information about a '
'dataset that has been transformed to the OMOP Common Data Model.'}
)
metadata_id: Mapped[int] = mapped_column(Integer, primary_key=True, comment='USER GUIDANCE: The unique key given to a Metadata record. | ETLCONVENTIONS: Attribute value is auto-generated')
metadata_concept_id: Mapped[int] = mapped_column(Integer)
metadata_type_concept_id: Mapped[int] = mapped_column(Integer)
name: Mapped[str] = mapped_column(String(250))
value_as_string: Mapped[Optional[str]] = mapped_column(String(250))
value_as_concept_id: Mapped[Optional[int]] = mapped_column(Integer)
value_as_number: Mapped[Optional[decimal.Decimal]] = mapped_column(Numeric, comment='USER GUIDANCE: This is the numerical value of the result of the Metadata, if applicable and available. It is not expected that all Metadata will have numeric results, rather, this field is here to house values should they exist. ')
metadata_date: Mapped[Optional[datetime.date]] = mapped_column(Date)
metadata_datetime: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime)
metadata_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[metadata_concept_id])
metadata_type_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[metadata_type_concept_id])
value_as_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[value_as_concept_id])
class NoteNlp(Base):
__tablename__ = 'note_nlp'
__table_args__ = (
ForeignKeyConstraint(['note_nlp_concept_id'], ['concept.concept_id'], name='fpk_note_nlp_note_nlp_concept_id'),
ForeignKeyConstraint(['note_nlp_source_concept_id'], ['concept.concept_id'], name='fpk_note_nlp_note_nlp_source_concept_id'),
ForeignKeyConstraint(['section_concept_id'], ['concept.concept_id'], name='fpk_note_nlp_section_concept_id'),
PrimaryKeyConstraint('note_nlp_id', name='xpk_note_nlp'),
Index('idx_note_nlp_concept_id_1', 'note_nlp_concept_id'),
Index('idx_note_nlp_note_id_1', 'note_id'),
{'comment': 'DESC: The NOTE_NLP table encodes all output of NLP on clinical '
'notes. Each row represents a single extracted term from a note.'}
)
note_nlp_id: Mapped[int] = mapped_column(Integer, primary_key=True, comment='USER GUIDANCE: A unique identifier for the NLP record.')
note_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: This is the NOTE_ID for the NOTE record the NLP record is associated to.')
lexical_variant: Mapped[str] = mapped_column(String(250), comment='USER GUIDANCE: Raw text extracted from the NLP tool.')
nlp_date: Mapped[datetime.date] = mapped_column(Date, comment='USER GUIDANCE: The date of the note processing.')
section_concept_id: Mapped[Optional[int]] = mapped_column(Integer, comment=' | ETLCONVENTIONS: The SECTION_CONCEPT_ID should be used to represent the note section contained in the NOTE_NLP record. These concepts can be found as parts of document panels and are based on the type of note written, i.e. a discharge summary. These panels can be found as concepts with the relationship "Subsumes" to CONCEPT_ID [45875957](https://athena.ohdsi.org/search-terms/terms/45875957).')
snippet: Mapped[Optional[str]] = mapped_column(String(250), comment='USER GUIDANCE: A small window of text surrounding the term')
offset: Mapped[Optional[str]] = mapped_column(String(50), comment='USER GUIDANCE: Character offset of the extracted term in the input note')
note_nlp_concept_id: Mapped[Optional[int]] = mapped_column(Integer)
note_nlp_source_concept_id: Mapped[Optional[int]] = mapped_column(Integer)
nlp_system: Mapped[Optional[str]] = mapped_column(String(250), comment=' | ETLCONVENTIONS: Name and version of the NLP system that extracted the term. Useful for data provenance.')
nlp_datetime: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment='USER GUIDANCE: The date and time of the note processing.')
term_exists: Mapped[Optional[str]] = mapped_column(String(1), comment=' | ETLCONVENTIONS: Term_exists is defined as a flag that indicates if the patient actually has or had the condition. Any of the following modifiers would make Term_exists false:\nNegation = true\nSubject = [anything other than the patient]\nConditional = true/li>\nRule_out = true\nUncertain = very low certainty or any lower certainties\nA complete lack of modifiers would make Term_exists true.\n')
term_temporal: Mapped[Optional[str]] = mapped_column(String(50), comment=' | ETLCONVENTIONS: Term_temporal is to indicate if a condition is present or just in the past. The following would be past:<br><br>\n- History = true\n- Concept_date = anything before the time of the report')
term_modifiers: Mapped[Optional[str]] = mapped_column(String(2000), comment=' | ETLCONVENTIONS: For the modifiers that are there, they would have to have these values:<br><br>\n- Negation = false\n- Subject = patient\n- Conditional = false\n- Rule_out = false\n- Uncertain = true or high or moderate or even low (could argue about low). Term_modifiers will concatenate all modifiers for different types of entities (conditions, drugs, labs etc) into one string. Lab values will be saved as one of the modifiers. ')
note_nlp_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[note_nlp_concept_id])
note_nlp_source_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[note_nlp_source_concept_id])
section_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[section_concept_id])
class Relationship(Base):
__tablename__ = 'relationship'
__table_args__ = (
ForeignKeyConstraint(['relationship_concept_id'], ['concept.concept_id'], name='fpk_relationship_relationship_concept_id'),
PrimaryKeyConstraint('relationship_id', name='xpk_relationship'),
Index('idx_relationship_rel_id', 'relationship_id'),
{'comment': 'DESC: The RELATIONSHIP table provides a reference list of all '
'types of relationships that can be used to associate any two '
'concepts in the CONCEPT_RELATIONSHP table.'}
)
relationship_id: Mapped[str] = mapped_column(String(20), primary_key=True, comment='USER GUIDANCE: The type of relationship captured by the\nrelationship record.')
relationship_name: Mapped[str] = mapped_column(String(255))
is_hierarchical: Mapped[str] = mapped_column(String(1), comment='USER GUIDANCE: Defines whether a relationship defines\nconcepts into classes or hierarchies. Values\nare 1 for hierarchical relationship or 0 if not.')
defines_ancestry: Mapped[str] = mapped_column(String(1), comment='USER GUIDANCE: Defines whether a hierarchical relationship\ncontributes to the concept_ancestor table.\nThese are subsets of the hierarchical\nrelationships. Valid values are 1 or 0.')
reverse_relationship_id: Mapped[str] = mapped_column(String(20), comment='USER GUIDANCE: The identifier for the relationship used to\ndefine the reverse relationship between two\nconcepts.')
relationship_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: A foreign key that refers to an identifier in\nthe [CONCEPT](https://ohdsi.github.io/CommonDataModel/cdm531.html#concept) table for the unique\nrelationship concept.')
relationship_concept: Mapped['Concept'] = relationship('Concept')
concept_relationship: Mapped[List['ConceptRelationship']] = relationship('ConceptRelationship', back_populates='relationship_')
class SourceToConceptMap(Base):
__tablename__ = 'source_to_concept_map'
__table_args__ = (
ForeignKeyConstraint(['source_concept_id'], ['concept.concept_id'], name='fpk_source_to_concept_map_source_concept_id'),
ForeignKeyConstraint(['target_concept_id'], ['concept.concept_id'], name='fpk_source_to_concept_map_target_concept_id'),
ForeignKeyConstraint(['target_vocabulary_id'], ['vocabulary.vocabulary_id'], name='fpk_source_to_concept_map_target_vocabulary_id'),
Index('idx_source_to_concept_map_1', 'source_vocabulary_id'),
Index('idx_source_to_concept_map_2', 'target_vocabulary_id'),
Index('idx_source_to_concept_map_3', 'target_concept_id'),
Index('idx_source_to_concept_map_c', 'source_code'),
{'comment': 'DESC: The source to concept map table is a legacy data structure '
'within the OMOP Common Data Model, recommended for use in ETL '
'processes to maintain local source codes which are not available '
'as Concepts in the Standardized Vocabularies, and to establish '
'mappings for each source code into a Standard Concept as '
'target_concept_ids that can be used to populate the Common Data '
'Model tables. The SOURCE_TO_CONCEPT_MAP table is no longer '
'populated with content within the Standardized Vocabularies '
'published to the OMOP community.'}
)
__mapper_args__ = {"primary_key": ['source_code', 'source_concept_id', 'source_vocabulary_id', 'target_concept_id', 'target_vocabulary_id', 'valid_start_date', 'valid_end_date']}
source_code: Mapped[str] = mapped_column(String(50), comment='USER GUIDANCE: The source code being translated\ninto a Standard Concept.')
source_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: A foreign key to the Source\nConcept that is being translated\ninto a Standard Concept. | ETLCONVENTIONS: This is either 0 or should be a number above 2 billion, which are the Concepts reserved for site-specific codes and mappings. ')
source_vocabulary_id: Mapped[str] = mapped_column(String(20), comment='USER GUIDANCE: A foreign key to the\nVOCABULARY table defining the\nvocabulary of the source code that\nis being translated to a Standard\nConcept.')
target_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: The target Concept\nto which the source code is being\nmapped.')
target_vocabulary_id: Mapped[str] = mapped_column(String(20), comment='USER GUIDANCE: The Vocabulary of the target Concept.')
valid_start_date: Mapped[datetime.date] = mapped_column(Date, comment='USER GUIDANCE: The date when the mapping\ninstance was first recorded.')
valid_end_date: Mapped[datetime.date] = mapped_column(Date, comment='USER GUIDANCE: The date when the mapping\ninstance became invalid because it\nwas deleted or superseded\n(updated) by a new relationship.\nDefault value is 31-Dec-2099.')
source_code_description: Mapped[Optional[str]] = mapped_column(String(255), comment='USER GUIDANCE: An optional description for the\nsource code. This is included as a\nconvenience to compare the\ndescription of the source code to\nthe name of the concept.')
invalid_reason: Mapped[Optional[str]] = mapped_column(String(1), comment='USER GUIDANCE: Reason the mapping instance was invalidated. Possible values are D (deleted), U (replaced with an update) or NULL when valid_end_date has the default value.')
source_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[source_concept_id])
target_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[target_concept_id])
target_vocabulary: Mapped['Vocabulary'] = relationship('Vocabulary', back_populates='source_to_concept_map')
class CareSite(Base):
__tablename__ = 'care_site'
__table_args__ = (
ForeignKeyConstraint(['location_id'], ['location.location_id'], name='fpk_care_site_location_id'),
ForeignKeyConstraint(['place_of_service_concept_id'], ['concept.concept_id'], name='fpk_care_site_place_of_service_concept_id'),
PrimaryKeyConstraint('care_site_id', name='xpk_care_site'),
Index('idx_care_site_id_1', 'care_site_id'),
{'comment': 'DESC: The CARE_SITE table contains a list of uniquely identified '
'institutional (physical or organizational) units where healthcare '
'delivery is practiced (offices, wards, hospitals, clinics, etc.). '
'| ETL CONVENTIONS: Care site is a unique combination of '
'location_id and place_of_service_source_value. Care site does not '
'take into account the provider (human) information such a '
'specialty. Many source data do not make a distinction between '
'individual and institutional providers. The CARE_SITE table '
'contains the institutional providers. If the source, instead of '
'uniquely identifying individual Care Sites, only provides limited '
'information such as Place of Service, generic or "pooled" Care '
'Site records are listed in the CARE_SITE table. There can be '
'hierarchical and business relationships between Care Sites. For '
'example, wards can belong to clinics or departments, which can in '
'turn belong to hospitals, which in turn can belong to hospital '
'systems, which in turn can belong to HMOs.The relationships '
'between Care Sites are defined in the FACT_RELATIONSHIP table.'}
)
care_site_id: Mapped[int] = mapped_column(Integer, primary_key=True, comment=' | ETLCONVENTIONS: Assign an ID to each combination of a location and nature of the site - the latter could be the Place of Service, name or another characteristic in your source data.')
care_site_name: Mapped[Optional[str]] = mapped_column(String(255), comment='USER GUIDANCE: The name of the care_site as it appears in the source data')
place_of_service_concept_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: This is a high-level way of characterizing a Care Site. Typically, however, Care Sites can provide care in multiple settings (inpatient, outpatient, etc.) and this granularity should be reflected in the visit. | ETLCONVENTIONS: Choose the concept in the visit domain that best represents the setting in which healthcare is provided in the Care Site. If most visits in a Care Site are Inpatient, then the place_of_service_concept_id should represent Inpatient. If information is present about a unique Care Site (e.g. Pharmacy) then a Care Site record should be created. [Accepted Concepts](https://athena.ohdsi.org/search-terms/terms?domain=Visit&standardConcept=Standard&page=2&pageSize=15&query=).')
location_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: The location_id from the LOCATION table representing the physical location of the care_site.')
care_site_source_value: Mapped[Optional[str]] = mapped_column(String(50), comment='USER GUIDANCE: The identifier of the care_site as it appears in the source data. This could be an identifier separate from the name of the care_site.')
place_of_service_source_value: Mapped[Optional[str]] = mapped_column(String(50), comment=' | ETLCONVENTIONS: Put the place of service of the care_site as it appears in the source data.')
location: Mapped['Location'] = relationship('Location', back_populates='care_site')
place_of_service_concept: Mapped['Concept'] = relationship('Concept')
provider: Mapped[List['Provider']] = relationship('Provider', back_populates='care_site')
person: Mapped[List['Person']] = relationship('Person', back_populates='care_site')
visit_occurrence: Mapped[List['VisitOccurrence']] = relationship('VisitOccurrence', back_populates='care_site')
visit_detail: Mapped[List['VisitDetail']] = relationship('VisitDetail', back_populates='care_site')
class ConceptRelationship(Base):
__tablename__ = 'concept_relationship'
__table_args__ = (
ForeignKeyConstraint(['concept_id_1'], ['concept.concept_id'], name='fpk_concept_relationship_concept_id_1'),
ForeignKeyConstraint(['concept_id_2'], ['concept.concept_id'], name='fpk_concept_relationship_concept_id_2'),
ForeignKeyConstraint(['relationship_id'], ['relationship.relationship_id'], name='fpk_concept_relationship_relationship_id'),
Index('idx_concept_relationship_id_1', 'concept_id_1'),
Index('idx_concept_relationship_id_2', 'concept_id_2'),
Index('idx_concept_relationship_id_3', 'relationship_id'),
{'comment': 'DESC: The CONCEPT_RELATIONSHIP table contains records that define '
'direct relationships between any two Concepts and the nature or '
'type of the relationship. Each type of a relationship is defined '
'in the RELATIONSHIP table.'}
)
__mapper_args__ = {"primary_key": ['concept_id_1', 'concept_id_2', 'relationship_id', 'valid_start_date', 'valid_end_date']}
concept_id_1: Mapped[int] = mapped_column(Integer, )
concept_id_2: Mapped[int] = mapped_column(Integer, )
relationship_id: Mapped[str] = mapped_column(String(20), comment='USER GUIDANCE: The relationship between CONCEPT_ID_1 and CONCEPT_ID_2. Please see the [Vocabulary Conventions](https://ohdsi.github.io/CommonDataModel/dataModelConventions.html#concept_relationships). for more information. ')
valid_start_date: Mapped[datetime.date] = mapped_column(Date, comment='USER GUIDANCE: The date when the relationship is first recorded.')
valid_end_date: Mapped[datetime.date] = mapped_column(Date, comment='USER GUIDANCE: The date when the relationship is invalidated.')
invalid_reason: Mapped[Optional[str]] = mapped_column(String(1), comment='USER GUIDANCE: Reason the relationship was invalidated. Possible values are "D" (deleted), "U" (updated) or NULL. ')
concept_1: Mapped['Concept'] = relationship('Concept', foreign_keys=[concept_id_1])
concept_2: Mapped['Concept'] = relationship('Concept', foreign_keys=[concept_id_2])
relationship_: Mapped['Relationship'] = relationship('Relationship', back_populates='concept_relationship')
class Provider(Base):
__tablename__ = 'provider'
__table_args__ = (
ForeignKeyConstraint(['care_site_id'], ['care_site.care_site_id'], name='fpk_provider_care_site_id'),
ForeignKeyConstraint(['gender_concept_id'], ['concept.concept_id'], name='fpk_provider_gender_concept_id'),
ForeignKeyConstraint(['gender_source_concept_id'], ['concept.concept_id'], name='fpk_provider_gender_source_concept_id'),
ForeignKeyConstraint(['specialty_concept_id'], ['concept.concept_id'], name='fpk_provider_specialty_concept_id'),
ForeignKeyConstraint(['specialty_source_concept_id'], ['concept.concept_id'], name='fpk_provider_specialty_source_concept_id'),
PrimaryKeyConstraint('provider_id', name='xpk_provider'),
Index('idx_provider_id_1', 'provider_id'),
{'comment': 'DESC: The PROVIDER table contains a list of uniquely identified '
'healthcare providers. These are individuals providing hands-on '
'healthcare to patients, such as physicians, nurses, midwives, '
'physical therapists etc. | USER GUIDANCE: Many sources do not '
'make a distinction between individual and institutional '
'providers. The PROVIDER table contains the individual providers. '
'If the source, instead of uniquely identifying individual '
'providers, only provides limited information such as specialty, '
'generic or "pooled" Provider records are listed in the PROVIDER '
'table.'}
)
provider_id: Mapped[int] = mapped_column(Integer, primary_key=True, comment='USER GUIDANCE: It is assumed that every provider with a different unique identifier is in fact a different person and should be treated independently. | ETLCONVENTIONS: This identifier can be the original id from the source data provided it is an integer, otherwise it can be an autogenerated number.')
provider_name: Mapped[Optional[str]] = mapped_column(String(255), comment=' | ETLCONVENTIONS: This field is not necessary as it is not necessary to have the actual identity of the Provider. Rather, the idea is to uniquely and anonymously identify providers of care across the database.')
npi: Mapped[Optional[str]] = mapped_column(String(20), comment='USER GUIDANCE: This is the National Provider Number issued to health care providers in the US by the Centers for Medicare and Medicaid Services (CMS).')
dea: Mapped[Optional[str]] = mapped_column(String(20), comment='USER GUIDANCE: This is the identifier issued by the DEA, a US federal agency, that allows a provider to write prescriptions for controlled substances.')
specialty_concept_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: This field either represents the most common specialty that occurs in the data or the most specific concept that represents all specialties listed, should the provider have more than one. This includes physician specialties such as internal medicine, emergency medicine, etc. and allied health professionals such as nurses, midwives, and pharmacists. | ETLCONVENTIONS: If a Provider has more than one Specialty, there are two options: 1. Choose a concept_id which is a common ancestor to the multiple specialties, or, 2. Choose the specialty that occurs most often for the provider. Concepts in this field should be Standard with a domain of Provider. [Accepted Concepts](http://athena.ohdsi.org/search-terms/terms?domain=Provider&standardConcept=Standard&page=1&pageSize=15&query=).')
care_site_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: This is the CARE_SITE_ID for the location that the provider primarily practices in. | ETLCONVENTIONS: If a Provider has more than one Care Site, the main or most often exerted CARE_SITE_ID should be recorded.')
year_of_birth: Mapped[Optional[int]] = mapped_column(Integer)
gender_concept_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: This field represents the recorded gender of the provider in the source data. | ETLCONVENTIONS: If given, put a concept from the gender domain representing the recorded gender of the provider. [Accepted Concepts](http://athena.ohdsi.org/search-terms/terms?domain=Gender&standardConcept=Standard&page=1&pageSize=15&query=).')
provider_source_value: Mapped[Optional[str]] = mapped_column(String(50), comment='USER GUIDANCE: Use this field to link back to providers in the source data. This is typically used for error checking of ETL logic. | ETLCONVENTIONS: Some use cases require the ability to link back to providers in the source data. This field allows for the storing of the provider identifier as it appears in the source.')
specialty_source_value: Mapped[Optional[str]] = mapped_column(String(50), comment='USER GUIDANCE: This is the kind of provider or specialty as it appears in the source data. This includes physician specialties such as internal medicine, emergency medicine, etc. and allied health professionals such as nurses, midwives, and pharmacists. | ETLCONVENTIONS: Put the kind of provider as it appears in the source data. This field is up to the discretion of the ETL-er as to whether this should be the coded value from the source or the text description of the lookup value.')
specialty_source_concept_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: This is often zero as many sites use proprietary codes to store physician speciality. | ETLCONVENTIONS: If the source data codes provider specialty in an OMOP supported vocabulary store the concept_id here.')
gender_source_value: Mapped[Optional[str]] = mapped_column(String(50), comment='USER GUIDANCE: This is provider"s gender as it appears in the source data. | ETLCONVENTIONS: Put the provider"s gender as it appears in the source data. This field is up to the discretion of the ETL-er as to whether this should be the coded value from the source or the text description of the lookup value.')
gender_source_concept_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: This is often zero as many sites use proprietary codes to store provider gender. | ETLCONVENTIONS: If the source data codes provider gender in an OMOP supported vocabulary store the concept_id here.')
care_site: Mapped['CareSite'] = relationship('CareSite', back_populates='provider')
gender_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[gender_concept_id])
gender_source_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[gender_source_concept_id])
specialty_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[specialty_concept_id])
specialty_source_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[specialty_source_concept_id])
person: Mapped[List['Person']] = relationship('Person', back_populates='provider')
visit_occurrence: Mapped[List['VisitOccurrence']] = relationship('VisitOccurrence', back_populates='provider')
visit_detail: Mapped[List['VisitDetail']] = relationship('VisitDetail', back_populates='provider')
condition_occurrence: Mapped[List['ConditionOccurrence']] = relationship('ConditionOccurrence', back_populates='provider')
device_exposure: Mapped[List['DeviceExposure']] = relationship('DeviceExposure', back_populates='provider')
drug_exposure: Mapped[List['DrugExposure']] = relationship('DrugExposure', back_populates='provider')
measurement: Mapped[List['Measurement']] = relationship('Measurement', back_populates='provider')
note: Mapped[List['Note']] = relationship('Note', back_populates='provider')
observation: Mapped[List['Observation']] = relationship('Observation', back_populates='provider')
procedure_occurrence: Mapped[List['ProcedureOccurrence']] = relationship('ProcedureOccurrence', back_populates='provider')
class Person(Base):
__tablename__ = 'person'
__table_args__ = (
ForeignKeyConstraint(['care_site_id'], ['care_site.care_site_id'], name='fpk_person_care_site_id'),
ForeignKeyConstraint(['ethnicity_concept_id'], ['concept.concept_id'], name='fpk_person_ethnicity_concept_id'),
ForeignKeyConstraint(['ethnicity_source_concept_id'], ['concept.concept_id'], name='fpk_person_ethnicity_source_concept_id'),
ForeignKeyConstraint(['gender_concept_id'], ['concept.concept_id'], name='fpk_person_gender_concept_id'),
ForeignKeyConstraint(['gender_source_concept_id'], ['concept.concept_id'], name='fpk_person_gender_source_concept_id'),
ForeignKeyConstraint(['location_id'], ['location.location_id'], name='fpk_person_location_id'),
ForeignKeyConstraint(['provider_id'], ['provider.provider_id'], name='fpk_person_provider_id'),
ForeignKeyConstraint(['race_concept_id'], ['concept.concept_id'], name='fpk_person_race_concept_id'),
ForeignKeyConstraint(['race_source_concept_id'], ['concept.concept_id'], name='fpk_person_race_source_concept_id'),
PrimaryKeyConstraint('person_id', name='xpk_person'),
Index('idx_gender', 'gender_concept_id'),
Index('idx_person_id', 'person_id'),
{'comment': 'DESC: This table serves as the central identity management for '
'all Persons in the database. It contains records that uniquely '
'identify each person or patient, and some demographic '
'information. | USER GUIDANCE: All records in this table are '
'independent Persons. | ETL CONVENTIONS: All Persons in a database '
'needs one record in this table, unless they fail data quality '
'requirements specified in the ETL. Persons with no Events should '
'have a record nonetheless. If more than one data source '
'contributes Events to the database, Persons must be reconciled, '
'if possible, across the sources to create one single record per '
'Person. The content of the BIRTH_DATETIME must be equivalent to '
'the content of BIRTH_DAY, BIRTH_MONTH and BIRTH_YEAR. '}
)
person_id: Mapped[int] = mapped_column(Integer, primary_key=True, comment='USER GUIDANCE: It is assumed that every person with a different unique identifier is in fact a different person and should be treated independently. | ETLCONVENTIONS: Any person linkage that needs to occur to uniquely identify Persons ought to be done prior to writing this table. This identifier can be the original id from the source data provided if it is an integer, otherwise it can be an autogenerated number.')
gender_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: This field is meant to capture the biological sex at birth of the Person. This field should not be used to study gender identity issues. | ETLCONVENTIONS: Use the gender or sex value present in the data under the assumption that it is the biological sex at birth. If the source data captures gender identity it should be stored in the [OBSERVATION](https://ohdsi.github.io/CommonDataModel/cdm531.html#observation) table. [Accepted gender concepts](http://athena.ohdsi.org/search-terms/terms?domain=Gender&standardConcept=Standard&page=1&pageSize=15&query=)')
year_of_birth: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: Compute age using year_of_birth. | ETLCONVENTIONS: For data sources with date of birth, the year should be extracted. For data sources where the year of birth is not available, the approximate year of birth could be derived based on age group categorization, if available.')
race_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: This field captures race or ethnic background of the person. | ETLCONVENTIONS: Only use this field if you have information about race or ethnic background. The Vocabulary contains Concepts about the main races and ethnic backgrounds in a hierarchical system. Due to the imprecise nature of human races and ethnic backgrounds, this is not a perfect system. Mixed races are not supported. If a clear race or ethnic background cannot be established, use Concept_Id 0. [Accepted Race Concepts](http://athena.ohdsi.org/search-terms/terms?domain=Race&standardConcept=Standard&page=1&pageSize=15&query=).')
ethnicity_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: This field captures Ethnicity as defined by the Office of Management and Budget (OMB) of the US Government: it distinguishes only between "Hispanic" and "Not Hispanic". Races and ethnic backgrounds are not stored here. | ETLCONVENTIONS: Only use this field if you have US-based data and a source of this information. Do not attempt to infer Ethnicity from the race or ethnic background of the Person. [Accepted ethnicity concepts](http://athena.ohdsi.org/search-terms/terms?domain=Ethnicity&standardConcept=Standard&page=1&pageSize=15&query=)')
month_of_birth: Mapped[Optional[int]] = mapped_column(Integer, comment=' | ETLCONVENTIONS: For data sources that provide the precise date of birth, the month should be extracted and stored in this field.')
day_of_birth: Mapped[Optional[int]] = mapped_column(Integer, comment=' | ETLCONVENTIONS: For data sources that provide the precise date of birth, the day should be extracted and stored in this field.')
birth_datetime: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment=' | ETLCONVENTIONS: This field is not required but highly encouraged. For data sources that provide the precise datetime of birth, that value should be stored in this field. If birth_datetime is not provided in the source, use the following logic to infer the date: If day_of_birth is null and month_of_birth is not null then use the first of the month in that year. If month_of_birth is null or if day_of_birth AND month_of_birth are both null and the person has records during their year of birth then use the date of the earliest record, otherwise use the 15th of June of that year. If time of birth is not given use midnight (00:00:0000).')
location_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: The location refers to the physical address of the person. This field should capture the last known location of the person. | ETLCONVENTIONS: Put the location_id from the [LOCATION](https://ohdsi.github.io/CommonDataModel/cdm531.html#location) table here that represents the most granular location information for the person. This could represent anything from postal code or parts thereof, state, or county for example. Since many databases contain deidentified data, it is common that the precision of the location is reduced to prevent re-identification. This field should capture the last known location. ')
provider_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: The Provider refers to the last known primary care provider (General Practitioner). | ETLCONVENTIONS: Put the provider_id from the [PROVIDER](https://ohdsi.github.io/CommonDataModel/cdm531.html#provider) table of the last known general practitioner of the person. If there are multiple providers, it is up to the ETL to decide which to put here.')
care_site_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: The Care Site refers to where the Provider typically provides the primary care.')
person_source_value: Mapped[Optional[str]] = mapped_column(String(50), comment='USER GUIDANCE: Use this field to link back to persons in the source data. This is typically used for error checking of ETL logic. | ETLCONVENTIONS: Some use cases require the ability to link back to persons in the source data. This field allows for the storing of the person value as it appears in the source. This field is not required but strongly recommended.')
gender_source_value: Mapped[Optional[str]] = mapped_column(String(50), comment='USER GUIDANCE: This field is used to store the biological sex of the person from the source data. It is not intended for use in standard analytics but for reference only. | ETLCONVENTIONS: Put the biological sex of the person as it appears in the source data.')
gender_source_concept_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: Due to the small number of options, this tends to be zero. | ETLCONVENTIONS: If the source data codes biological sex in a non-standard vocabulary, store the concept_id here.')
race_source_value: Mapped[Optional[str]] = mapped_column(String(50), comment='USER GUIDANCE: This field is used to store the race of the person from the source data. It is not intended for use in standard analytics but for reference only. | ETLCONVENTIONS: Put the race of the person as it appears in the source data.')
race_source_concept_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: Due to the small number of options, this tends to be zero. | ETLCONVENTIONS: If the source data codes race in an OMOP supported vocabulary store the concept_id here.')
ethnicity_source_value: Mapped[Optional[str]] = mapped_column(String(50), comment='USER GUIDANCE: This field is used to store the ethnicity of the person from the source data. It is not intended for use in standard analytics but for reference only. | ETLCONVENTIONS: If the person has an ethnicity other than the OMB standard of "Hispanic" or "Not Hispanic" store that value from the source data here.')
ethnicity_source_concept_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: Due to the small number of options, this tends to be zero. | ETLCONVENTIONS: If the source data codes ethnicity in an OMOP supported vocabulary, store the concept_id here.')
care_site: Mapped['CareSite'] = relationship('CareSite', back_populates='person')
ethnicity_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[ethnicity_concept_id])
ethnicity_source_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[ethnicity_source_concept_id])
gender_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[gender_concept_id])
gender_source_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[gender_source_concept_id])
location: Mapped['Location'] = relationship('Location', back_populates='person')
provider: Mapped['Provider'] = relationship('Provider', back_populates='person')
race_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[race_concept_id])
race_source_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[race_source_concept_id])
condition_era: Mapped[List['ConditionEra']] = relationship('ConditionEra', back_populates='person')
dose_era: Mapped[List['DoseEra']] = relationship('DoseEra', back_populates='person')
drug_era: Mapped[List['DrugEra']] = relationship('DrugEra', back_populates='person')
episode: Mapped[List['Episode']] = relationship('Episode', back_populates='person')
observation_period: Mapped[List['ObservationPeriod']] = relationship('ObservationPeriod', back_populates='person')
payer_plan_period: Mapped[List['PayerPlanPeriod']] = relationship('PayerPlanPeriod', back_populates='person')
specimen: Mapped[List['Specimen']] = relationship('Specimen', back_populates='person')
visit_occurrence: Mapped[List['VisitOccurrence']] = relationship('VisitOccurrence', back_populates='person')
visit_detail: Mapped[List['VisitDetail']] = relationship('VisitDetail', back_populates='person')
condition_occurrence: Mapped[List['ConditionOccurrence']] = relationship('ConditionOccurrence', back_populates='person')
device_exposure: Mapped[List['DeviceExposure']] = relationship('DeviceExposure', back_populates='person')
drug_exposure: Mapped[List['DrugExposure']] = relationship('DrugExposure', back_populates='person')
measurement: Mapped[List['Measurement']] = relationship('Measurement', back_populates='person')
note: Mapped[List['Note']] = relationship('Note', back_populates='person')
observation: Mapped[List['Observation']] = relationship('Observation', back_populates='person')
procedure_occurrence: Mapped[List['ProcedureOccurrence']] = relationship('ProcedureOccurrence', back_populates='person')
class ConditionEra(Base):
__tablename__ = 'condition_era'
__table_args__ = (
ForeignKeyConstraint(['condition_concept_id'], ['concept.concept_id'], name='fpk_condition_era_condition_concept_id'),
ForeignKeyConstraint(['person_id'], ['person.person_id'], name='fpk_condition_era_person_id'),
PrimaryKeyConstraint('condition_era_id', name='xpk_condition_era'),
Index('idx_condition_era_concept_id_1', 'condition_concept_id'),
Index('idx_condition_era_person_id_1', 'person_id'),
{'comment': 'DESC: A Condition Era is defined as a span of time when the '
'Person is assumed to have a given condition. Similar to Drug '
'Eras, Condition Eras are chronological periods of Condition '
'Occurrence. Combining individual Condition Occurrences into a '
'single Condition Era serves two purposes:\n'
'\n'
'- It allows aggregation of chronic conditions that require '
'frequent ongoing care, instead of treating each Condition '
'Occurrence as an independent event.\n'
'- It allows aggregation of multiple, closely timed doctor visits '
'for the same Condition to avoid double-counting the Condition '
'Occurrences.\n'
'For example, consider a Person who visits her Primary Care '
'Physician (PCP) and who is referred to a specialist. At a later '
'time, the Person visits the specialist, who confirms the PCP"s '
'original diagnosis and provides the appropriate treatment to '
'resolve the condition. These two independent doctor visits should '
'be aggregated into one Condition Era. | ETL CONVENTIONS: Each '
'Condition Era corresponds to one or many Condition Occurrence '
'records that form a continuous interval.\n'
'The condition_concept_id field contains Concepts that are '
'identical to those of the CONDITION_OCCURRENCE table records that '
'make up the Condition Era. In contrast to Drug Eras, Condition '
'Eras are not aggregated to contain Conditions of different '
'hierarchical layers. The SQl Script for generating CONDITION_ERA '
'records can be found '
'[here](https://ohdsi.github.io/CommonDataModel/sqlScripts.html#condition_eras)\n'
'The Condition Era Start Date is the start date of the first '
'Condition Occurrence.\n'
'The Condition Era End Date is the end date of the last Condition '
'Occurrence. Condition Eras are built with a Persistence Window of '
'30 days, meaning, if no occurrence of the same '
'condition_concept_id happens within 30 days of any one '
'occurrence, it will be considered the condition_era_end_date.'}
)
condition_era_id: Mapped[int] = mapped_column(Integer, primary_key=True)
person_id: Mapped[int] = mapped_column(Integer)
condition_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: The Concept Id representing the Condition.')
condition_era_start_date: Mapped[datetime.date] = mapped_column(Date, comment='USER GUIDANCE: The start date for the Condition Era\nconstructed from the individual\ninstances of Condition Occurrences.\nIt is the start date of the very first\nchronologically recorded instance of\nthe condition with at least 31 days since any prior record of the same Condition. ')
condition_era_end_date: Mapped[datetime.date] = mapped_column(Date, comment='USER GUIDANCE: The end date for the Condition Era\nconstructed from the individual\ninstances of Condition Occurrences.\nIt is the end date of the final\ncontinuously recorded instance of the\nCondition.')
condition_occurrence_count: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: The number of individual Condition\nOccurrences used to construct the\ncondition era.')
condition_concept: Mapped['Concept'] = relationship('Concept')
person: Mapped['Person'] = relationship('Person', back_populates='condition_era')
class Death(Base):
__tablename__ = 'death'
__table_args__ = (
ForeignKeyConstraint(['cause_concept_id'], ['concept.concept_id'], name='fpk_death_cause_concept_id'),
ForeignKeyConstraint(['cause_source_concept_id'], ['concept.concept_id'], name='fpk_death_cause_source_concept_id'),
ForeignKeyConstraint(['death_type_concept_id'], ['concept.concept_id'], name='fpk_death_death_type_concept_id'),
ForeignKeyConstraint(['person_id'], ['person.person_id'], name='fpk_death_person_id'),
Index('idx_death_person_id_1', 'person_id'),
{'comment': 'DESC: The death domain contains the clinical event for how and '
'when a Person dies. A person can have up to one record if the '
'source system contains evidence about the Death, such as: '
'Condition in an administrative claim, status of enrollment into a '
'health plan, or explicit record in EHR data.'}
)
__mapper_args__ = {"primary_key": ['person_id']}
person_id: Mapped[int] = mapped_column(Integer, )
death_date: Mapped[datetime.date] = mapped_column(Date, comment='USER GUIDANCE: The date the person was deceased. | ETLCONVENTIONS: If the precise date include day or month is not known or not allowed, December is used as the default month, and the last day of the month the default day.')
death_datetime: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment=' | ETLCONVENTIONS: If not available set time to midnight (00:00:00)')
death_type_concept_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: This is the provenance of the death record, i.e., where it came from. It is possible that an administrative claims database would source death information from a government file so do not assume the Death Type is the same as the Visit Type, etc. | ETLCONVENTIONS: Use the type concept that be reflects the source of the death record. [Accepted Concepts](https://athena.ohdsi.org/search-terms/terms?domain=Type+Concept&standardConcept=Standard&page=1&pageSize=15&query=). A more detailed explanation of each Type Concept can be found on the [vocabulary wiki](https://github.com/OHDSI/Vocabulary-v5.0/wiki/Vocab.-TYPE_CONCEPT). ')
cause_concept_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: This is the Standard Concept representing the Person"s cause of death, if available. | ETLCONVENTIONS: There is no specified domain for this concept, just choose the Standard Concept Id that best represents the person"s cause of death.')
cause_source_value: Mapped[Optional[str]] = mapped_column(String(50), comment=' | ETLCONVENTIONS: If available, put the source code representing the cause of death here. ')
cause_source_concept_id: Mapped[Optional[int]] = mapped_column(Integer, comment=' | ETLCONVENTIONS: If the cause of death was coded using a Vocabulary present in the OMOP Vocabularies put the CONCEPT_ID representing the cause of death here.')
cause_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[cause_concept_id])
cause_source_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[cause_source_concept_id])
death_type_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[death_type_concept_id])
class DoseEra(Base):
__tablename__ = 'dose_era'
__table_args__ = (
ForeignKeyConstraint(['drug_concept_id'], ['concept.concept_id'], name='fpk_dose_era_drug_concept_id'),
ForeignKeyConstraint(['person_id'], ['person.person_id'], name='fpk_dose_era_person_id'),
ForeignKeyConstraint(['unit_concept_id'], ['concept.concept_id'], name='fpk_dose_era_unit_concept_id'),
PrimaryKeyConstraint('dose_era_id', name='xpk_dose_era'),
Index('idx_dose_era_concept_id_1', 'drug_concept_id'),
Index('idx_dose_era_person_id_1', 'person_id'),
{'comment': 'DESC: A Dose Era is defined as a span of time when the Person is '
'assumed to be exposed to a constant dose of a specific active '
'ingredient. | ETL CONVENTIONS: Dose Eras will be derived from '
'records in the DRUG_EXPOSURE table and the Dose information from '
'the DRUG_STRENGTH table using a standardized algorithm. Dose Form '
'information is not taken into account. So, if the patient changes '
'between different formulations, or different manufacturers with '
'the same formulation, the Dose Era is still spanning the entire '
'time of exposure to the Ingredient. '}
)
dose_era_id: Mapped[int] = mapped_column(Integer, primary_key=True)
person_id: Mapped[int] = mapped_column(Integer)
drug_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: The Concept Id representing the specific drug ingredient.')
unit_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: The Concept Id representing the unit of the specific drug ingredient.')
dose_value: Mapped[decimal.Decimal] = mapped_column(Numeric, comment='USER GUIDANCE: The numeric value of the dosage of the drug_ingredient.')
dose_era_start_date: Mapped[datetime.date] = mapped_column(Date, comment='USER GUIDANCE: The date the Person started on the specific dosage, with at least 31 days since any prior exposure.')
dose_era_end_date: Mapped[datetime.date] = mapped_column(Date, comment=' | ETLCONVENTIONS: The date the Person was no longer exposed to the dosage of the specific drug ingredient. An era is ended if there are 31 days or more between dosage records.')
drug_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[drug_concept_id])
person: Mapped['Person'] = relationship('Person', back_populates='dose_era')
unit_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[unit_concept_id])
class DrugEra(Base):
__tablename__ = 'drug_era'
__table_args__ = (
ForeignKeyConstraint(['drug_concept_id'], ['concept.concept_id'], name='fpk_drug_era_drug_concept_id'),
ForeignKeyConstraint(['person_id'], ['person.person_id'], name='fpk_drug_era_person_id'),
PrimaryKeyConstraint('drug_era_id', name='xpk_drug_era'),
Index('idx_drug_era_concept_id_1', 'drug_concept_id'),
Index('idx_drug_era_person_id_1', 'person_id'),
{'comment': 'DESC: A Drug Era is defined as a span of time when the Person is '
'assumed to be exposed to a particular active ingredient. A Drug '
'Era is not the same as a Drug Exposure: Exposures are individual '
'records corresponding to the source when Drug was delivered to '
'the Person, while successive periods of Drug Exposures are '
'combined under certain rules to produce continuous Drug Eras. | '
'ETL CONVENTIONS: The SQL script for generating DRUG_ERA records '
'can be found '
'[here](https://ohdsi.github.io/CommonDataModel/sqlScripts.html#drug_eras).'}
)
drug_era_id: Mapped[int] = mapped_column(Integer, primary_key=True)
person_id: Mapped[int] = mapped_column(Integer)
drug_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: The Concept Id representing the specific drug ingredient.')
drug_era_start_date: Mapped[datetime.date] = mapped_column(Date, comment=' | ETLCONVENTIONS: The Drug Era Start Date is the start date of the first Drug Exposure for a given ingredient, with at least 31 days since the previous exposure. ')
drug_era_end_date: Mapped[datetime.date] = mapped_column(Date, comment=' | ETLCONVENTIONS: The Drug Era End Date is the end date of the last Drug Exposure. The End Date of each Drug Exposure is either taken from the field drug_exposure_end_date or, as it is typically not available, inferred using the following rules:\nFor pharmacy prescription data, the date when the drug was dispensed plus the number of days of supply are used to extrapolate the End Date for the Drug Exposure. Depending on the country-specific healthcare system, this supply information is either explicitly provided in the day_supply field or inferred from package size or similar information.\nFor Procedure Drugs, usually the drug is administered on a single date (i.e., the administration date).\nA standard Persistence Window of 30 days (gap, slack) is permitted between two subsequent such extrapolated DRUG_EXPOSURE records to be considered to be merged into a single Drug Era.')
drug_exposure_count: Mapped[Optional[int]] = mapped_column(Integer)
gap_days: Mapped[Optional[int]] = mapped_column(Integer, comment=' | ETLCONVENTIONS: The Gap Days determine how many total drug-free days are observed between all Drug Exposure events that contribute to a DRUG_ERA record. It is assumed that the drugs are "not stockpiled" by the patient, i.e. that if a new drug prescription or refill is observed (a new DRUG_EXPOSURE record is written), the remaining supply from the previous events is abandoned. The difference between Persistence Window and Gap Days is that the former is the maximum drug-free time allowed between two subsequent DRUG_EXPOSURE records, while the latter is the sum of actual drug-free days for the given Drug Era under the above assumption of non-stockpiling.')
drug_concept: Mapped['Concept'] = relationship('Concept')
person: Mapped['Person'] = relationship('Person', back_populates='drug_era')
class Episode(Base):
__tablename__ = 'episode'
__table_args__ = (
ForeignKeyConstraint(['episode_concept_id'], ['concept.concept_id'], name='fpk_episode_episode_concept_id'),
ForeignKeyConstraint(['episode_object_concept_id'], ['concept.concept_id'], name='fpk_episode_episode_object_concept_id'),
ForeignKeyConstraint(['episode_source_concept_id'], ['concept.concept_id'], name='fpk_episode_episode_source_concept_id'),
ForeignKeyConstraint(['episode_type_concept_id'], ['concept.concept_id'], name='fpk_episode_episode_type_concept_id'),
ForeignKeyConstraint(['person_id'], ['person.person_id'], name='fpk_episode_person_id'),
PrimaryKeyConstraint('episode_id', name='xpk_episode'),
{'comment': 'DESC: The EPISODE table aggregates lower-level clinical events '
'(VISIT_OCCURRENCE, DRUG_EXPOSURE, PROCEDURE_OCCURRENCE, '
'DEVICE_EXPOSURE) into a higher-level abstraction representing '
'clinically and analytically relevant disease phases,outcomes and '
'treatments. The EPISODE_EVENT table connects qualifying clinical '
'events (VISIT_OCCURRENCE, DRUG_EXPOSURE, PROCEDURE_OCCURRENCE, '
'DEVICE_EXPOSURE) to the appropriate EPISODE entry. For example '
'cancers including their development over time, their treatment, '
'and final resolution. | USER GUIDANCE: Valid Episode Concepts '
'belong to the "Episode" domain. For cancer episodes please see '
'[article], for non-cancer episodes please see [article]. If your '
'source data does not have all episodes that are relevant to the '
'therapeutic area, write only those you can easily derive from the '
'data. It is understood that that table is not currently expected '
'to be comprehensive. '}
)
episode_id: Mapped[int] = mapped_column(Integer, primary_key=True, comment='USER GUIDANCE: A unique identifier for each Episode.')
person_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: The PERSON_ID of the PERSON for whom the episode is recorded.')
episode_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: The EPISODE_CONCEPT_ID represents the kind abstraction related to the disease phase, outcome or treatment. | ETLCONVENTIONS: Choose a concept in the Episode domain that best represents the ongoing disease phase, outcome, or treatment. Please see [article] for cancers and [article] for non-cancers describing how these are defined. [Accepted Concepts](https://athena.ohdsi.org/search-terms/terms?domain=Episode&page=1&pageSize=15&query=)')
episode_start_date: Mapped[datetime.date] = mapped_column(Date, comment='USER GUIDANCE: The date when the Episode beings. | ETLCONVENTIONS: Please see [article] for how to define an Episode start date.')
episode_object_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: A Standard Concept representing the disease phase, outcome, or other abstraction of which the episode consists. For example, if the EPISODE_CONCEPT_ID is [treatment regimen](https://athena.ohdsi.org/search-terms/terms/32531) then the EPISODE_OBJECT_CONCEPT_ID should contain the chemotherapy regimen concept, like [Afatinib monotherapy](https://athena.ohdsi.org/search-terms/terms/35804392). | ETLCONVENTIONS: Episode entries from the "Disease Episode" concept class should have an episode_object_concept_id that comes from the Condition domain. Episode entries from the "Treatment Episode" concept class should have an episode_object_concept_id that scome from the "Procedure" domain or "Regimen" concept class.')
episode_type_concept_id: Mapped[int] = mapped_column(Integer, comment='USER GUIDANCE: This field can be used to determine the provenance of the Episode record, as in whether the episode was from an EHR system, insurance claim, registry, or other sources. | ETLCONVENTIONS: Choose the EPISODE_TYPE_CONCEPT_ID that best represents the provenance of the record. [Accepted Concepts](https://athena.ohdsi.org/search-terms/terms?domain=Type+Concept&standardConcept=Standard&page=1&pageSize=15&query=). A more detailed explanation of each Type Concept can be found on the [vocabulary wiki](https://github.com/OHDSI/Vocabulary-v5.0/wiki/Vocab.-TYPE_CONCEPT). ')
episode_start_datetime: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment='USER GUIDANCE: The date and time when the Episode begins.')
episode_end_date: Mapped[Optional[datetime.date]] = mapped_column(Date, comment='USER GUIDANCE: The date when the instance of the Episode is considered to have ended. | ETLCONVENTIONS: Please see [article] for how to define an Episode end date.')
episode_end_datetime: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment='USER GUIDANCE: The date when the instance of the Episode is considered to have ended.')
episode_parent_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: Use this field to find the Episode that subsumes the given Episode record. This is used in the case that an Episode are nested into each other. | ETLCONVENTIONS: If there are multiple nested levels to how Episodes are represented, the EPISODE_PARENT_ID can be used to record this relationship. ')
episode_number: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: For sequences of episodes, this is used to indicate the order the episodes occurred. For example, lines of treatment could be indicated here. | ETLCONVENTIONS: Please see [article] for the details of how to count episodes.')
episode_source_value: Mapped[Optional[str]] = mapped_column(String(50), comment='USER GUIDANCE: The source code for the Episdoe as it appears in the source data. This code is mapped to a Standard Condition Concept in the Standardized Vocabularies and the original code is stored here for reference.')
episode_source_concept_id: Mapped[Optional[int]] = mapped_column(Integer, comment='USER GUIDANCE: A foreign key to a Episode Concept that refers to the code used in the source. | ETLCONVENTIONS: Given that the Episodes are user-defined it is unlikely that there will be a Source Concept available. If that is the case then set this field to zero. ')
episode_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[episode_concept_id])
episode_object_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[episode_object_concept_id])
episode_source_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[episode_source_concept_id])
episode_type_concept: Mapped['Concept'] = relationship('Concept', foreign_keys=[episode_type_concept_id])
person: Mapped['Person'] = relationship('Person', back_populates='episode')
episode_event: Mapped[List['EpisodeEvent']] = relationship('EpisodeEvent', back_populates='episode')
class ObservationPeriod(Base):
__tablename__ = 'observation_period'
__table_args__ = (
ForeignKeyConstraint(['period_type_concept_id'], ['concept.concept_id'], name='fpk_observation_period_period_type_concept_id'),
ForeignKeyConstraint(['person_id'], ['person.person_id'], name='fpk_observation_period_person_id'),
PrimaryKeyConstraint('observation_period_id', name='xpk_observation_period'),
Index('idx_observation_period_id_1', 'person_id'),
{'comment': 'DESC: This table contains records which define spans of time '
'during which two conditions are expected to hold: (i) Clinical '
'Events that happened to the Person are recorded in the Event '
'tables, and (ii) absense of records indicate such Events did not '
'occur during this span of time. | USER GUIDANCE: For each Person, '
'one or more OBSERVATION_PERIOD records may be present, but they '
'will not overlap or be back to back to each other. Events may '
'exist outside all of the time spans of the OBSERVATION_PERIOD '
'records for a patient, however, absence of an Event outside these '
'time spans cannot be construed as evidence of absence of an '
'Event. Incidence or prevalence rates should only be calculated '
'for the time of active OBSERVATION_PERIOD records. When '
'constructing cohorts, outside Events can be used for inclusion '
'criteria definition, but without any guarantee for the '
'performance of these criteria. Also, OBSERVATION_PERIOD records '
'can be as short as a single day, greatly disturbing the '
'denominator of any rate calculation as part of cohort '
'characterizations. To avoid that, apply minimal observation time '
'as a requirement for any cohort definition. | ETL CONVENTIONS: '
'Each Person needs to have at least one OBSERVATION_PERIOD record, '