---
output: html_document
---
  
### Participants

The target population ``r target$name`` is defined as:

```{r results='asis', echo=FALSE}
markdown <- tryCatch(
  {CirceR::cohortPrintFriendly(target$expression)}, 
  error = function(e) return('')
)

markdown <- gsub('###', '####',markdown)
cat(markdown)
```

Additional inclusion criteria:
```{r, echo=FALSE, results='asis'}

if(populationSettings$firstExposureOnly){
  cat('\n - Patients are only in the cohort once.  The earliest index date is used per patient. \n')
}

if(restrictPlpDataSettings$washoutPeriod > populationSettings$washoutPeriod){
  washout <- restrictPlpDataSettings$washoutPeriod
} else{
  washout <- populationSettings$washoutPeriod
}

if(!is.null(target$expression)){
if(washout > ParallelLogger::convertJsonToSettings(target$expression)$PrimaryCriteria$ObservationWindow[1]){
  cat('\n - Patients with less than ',
      washout,' days observation prior to index',
      ' are excluded \n')
}
}

if(populationSettings$removeSubjectsWithPriorOutcome){
  cat('\n - Patients with the outcome within ',
      populationSettings$priorOutcomeLookback,' days prior to index',
      ' are excluded \n')
}

if(populationSettings$requireTimeAtRisk){
  cat('\n - Patients who are lost to follow up within ',
      populationSettings$minTimeAtRisk,' days post index',
      ' are excluded \n')
  if(populationSettings$includeAllOutcomes){
  cat('\n - Except patients with the outcome who are lost to follow up within',
      populationSettings$minTimeAtRisk,' days post index',
  ' (they are still included) \n')
  }
}

if(restrictPlpDataSettings$studyStartDate != ""){
  cat('\n - Restrict to patients with an index date on or after ',restrictPlpDataSettings$studyStartDate,' \n')
}

if(restrictPlpDataSettings$studyEndDate != ""){
  cat('\n - Restrict to patients with an index date on or before ',restrictPlpDataSettings$studyEndDate,' \n')
}

  

```

**Sampling**

```{r, echo=FALSE, results='asis'}

if(!is.null(restrictPlpDataSettings$sampleSize)){
  cat('\n Randomly sample ',restrictPlpDataSettings$sampleSize,' patients from the target population \n')
}

if(!is.null(attr(sampleSettings[[1]],"fun"))){
  if(attr(sampleSettings[[1]],"fun") == 'sameData'){
    cat('\n No over/under-sampling of the patients based on class was done \n')
  }
  
  if(attr(sampleSettings[[1]],"fun") != 'sameData'){
    cat('\n An over/under-sampling of the patients based on class was done using ',
        attr(sampleSettings[[1]],"fun"),' with the  settings: \n')

    sampleDat <- data.frame(
      names = names(sampleSettings[[1]]),
      values = unlist(lapply(sampleSettings[[1]], function(x) paste(x, sep='-', collapse = '-')))
    )

    print(knitr::kable(x = sampleDat, caption = paste('Sampling settings')))
  }
}



```

