---
output: html_document
---

```{r get model design, echo=FALSE, results='asis'}

modelDesign <- OhdsiReportGenerator::getPredictionModelDesigns(
  connectionHandler = params$connectionHandler,
  schema = params$resultSchema, 
  plpTablePrefix = params$myTableAppend, 
  cgTablePrefix = params$cohortTableAppend#, 
  #modelDesignId = params$modelDesignIds[i] # need to add this as optional input
  ) %>% 
  dplyr::filter(.data$modelDesignId == !!params$modelDesignIds[i])


target <- list(
  name = modelDesign$developmentTargetName,
  id = modelDesign$developmentTargetId,
  expression = modelDesign$developmentTargetJson
  )
outcome <- list(
  name = modelDesign$developmentOutcomeName,
  id = modelDesign$developmentOutcomeId,
  expression = modelDesign$developmentOutcomeJson
)

populationSettings <- ParallelLogger::convertJsonToSettings(modelDesign$populationSettingsJson)
covariateSettings <- ParallelLogger::convertJsonToSettings(modelDesign$covariateSettingsJson)
featureEngineeringSettings <- ParallelLogger::convertJsonToSettings(modelDesign$featureEngineeringSettingsJson)
preprocessSettings <- ParallelLogger::convertJsonToSettings(modelDesign$tidyCovariatesSettingsJson)
modelSettings <- ParallelLogger::convertJsonToSettings(modelDesign$modelSettingsJson)
sampleSettings <- ParallelLogger::convertJsonToSettings(modelDesign$sampleSettingsJson)
restrictPlpDataSettings <- ParallelLogger::convertJsonToSettings(modelDesign$plpDataSettingsJson)
splitSettings <- ParallelLogger::convertJsonToSettings(modelDesign$splitSettingsJson)
 
```



```{r print model heading, echo=FALSE, results='asis'}
cat('\n# Model ', params$modelDesignIds[i], '\n')
```


## Model Design

```{r participants, child = "plp-participants.Rmd"}
```

```{r predictors, child = "plp-predictors.Rmd"}
```

```{r outcome, child = "plp-outcome.Rmd"}
```

```{r analysis, child = "plp-analysis.Rmd"}
```
