1
.onLoad <- function(libname = find.package("cleanEHR"), pkgname = "cleanEHR") {
2 0
    env <- parent.env(environment())
3
    
4
    # Assign ITEM_REF tables
5 0
    utils::data("ITEM_REFTABLE", package="cleanEHR", envir=env)
6 0
    utils::data('icnarc_table', package="cleanEHR")
7

8 0
    ITEM_REF <- yaml.load_file(system.file("conf/ITEM_REF.yaml", package="cleanEHR"))
9 0
    assign("ITEM_REF", ITEM_REF, envir=env)
10

11 0
    icnarc.dict <- as.character(icnarc_table$diagosis)
12 0
    names(icnarc.dict) <- as.character(icnarc_table$code)
13
    
14 0
    assign("icnarc.dict", icnarc.dict, envir=env)
15
  
16

17 0
    unit.dict <- unlist(sapply(ITEM_REF, function(x) x$Units))
18 0
    assign("unit.dict", unit.dict, envir=env)
19

20
    # Build up short name / NIHR code / Classification conversion dictionary
21 0
    reverse.name.value <- function(vec) {
22 0
        new <- names(vec)
23 0
        names(new) <- vec
24 0
        return(new)
25
    }
26

27 0
    stname <- vapply(ITEM_REF, function(x) x$shortName, "")
28 0
    meta <- paste0(stname, ".meta")
29 0
    names(meta) <- paste0(names(stname), ".meta")
30 0
    code2stname.dict <- c(stname, meta)
31 0
    stname2code.dict <- reverse.name.value(code2stname.dict)
32

33

34 0
    longnames <- vapply(ITEM_REF, function(x) x$dataItem, "")
35 0
    stname2longname.dict <- longnames
36 0
    names(stname2longname.dict) <- stname
37 0
    long2stname.dict <- reverse.name.value(stname2longname.dict)
38

39
    # classification dictionary: demographic, nurse, physiology, laboratory, drugs
40 0
    class.dict_code <-  vapply(ITEM_REF, function(x) x$Classification1, "")
41 0
    class.dict_stname <- class.dict_code
42 0
    names(class.dict_stname) <- as.character(code2stname.dict[class.dict_stname])
43

44
    # Time variable dictionary
45 0
    tval.dict_code <- data.checklist$NHICdtCode != "NULL" 
46 0
    tval.dict_stname <- tval.dict_code
47 0
    names(tval.dict_stname) <- as.character(data.checklist$NHICcode)
48 0
    names(tval.dict_code) <- as.character(data.checklist$NHICcode)
49

50 0
    assign("ITEM_REF"         , ITEM_REF         , envir=env) 
51 0
    assign("code2stname.dict" , code2stname.dict , envir=env) 
52 0
    assign("stname2code.dict" , stname2code.dict , envir=env) 
53 0
    assign("stname2longname.dict" , stname2longname.dict , envir=env) 
54 0
    assign("long2stname.dict" , long2stname.dict , envir=env) 
55 0
    assign("class.dict_code"  , class.dict_code  , envir=env)
56 0
    assign("class.dict_stname", class.dict_stname, envir=env) 
57 0
    assign("tval.dict_code"   , tval.dict_code   , envir=env) 
58 0
    assign("tval.dict_stname" , tval.dict_stname , envir=env) 
59

60 0
    assign('checklist', extract_index_table(), envir=env)
61
}

Read our documentation on viewing source code .

Loading