whichPatientDrug.joins: Identify which patients have anti-microbial resistance and...

Description Usage Arguments Details Author(s) See Also Examples

View source: R/hospCodesFns.R

Description

Patients are grouped into either tested to be resistant, susceptible or not tested against a specific antibiotic.

Usage

1
whichPatientDrug.joins(inf.drug.data, drugGuideline.data)

Arguments

inf.drug.data

data for each patient

drugGuideline.data

look-up table of guidline drugs for each organism

Details

This is an alternative to the original whichPatientDrug function which uses loops rather than the joining operations.

Author(s)

N Green

See Also

whichPatientDrug

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (inf.drug.data, drugGuideline.data) 
{
    lookup <- drugGuideline.data[, c("suspected_organism", "Generic.Antimicrobial.Code")]
    colnames(lookup) <- c("organism", "drug")
    lookup <- lookup[!duplicated(lookup), ]
    colnames(inf.drug.data) <- drug.names
    inf.drug.data$patient <- rownames(inf.drug.data)
    inf.drug.data <- cbind(inf.drug.data, organism = inf.data$lab_group)
    moltendata <- melt(inf.drug.data, id = c("patient", "organism"))
    colnames(moltendata) <- c("patient", "organism", "drug", 
        "value")
    moltendata <- moltendata[order(moltendata$patient), ]
    lookup <- apply(lookup, 2, toupper)
    moltendata <- apply(moltendata, 2, toupper)
    GLoutput <- merge(moltendata, lookup, by = c("drug", "organism"))
    GLoutput <- subset(GLoutput, select = c("drug", "patient", 
        "value"))
    GLoutput.generic <- merge(moltendata, lookup[lookup[, "organism"] == 
        "", ], by = "drug")
    GLoutput.generic <- subset(GLoutput.generic, select = c("drug", 
        "patient", "value"))
    GLoutput <- rbind(GLoutput, GLoutput.generic)
    GLoutput$patient <- as.numeric(as.character(GLoutput$patient))
    GLoutput <- GLoutput[order(GLoutput$patient), ]
    GLoutput <- GLoutput[!duplicated(GLoutput), ]
    GLstrata <- list()
    GLstrata$res <- GLoutput[GLoutput$value == 1 & !is.na(GLoutput$value), 
        ]
    GLstrata$sus <- GLoutput[GLoutput$value == 0 & !is.na(GLoutput$value), 
        ]
    GLstrata$notest <- GLoutput[is.na(GLoutput$value), ]
    return(GLstrata)
  }

n8thangreen/HESmanip documentation built on March 21, 2020, 12:20 a.m.