Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

measurementCohort - allow valueAsNumber without a unit concept id #387

Closed
edward-burn opened this issue Nov 26, 2024 · 1 comment · Fixed by #388
Closed

measurementCohort - allow valueAsNumber without a unit concept id #387

edward-burn opened this issue Nov 26, 2024 · 1 comment · Fixed by #388

Comments

@edward-burn
Copy link
Collaborator

Would want the second case below to work

library(CohortConstructor)
cdm <- mockCohortConstructor(con = NULL, seed = 1)
cdm$concept <- cdm$concept |>
  dplyr::union_all(
    dplyr::tibble(
      concept_id = c(4326744, 4298393, 45770407, 8876, 4124457, 999999, 123456) |> as.integer(),
      concept_name = c("Blood pressure", "Systemic blood pressure",
                       "Baseline blood pressure", "millimeter mercury column",
                       "Normal range", "Normal", "outObs"),
      domain_id = "Measurement",
      vocabulary_id = c("SNOMED", "SNOMED", "SNOMED", "UCUM", "SNOMED", "SNOMED", "hi"),
      standard_concept = "S",
      concept_class_id = c("Observable Entity", "Observable Entity",
                           "Observable Entity", "Unit", "Qualifier Value",
                           "Qualifier Value", "hi"),
      concept_code = NA,
      valid_start_date = NA,
      valid_end_date = NA,
      invalid_reason = NA
    )
  )
cdm$measurement <- dplyr::tibble(
  measurement_id = 1:3L,
  person_id = as.integer(c(1, 2, 3)),
  measurement_concept_id = c(4326744L, 4326744L, 4326744L),
  measurement_date = as.Date(c("2000-07-01", "2000-12-11", "2002-09-08")),
  measurement_type_concept_id = NA_integer_,
  value_as_number = c(100, 105, 110),
  value_as_concept_id = c(0, 0, 0) ,
  unit_concept_id = c(8876, 8876, 0)
)



measurementCohort(
  cdm = cdm,
  name = "cohort",
  conceptSet = list("normal_blood_pressure" = c(4326744, 4298393, 45770407)),
  valueAsConcept = c(4124457),
  valueAsNumber = list("8876" = c(70L, 120L))
)
#> Warning: ! `codelist` contains numeric values, they are casted to integers.
#> ℹ Subsetting measurement table.
#> ℹ Applying measurement requirements.
#> ! cohort columns will be reordered to match the expected order:
#>   cohort_definition_id, subject_id, cohort_start_date, and cohort_end_date.
#> ℹ Getting records in observation.
#> ℹ Creating cohort attributes.
#> ✔ Cohort cohort created.
#> # A tibble: 2 × 4
#>   cohort_definition_id subject_id cohort_start_date cohort_end_date
#> *                <int>      <int> <date>            <date>         
#> 1                    1          1 2000-07-01        2000-07-01     
#> 2                    1          2 2000-12-11        2000-12-11

# removing unit_concept_id 8876 - should mean any value between 70 and 120 would be included
# and we should now get person 3 included
measurementCohort(
  cdm = cdm,
  name = "cohort",
  conceptSet = list("normal_blood_pressure" = c(4326744L, 4298393L, 45770407L)),
  valueAsConcept = c(4124457),
  valueAsNumber = list(c(70L, 120L))
)
#> Error in `validateValueAsNumber()`:
#> ✖ `valueAsNumber` must be named.
#> ! `valueAsNumber` must be a list with objects of class integer and numeric; it
#>   can not contain NA; it has to be named.
#> Backtrace:
#>     ▆
#>  1. └─CohortConstructor::measurementCohort(...)
#>  2.   └─CohortConstructor:::validateValueAsNumber(valueAsNumber)
#>  3.     └─omopgenerics::assertList(...)
#>  4.       └─omopgenerics:::errorMessage(...)
#>  5.         └─cli::cli_abort(message = message, call = call)
#>  6.           └─rlang::abort(...)

Created on 2024-11-26 with reprex v2.0.2

@edward-burn
Copy link
Collaborator Author

We should though require all named or none - otherwise the unnamed would supersede the named (as it would apply to all)

edward-burn added a commit that referenced this issue Nov 26, 2024
closes #387

Allows valueAsNumber to be unnamed list. But in this case list must only have length 1 (so as to not mix named and unnamed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant