measurementCohort()
creates cohorts based on patient records contained
in the measurement table. This function extends the conceptCohort()
as it
allows for measurement values associated with the records to be specified.
If
valueAsConcept
andvalueAsNumber
are NULL then no requirements on of the values associated with measurement records and usingmeasurementCohort()
will lead to the same result as usingconceptCohort()
(so long as all concepts are from the measurement domain).If one of
valueAsConcept
andvalueAsNumber
is not NULL then records will be required to have values that satisfy the requirement specified.If both
valueAsConcept
andvalueAsNumber
are not NULL, records will be required to have values that fulfill either of the requirements
Usage
measurementCohort(
cdm,
conceptSet,
name,
valueAsConcept = NULL,
valueAsNumber = NULL,
table = c("measurement", "observation"),
useRecordsBeforeObservation = FALSE
)
Arguments
- cdm
A cdm reference.
- conceptSet
A conceptSet, which can either be a codelist or a conceptSetExpression.
- name
Name of the new cohort table created in the cdm object.
- valueAsConcept
A vector of cohort IDs used to filter measurements. Only measurements with these values in the
value_as_concept_id
column of the measurement table will be included. If NULL all entries independent of their value as concept will be considered.- valueAsNumber
A list indicating the range of values and the unit they correspond to, as follows: list("unit_concept_id" = c(rangeValue1, rangeValue2)). If no name is supplied in the list, no requirement on unit concept id will be applied. If NULL, all entries independent of their value as number will be included.
- table
Name of OMOP tables to search for records of the concepts provided. Options are "measurement" and/or "observation".
- useRecordsBeforeObservation
If FALSE, only records in observation will be used. If FALSE, records before the start of observation period will be considered, with cohort start date set to the start of their next observation period.
Examples
# \donttest{
library(CohortConstructor)
cdm <- mockCohortConstructor(con = NULL)
cdm$concept <- cdm$concept |>
dplyr::union_all(
dplyr::tibble(
concept_id = c(4326744, 4298393, 45770407, 8876, 4124457),
concept_name = c("Blood pressure", "Systemic blood pressure",
"Baseline blood pressure", "millimeter mercury column",
"Normal range"),
domain_id = "Measurement",
vocabulary_id = c("SNOMED", "SNOMED", "SNOMED", "UCUM", "SNOMED"),
standard_concept = "S",
concept_class_id = c("Observable Entity", "Observable Entity",
"Observable Entity", "Unit", "Qualifier Value"),
concept_code = NA,
valid_start_date = NA,
valid_end_date = NA,
invalid_reason = NA
)
)
#> Warning: ! 1 casted column in concept as do not match expected column type:
#> • `concept_id` from numeric to integer
cdm$measurement <- dplyr::tibble(
measurement_id = 1:4,
person_id = c(1, 1, 2, 3),
measurement_concept_id = c(4326744, 4298393, 4298393, 45770407),
measurement_date = as.Date(c("2000-07-01", "2000-12-11", "2002-09-08",
"2015-02-19")),
measurement_type_concept_id = NA,
value_as_number = c(100, 125, NA, NA),
value_as_concept_id = c(0, 0, 0, 4124457),
unit_concept_id = c(8876, 8876, 0, 0)
)
cdm <- CDMConnector::copyCdmTo(
con = DBI::dbConnect(duckdb::duckdb()),
cdm = cdm, schema = "main")
cdm$cohort <- measurementCohort(
cdm = cdm,
name = "cohort",
conceptSet = list("normal_blood_pressure" = c(4326744, 4298393, 45770407)),
valueAsConcept = c(4124457),
valueAsNumber = list("8876" = c(70, 120)),
useRecordsBeforeObservation = FALSE
)
#> Warning: ! `codelist` casted to integers.
#> Warning: ✖ Domain observation (3 concepts) excluded because table observation is not
#> present in the cdm.
#> ℹ Subsetting table measurement using 3 concepts with domain: measurement.
#> ℹ Combining tables.
#> ℹ Applying measurement requirements.
#> ℹ Getting records in observation.
#> ℹ Creating cohort attributes.
#> ✔ Cohort cohort created.
cdm$cohort
#> # Source: table<cohort> [?? x 4]
#> # Database: DuckDB 1.4.0 [unknown@Linux 6.11.0-1018-azure:R 4.5.1/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> <int> <dbl> <date> <date>
#> 1 1 1 2000-07-01 2000-07-01
# You can also create multiple measurement cohorts, and include records
# outside the observation period.
cdm$cohort2 <- measurementCohort(
cdm = cdm,
name = "cohort2",
conceptSet = list("normal_blood_pressure" = c(4326744, 4298393, 45770407),
"high_blood_pressure" = c(4326744, 4298393, 45770407)),
valueAsConcept = c(4124457),
valueAsNumber = list("8876" = c(70, 120),
"8876" = c(121, 200)),
useRecordsBeforeObservation = FALSE
)
#> Warning: ! `codelist` casted to integers.
#> Warning: ✖ Domain observation (6 concepts) excluded because table observation is not
#> present in the cdm.
#> ℹ Subsetting table measurement using 6 concepts with domain: measurement.
#> ℹ Combining tables.
#> ℹ Applying measurement requirements.
#> ℹ Getting records in observation.
#> ℹ Creating cohort attributes.
#> ✔ Cohort cohort2 created.
cdm$cohort2
#> # Source: table<cohort2> [?? x 4]
#> # Database: DuckDB 1.4.0 [unknown@Linux 6.11.0-1018-azure:R 4.5.1/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> <int> <dbl> <date> <date>
#> 1 1 1 2000-07-01 2000-07-01
#> 2 1 1 2000-12-11 2000-12-11
#> 3 2 1 2000-07-01 2000-07-01
#> 4 2 1 2000-12-11 2000-12-11
# }