OHDSI / Capr

Cohort definition Application Programming in R
https://ohdsi.github.io/Capr
Apache License 2.0
17 stars 11 forks source link

Error when trying to specify unit for measurement #95

Closed schuemie closed 6 months ago

schuemie commented 6 months ago

I can't figure out how to specify a unit for a measurement. Here's my current code:

essentialHypertension <- cs(
  descendants(320128),
  exclude(descendants(3012888)),
  name = "Essential hypertension"
)

sbp <- cs(3004249, name = "SBP")
dbp <- cs(3012888, name = "DBP")
mmHg <- cs(8876, name = "mmHg")

hypertensionCohort <- cohort(
  entry = entry(
    conditionOccurrence(essentialHypertension),
    measurement(sbp, valueAsNumber(gte(130)), unit(mmHg)),
    measurement(dbp, valueAsNumber(gte(80)), unit(mmHg))
  ),
  exit = exit(
    endStrategy = observationExit()
  )
)

which will throw this error:

Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'x' in selecting a method for function 'as.data.frame': argument "name" is missing, with no default
mdlavallee92 commented 6 months ago

I see your thought process....the concept attribute class doesn't take a conceptSet class, it takes on a concept class which is constructed on-the-fly by the function. You just need the concept id as the input for unit.

Better documentation is required....will work on that. Also, will think about vocabulary helper functions to find the concept id that is appropriate to the measurement, something that is non-trivial.

Try this:

essentialHypertension <- cs(
  descendants(320128),
  exclude(descendants(3012888)),
  name = "Essential hypertension"
)

sbp <- cs(3004249, name = "SBP")
dbp <- cs(3012888, name = "DBP")
#mmHg <- cs(8876, name = "mmHg")

hypertensionCohort <- cohort(
  entry = entry(
    conditionOccurrence(essentialHypertension),
    measurement(sbp, valueAsNumber(gte(130)), unit(8876)),
    measurement(dbp, valueAsNumber(gte(80)), unit(8876))
  ),
  exit = exit(
    endStrategy = observationExit()
  )
)
schuemie commented 6 months ago

Thanks!

I'm struggling a bit to figure our what type of values can be used as arguments. Maybe there's a better way to document this?

Anyway, maybe this example could be added to the examples vignette? (Which I find very useful)

mdlavallee92 commented 6 months ago

yeah myself and @rbcavanaugh (who has offered to help with some documentation) will add some more examples of how to use Capr. Sorry about that, planning on having a bit more time to dedicate to Capr coming up!