---
title: "The Phoenix Sepsis Criteria"
output:
 rmarkdown::html_vignette:
   toc: true
   toc_depth: 2
   number_sections: false
bibliography: references.bib
vignette: >
 %\VignetteIndexEntry{The Phoenix Sepsis Criteria}
 %\VignetteEngine{knitr::rmarkdown}
 %\VignetteEncoding{UTF-8}
---


```{r label = "setup", include = FALSE}

################################################################################
###                          !!! IMPORTANT NOTE !!!                          ###
###                                                                          ###
###          THIS FILE WAS GENERATED BY vignette-spinners/phoenix.R          ###
###                                                                          ###
###                         MAKE EDITS IN THAT FILE                          ###
################################################################################

library(qwraps2)
options(qwraps2_markup = "markdown")
knitr::opts_chunk$set(collapse = TRUE)
```



```{r}
library(phoenix)
packageVersion("phoenix")
```


# Development and International Consensus

Details on the development of the diagnostic Phoenix Sepsis Criteria are in
[@sanchez_2024_development](https://doi.org/10.1001/jama.2024.0196).  This
manuscript covers the data-driven and modified Delphi process leading to an
international consensus for the criteria
([@schlapbach_2024_international](https://doi.org/10.1001/jama.2024.0179)).

This R package provides utilities to quickly and easily apply the Phoenix
Sepsis scoring rubric to your data sets.

# Phoenix Sepsis and Septic Shock

There are two sets of criteria, the Phoenix and Phoenix 8 criteria.  It was
determined during the development of the criteria that a score based on four
organ systems was sufficient for diagnosis of sepsis and septic shock.  An
extended score based on eight organ systems was reported as well.

**Sepsis Definition:**

A pediatric patient is to be diagnosed as having sepsis if:

1. Suspected/Confirmed infection (receipt of systemic antimicrobials and
microbiological testing with in first 24 hours of hospital presentation), and

2. A total Phoenix Sepsis Score &geq; 2.

**Septic Shock Definition:**

A patient is to be diagnosed as having septic shock if the patient meets the
criteria for sepsis and has any cardiovascular dysfunction (cardiovascular
score &geq; 1).

## Phoenix Scoring

|        | 0 Points | 1 Point | 2 Points | 3 Points |
|:-------|:-------- |:------- |:-------- |:-------- |
|**Respiratory** (0-3 points) | PaO<sub>2</sub>:FiO<sub>2</sub> &geq; 400 and SpO<sub>2</sub>:FiO<sub>2</sub> &geq; 292 | (PaO<sub>2</sub>:FiO<sub>2</sub> &lt; 400 or SpO<sub>2</sub>:FiO<sub>2</sub> &lt; 292) and any respiratory support | (PaO<sub>2</sub>:FiO<sub>2</sub> &lt; 200 or SpO<sub>2</sub>:FiO<sub>2</sub> &lt; 220) and IMV | (PaO<sub>2</sub>:FiO<sub>2</sub> &lt; 100 or SpO<sub>2</sub>:FiO<sub>2</sub> &lt; 148) and IMV |
|**Cardiovascular** (0-6 points) |
|&nbsp;&nbsp; _Vasoactive Medications_ | No medications | 1 medication | 2 or more medications |
|&nbsp;&nbsp; _Lactate_ | [0, 5) mmol/L | [5, 11) mmol/L | [11, &infin;) mmol/L |
|&nbsp;&nbsp; _MAP_ | | | |
|&nbsp;&nbsp;&nbsp;&nbsp;   0 &leq; Age &lt;    1 | [31, &infin;) mmHg | [17, 31) mmHg | [0, 17) mmHg |
|&nbsp;&nbsp;&nbsp;&nbsp;   1 &leq; Age &lt;   12 | [39, &infin;) mmHg | [25, 39) mmHg | [0, 25) mmHg |
|&nbsp;&nbsp;&nbsp;&nbsp;  12 &leq; Age &lt;   24 | [44, &infin;) mmHg | [31, 44) mmHg | [0, 31) mmHg |
|&nbsp;&nbsp;&nbsp;&nbsp;  24 &leq; Age &lt;   60 | [45, &infin;) mmHg | [32, 45) mmHg | [0, 32) mmHg |
|&nbsp;&nbsp;&nbsp;&nbsp;  60 &leq; Age &lt;  144 | [49, &infin;) mmHg | [36, 49) mmHg | [0, 36) mmHg |
|&nbsp;&nbsp;&nbsp;&nbsp; 144 &leq; Age &leq; 216 | [52, &infin;) mmHg | [38, 52) mmHg | [0, 38) mmHg |
|**Coagulation** (0-2 points) | | 1 point each; max 2 |
|&nbsp;&nbsp; Platelets  | [100, &infin;) K/&mu;L | [0, 100) K/&mu;L |
|&nbsp;&nbsp; INR        | [0 , 1.3] | (1.3, &infin;) |
|&nbsp;&nbsp; D-Dimer    | [0, 2] mg/L FEU | (2, &infin;) mg/L FEU |
|&nbsp;&nbsp; Fibrinogen | [100, &infin;) mg/dL | [0, 100) mg/dL |
|**Neurologic** (0-2 points) | GCS &#8712; {11, 12, 13, 14, 15} | GCS &#8712; {3, 4, ..., 10} | Bilaterally fixed pupils |
<small>
  <ul>
    <li>Abbreviations:</li>
      <ul>
        <li> FEU: fibrinogen equivalent units </li>
        <li> FiO<sub>2</sub>: fraction of inspired oxygen </li>
        <li> GCS: Glasgow Coma Score </li>
        <li> IMV: invasive mechanical ventalation</li>
        <li> INR: International normalized ratio </li>
        <li> MAP: mean arterial pressure</li>
        <li> SpO<sub>2</sub>: pulse oximetry oxygen saturation</li>
    </ul>
    <li> Age: measured in months and is not adjusted for prematurity. </li>
    <li> SpO<sub>2</sub> : FiO<sub>2</sub> is only to be used when SpO<sub>2</sub> &leq; 97. </li>
    <li> Vasoactive medications: any systmic dose of dobutamine, dopamine, epinephrine, milrinone, norepinephrine, and/or vasopressin. </li>
    <li> lactate can be arterial or venous.  Reference range 0.5 - 2.2 mmol/L </li>
    <li> MAP - Use measured arterial pressue preferentially (invasive arterial if available, or non-invasive oscillometric), alternatively use the calculation diastolic + (systolic - diastolic) / 3 </li>
    <li> Coagulation variable reference ranges: platelets, 150-450 10<sup>3</sup>/&mu;L; D-dimer, &lt; 0.5 mg/L FEU; fibrinogen, 180-410 mg/dL.  International normalized ratio reference range is based on local reference prothrombintime. </li>
    <li> Neurologi dysfunciton scoring was pragmatically validated in both sedated and onsedated patients and those with and without IMV. </li>
    <li> GCS measures level of consciousness based on verbal, eye, and motor respose.  Values are integers from 3 to 15 with higher scores indicating better neurologic function. </li>
  </ul>
</small>


## Phoenix 8 Scoring

This extended criteria uses the four organ systems above along with four additional organ dysfunction scores.


|        | 0 Points | 1 Point |
|:-------|:-------- |:------- |
|**Endocrine** (0-1 point) | blood glucose &#8712; [50, 150] mg/dL | blood glucose &#8713; [50, 150] mg/dL |
|**Immunologic** (0-1 point) | ANC &geq; 500 and ALC &geq; 1000 cells /mm<sup>3</sup> | ANC &lt; 500 and/or ALC &lt; 1000 cells/mm<sup>3</sup> |
|**Renal** (0-1 point) |
|&nbsp;&nbsp;   0 &leq; Age &lt;    1 | Creatinine &lt; 0.8 mg/dL | Creatinine &geq; 0.8 mg/dL |
|&nbsp;&nbsp;   1 &leq; Age &lt;   12 | Creatinine &lt; 0.3 mg/dL | Creatinine &geq; 0.3 mg/dL |
|&nbsp;&nbsp;  12 &leq; Age &lt;   24 | Creatinine &lt; 0.4 mg/dL | Creatinine &geq; 0.4 mg/dL |
|&nbsp;&nbsp;  24 &leq; Age &lt;   60 | Creatinine &lt; 0.6 mg/dL | Creatinine &geq; 0.6 mg/dL |
|&nbsp;&nbsp;  60 &leq; Age &lt;  144 | Creatinine &lt; 0.7 mg/dL | Creatinine &geq; 0.7 mg/dL |
|&nbsp;&nbsp; 144 &leq; Age &leq; 216 | Creatinine &lt; 1.0 mg/dL | Creatinine &geq; 1.0 mg/dL |
|**Hepatic** (0-1 point) | Total bilirubin &lt; 4 mg/dL and ALT &gt; 102 IU/L | Total bilirubin &geq; 4 mg/dL and/or ALT &gt; 102 IU/L |

<small>
  <ul>
    <li> ANC: Absolute neutrophil count
    <li> ALC: Absolute lymphocyte count
    <li> ALT: alanine aminotransferase
  </ul>
</small>

# Development of the Criteria

Details on the developed of the criteria are described in
@sanchez_2024_development and @schlapbach_2024_international and end users
are encouraged to review these papers.  A couple quick notes about the data
and use in general.  Some specific details will be provided in each of the
sections for each organ system.

**Missing data = 0 points:** During the development of the Phoenix criteria
missing data was mapped to zero points. This was done as it was reasonable to
assume that for some labs and metrics, missing data could indicate that there
was no concern and the testing was not order.  Further, the Phoenix criteria
was developed to be useful in both high, medium, and low resource settings
where some labs and values might be uncommon or impossible to get.  As such,
we encourage end users of this package to do the same - missing values are
missing and should not be imputed.

<center>**__The Phoenix Criteria is valid on "known data"__**</center>

**Worst in first 24 hours:** The score was developed on the worse measured
value during the first 24 hours of an hospital encounter.
For example, consider the following
patient encounter and organ dysfunction scores:

| encounter time | resp | card | coag | neuro | total |
| :------------: | :--: | :--: | :--: | :---: | :---: |
| 0              |  1   |  0   |  0   |   1   |  2    |
| 120            |  0   |  1   |  0   |   1   |  2    |
| 720            |  0   |  0   |  0   |   1   |  1    |

This patient never had a total score exceeding 2 during the first 720 minutes
of the encounter.  However, if we took the max score for the four components
and summed them for the total then the resulting score would be 3.

The development of the Phoenix Criteria was based on the worse total score
observed during the first 24 hours of an encounter.  The correct signal score
for the patient in the above example is 2, not 3.  Please keep this in mind
when you are preparing your data sets.

**Age Restrictions:**
Age measurements are not adjusted for prematurity.  The Phoenix criteria was
developed on non-birth hospitalizations (implication is age &gt; 0), children
when gestational age &gt; 37 weeks; and those aged &leq; 216 months (18
years).

# Package Use

There are functions to apply the Phoenix criteria to a data set for each of
the organ systems and wrappers for full Phoenix and Phoenix-8 scores.

Inputs for the organ dysfunction scoring functions are expected to be
numeric vectors and to have a common length _or_ a length of 1.  For example,
the respiratory score requires four inputs.  The lengths of the inputs could
be
`r  backtick(c(1, 10, 10, 10))  `
indicating that the first input is constant for all other values.  An input
of
`r  backtick(c(2, 10, 10, 10))  `
will result in an error. If you wish to 'recycle' an input of length greater
than 1 and less than the max length of another, then wrap the shorter inputs
in
`r  backtick(rep())  `
for clarity.

In the following subsections example use of the functions require the use of
the provided example synthetic dataset
`r  paste0(backtick(sepsis), ".")  `
This data set has
`r  nrow(sepsis)  `
rows and
`r  ncol(sepsis)  `
variables. See
`r  backtick(?sepsis)  `
for more details.

## Respiratory

### Inputs:
*
`r  backtick(pf_ratio)  `
is the ratio of PaO<sub>2</sub> (partial pressure or oxygen in arterial
blood, units of mmHg) to FiO<sub>2</sub> (fraction of inspiratory oxygen,
values expected to be between 0.21 for room air, to 1.00).  Gathering the
PaO<sub>2</sub> is an invasive procedure.

*
`r  backtick(sf_ratio)  `
The SpO<sub>2</sub> (pulse
oximetry) to FiO<sub>2</sub> ratio is a non-invasive surrogate for the PF
ratio.  Important note: during the development of the Phoenix criteria SF
ratios were only valid to consider if the SpO<sub>2</sub> is &leq; 97.

*
`r  backtick(imv)  `
Invasive mechanical ventilation.  This is an integer valued indicator
variable: 0 = not intubated; 1 = intubated.

*
`r  backtick(other_respiratory_support)  `
Any oxygen support, e.g., high-flow, non-invasive positive pressure, or IMV.

### Scores


```{r echo = FALSE, results = "hide", fig.width = 7, fig.height = 4}
resp_data <-
  expand.grid(pfr = seq(0, 450, by = 10), sfr = seq(0, 450, by = 10), imv = c(0, 1), o2 = c(0, 1))
resp_data$o2 <- pmax(resp_data$imv, resp_data$o2)
resp_data <- unique(resp_data)
resp_data$phoenix_respiratory_score <- factor(phoenix_respiratory(pfr, sfr, imv, o2, data = resp_data))

resp_data$oxygen_support <-
  factor(
    interaction(resp_data$imv, resp_data$o2),
    levels = c("0.0", "0.1", "1.1"),
    labels = c("No Oxygen Support", "Non-invasive Oxygen Support", "Invasive Oxygen Support")
  )

ggplot2::ggplot(data = resp_data) +
  ggplot2::theme_classic() +
  ggplot2::aes(x = sfr, y = pfr, fill = phoenix_respiratory_score) +
  ggplot2::geom_tile() +
  ggplot2::facet_wrap( ~ oxygen_support, nrow = 1) +
  ggplot2::scale_fill_brewer(name = "Phoenix Respiratory Score", palette = "Spectral", direction = -1) +
  ggplot2::ylab(expression(PaO[2] : FiO[2])) +
  ggplot2::xlab(expression(SpO[2] : FiO[2])) +
  ggplot2::theme(legend.position = "bottom")
```


### Example Use

The function
`r  backtick(phoenix_respiratory)  `
will return an integer vector.

A patient with a nasal cannula at 5 L/min (approximate FiO<sub>2</sub> of
0.4) and SpO<sub>2</sub> of 87:

```{r}
phoenix_respiratory(
  sf_ratio = 87 / 0.40,
  other_respiratory_support = 1)
```


Notice that the
`r  backtick(pf_ratio)  `
and
`r  backtick(imv)  `
arguments have been omitted.  When an input is missing it is assumed to be
`r paste0(backtick(NA), ".") `

When your data is in a
`r  backtick(data.frame)  `
then:

```{r}
DF <- read.table(sep = "|", header = TRUE, text =
"
pfr | sfr | imv | o2
    | 438 |     |
    | 175 |     | 1
    | 175 |     | 1
186 |     |  1  | 0
300 | 277 |  0  | 1
    |     |     |
")

DF$resp_score <- phoenix_respiratory(pfr, sfr, imv, o2, DF)

DF
```


Another example using the provided example data set
`r  paste0(backtick(sepsis), ".")  `
Here we have to construct a few variables as we only have information on
FiO<sub>2</sub>, PaO<sub>2</sub>, SpO<sub>2</sub>, and invasive mechanical
ventilation.


```{r}
resp_example <- sepsis[c("pid", "fio2", "pao2", "spo2", "vent")]
```


Implied in this data is other respiratory support when FiO<sub>2</sub> is
greater than 0.21, the approximate fraction of oxygen in the atmosphere.

```{r results = "hide"}
resp_example$score <-
  phoenix_respiratory(
  pf_ratio = pao2 / fio2,
  sf_ratio = ifelse(spo2 <= 97, spo2 / fio2, NA_real_),
  imv = vent,
  other_respiratory_support = as.integer(fio2 > 0.21),
  data = sepsis
  )
resp_example
```



```{r echo = FALSE, results = "asis"}
knitr::kable(resp_example)
```


## Cardiovascular

### Inputs
*
`r  backtick(vasoactives)  `
is an integer count of the number of systemic vasoactive medications the
patient is currently receiving.  During development of the Phoenix criteria
it was found that just the count of the medications was sufficient to be
useful, the dosage was not needed.  There were six medications considered,
dobutamine, dopamine, epinephrine, milrinone, norepinephrine, and
vasopressin.  Again, it is systemic use of the medication that is important.
For example, an injection of epinephrine to halt an allergic reaction would
not count, whereas having an epinephrine drip to treat hypotension or
bradycardia would count.

*
`r  backtick(lactate)  `
level of lactate in the blood, measured in mmol/L

*
`r  backtick(age)  `
in months

*
`r  backtick(map)  `
mean arterial pressure (mmHg).  During development of the Phoenix criteria,
map, and blood pressure values in general, obtained from arterial measures
were used preferentially over values obtained from cuffs.  Reported values
were used preferentially over calculated values.  If you need to calculate
the map use DBP + (1/3) * (SBP - DBP) where DBP is diastolic blood pressure
(mmHg) and SBP is systemic blood pressure (mmHg).

### Scores


```{r echo = FALSE, results = "hide", fig.width = 7, fig.height = 7}
DF <- expand.grid(vasoactives = 0:2,
                  lactate = seq(0, 15, by = 1),
                  age = seq(0, 18 * 12, by = 1),
                  MAP = seq(00, 60, by = ))
DF$phoenix_cardiovascular_score <-
  factor(
    phoenix_cardiovascular(vasoactives, lactate, age, MAP, data = DF)
  )
DF$lactate_bin <- cut(DF$lactate, breaks = c(0, 5, 11, Inf), right = F)
levels(DF$lactate_bin) <- paste("Lactate", levels(DF$lactate_bin))

ggplot2::ggplot(DF) +
  ggplot2::theme_classic() +
  ggplot2::aes(x = age, y = MAP, fill = phoenix_cardiovascular_score) +
  ggplot2::geom_tile() +
  ggplot2::facet_grid(lactate_bin ~ paste("Vasoactive Medications:", vasoactives)) +
  ggplot2::scale_fill_brewer(name = "Phoenix Cardiovascular Score", palette = "Spectral", direction = -1) +
  ggplot2::ylab("Mean Arterial Pressue (mmHg)") +
  ggplot2::xlab("Age (months)") +
  ggplot2::guides(fill = ggplot2::guide_legend(nrow = 1)) +
  ggplot2::theme(legend.position = "bottom")
```


### Example Use


```{r results = "hide"}
card_example <-
  sepsis[c("pid", "dobutamine", "dopamine", "epinephrine", "milrinone", "norepinephrine", "vasopressin", "lactate", "dbp", "sbp", "age")]

card_example$score <-
  phoenix_cardiovascular(
    vasoactives = dobutamine + dopamine + epinephrine + milrinone + norepinephrine + vasopressin,
    lactate = lactate,
    age = age,
    map = dbp + (sbp - dbp)/3,
    data = sepsis)

card_example
```



```{r results = "asis", echo = FALSE}
knitr::kable(card_example)
```


## Coagulation

### Inputs

*
`r  backtick(platelets)  `
in units of 1,000/&mu;L

*
`r  backtick(inr)  `
international normalized ratio; a metric for time require for blood to clot.

*
`r  backtick(d_dimer)  `
in units of mg/L FEU

*
`r  backtick(fibrinogen)  `
in units of mg/dL

### Scores

While there are four components to this score, the maximum number of points
assigned is 2.


```{r echo = FALSE, results = "hide", fig.height = 7, fig.width = 7}
DF <- expand.grid(platelets = c(10, 150),
                  inr = c(1.0, 1.5),
                  d_dimer = c(1.2, 4.0),
                  fib = c(10, 150))
DF$plt_bin <-
  factor(DF$platelets, levels = c(150, 10), labels = c("Platelets >= 100", "Platelets < 100"))

DF$inr_bin <-
  factor(DF$inr, levels = c(1.0, 1.5), labels = c("INR <= 1.3", "INR > 1.3"))

DF$ddm_bin <-
  factor(DF$d_dimer, levels = c(1.2, 4.0), labels = c("D-dimer <= 2", "D-dimer > 2"))

DF$fib_bin <- factor(DF$fib, levels = c(150, 10),
                     labels = c("Fibrinogen >= 100", "Fibrinogen < 100"))

DF$phoenix_coagulation_score <-
  factor(
    phoenix_coagulation(platelets, inr, d_dimer, fib, data = DF)
  )

ggplot2::ggplot(DF) +
  ggplot2::theme_classic() +
  ggplot2::aes(x = plt_bin, y = fib_bin, fill = phoenix_coagulation_score) +
  ggplot2::geom_tile() +
  ggplot2::facet_grid(inr_bin ~ ddm_bin) +
  ggplot2::scale_fill_brewer(name = "Phoenix Coagulation Score", palette = "Spectral", direction = -1) +
  ggplot2::ylab("")+
  ggplot2::xlab("")+
  ggplot2::theme(legend.position = "bottom")
```


### Example Use


```{r results = "hide"}
coag_example <- sepsis[c("pid", "platelets", "inr", "d_dimer", "fibrinogen")]
coag_example$score <-
  phoenix_coagulation(platelets, inr, d_dimer, fibrinogen, data = sepsis)
coag_example
```



```{r echo = FALSE, results = 'asis'}
knitr::kable(coag_example)
```


## Neurologic

### Inputs

*
`r  backtick(gcs)  `
an integer vector for the (total) Glasgow Comma Score.  The total score is
the sum of the eye, verbal, and motor scores.

*
`r  backtick(fixed_pupils)  `
an integer vector of zeros and ones.  1 = bilaterally fixed pupils, 0
otherwise.

### Example Use


```{r results = 'hide'}
neuro_example <- sepsis[c("pid", "gcs_total", "pupil")]
neuro_example$score <-
  phoenix_neurologic(gcs = gcs_total, fixed_pupils = as.integer(pupil == "both-fixed"), data = sepsis)
neuro_example
```



```{r echo = FALSE, results = "asis"}
knitr::kable(neuro_example)
```



## Endocrine

The endocrine criteria is only applicable to the extended Phoenix-8 scoring.

### Inputs
*
`r  backtick(glucose)  `
in mg/dL

### Example Use


```{r results = 'hide'}
endo_example <- sepsis[c("pid", "glucose")]
endo_example$score <- phoenix_endocrine(glucose, data = sepsis)
endo_example
```



```{r echo = FALSE, results = "asis"}
knitr::kable(endo_example)
```


## Immunologic

The immunologic score is only applicable to the extended Phoenix-8 scoring.

### Inputs

*
`r  backtick(anc)  `
in units of 1,000 cells per cubic millimeter
*
`r  backtick(alc)  `
in units of 1,000 cells per cubic millimeter

### Example Use


```{r results = "hide"}
immu_example <- sepsis[c("pid", "anc", "alc")]
immu_example$score <- phoenix_immunologic(anc, alc, sepsis)
immu_example
```



```{r echo = FALSE, results = "asis"}
knitr::kable(immu_example)
```



## Renal

The renal score is only applicable to the extended Phoenix-8 scoring.

### Inputs

*
`r  backtick(creatinine)  `
in units of mg/dL

*
`r  backtick(age)  `
in months

### Example Use


```{r results = "hide"}
renal_example <- sepsis[c("creatinine", "age")]
renal_example$score <- phoenix_renal(creatinine, age, sepsis)
renal_example
```



```{r echo = FALSE, results = "asis"}
knitr::kable(renal_example)
```


## Hepatic

The hepatic score is only applicable to the extended Phoenix-8 scoring.

### Inputs
`r  backtick(bilirubin)  `
total bilirubin in units of mg/dL

`r  backtick(alt)  `
in units of IU/L

### Example Use


```{r results = "hide"}
hep_example <- sepsis[c("pid", "bilirubin", "alt")]
hep_example$score <- phoenix_hepatic(bilirubin, alt, sepsis)
hep_example
```



```{r echo = FALSE, results = "asis"}
knitr::kable(hep_example)
```



## Phoenix

The
`r  backtick(phoenix)  `
function is a wrapper around
`r  paste0(backtick(phoenix_respiratory), ", ", backtick(phoenix_cardiovascular), ", ", backtick(phoenix_coagulation), ", and ", backtick(phoenix_neurologic), ".")  `
Where the individual component scoring functions return integer vectors,
`r  backtick(phoenix)  `
returns a
`r  backtick(data.frame)  `
with a column for each of the component organ dysfunction scores, a total
score, and two indicator columns, one for sepsis (total score &geq; 2) and
another for septic shock (total score &geq; 2 and cardiovascular dysfunction
&geq; 1).

The range of Phoenix Sepsis scores is from 0 to 13.

### Inputs
All of the inputs are the same as for the component organ dysfunction scores.

### Example Use


```{r}
phoenix_scores <-
  phoenix(
    # respiratory
      pf_ratio = pao2 / fio2,
      sf_ratio = ifelse(spo2 <= 97, spo2 / fio2, NA_real_),
      imv = vent,
      other_respiratory_support = as.integer(fio2 > 0.21),
    # cardiovascular
      vasoactives = dobutamine + dopamine + epinephrine + milrinone + norepinephrine + vasopressin,
      lactate = lactate,
      age = age,
      map = dbp + (sbp - dbp)/3,
    # coagulation
      platelets = platelets,
      inr = inr,
      d_dimer = d_dimer,
      fibrinogen = fibrinogen,
    # neurologic
      gcs = gcs_total,
      fixed_pupils = as.integer(pupil == "both-fixed"),
    data = sepsis
  )

str(phoenix_scores)
```


The results as a easy to read table:

```{r echo = FALSE, results = "asis"}
names(phoenix_scores) <- gsub("_", "\n", names(phoenix_scores))
knitr::kable(phoenix_scores, format = "html", align = "c")
```


## Phoenix 8

`r backtick(phoenix8) `
returns a
`r backtick(data.frame) `
with all the columns that
`r backtick(phoenix) `
returns, with the addition of columns for the endocrine, immunologic, renal,
hepatic, and Phoenix-8 total score.

### Inputs
All the same inputs as the individual organ dysfunction scoring functions.
The one minor caveat is that
`r backtick(age) `
is used in the cardiovascular and the renal scores and need only be provided
once when calling
`r paste0(backtick(phoenix8), ".") `

### Example Use


```{r}
phoenix8_scores <-
  phoenix8(
    # respiratory
      pf_ratio = pao2 / fio2,
      sf_ratio = ifelse(spo2 <= 97, spo2 / fio2, NA_real_),
      imv = vent,
      other_respiratory_support = as.integer(fio2 > 0.21),
    # cardiovascular
      vasoactives = dobutamine + dopamine + epinephrine + milrinone + norepinephrine + vasopressin,
      lactate = lactate,
      age = age, # Also used in the renal assessment.
      map = dbp + (sbp - dbp)/3,
    # coagulation
      platelets = platelets,
      inr = inr,
      d_dimer = d_dimer,
      fibrinogen = fibrinogen,
    # neurologic
      gcs = gcs_total,
      fixed_pupils = as.integer(pupil == "both-fixed"),
    # endocrine
      glucose = glucose,
    # immunologic
      anc = anc,
      alc = alc,
    # renal
      creatinine = creatinine,
      # no need to specify age again
    # hepatic
      bilirubin = bilirubin,
      alt = alt,
    data = sepsis
  )

str(phoenix8_scores)
```


The results as a easy to read table:

```{r echo = FALSE, results = "asis"}
names(phoenix8_scores) <- gsub("_", "\n", names(phoenix8_scores))
knitr::kable(phoenix8_scores, format = "html", align = "c")
```



# Clinical Vignettes

These are taken from the supplemental material of
[@sanchez_2024_development](https://doi.org/10.1001/jama.2024.0196)

## Clinical Vignette 1

A previously healthy 3-year-old girl presents to an emergency department in
Lima, Peru, with a temperature of 39&deg;C, tachycardia, and irritability. Blood
pressure with an oscillometric device is 67/32 mmHg (mean arterial pressure
of 43 mmHg). She is given fluid resuscitation per local best practice
guidelines, is started on broad spectrum antibiotics, and blood and urine
cultures are sent. After an hour, she becomes hypotensive again and she is
started on a norepinephrine drip. A complete blood count reveals
leukocytosis, mild anemia, and a platelet count of 95 K/&mu;L.

_Phoenix Sepsis Score:_

* 0 respiratory points (no hypoxemia or respiratory support)
* 2 cardiovascular points (1 for low mean arterial pressure for age, 1 for use of a vasoactive medication)
* 1 coagulation points (for low platelet count)
* 0 neurologic points (irritability would result in a Glasgow
Coma Scale of approximately 14)
* total = 3 points.

_Phoenix Sepsis Criteria:_
The patient has suspected infection, &geq; 2 points of the Phoenix Sepsis Score, and
&geq;1 cardiovascular points, so she meets criteria for septic shock.


```{r}
phoenix(
  vasoactives = 1,  # norepinephrine drip
  map = 32 + (67 - 32) / 3, # 43.667 mmHg
  platelets = 95,
  gcs = 14, # irritability
  age = 3 * 12 # expected input for age is in months
  )
```


## Clinical Vignette 2

A 6-year-old boy with a history of prematurity presents with respiratory
distress to his pediatrician’s office in Tucson, Arizona. He is noted to have
a temperature of 38.7&deg;C, tachypnea, crackles in the left lower quadrant on
chest auscultation, and an oxygen saturation of 89% on room air. He is
started on supplemental oxygen and is transported to the local emergency
department via ambulance. In the emergency department, a chest X-ray shows a
consolidation in the left lower lobe and hazy bilateral lung opacities, so he
is started on antibiotics for a suspected bacterial pneumonia. His
respiratory status worsens, and he is started on non-invasive positive
pressure ventilation. While awaiting to be admitted, his level of
consciousness deteriorates rapidly: with nailbed pressure he only opens his
eyes briefly, moans in pain, and withdraws his hand (Glasgow Coma Scale: 2
for eye response + 2 for verbal response + 4 for motor response = 8). He is
intubated using rapid sequence induction and placed on a conventional
ventilator. During this time, his lowest mean arterial pressure using a
non-invasive oscillometric device is 52 mmHg and he receives a fluid bolus.
He is then transferred to the pediatric intensive care unit where he requires
a high positive end expiratory pressure and an FiO<sub>2</sub> of 0.45 to achieve an
oxygen saturation of 92% (S/F ratio: 204). Complete blood count and lactate
level reveal a platelet count of 120 K/&mu;L and a serum lactate of 2.9 mmol/L.
Given his platelet count below the normal reference range, a coagulation
panel is sent, which reveals an INR of 1.7, a D-Dimer of 4.4 mg/L, and a
fibrinogen of 120 mg/dL.

_Phoenix Sepsis Score:_

* 2 respiratory points (for an S/F ratio &lt;292 on invasive mechanical ventilator)
* 0 cardiovascular points (mean arterial pressure &gt;48 mmHg and Lactate level &lt;5 mmol/L)
* 2 coagulation points (for high INR and D-Dimer)
* 1 neurologic point (Glasgow Coma Scale &leq;10)
* total = 5 points.

_Phoenix Sepsis Criteria:_ The patient has a suspected
infection, &geq;2 points of the Phoenix Sepsis Score, and 0 cardiovascular
points, so he meets criteria for sepsis.


```{r}
phoenix(
  gcs = 2 + 2 + 4, # eye + verbal + motor
  map = 52,
  imv = 1,
  sf_ratio = 92 / 0.45,
  platelets = 120,
  lactate = 2.9,
  inr = 1.7,
  d_dimer = 4.4,
  fibrinogen = 120)
```


# References
<div id="refs"></div>



