Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions ext/HealthBaseOMOPCDMExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,41 @@ function HealthBase.HealthTable(
end
end

validation_msgs = String[]
validation_errors = String[]
validation_infos = String[]

# ---- TYPE ERRORS (must fail) ----
if !isempty(failed_columns)
error_details = join(["Column '$(err.colname)': has type $(err.type), expected $(err.expected)" for err in failed_columns], "\n")
push!(validation_msgs, "OMOP CDM type validation failed for the following columns:\n" * error_details)
error_details = join(
["Column '$(err.colname)': has type $(err.type), expected $(err.expected)"
for err in failed_columns], "\n"
)
push!(validation_errors,
"OMOP CDM type validation failed for the following columns:\n" * error_details)
end

if !isempty(validation_msgs)
full_message = join(validation_msgs, "\n\n") * "\n"
# ---- EXTRA COLUMNS (info only) ----
if !isempty(extra_columns)
push!(validation_infos,
"Note: The following columns are not part of the OMOP CDM schema and will be ignored for validation: " *
join(extra_columns, ", "))
end

# ---- THROW ONLY FOR REAL ERRORS ----
if !isempty(validation_errors)
full_message = join(validation_errors, "\n\n") * "\n"
if disable_type_enforcement
@warn full_message * "\nType enforcement is disabled. Unexpected behavior may occur."
else
throw(ArgumentError(full_message))
end
end

# ---- LOG INFO MESSAGES ----
for msg in validation_infos
@info msg
end

DataFrames.metadata!(df, "omop_cdm_version", omop_cdm_version)

return HealthBase.HealthTable{typeof(df)}(df)
Expand Down
8 changes: 8 additions & 0 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ This method is purely for display; it returns `nothing`.
function Base.show(io::IO, ht::HealthTable)
df = ht.source

# Summary line (NEW FEATURE)
rows, cols = size(df)
ver_short = haskey(metadata(df), "omop_cdm_version") ?
" (OMOP $(metadata(df, "omop_cdm_version")))" : ""
println(io, "HealthTable$ver_short: $rows rows x $cols columns")

# Table display (EXISTING BEHAVIOR)
if nrow(df) == 0
pretty_table(io, ["HealthTable is empty"]; header = [""])
else
pretty_table(io, df; alignment = :l)
end

# IMPORTANT: keep old output for tests
if haskey(metadata(df), "omop_cdm_version")
println(io, "\nOMOP CDM version: ", metadata(df, "omop_cdm_version"))
end
Expand Down
5 changes: 5 additions & 0 deletions test/omopcdmext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@

ht_extra = HealthBase.HealthTable(df_extra; omop_cdm_version="v5.4.1")
@test "extra_column" in names(ht_extra.source)

# NEW behaviour: user is informed via log message
@test_logs (:info, r"not part of the OMOP CDM schema") begin
HealthBase.HealthTable(df_extra; omop_cdm_version="v5.4.1")
end
end

@testset "Schema Validation Edge Cases" begin
Expand Down
Loading