Skip to content

Commit

Permalink
docs: attributes and values should be in ASCII encoding
Browse files Browse the repository at this point in the history
see #58
  • Loading branch information
aviezerl committed Dec 23, 2021
1 parent b68efe3 commit 69558c7
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 3 deletions.
2 changes: 2 additions & 0 deletions R/track.R
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ emr_track.attr.rm <- function(track = NULL, attr = NULL) {
#' This function creates a track attribute and assigns 'value' to it. If the
#' attribute already exists its value is overwritten.
#'
#' Note that both attributes and values sould be in ASCII encoding.
#'
#' @param track track name
#' @param attr attribute name
#' @param value value
Expand Down
2 changes: 2 additions & 0 deletions man/emr_track.attr.set.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/EMRTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ EMRTrack::TrackAttrs EMRTrack::load_attrs(const char *, const char *filename)
} else {
if (idx) {
if (name.empty() || val.empty())
TGLError<EMRTrack>(BAD_FORMAT, "Invalid format of attributes file %s", filename);
TGLError<EMRTrack>(BAD_FORMAT, "Invalid format of attributes file %s (1)", filename);

if (attrs.find(name) != attrs.end()) // duplicated attributes
TGLError<EMRTrack>(BAD_FORMAT, "Invalid format of attributes file %s", filename);
TGLError<EMRTrack>(BAD_FORMAT, "Invalid format of attributes file %s (2)", filename);

attrs[name] = val;
name.clear();
Expand All @@ -210,7 +210,7 @@ EMRTrack::TrackAttrs EMRTrack::load_attrs(const char *, const char *filename)
TGLError<EMRTrack>(FILE_ERROR, "Failed to read attributes file %s: %s", filename, strerror(errno));

if (idx)
TGLError<EMRTrack>(BAD_FORMAT, "Invalid format of attributes file %s", filename);
TGLError<EMRTrack>(BAD_FORMAT, "Invalid format of attributes file %s (3)", filename);
return attrs;
}

Expand Down
81 changes: 81 additions & 0 deletions tests/testthat/mock_tests.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
mock <- "/net/mraid14/export/tgdata/db/tgdb/emr/mock/"
tmp <- tempdir()
emr_db.connect(c(mock, tmp))

## 1 anemia

withr::local_options(list(emr_max.data.size = 1e9))
emr_filter.create("female", "patients.female", time.shift = c(-years(120), 0))
emr_filter.create("male", "patients.male", time.shift = c(-years(120), 0))
hgb_female <- emr_screen("lab.103 < 12", filter = "female", keepref = TRUE)
hgb_male <- emr_screen("lab.103 < 14", filter = "male", keepref = TRUE)
emr_filter.create("abnormal_hgb_female", hgb_female %>% dplyr::distinct(id, time))
emr_filter.create("abnormal_hgb_male", hgb_male %>% dplyr::distinct(id, time))
emr_track.create("anemia",
categorical = FALSE, expr = "lab.103",
filter = "abnormal_hgb_female | abnormal_hgb_male"
)
# 14.642 seconds
a <- emr_extract("anemia", names = "v")

withr::local_options(list(emr_max.data.size = 1e9))
emr_filter.create("female", "patients.female", time.shift = c(-years(120), 0))
emr_filter.create("male", "patients.male", time.shift = c(-years(120), 0))
emr_filter.create("abnormal_hgb_female", src = "lab.103", val = 12, operator = "<")
emr_filter.create("abnormal_hgb_male", src = "lab.103", val = 14, operator = "<")
emr_track.create("anemia1",
categorical = FALSE, expr = "lab.103",
filter = "(female & abnormal_hgb_female) | (male & abnormal_hgb_male)"
)
# 5.504 seconds

b <- emr_extract("anemia1", names = "v")
expect_equal(a, b)

## 3 abnormal hematocrit second time
withr::local_options(list(emr_max.data.size = 1e9))
emr_filter.create("female", "patients.female", time.shift = c(-years(120), 0))
emr_filter.create("male", "patients.male", time.shift = c(-years(120), 0))
hct_female_48 <- emr_screen("lab.104 > 48", filter = "female", keepref = TRUE)
hct_male_49 <- emr_screen("lab.104 > 49", filter = "male", keepref = TRUE)
emr_filter.create("abnormal_hct_female_past", hct_female_48 %>% dplyr::distinct(id, time), time.shift = c(-years(3), -1))
emr_filter.create("abnormal_hct_male_past", hct_male_49 %>% dplyr::distinct(id, time), time.shift = c(-years(3), -1))
emr_filter.create("abnormal_hct_female_current", hct_female_48 %>% dplyr::distinct(id, time))
emr_filter.create("abnormal_hct_male_current", hct_male_49 %>% dplyr::distinct(id, time))
emr_track.create("abnormal_hct_second_time",
categorical = FALSE, expr = "lab.104",
filter = "(abnormal_hct_female_past & abnormal_hct_female_current) | (abnormal_hct_male_past & abnormal_hct_male_current)"
)
# 3.339 seconds

a <- emr_extract("abnormal_hct_second_time", names = "v")

emr_filter.clear()
withr::local_options(list(emr_max.data.size = 1e9))
emr_filter.create("female", "patients.female", time.shift = c(-years(120), 0))
emr_filter.create("male", "patients.male", time.shift = c(-years(120), 0))
emr_filter.create("abnormal_hct_female", src = "lab.104", val = 48, operator = ">")
emr_filter.create("abnormal_hct_male", src = "lab.104", val = 49, operator = ">")
emr_vtrack.create("abnormal_hct_past", src = "lab.104", filter = "(female & abnormal_hct_female) | (male & abnormal_hct_male)", time.shift = c(-years(3), -1))
emr_track.create("abnormal_hct_second_time1",
categorical = FALSE, expr = "lab.104",
filter = "abnormal_hct_past & ((female & abnormal_hct_female) | (male & abnormal_hct_male))", iterator = "lab.104"
)
# 2.222 seconds

b <- emr_extract("abnormal_hct_second_time1", names = "v")
expect_equal(a, b)

withr::local_options(list(emr_max.data.size = 1e9))
emr_filter.clear()
emr_filter.create("female", "patients.female", time.shift = c(-years(120), 0))
emr_filter.create("male", "patients.male", time.shift = c(-years(120), 0))
emr_filter.create("abnormal_hct_female", src = "lab.104", val = 48, operator = ">")
emr_filter.create("abnormal_hct_male", src = "lab.104", val = 49, operator = ">")
emr_vtrack.create("num_abnormal_hct", src = "lab.104", func = "size", filter = "(female & abnormal_hct_female) | (male & abnormal_hct_male)", time.shift = c(-years(3), 0))
emr_filter.create("abnormal_hct_twice", src = "num_abnormal_hct", val = 2, operator = ">=")
emr_track.create("abnormal_hct_second_time2", categorical = FALSE, expr = "lab.104", filter = "abnormal_hct_twice & ((female & abnormal_hct_female) | (male & abnormal_hct_male))", iterator = "lab.104")
# 2.347 seconds

d <- emr_extract("abnormal_hct_second_time2", names = "v")
expect_equal(a, d)

0 comments on commit 69558c7

Please sign in to comment.