Skip to content

Commit

Permalink
support drug_era
Browse files Browse the repository at this point in the history
  • Loading branch information
eroell committed Nov 22, 2024
1 parent 6b0e57e commit 9dc6637
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ehrdata/io/omop/_check_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"condition_occurrence",
"procedure_occurrence",
"device_exposure",
"drug_era",
]
VALID_KEEP_DATES = ["start", "end", "interval"]

Expand Down
3 changes: 3 additions & 0 deletions src/ehrdata/io/omop/_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"condition_occurrence": "condition",
"procedure_occurrence": "procedure",
"device_exposure": "device",
"drug_era": "drug",
}
# DATA_TABLE_DATE_TRUNK = {
# "measurement": "measurement",
Expand All @@ -57,6 +58,7 @@
"condition_occurrence": "condition_start_date",
"procedure_occurrence": "procedure_date", # in v5.3, procedure didnt have end date
"device_exposure": "device_exposure_start_date",
"drug_era": "drug_era_start_date",
},
"end": {
"visit_occurrence": "visit_end_date",
Expand All @@ -66,6 +68,7 @@
"condition_occurrence": "condition_end_date",
"procedure_occurrence": "procedure_end_date", # in v5.3, procedure didnt have end date TODO v5.3 support
"device_exposure": "device_exposure_end_date",
"drug_era": "drug_era_end_date",
},
}

Expand Down
10 changes: 10 additions & 0 deletions tests/data/toy_omop/vanilla/drug_era.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
drug_era_id,person_id,drug_concept_id,drug_era_start_date,drug_era_end_date,drug_exposure_count,gap_days
1,1,1124957,2100-01-01,2100-01-31,2,1
2,1,1124957,2100-02-01,2100-02-28,2,1
3,1,1368671,2100-01-01,2100-01-31,4,3
4,2,1124957,2100-01-01,2100-01-31,2,1
5,2,1124957,2100-02-01,2100-02-28,2,1
6,2,1368671,2100-01-01,2100-01-31,4,3
7,3,1124957,2100-01-01,2100-01-31,2,2
8,3,1124957,2100-02-01,2100-02-28,2,1
9,3,1368671,2100-01-01,2100-01-31,4,3
62 changes: 61 additions & 1 deletion tests/test_io/test_omop.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"condition_occurrence": 2,
"procedure_occurrence": 2,
"device_exposure": 2,
"drug_era": 2,
}

# constants for setup_variables
Expand Down Expand Up @@ -444,7 +445,66 @@ def test_setup_variables(
[[1, 1, 1, 1], [1, 1, 1, 1]],
],
),
# (["note"], ["is_present"]),
(
["drug_era"],
["drug_exposure_count"],
"start",
[
[[2, np.nan, np.nan, np.nan], [4, np.nan, np.nan, np.nan]],
[[2, np.nan, np.nan, np.nan], [4, np.nan, np.nan, np.nan]],
[[2, np.nan, np.nan, np.nan], [4, np.nan, np.nan, np.nan]],
],
),
(
["drug_era"],
["drug_exposure_count"],
"end",
[
[[np.nan, np.nan, np.nan, np.nan], [np.nan, np.nan, np.nan, np.nan]],
[[np.nan, np.nan, np.nan, np.nan], [np.nan, np.nan, np.nan, np.nan]],
[[np.nan, np.nan, np.nan, np.nan], [np.nan, np.nan, np.nan, np.nan]],
],
),
(
["drug_era"],
["drug_exposure_count"],
"interval",
[
[[2, 2, 2, 2], [4, 4, 4, 4]],
[[2, 2, 2, 2], [4, 4, 4, 4]],
[[2, 2, 2, 2], [4, 4, 4, 4]],
],
),
(
["drug_era"],
["is_present"],
"start",
[
[[1, np.nan, np.nan, np.nan], [1, np.nan, np.nan, np.nan]],
[[1, np.nan, np.nan, np.nan], [1, np.nan, np.nan, np.nan]],
[[1, np.nan, np.nan, np.nan], [1, np.nan, np.nan, np.nan]],
],
),
(
["drug_era"],
["is_present"],
"end",
[
[[np.nan, np.nan, np.nan, np.nan], [np.nan, np.nan, np.nan, np.nan]],
[[np.nan, np.nan, np.nan, np.nan], [np.nan, np.nan, np.nan, np.nan]],
[[np.nan, np.nan, np.nan, np.nan], [np.nan, np.nan, np.nan, np.nan]],
],
),
(
["drug_era"],
["is_present"],
"interval",
[
[[1, 1, 1, 1], [1, 1, 1, 1]],
[[1, 1, 1, 1], [1, 1, 1, 1]],
[[1, 1, 1, 1], [1, 1, 1, 1]],
],
),
],
)
@pytest.mark.parametrize(
Expand Down

0 comments on commit 9dc6637

Please sign in to comment.