ddediu / AdhereR

Computation of adherence to medications from Electronic Healthcare Data in R
25 stars 6 forks source link

Medication group names starting with a digit (or any other weird character) #162

Closed ddediu closed 3 years ago

ddediu commented 3 years ago

Reproducible example:

dfViZCheck <- structure(list(CHI = c(2645301355, 2645301355, 2645301355, 2645301355, 2645301355, 2645301355, 2645301355),
                             AdhereRLabel2 = c("0403 Citalopram",
                                               "0204 Propranolol hydrochloride", "0403 Citalopram", "0501 Flucloxacillin",
                                               "0501 Nitrofurantoin", "0901 Cyanocobalamin", "0901 Folic acid"),
                             DisDate = structure(c(1507593600, 1507593600, 1511395200, 563408000, 1564704000, 1583884800, 1583884800),
                                                 tzone = "UTC", class = c("POSIXct", "POSIXt")),
                             MarkerLength = c(56, 28, 56, 5, 7, 1e-06, 1e-06),
                             Quantity = c(56, 84, 56, 20, 28, 100, 84),
                             PISSectionCode = c("0403","0204", "0403", "0501", "0501", "0901", "0901"),
                             AN = c("CITALOPRAM", "PROPRANOLOL HYDROCHLORIDE", "CITALOPRAM", "FLUCLOXACILLIN", "NITROFURANTOIN", "CYANOCOBALAMIN", "FOLIC ACID")),
                        row.names = c(NA, -7L),
                        class = c("tbl_df", "tbl", "data.frame"));

medgroupsdf_FAIL <- c('04something' = "(PISSectionCode == '0403')",
                      '04somethingFLUX' = "({04something} | AN == 'FLUCLOXACILLIN')",
                      '04somethingFLUXLT50' = "({04somethingFLUX} & Quantity < 50)",
                      'Not04something' = "(!{04something})")

mg_test_FAIL <- AdhereR:::.apply.medication.groups(medication.groups=medgroupsdf_FAIL, data=dfViZCheck, suppress.warnings=FALSE);

cma1_types_FAIL <- CMA1(data=dfViZCheck,
                        ID.colname="CHI",
                        event.date.colname="DisDate",
                        event.duration.colname="MarkerLength",
                        medication.groups=medgroupsdf_FAIL,
                        date.format="%m/%d/%Y");
cma1_types_FAIL;
getMGs(cma1_types_FAIL);
getCMA(cma1_types_FAIL);
plot(cma1_types_FAIL, show.legend=FALSE)
plot_interactive_cma(data=dfViZCheck,
                     cma.class = "simple",
                     ID.colname="CHI",
                     event.date.colname="DisDate",
                     event.duration.colname="MarkerLength",
                     medication.groups = medgroupsdf_FAIL,
                     date.format="%m/%d/%Y")

cma0_types_FAIL <- CMA0(data=dfViZCheck,
                        ID.colname="CHI",
                        event.date.colname="DisDate",
                        event.duration.colname="MarkerLength",
                        medication.groups=medgroupsdf_FAIL,
                        date.format="%m/%d/%Y");
cma0_types_FAIL;
getMGs(cma0_types_FAIL);
getCMA(cma0_types_FAIL);
plot(cma0_types_FAIL, show.legend=FALSE)

medgroupsdf_OK <- c('ohfoursomething' = "(PISSectionCode == '0403')",
                    'ohfoursomethingFLUX' = "({ohfoursomething} | AN == 'FLUCLOXACILLIN')",
                    'ohfoursomethingFLUXLT50' = "({ohfoursomethingFLUX} & Quantity < 50)",
                    'Not04something' = "(!{ohfoursomething})")

mg_test_OK <- AdhereR:::.apply.medication.groups(medication.groups=medgroupsdf_OK, data=dfViZCheck, suppress.warnings=FALSE);

cma1_types_OK <- CMA1(data=dfViZCheck,
                        ID.colname="CHI",
                        event.date.colname="DisDate",
                        event.duration.colname="MarkerLength",
                        medication.groups=medgroupsdf_OK,
                        date.format="%m/%d/%Y");
cma1_types_OK;
getMGs(cma1_types_OK);
getCMA(cma1_types_OK);
plot(cma1_types_OK, show.legend=FALSE)
plot_interactive_cma(data=dfViZCheck,
                     cma.class = "simple",
                     ID.colname="CHI",
                     event.date.colname="DisDate",
                     event.duration.colname="MarkerLength",
                     medication.groups = medgroupsdf_OK,
                     date.format="%m/%d/%Y")

cma0_types_OK <- CMA0(data=dfViZCheck,
                      ID.colname="CHI",
                      event.date.colname="DisDate",
                      event.duration.colname="MarkerLength",
                      medication.groups=medgroupsdf_OK,
                      date.format="%m/%d/%Y");
cma0_types_OK;
getMGs(cma0_types_OK);
getCMA(cma0_types_OK);
plot(cma0_types_OK, show.legend=FALSE)
ddediu commented 3 years ago

Fixed ?