CustomMatch.RdA class that creates a custom SQL indicator based on user-defined logic, allowing for flexible evaluation of conditions within a dataset.
CustomMatch(indicator_name, sql_logic)Returns an instance of CustomMatch with the generated SQL query.
When a `CustomMatch` indicator depends on another previously calculated indicator, the required indicator must appear before the `CustomMatch` in the list of indicators provided to the `RuleEngine`. Additionally, the user must ensure that all variables referenced in the `CustomMatch` are present in the data frame.
Explore all the logical operators you can use in DuckDB https://duckdb.org/docs/stable/sql/query_syntax/where
if (FALSE) { # \dontrun{
hosp_dataframe <- data.frame(
episode_id = c(1, 2, 3),
age = c(45, 60, 32),
sex = c("M", "F", "M"),
diagnosis1 = c("F10.10", "I20", "I60"),
diagnosis2 = c("E11", "J45", "I25"),
diagnosis3 = c("I60", "K35", "F10.120")
)
reng <- RuleEngine(hosp_dataframe,"episode_id")
target_columns <- c("diagnosis1")
definition_codes <- c("F10.10","F10.11","F10.120","F10.121")
alcohol_indicator <- IndicR4Health::MatchAll(
reng,
"alcohol_i",
target_columns,
definition_codes
)
custom_alcohol_indicator <- IndicR4Health::CustomMatch(
"alcohol_i_plus40", # Name of the indicator
"alcohol_i AND age >= 40" # Logic of the indicator
)
indicators_list <- list(alcohol_indicator,custom_alcohol_indicator)
IndicR4Health::RunIndicators(reng,
indicators_list,
append_results = FALSE,
csv_path="./results.csv"
)
} # }