Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanSteinberg committed Dec 31, 2023
1 parent 095a8cd commit 9372110
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/meds_etl/omop.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import shutil
import subprocess
import tempfile
import sys

import jsonschema
import meds
Expand All @@ -28,7 +29,7 @@ def get_table_files(src_omop, table_name, table_details={}):
elif os.path.exists(folder_name + ".csv"):
return [folder_name + ".csv"]
elif os.path.exists(folder_name + ".csv.gz"):
return [folder_name + ".csv"]
return [folder_name + ".csv.gz"]
else:
return []

Expand Down Expand Up @@ -82,7 +83,7 @@ def process_table(args):

if table_name == "person":
time = pl.coalesce(
pl.col("birth_datetime").str.to_datetime("%Y-%m-%d %H:%M:%S%.f", strict=False),
pl.col("birth_datetime").str.to_datetime("%Y-%m-%d %H:%M:%S%.f", strict=False, time_unit='ms'),
pl.datetime(
pl.col("year_of_birth"),
pl.coalesce(pl.col("month_of_birth"), 1),
Expand All @@ -97,8 +98,8 @@ def process_table(args):
assert len(options) > 0, f"Could not find the time column {batch.columns}"
time = pl.coalesce(options)
time = pl.coalesce(
time.str.to_datetime("%Y-%m-%d %H:%M:%S%.f", strict=False),
time.str.to_datetime("%Y-%m-%d", strict=False).dt.offset_by("1d").dt.offset_by("-1s"),
time.str.to_datetime("%Y-%m-%d %H:%M:%S%.f", strict=False, time_unit='ms'),
time.str.to_datetime("%Y-%m-%d", strict=False, time_unit='ms').dt.offset_by("1d").dt.offset_by("-1s"),
)

if table_details.get("force_concept_id"):
Expand Down Expand Up @@ -161,8 +162,8 @@ def process_table(args):
value = pl.coalesce(value, backup_value)

datetime_value = pl.coalesce(
value.str.to_datetime("%Y-%m-%d %H:%M:%S%.f", strict=False),
value.str.to_datetime("%Y-%m-%d", strict=False),
value.str.to_datetime("%Y-%m-%d %H:%M:%S%.f", strict=False, time_unit='ms'),
value.str.to_datetime("%Y-%m-%d", strict=False, time_unit='ms'),
)
numeric_value = value.cast(pl.Float32, strict=False)

Expand Down Expand Up @@ -191,8 +192,8 @@ def process_table(args):
if (table_name + "_end_datetime") in batch.columns:
end = pl.col(table_name + "_end_datetime")
end = pl.coalesce(
end.str.to_datetime("%Y-%m-%d %H:%M:%S%.f", strict=False),
end.str.to_datetime("%Y-%m-%d", strict=False).dt.offset_by("1d").dt.offset_by("-1s"),
end.str.to_datetime("%Y-%m-%d %H:%M:%S%.f", strict=False, time_unit='ms'),
end.str.to_datetime("%Y-%m-%d", strict=False, time_unit='ms').dt.offset_by("1d").dt.offset_by("-1s"),
)
metadata["end"] = end

Expand Down

0 comments on commit 9372110

Please sign in to comment.