Skip to content

Commit 654d9b4

Browse files
committed
updated omop cdm extension
1 parent 414e423 commit 654d9b4

File tree

3 files changed

+52
-12
lines changed

3 files changed

+52
-12
lines changed

Project.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ OMOPCommonDataModel = "ba65db9e-6590-4054-ab8a-101ed9124986"
1010

1111
[extensions]
1212
HealthBaseDrWatsonExt = "DrWatson"
13-
HealthBaseOMOPExt = ["DataFrames", "OMOPCommonDataModel"]
13+
HealthBaseOMOPCDMExt = ["DataFrames", "OMOPCommonDataModel"]
1414

1515
[compat]
16-
DataFrames = "1.7.0"
17-
OMOPCommonDataModel = "0.1.4"
1816
julia = "1.10"
1917

2018
[extras]

ext/HealthBaseOMOPCDMExt.jl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module HealthBaseOMOPExt
2+
3+
using HealthBase
4+
using DataFrames
5+
using OMOPCommonDataModel
6+
7+
__init__() = @info "OMOP CDM extension for HealthBase has been loaded!"
8+
9+
"""
10+
HealthTable(df::DataFrame, omop_cdm_version="5.4"; disable_type_enforcement=false)
11+
12+
Validate a DataFrame against the OMOP CDM specification for the given version.
13+
14+
Checks column names/types, attaches OMOP metadata to columns, and returns the DataFrame.
15+
16+
If `disable_type_enforcement` is true, type mismatches emit warnings instead of errors.
17+
"""
18+
function HealthBase.HealthTable(df::DataFrame, omop_cdm_version="5.4"; disable_type_enforcement=false)
19+
# TODO: have to add logic for version specific fields types
20+
omop_fields = Dict{String, Dict{Symbol, Any}}()
21+
22+
for t in subtypes(OMOPCommonDataModel.CDMType)
23+
for f in fieldnames(t)
24+
actual_field_type = fieldtype(t, f)
25+
omop_fields[string(f)] = Dict(:type => actual_field_type)
26+
end
27+
end
28+
29+
for col in names(df)
30+
if haskey(omop_fields, col)
31+
fieldinfo = omop_fields[col]
32+
expected_type = get(fieldinfo, :type, Any)
33+
actual_type = eltype(df[!, col])
34+
35+
if !(actual_type <: expected_type)
36+
msg = "Column '$(col)' has type $(actual_type), expected $(expected_type)"
37+
if disable_type_enforcement
38+
@warn msg
39+
else
40+
throw(ArgumentError(msg))
41+
end
42+
end
43+
44+
for (key, val) in fieldinfo
45+
colmetadata!(df, col, string(key), string(val), style=:note)
46+
end
47+
end
48+
end
49+
50+
return df
51+
end

ext/HealthBaseOMOPExt.jl

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)