ramses-antibiotics / ramses-package

R Package for Data-Driven Antimicrobial Stewardship & Surveillance in Hospitals
https://ramses-antibiotics.web.app/
GNU General Public License v3.0
10 stars 1 forks source link

TherapyEpisodes of length > 3: object 'id' not found #100

Closed peterdutey closed 2 years ago

peterdutey commented 2 years ago

Error in show(therapy_object_multi4) : object 'id' not found

conDuckDB <- DBI::dbConnect(duckdb::duckdb(), ":memory:", timezone_out = "UTC")
on.exit({DBI::dbDisconnect(conDuckDB, shutdown = TRUE)})

fake_prescription <- data.frame(
  patient_id = c("5124578766", "5124578767", "5124578768", "5124578769"),
  prescription_id = 111:114,
  prescription_text = "Piperacillin / Tazobactam IVI 4.5 g TDS",
  authoring_date = structure(1438690036,
                             class = c("POSIXct", "POSIXt"),
                             tzone = "Europe/London"),
  prescription_start = structure(1438695916,
                                 class = c("POSIXct", "POSIXt"),
                                 tzone = "Europe/London"),
  prescription_end = structure(1438955116,
                               class = c("POSIXct", "POSIXt"),
                               tzone = "Europe/London"),
  drug_code = "TZP",
  drug_name = "Piperacillin + Tazobactam",
  drug_display_name = "Piperacillin + Tazobactam",
  drug_group = "Beta-lactams/penicillins",
  prescription_status = "completed",
  route = "IV",
  ATC_route = "P",
  ATC_code = "J01CR05",
  prescription_context = "inpatient",
  dose = 4.5,
  unit = "g",
  frequency = "TDS",
  daily_frequency = 3,
  duration = 3,
  antiinfective_type = "antibacterial",
  stringsAsFactors = FALSE
)
dplyr::copy_to(conDuckDB, df = dplyr::tibble(patient_id="5124578766"), 
               name = "patients", temporary = FALSE)
load_medications(conn = conDuckDB,
                 prescriptions = fake_prescription,
                 overwrite = TRUE)
therapy_object_multi4 <- TherapyEpisode(conDuckDB, 111:114)

show(therapy_object_multi4)

# affects all clinical_feature_x() generics due to the tryCatch line first thing