Open
Conversation
This was
linked to
issues
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello Doug,
Hope you are doing well. I have completely refactored how medications are recoded in the CHMS by addressing CRAN-blocking issues 13 and 15. Here is what has been done:
Issue #13 — Circular/self-referential medication metadata
The old medication variables (
any_htn_med2,diab_med2) were referenced by downstream functions inR/blood-pressure.RandR/diabetes.Rusing the old naming convention. These have been replaced throughout:any_htn_med2→any_htn_medanddiab_med2→diab_medin all HTN and diabetes functions (derive_diabetes_status(),derive_hypertension(),derive_hypertension_adj(),derive_hypertension_control(),derive_hypertension_control_adj()) and theirman/docsinst/extdata/variable-details.csvupdated with clean, non-circular entries forany_htn_medanddiab_medacross three database tiers:cycle1_meds/cycle2_meds—DerivedVar::derived from 80atc_*/mhr_*columns viaFunc::is_*_cycles1to2cycle3_meds–cycle6_meds—DerivedVar::derived frommeucatc/npi_25bviaFunc::is_*cycle1–cycle6—copypassthrough once the column has been merged into the main cycle data byrecode_meds_*()inst/extdata/variables.csvupdated to match;data/variable_details.rdaanddata/variables.rdaregenerated from the updated CSVsIssue #15 — No aggregation wrapper for cycles 3-6
Cycles 3-6 store medications in long format (one row per medication per respondent). Previously users had to manually recode, aggregate, and join in three separate steps. Three new wrapper functions now handle the full pipeline:
recode_meds_cycles1to2(data, meds_data, variables, ...)Accepts the main cycle data frame and the wide-format medication data frame (up to 80
atc_*/mhr_*column pairs). Normalises uppercase column names, recodes viarec_with_table(), converts to numeric, and left-joins medication columns back intodata. Returns the enriched main data frame.recode_meds_cycles3to6(data, meds_data, variables, ...)Accepts the main cycle data frame and the long-format medication data frame. Recodes via
rec_with_table(), aggregates to one row per respondent viaaggregate_meds_by_person(), and left-joins intodata. Returns the enriched main data frame.aggregate_meds_by_person(data, variables, by)Collapses long-format medication data to one row per respondent using
max(). All-NArows becometagged_na("b").Both recode functions share the same call signature, so the workflow is identical regardless of cycle:
Additional fixes
recode_after_meds()— fixed two issues: (1) medication rows are filtered out ofvariable_detailsbefore callingrec_with_table(), so pre-computed medication columns are passed through via thecopyentries rather than re-derived; (2)clinicidwas being silently dropped because it was not included in thevariablesargument passed torec_with_table()and therefore not returned in the output; restored viadplyr::bind_cols(data[, by, drop = FALSE], recoded).Changes
inst/extdata/variable-details.csvany_htn_med2/diab_med2entries withDerivedVarrows for_medsdatabases andcopyrows for main cycle databasesinst/extdata/variables.csvdata/variable_details.rda,data/variables.rdaR/blood-pressure.Rany_htn_med2→any_htn_medthroughout all HTN functionsR/diabetes.Rdiab_med2→diab_medthroughout diabetes functionsR/medications.Rrecode_after_meds()clinicidfix; ordered cycles 1-2 → cycles 3-6man/vignettes/recoding_medications.qmdis_*usage); all chunks now execute;library()calls consolidated into setup chunktests/testthat/test-medications.Rclinicidpresence assertion added; ordered cycles 1-2 → cycles 3-6Test plan
devtools::check()passes with 0 errors, 0 warnings, 0 notesrecode_meds_cycles1to2()merges medication columns into main data framerecode_meds_cycles3to6()aggregates and merges medication columns into main data framerecode_after_meds()output containsclinicidrecode_after_meds()does not re-derive medication variablesany_htn_med/diab_medwithout errorPlease let me know what you think.
Sincerely,
Rafidul