---
title: "Pediatric Complex Chronic Conditions"
author: "Jack O. Wasey"
date: "`r Sys.Date()`"
output:
  html_document:
    toc: yes
vignette: >
  %\VignetteIndexEntry{Pediatric Complex Chronic Conditions}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteDepends{icd.data}
  %\VignetteEncoding{UTF-8}
bibliography: icdpkg.bib
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library("icd")
n <- 10000
set.seed(1441)
dat <- data.frame(id = n + seq(n),
                  icd_dx1 = sample(icd10cm2016$code, n, replace = TRUE),
                  icd_dx2 = sample(icd10cm2016$code, n, replace = TRUE),
                  icd_pcs1 = sample(icd10_pcs_2018$pcs, n, replace = TRUE),
                  icd_pcs2 = sample(icd10_pcs_2018$pcs, n, replace = TRUE)
)
```

# Pediatric Complex Chronic Conditions

## Introduction

The adult comorbidities defined by authors such as Charlson, Quan and Elixhuaser are not suitable for pediatric research. Feudtner and others produced comorbidity definitions suitable for infants and children, with mappings defined for both ICD-9 and ICD-10 codes [@Feinstein_packagepediatriccomplex_2018; Feudtner_Pediatriccomplexchronic_2014]. These are now included in the [icd package](https://cran.r-project.org/package=icd) for R, which enables [fast calculation of comorbidities](introduction.html) for PCCC and other ICD code to comorbidity maps.

## Calculating PCCC comorbidities.

The PCCC comorbidities may be derived from both diagnostic and procedure codes. The following simulated data has both:

```{r headdat}
head(dat)
```
The data is in 'wide' format. Currently `icd` requires it be in 'long' format, which can be achieved as follows:
```{r widelong}
dx <- wide_to_long(dat[1:3])
pcs <- wide_to_long(dat[c(1, 4:5)], icd_name = "pcs", icd_regex = "icd_pcs")
head(dx)
head(pcs)
```
Now the PCCC comorbidity classes can be computed and summarized in a plot:
```{r calc}
pccc_dx <- comorbid_pccc_dx(dx)
pccc_pcs <- icd10_comorbid_pccc_pcs(pcs, 
                                    visit_name = "id", icd_name = "pcs")
res <- pccc_dx | pccc_pcs
```

```{r pcccbarplot, fig.asp=0.5, echo=FALSE}
barplot(sort(colSums(res), decreasing = TRUE), 
        ylim = c(0, 70),
        ylab = "count", las = 2)
```

# References
