cehrgpt 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- __init__.py +0 -0
- cehrgpt/__init__.py +0 -0
- cehrgpt/analysis/__init__.py +0 -0
- cehrgpt/analysis/privacy/__init__.py +0 -0
- cehrgpt/analysis/privacy/attribute_inference.py +275 -0
- cehrgpt/analysis/privacy/attribute_inference_config.yml +8975 -0
- cehrgpt/analysis/privacy/member_inference.py +172 -0
- cehrgpt/analysis/privacy/nearest_neighbor_inference.py +189 -0
- cehrgpt/analysis/privacy/reid_inference.py +407 -0
- cehrgpt/analysis/privacy/utils.py +255 -0
- cehrgpt/cehrgpt_args.py +142 -0
- cehrgpt/data/__init__.py +0 -0
- cehrgpt/data/hf_cehrgpt_dataset.py +80 -0
- cehrgpt/data/hf_cehrgpt_dataset_collator.py +482 -0
- cehrgpt/data/hf_cehrgpt_dataset_mapping.py +116 -0
- cehrgpt/generation/__init__.py +0 -0
- cehrgpt/generation/chatgpt_generation.py +106 -0
- cehrgpt/generation/generate_batch_hf_gpt_sequence.py +333 -0
- cehrgpt/generation/omop_converter_batch.py +644 -0
- cehrgpt/generation/omop_entity.py +515 -0
- cehrgpt/gpt_utils.py +331 -0
- cehrgpt/models/__init__.py +0 -0
- cehrgpt/models/config.py +205 -0
- cehrgpt/models/hf_cehrgpt.py +1817 -0
- cehrgpt/models/hf_modeling_outputs.py +158 -0
- cehrgpt/models/pretrained_embeddings.py +82 -0
- cehrgpt/models/special_tokens.py +30 -0
- cehrgpt/models/tokenization_hf_cehrgpt.py +1077 -0
- cehrgpt/omop/__init__.py +0 -0
- cehrgpt/omop/condition_era.py +20 -0
- cehrgpt/omop/observation_period.py +43 -0
- cehrgpt/omop/omop_argparse.py +38 -0
- cehrgpt/omop/omop_table_builder.py +86 -0
- cehrgpt/omop/queries/__init__.py +0 -0
- cehrgpt/omop/queries/condition_era.py +86 -0
- cehrgpt/omop/queries/observation_period.py +135 -0
- cehrgpt/omop/sample_omop_tables.py +71 -0
- cehrgpt/runners/__init__.py +0 -0
- cehrgpt/runners/gpt_runner_util.py +99 -0
- cehrgpt/runners/hf_cehrgpt_finetune_runner.py +746 -0
- cehrgpt/runners/hf_cehrgpt_pretrain_runner.py +370 -0
- cehrgpt/runners/hf_gpt_runner_argument_dataclass.py +137 -0
- cehrgpt/runners/hyperparameter_search_util.py +223 -0
- cehrgpt/time_to_event/__init__.py +0 -0
- cehrgpt/time_to_event/config/30_day_readmission.yaml +8 -0
- cehrgpt/time_to_event/config/next_visit_type_prediction.yaml +8 -0
- cehrgpt/time_to_event/config/t2dm_hf.yaml +8 -0
- cehrgpt/time_to_event/time_to_event_model.py +226 -0
- cehrgpt/time_to_event/time_to_event_prediction.py +347 -0
- cehrgpt/time_to_event/time_to_event_utils.py +55 -0
- cehrgpt/tools/__init__.py +0 -0
- cehrgpt/tools/ehrshot_benchmark.py +74 -0
- cehrgpt/tools/generate_pretrained_embeddings.py +130 -0
- cehrgpt/tools/merge_synthetic_real_dataasets.py +218 -0
- cehrgpt/tools/upload_omop_tables.py +108 -0
- cehrgpt-0.0.1.dist-info/LICENSE +21 -0
- cehrgpt-0.0.1.dist-info/METADATA +66 -0
- cehrgpt-0.0.1.dist-info/RECORD +60 -0
- cehrgpt-0.0.1.dist-info/WHEEL +5 -0
- cehrgpt-0.0.1.dist-info/top_level.txt +2 -0
@@ -0,0 +1,515 @@
|
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
from datetime import date, datetime
|
3
|
+
from typing import Union
|
4
|
+
|
5
|
+
|
6
|
+
def fill_datetime(year: int) -> str:
|
7
|
+
"""Helper function to create an ISO 8601 datetime string for 01/01 of a given year."""
|
8
|
+
return datetime.strptime(f"{year}-01-01", "%Y-%m-%d").isoformat()
|
9
|
+
|
10
|
+
|
11
|
+
def fill_start_datetime(d: Union[date, datetime]) -> str:
|
12
|
+
"""Helper function to create an ISO 8601 string at 00:00:00 (start of day)."""
|
13
|
+
if isinstance(d, datetime):
|
14
|
+
return d.isoformat()
|
15
|
+
elif isinstance(d, date):
|
16
|
+
return datetime.combine(d, datetime.min.time()).isoformat()
|
17
|
+
raise RuntimeError(f"{type(d)} is not supported by this function.")
|
18
|
+
|
19
|
+
|
20
|
+
def fill_end_datetime(d: Union[date, datetime]) -> str:
|
21
|
+
"""Helper function to create an ISO 8601 string at 23:59:59.999999 (end of day)."""
|
22
|
+
if isinstance(d, datetime):
|
23
|
+
return d.isoformat()
|
24
|
+
elif isinstance(d, date):
|
25
|
+
return datetime.combine(d, datetime.max.time()).isoformat()
|
26
|
+
raise RuntimeError(f"{type(d)} is not supported by this function.")
|
27
|
+
|
28
|
+
|
29
|
+
class OmopEntity(ABC):
|
30
|
+
"""
|
31
|
+
Abstract base class that all OMOP CDM entities inherit from.
|
32
|
+
|
33
|
+
Ensures that each entity can export its data as JSON,
|
34
|
+
retrieve its schema, and provide a table name.
|
35
|
+
"""
|
36
|
+
|
37
|
+
@abstractmethod
|
38
|
+
def export_as_json(self):
|
39
|
+
pass
|
40
|
+
|
41
|
+
@classmethod
|
42
|
+
@abstractmethod
|
43
|
+
def get_schema(cls):
|
44
|
+
pass
|
45
|
+
|
46
|
+
@abstractmethod
|
47
|
+
def get_table_name(self):
|
48
|
+
pass
|
49
|
+
|
50
|
+
|
51
|
+
# -----------------------------------------------------------------------------
|
52
|
+
# PERSON
|
53
|
+
# https://ohdsi.github.io/CommonDataModel/cdm54.html#person
|
54
|
+
# -----------------------------------------------------------------------------
|
55
|
+
class Person(OmopEntity):
|
56
|
+
def __init__(self, person_id, gender_concept_id, year_of_birth, race_concept_id):
|
57
|
+
self._person_id = person_id
|
58
|
+
self._gender_concept_id = gender_concept_id
|
59
|
+
self._year_of_birth = year_of_birth
|
60
|
+
self._race_concept_id = race_concept_id
|
61
|
+
|
62
|
+
def export_as_json(self):
|
63
|
+
return {
|
64
|
+
"person_id": self._person_id,
|
65
|
+
"gender_concept_id": self._gender_concept_id,
|
66
|
+
"year_of_birth": self._year_of_birth,
|
67
|
+
"month_of_birth": 1,
|
68
|
+
"day_of_birth": 1,
|
69
|
+
"birth_datetime": fill_datetime(self._year_of_birth),
|
70
|
+
"race_concept_id": self._race_concept_id,
|
71
|
+
"ethnicity_concept_id": 0,
|
72
|
+
"location_id": 0,
|
73
|
+
"provider_id": 0,
|
74
|
+
"care_site_id": 0,
|
75
|
+
"person_source_value": "",
|
76
|
+
"gender_source_value": "",
|
77
|
+
"gender_source_concept_id": 0,
|
78
|
+
"race_source_value": "",
|
79
|
+
"race_source_concept_id": 0,
|
80
|
+
"ethnicity_source_value": "",
|
81
|
+
"ethnicity_source_concept_id": 0,
|
82
|
+
}
|
83
|
+
|
84
|
+
@classmethod
|
85
|
+
def get_schema(cls):
|
86
|
+
return {
|
87
|
+
"person_id": int,
|
88
|
+
"gender_concept_id": int,
|
89
|
+
"year_of_birth": int,
|
90
|
+
"month_of_birth": int,
|
91
|
+
"day_of_birth": int,
|
92
|
+
"birth_datetime": datetime,
|
93
|
+
"race_concept_id": int,
|
94
|
+
"ethnicity_concept_id": int,
|
95
|
+
"location_id": int,
|
96
|
+
"provider_id": int,
|
97
|
+
"care_site_id": int,
|
98
|
+
"person_source_value": str,
|
99
|
+
"gender_source_value": str,
|
100
|
+
"gender_source_concept_id": int,
|
101
|
+
"race_source_value": str,
|
102
|
+
"race_source_concept_id": int,
|
103
|
+
"ethnicity_source_value": str,
|
104
|
+
"ethnicity_source_concept_id": int,
|
105
|
+
}
|
106
|
+
|
107
|
+
def get_table_name(self):
|
108
|
+
return "person"
|
109
|
+
|
110
|
+
|
111
|
+
# -----------------------------------------------------------------------------
|
112
|
+
# VISIT_OCCURRENCE
|
113
|
+
# https://ohdsi.github.io/CommonDataModel/cdm54.html#visit_occurrence
|
114
|
+
# -----------------------------------------------------------------------------
|
115
|
+
class VisitOccurrence(OmopEntity):
|
116
|
+
def __init__(
|
117
|
+
self,
|
118
|
+
visit_occurrence_id: int,
|
119
|
+
visit_concept_id: int,
|
120
|
+
visit_start_datetime: datetime,
|
121
|
+
person: Person,
|
122
|
+
discharged_to_concept_id: int = 0,
|
123
|
+
):
|
124
|
+
self._visit_occurrence_id = visit_occurrence_id
|
125
|
+
self._visit_concept_id = visit_concept_id
|
126
|
+
self._visit_start_date = visit_start_datetime.date()
|
127
|
+
self._visit_start_datetime = fill_start_datetime(visit_start_datetime)
|
128
|
+
self._visit_end_date = visit_start_datetime.date()
|
129
|
+
self._visit_end_datetime = fill_end_datetime(visit_start_datetime)
|
130
|
+
self._person = person
|
131
|
+
self._discharged_to_concept_id = discharged_to_concept_id
|
132
|
+
|
133
|
+
def export_as_json(self):
|
134
|
+
return {
|
135
|
+
"visit_occurrence_id": self._visit_occurrence_id,
|
136
|
+
"visit_concept_id": self._visit_concept_id,
|
137
|
+
"person_id": self._person._person_id,
|
138
|
+
"visit_start_date": self._visit_start_date,
|
139
|
+
"visit_start_datetime": self._visit_start_datetime,
|
140
|
+
"visit_end_date": self._visit_end_date,
|
141
|
+
"visit_end_datetime": self._visit_end_datetime,
|
142
|
+
"visit_type_concept_id": 44818702, # default concept (e.g. Inpatient Visit)
|
143
|
+
"provider_id": 0,
|
144
|
+
"care_site_id": 0,
|
145
|
+
"visit_source_value": "",
|
146
|
+
"visit_source_concept_id": self._visit_concept_id,
|
147
|
+
"admitted_from_concept_id": 0, # replaced "admitting_source_concept_id"
|
148
|
+
"admitted_from_source_value": "", # replaced "admitting_source_value"
|
149
|
+
"discharged_to_concept_id": self._discharged_to_concept_id,
|
150
|
+
"discharged_to_source_value": "",
|
151
|
+
"preceding_visit_occurrence_id": 0,
|
152
|
+
}
|
153
|
+
|
154
|
+
@classmethod
|
155
|
+
def get_schema(cls):
|
156
|
+
return {
|
157
|
+
"visit_occurrence_id": int,
|
158
|
+
"visit_concept_id": int,
|
159
|
+
"person_id": int,
|
160
|
+
"visit_start_date": date,
|
161
|
+
"visit_start_datetime": datetime,
|
162
|
+
"visit_end_date": date,
|
163
|
+
"visit_end_datetime": datetime,
|
164
|
+
"visit_type_concept_id": int,
|
165
|
+
"provider_id": int,
|
166
|
+
"care_site_id": int,
|
167
|
+
"visit_source_value": str,
|
168
|
+
"visit_source_concept_id": int,
|
169
|
+
"admitted_from_concept_id": int,
|
170
|
+
"admitted_from_source_value": str,
|
171
|
+
"discharged_to_concept_id": int,
|
172
|
+
"discharged_to_source_value": str,
|
173
|
+
"preceding_visit_occurrence_id": int,
|
174
|
+
}
|
175
|
+
|
176
|
+
def get_table_name(self):
|
177
|
+
return "visit_occurrence"
|
178
|
+
|
179
|
+
@property
|
180
|
+
def person(self):
|
181
|
+
return self._person
|
182
|
+
|
183
|
+
@property
|
184
|
+
def discharged_to_concept_id(self):
|
185
|
+
return self._discharged_to_concept_id
|
186
|
+
|
187
|
+
def set_discharged_to_concept_id(self, discharged_to_concept_id: int):
|
188
|
+
self._discharged_to_concept_id = discharged_to_concept_id
|
189
|
+
|
190
|
+
def set_visit_end_date(self, visit_end_datetime: datetime):
|
191
|
+
self._visit_end_date = visit_end_datetime.date()
|
192
|
+
self._visit_end_datetime = fill_end_datetime(visit_end_datetime)
|
193
|
+
|
194
|
+
|
195
|
+
# -----------------------------------------------------------------------------
|
196
|
+
# CONDITION_OCCURRENCE
|
197
|
+
# https://ohdsi.github.io/CommonDataModel/cdm54.html#condition_occurrence
|
198
|
+
# -----------------------------------------------------------------------------
|
199
|
+
class ConditionOccurrence(OmopEntity):
|
200
|
+
def __init__(
|
201
|
+
self,
|
202
|
+
condition_occurrence_id: int,
|
203
|
+
condition_concept_id: int,
|
204
|
+
visit_occurrence: VisitOccurrence,
|
205
|
+
condition_datetime: datetime,
|
206
|
+
):
|
207
|
+
self._condition_occurrence_id = condition_occurrence_id
|
208
|
+
self._condition_concept_id = condition_concept_id
|
209
|
+
self._visit_occurrence = visit_occurrence
|
210
|
+
self._condition_start_date = condition_datetime.date()
|
211
|
+
self._condition_start_datetime = fill_start_datetime(condition_datetime)
|
212
|
+
self._condition_end_date = condition_datetime.date()
|
213
|
+
self._condition_end_datetime = fill_start_datetime(condition_datetime)
|
214
|
+
|
215
|
+
def export_as_json(self):
|
216
|
+
return {
|
217
|
+
"condition_occurrence_id": self._condition_occurrence_id,
|
218
|
+
"person_id": self._visit_occurrence._person._person_id,
|
219
|
+
"condition_concept_id": self._condition_concept_id,
|
220
|
+
"condition_start_date": self._condition_start_date,
|
221
|
+
"condition_start_datetime": self._condition_start_datetime,
|
222
|
+
"condition_end_date": self._condition_end_date,
|
223
|
+
"condition_end_datetime": self._condition_end_datetime,
|
224
|
+
"condition_type_concept_id": 32817, # default concept
|
225
|
+
"stop_reason": "",
|
226
|
+
"provider_id": 0,
|
227
|
+
"visit_occurrence_id": self._visit_occurrence._visit_occurrence_id,
|
228
|
+
"visit_detail_id": 0,
|
229
|
+
"condition_source_value": "",
|
230
|
+
"condition_source_concept_id": self._condition_concept_id,
|
231
|
+
"condition_status_source_value": "",
|
232
|
+
"condition_status_concept_id": 0,
|
233
|
+
}
|
234
|
+
|
235
|
+
@classmethod
|
236
|
+
def get_schema(cls):
|
237
|
+
return {
|
238
|
+
"condition_occurrence_id": int,
|
239
|
+
"person_id": int,
|
240
|
+
"condition_concept_id": int,
|
241
|
+
"condition_start_date": date,
|
242
|
+
"condition_start_datetime": datetime,
|
243
|
+
"condition_end_date": date,
|
244
|
+
"condition_end_datetime": datetime,
|
245
|
+
"condition_type_concept_id": int,
|
246
|
+
"stop_reason": str,
|
247
|
+
"provider_id": int,
|
248
|
+
"visit_occurrence_id": int,
|
249
|
+
"visit_detail_id": int,
|
250
|
+
"condition_source_value": str,
|
251
|
+
"condition_source_concept_id": int,
|
252
|
+
"condition_status_source_value": str,
|
253
|
+
"condition_status_concept_id": int,
|
254
|
+
}
|
255
|
+
|
256
|
+
def get_table_name(self):
|
257
|
+
return "condition_occurrence"
|
258
|
+
|
259
|
+
|
260
|
+
# -----------------------------------------------------------------------------
|
261
|
+
# DRUG_EXPOSURE
|
262
|
+
# https://ohdsi.github.io/CommonDataModel/cdm54.html#drug_exposure
|
263
|
+
# -----------------------------------------------------------------------------
|
264
|
+
class DrugExposure(OmopEntity):
|
265
|
+
def __init__(
|
266
|
+
self,
|
267
|
+
drug_exposure_id: int,
|
268
|
+
drug_concept_id: int,
|
269
|
+
visit_occurrence: VisitOccurrence,
|
270
|
+
drug_datetime: datetime,
|
271
|
+
):
|
272
|
+
self._drug_exposure_id = drug_exposure_id
|
273
|
+
self._drug_concept_id = drug_concept_id
|
274
|
+
self._visit_occurrence = visit_occurrence
|
275
|
+
self._drug_exposure_start_date = drug_datetime.date()
|
276
|
+
self._drug_exposure_start_datetime = fill_start_datetime(drug_datetime)
|
277
|
+
self._drug_exposure_end_date = drug_datetime.date()
|
278
|
+
self._drug_exposure_end_datetime = fill_start_datetime(drug_datetime)
|
279
|
+
|
280
|
+
def export_as_json(self):
|
281
|
+
return {
|
282
|
+
"drug_exposure_id": self._drug_exposure_id,
|
283
|
+
"person_id": self._visit_occurrence._person._person_id,
|
284
|
+
"drug_concept_id": self._drug_concept_id,
|
285
|
+
"drug_exposure_start_date": self._drug_exposure_start_date,
|
286
|
+
"drug_exposure_start_datetime": self._drug_exposure_start_datetime,
|
287
|
+
"drug_exposure_end_date": self._drug_exposure_end_date,
|
288
|
+
"drug_exposure_end_datetime": self._drug_exposure_end_datetime,
|
289
|
+
"verbatim_end_date": self._drug_exposure_end_date,
|
290
|
+
"drug_type_concept_id": 38000177, # default concept
|
291
|
+
"stop_reason": "",
|
292
|
+
"refills": None,
|
293
|
+
"quantity": None,
|
294
|
+
"days_supply": None,
|
295
|
+
"sig": "",
|
296
|
+
"route_concept_id": 0,
|
297
|
+
"lot_number": "",
|
298
|
+
"provider_id": 0,
|
299
|
+
"visit_occurrence_id": self._visit_occurrence._visit_occurrence_id,
|
300
|
+
"visit_detail_id": 0,
|
301
|
+
"drug_source_value": "",
|
302
|
+
"drug_source_concept_id": self._drug_concept_id,
|
303
|
+
"route_source_value": "",
|
304
|
+
"dose_unit_source_value": "",
|
305
|
+
}
|
306
|
+
|
307
|
+
@classmethod
|
308
|
+
def get_schema(cls):
|
309
|
+
return {
|
310
|
+
"drug_exposure_id": int,
|
311
|
+
"person_id": int,
|
312
|
+
"drug_concept_id": int,
|
313
|
+
"drug_exposure_start_date": date,
|
314
|
+
"drug_exposure_start_datetime": datetime,
|
315
|
+
"drug_exposure_end_date": date,
|
316
|
+
"drug_exposure_end_datetime": datetime,
|
317
|
+
"verbatim_end_date": date,
|
318
|
+
"drug_type_concept_id": int,
|
319
|
+
"stop_reason": str,
|
320
|
+
"refills": int,
|
321
|
+
"quantity": int,
|
322
|
+
"days_supply": int,
|
323
|
+
"sig": str,
|
324
|
+
"route_concept_id": int,
|
325
|
+
"lot_number": str,
|
326
|
+
"provider_id": int,
|
327
|
+
"visit_occurrence_id": int,
|
328
|
+
"visit_detail_id": int,
|
329
|
+
"drug_source_value": str,
|
330
|
+
"drug_source_concept_id": int,
|
331
|
+
"route_source_value": str,
|
332
|
+
"dose_unit_source_value": str,
|
333
|
+
}
|
334
|
+
|
335
|
+
def get_table_name(self):
|
336
|
+
return "drug_exposure"
|
337
|
+
|
338
|
+
|
339
|
+
# -----------------------------------------------------------------------------
|
340
|
+
# PROCEDURE_OCCURRENCE
|
341
|
+
# https://ohdsi.github.io/CommonDataModel/cdm54.html#procedure_occurrence
|
342
|
+
# -----------------------------------------------------------------------------
|
343
|
+
class ProcedureOccurrence(OmopEntity):
|
344
|
+
def __init__(
|
345
|
+
self,
|
346
|
+
procedure_occurrence_id: int,
|
347
|
+
procedure_concept_id: int,
|
348
|
+
visit_occurrence: VisitOccurrence,
|
349
|
+
procedure_datetime: datetime,
|
350
|
+
):
|
351
|
+
self._procedure_occurrence_id = procedure_occurrence_id
|
352
|
+
self._procedure_concept_id = procedure_concept_id
|
353
|
+
self._visit_occurrence = visit_occurrence
|
354
|
+
self._procedure_date = procedure_datetime.date()
|
355
|
+
self._procedure_datetime = fill_start_datetime(procedure_datetime)
|
356
|
+
|
357
|
+
def export_as_json(self):
|
358
|
+
return {
|
359
|
+
"procedure_occurrence_id": self._procedure_occurrence_id,
|
360
|
+
"person_id": self._visit_occurrence._person._person_id,
|
361
|
+
"procedure_concept_id": self._procedure_concept_id,
|
362
|
+
"procedure_date": self._procedure_date,
|
363
|
+
"procedure_datetime": self._procedure_datetime,
|
364
|
+
"procedure_type_concept_id": 38000178, # default
|
365
|
+
"modifier_concept_id": 0,
|
366
|
+
"quantity": 1,
|
367
|
+
"provider_id": 0,
|
368
|
+
"visit_occurrence_id": self._visit_occurrence._visit_occurrence_id,
|
369
|
+
"visit_detail_id": 0,
|
370
|
+
"procedure_source_value": "",
|
371
|
+
"procedure_source_concept_id": self._procedure_concept_id,
|
372
|
+
"qualifier_source_value": "",
|
373
|
+
}
|
374
|
+
|
375
|
+
@classmethod
|
376
|
+
def get_schema(cls):
|
377
|
+
return {
|
378
|
+
"procedure_occurrence_id": int,
|
379
|
+
"person_id": int,
|
380
|
+
"procedure_concept_id": int,
|
381
|
+
"procedure_date": date,
|
382
|
+
"procedure_datetime": datetime,
|
383
|
+
"procedure_type_concept_id": int,
|
384
|
+
"modifier_concept_id": int,
|
385
|
+
"quantity": int,
|
386
|
+
"provider_id": int,
|
387
|
+
"visit_occurrence_id": int,
|
388
|
+
"visit_detail_id": int,
|
389
|
+
"procedure_source_value": str,
|
390
|
+
"procedure_source_concept_id": int,
|
391
|
+
"qualifier_source_value": str,
|
392
|
+
}
|
393
|
+
|
394
|
+
def get_table_name(self):
|
395
|
+
return "procedure_occurrence"
|
396
|
+
|
397
|
+
|
398
|
+
# -----------------------------------------------------------------------------
|
399
|
+
# DEATH
|
400
|
+
# https://ohdsi.github.io/CommonDataModel/cdm54.html#death
|
401
|
+
# -----------------------------------------------------------------------------
|
402
|
+
class Death(OmopEntity):
|
403
|
+
def __init__(
|
404
|
+
self,
|
405
|
+
person: Person,
|
406
|
+
death_date: date,
|
407
|
+
death_type_concept_id: int = 0,
|
408
|
+
):
|
409
|
+
self._person = person
|
410
|
+
self._death_date = death_date
|
411
|
+
self._death_datetime = fill_end_datetime(death_date)
|
412
|
+
self._death_type_concept_id = death_type_concept_id
|
413
|
+
|
414
|
+
def export_as_json(self):
|
415
|
+
return {
|
416
|
+
"person_id": self._person._person_id,
|
417
|
+
"death_date": self._death_date,
|
418
|
+
"death_datetime": self._death_datetime,
|
419
|
+
"death_type_concept_id": self._death_type_concept_id,
|
420
|
+
"cause_concept_id": 0,
|
421
|
+
"cause_source_value": "",
|
422
|
+
"cause_source_concept_id": 0,
|
423
|
+
}
|
424
|
+
|
425
|
+
@classmethod
|
426
|
+
def get_schema(cls):
|
427
|
+
return {
|
428
|
+
"person_id": int,
|
429
|
+
"death_date": date,
|
430
|
+
"death_datetime": datetime,
|
431
|
+
"death_type_concept_id": int,
|
432
|
+
"cause_concept_id": int,
|
433
|
+
"cause_source_value": str,
|
434
|
+
"cause_source_concept_id": int,
|
435
|
+
}
|
436
|
+
|
437
|
+
def get_table_name(self):
|
438
|
+
return "death"
|
439
|
+
|
440
|
+
|
441
|
+
# -----------------------------------------------------------------------------
|
442
|
+
# MEASUREMENT
|
443
|
+
# https://ohdsi.github.io/CommonDataModel/cdm54.html#measurement
|
444
|
+
# -----------------------------------------------------------------------------
|
445
|
+
class Measurement(OmopEntity):
|
446
|
+
def __init__(
|
447
|
+
self,
|
448
|
+
measurement_id: int,
|
449
|
+
measurement_concept_id: int,
|
450
|
+
value_as_number: float,
|
451
|
+
is_numeric_type,
|
452
|
+
value_as_concept_id,
|
453
|
+
visit_occurrence: VisitOccurrence,
|
454
|
+
measurement_datetime: datetime,
|
455
|
+
unit_source_value,
|
456
|
+
):
|
457
|
+
self._measurement_id = measurement_id
|
458
|
+
self._measurement_concept_id = measurement_concept_id
|
459
|
+
self._value_as_number = value_as_number
|
460
|
+
self._value_as_concept_id = value_as_concept_id
|
461
|
+
self._visit_occurrence = visit_occurrence
|
462
|
+
self._measurement_date = measurement_datetime.date()
|
463
|
+
self._measurement_datetime = fill_start_datetime(measurement_datetime)
|
464
|
+
self._operator_concept_id = 4172703 if is_numeric_type == 1 else 0
|
465
|
+
self._unit_source_value = unit_source_value
|
466
|
+
|
467
|
+
def export_as_json(self):
|
468
|
+
return {
|
469
|
+
"measurement_id": self._measurement_id,
|
470
|
+
"person_id": self._visit_occurrence._person._person_id,
|
471
|
+
"measurement_concept_id": self._measurement_concept_id,
|
472
|
+
"measurement_date": self._measurement_date,
|
473
|
+
"measurement_datetime": self._measurement_datetime,
|
474
|
+
"measurement_type_concept_id": 0,
|
475
|
+
"operator_concept_id": self._operator_concept_id,
|
476
|
+
"value_as_number": self._value_as_number,
|
477
|
+
"value_as_concept_id": self._value_as_concept_id,
|
478
|
+
"unit_concept_id": 0,
|
479
|
+
"range_low": None,
|
480
|
+
"range_high": None,
|
481
|
+
"provider_id": 0,
|
482
|
+
"visit_occurrence_id": self._visit_occurrence._visit_occurrence_id,
|
483
|
+
"visit_detail_id": 0,
|
484
|
+
"measurement_source_value": "",
|
485
|
+
"measurement_source_concept_id": self._measurement_concept_id,
|
486
|
+
"unit_source_value": self._unit_source_value,
|
487
|
+
"value_source_value": "",
|
488
|
+
}
|
489
|
+
|
490
|
+
@classmethod
|
491
|
+
def get_schema(cls):
|
492
|
+
return {
|
493
|
+
"measurement_id": int,
|
494
|
+
"person_id": int,
|
495
|
+
"measurement_concept_id": int,
|
496
|
+
"measurement_date": date,
|
497
|
+
"measurement_datetime": datetime,
|
498
|
+
"measurement_type_concept_id": int,
|
499
|
+
"operator_concept_id": int,
|
500
|
+
"value_as_number": float,
|
501
|
+
"value_as_concept_id": int,
|
502
|
+
"unit_concept_id": int,
|
503
|
+
"range_low": float,
|
504
|
+
"range_high": float,
|
505
|
+
"provider_id": int,
|
506
|
+
"visit_occurrence_id": int,
|
507
|
+
"visit_detail_id": int,
|
508
|
+
"measurement_source_value": str,
|
509
|
+
"measurement_source_concept_id": int,
|
510
|
+
"unit_source_value": str,
|
511
|
+
"value_source_value": str,
|
512
|
+
}
|
513
|
+
|
514
|
+
def get_table_name(self):
|
515
|
+
return "measurement"
|