# Report-specific parameters
template: plotTemplate.Rmd
templatePackage: clinDataReview
reportTitle: "Laboratory profiles by visit"
reportTitleLevel: 2
split_by: 4

# Dataset of interest
dataFileName: lb.xpt
dataProcessing:
  - annotate:
    - dataset: dm
      vars: ["RFXSTDTC", "ARM", "ARMCD"]
    - vars: VISIT
      varFct: reorder(VISIT, VISITNUM)
    - vars: LBCAT
      varFct: 'ifelse(LBCAT == "", "Not Coded", LBCAT)'
    # combine parameter name and unit
    - vars: LBTESTSP
      varLabel: "Lab Test (Standard Units)"
      varFct: paste0(LBTEST, " (", LBSTRESU, ")")
      
  - filter:
    # safety analysis set: treated-patients
    - var: "RFXSTDTC" 
      value: ""
      rev: true
    # unscheduled visits
    - var: "VISIT"
      valueFct: 'function(x) grep("UNSCHEDULED|AMBUL|RETRIEVAL", x, value = TRUE)'
      rev: true

# Compute number of subjects by visit/treatment/parameter
tableParams:
  var: LBSTRESN
  rowVar: ["LBTESTSP", "VISIT"]
  colVar: ["ARM", "ARMCD"]
  stats: 'n'
tableProcessing:
  - annotate:
    - vars: ARMCD_n
      varFct: 'paste0(ARMCD, ": N = ", n)'

# Looping parameters
loopingVar: ["LBCAT", "LBTESTSP"]

# Plot parameters
plotFunction: "scatterplotClinData"
plotParams:
  xVar: "VISIT"
  yVar: "LBSTRESN"
  xLabVars: ["VISIT", "ARMCD_n"]
  aesPointVar:
    colour: "ARM"
    fill: "ARM"
    shape: "LBNRIND"
  aesLineVar:
    group: "USUBJID"
  scalePars:
    - aesthetic: shape
      values: !r-lazy clinUtils::getPaletteCDISC(x = dataI$LBNRIND, var = "NRIND", type = "shape")
  themePars:
      legend.position: "none"
  width: 1000
  subtitle: "Only scheduled visits are displayed."
