---
output: html_document
---


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

sql <- "select distinct 
               p.development_database_id as dbval,
               dm.cdm_source_abbreviation as dbname
      from 
      @result_schema.@my_table_appendperformances p
      inner join @result_schema.@my_table_appenddatabase_details d
      on d.database_id = p.development_database_id
      inner join @result_schema.@database_table_appenddatabase_meta_data dm
      on d.database_meta_data_id = dm.database_id
      where p.model_design_id = @model_design_id 
      and p.model_development = 1 
      ;
    "
 
  res <- connectionHandler$queryDb(
    sql = sql, 
    result_schema = params$resultSchema,
    my_table_append = params$myTableAppend,
    database_table_append = params$databaseTableAppend,
    model_design_id = params$modelDesignIds[i]
  )
  
  # get all the databases with models
  devDatabases <- res$dbval

    if(length(devDatabases)>0){
    for (databaseInd in 1:length(devDatabases)) {
      devDatabase <- devDatabases[databaseInd]
      
      cat('\n## ', paste0(res$dbname[databaseInd], ' model results'), '\n')
      
      internalRes <- knitr::knit_child("plp-results-internal.Rmd", quiet = TRUE, envir = environment())
      cat(internalRes, sep = '\n')
      
      externalRes <- knitr::knit_child("plp-results-external.Rmd", quiet = TRUE, envir = environment())
      cat(externalRes  , sep = '\n')
      

    }
    }

```
