Skip to contents

Scores a per-subject table of instrument responses into a list of ClinicalScore objects, each tagged with its subject_id, ready to drive the FHIR / OMOP / CDISC exporters (writeFHIRBundle(), toOMOP(), toCDISC_QS()) directly. The subject_col and item columns can come straight from a cohort's data (e.g. a PhysioCohort subject table joined to captured responses).

Usage

scoreCohort(
  responses,
  instrument,
  subject_col = "subject_id",
  timestamp_col = NULL,
  missing = c("error", "prorate", "na")
)

Arguments

responses

A data.frame: one row per subject, with a subject-id column and one column per instrument item (columns not matching an item are ignored).

instrument

A ClinicalInstrument or an instrument id (resolved via getInstrument()).

subject_col

Name of the subject-id column (default "subject_id").

timestamp_col

Optional name of a timestamp column stored on each score.

missing

Missing-data policy passed to scoreInstrument() (default "error"; use "prorate" / "na" when only some items are present).

Value

A named list (by subject id) of ClinicalScore objects.

Examples

items <- getInstrument("katz_adl")@items
resp <- data.frame(subject_id = c("P01", "P02"),
  stats::setNames(as.data.frame(rbind(rep(1, 6), c(1, 0, 1, 1, 0, 1))), items))
scores <- scoreCohort(resp, "katz_adl")
vapply(scores, function(s) s@total, numeric(1))
#> P01 P02 
#>   6   4