Create lab_cleaning.R - #312
Conversation
Lab cleaning functions for tidypolis
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bfd462cb14
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } else { | ||
| clean_lab_data_regional( | ||
| lab_data, start_date, end_date, | ||
| afp_data, ctry_name, lab_locs_path, use_edav |
There was a problem hiding this comment.
Pass regional cleaner arguments in declared order
The clean_lab_data_regional() call swaps use_edav and lab_locs_path by position, so the default path (lab_locs_path = NULL, use_edav = TRUE) is passed as use_edav = NULL and lab_locs_path = TRUE. In the current implementation this drives get_lab_locs() into the CSV branch and attempts to read TRUE as a file path, which breaks regional cleaning before any data processing occurs. Use named arguments (or reorder the positional args) so use_edav and lab_locs_path are not inverted.
Useful? React with 👍 / 👎.
| } | ||
|
|
||
| if (is.null(afp_data)) { | ||
| lab_data$ctry <- NA |
There was a problem hiding this comment.
Preserve existing country values when AFP data is absent
When afp_data is NULL, impute_missing_lab_geo() unconditionally sets ctry to NA and returns. Downstream logic filters by ctry when ctry_name is provided and also derives WHO region from this field, so this branch effectively disables country filtering and can force incorrect region output whenever callers rely on default afp_data = NULL. This should keep any pre-existing country signal (or fall back to country/Name) instead of blanking ctry for every row.
Useful? React with 👍 / 👎.
Removed the out object and replaced it with lab_data
Enhance lab cleaning with sirfunctions-compatible output, EPID parsing, and future-date handling
Summary
This PR adds a standalone
clean_lab_data()workflow to tidypolis that mirrors the output shape and key derived fields produced bysirfunctions::clean_lab_data(). It supports both WHO-style lab inputs withMasterKeyand regional lab extracts, harmonizes them into a consistent output schema, computes lab turnaround metrics, fills EPID component fields, optionally backfills geography from AFP data, and removes future dates from lab date fields.This PR also adds
load_lab_data()as a helper for loading raw CSV or Excel lab files.What
clean_lab_data()doesclean_lab_data()is the top-level lab cleaning function. It accepts: