mirror of
https://github.com/msberends/AMR.git
synced 2026-03-05 22:44:54 +01:00
Claude/fix issue 245 (#262)
* fix: restore valid AB codes mangled by generalise_antibiotic_name() (#245) When as.ab() received a vector containing both valid AB codes (like ETH, PHN, PHE, STH, THA, MTH, THI1) and an untranslatable value, the fast path at line 100 was skipped. The slow path then applied generalise_antibiotic_name(), which rewrites "TH"->"T" and "PH"->"F", mangling these short AB codes (e.g. ETH->"ET", PHN->"FN") so they could no longer be found in the lookup table. Fix: save the pre-generalised values before applying generalise_antibiotic_name(), then restore any elements that were already valid AB codes in their original form. https://claude.ai/code/session_01Sujw89qa48NoUmMPDBJLz9 * fix: use toupper() in AB code restoration to handle lowercase input (#245) Ensures that lowercase user input (e.g. 'eth', 'phn') is matched case-insensitively against the uppercase AB codes in $ab, and that the restored value is stored in uppercase to match the lookup table. https://claude.ai/code/session_01Sujw89qa48NoUmMPDBJLz9 * revert: remove unnecessary toupper() since x is already uppercased https://claude.ai/code/session_01Sujw89qa48NoUmMPDBJLz9 * Revise versioning and date bump requirements for PRs Updated versioning instructions for pull requests to include date bump. --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
7
R/ab.R
7
R/ab.R
@@ -119,7 +119,14 @@ as.ab <- function(x, flag_multiple_results = TRUE, language = get_AMR_locale(),
|
||||
x[x %like_case% "^PENICILLIN" & x %unlike_case% "[ /+-]"] <- "benzylpenicillin"
|
||||
x_bak_clean <- x
|
||||
if (already_regex == FALSE) {
|
||||
x_bak_clean_before_gen <- x_bak_clean
|
||||
x_bak_clean <- generalise_antibiotic_name(x_bak_clean)
|
||||
# generalise_antibiotic_name() rewrites "PH"->"F" and "TH"->"T", which
|
||||
# mangles short valid AB codes (e.g. "ETH"->"ET", "PHN"->"FN", "STH"->"ST")
|
||||
# making them unrecognisable in the lookup. Restore any values that were
|
||||
# already valid AB codes before generalisation (#245).
|
||||
is_valid_ab_code <- x_bak_clean_before_gen %in% AMR_env$AB_lookup$ab
|
||||
x_bak_clean[is_valid_ab_code] <- x_bak_clean_before_gen[is_valid_ab_code]
|
||||
}
|
||||
|
||||
x <- unique(x_bak_clean) # this means that every x is in fact generalise_antibiotic_name(x)
|
||||
|
||||
Reference in New Issue
Block a user