---
title: "Liver transplant risk stratification"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{liver_transplant_risk_stratification}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

# Introduction

## Adult risk stratification

The **MELD** score was originally developed at the Mayo Clinic to risk stratify elective transhepatic porto-systemic shunt (TIPS) procedures in patients with liver cirrhosis(_1_). It has also been widely used as part of clinical urgency prioritisation in liver transplant matching algorithms, although UNOS changed to the alternative **MELD-Na** score(_2_), which incorporates serum sodium levels, in January 2016. The scores have been shown to predict short-term mortality after transhepatic porto-systemic shunt (TIPS) procedure, non-liver transplant surgery in cirrhotic patients, acute alcoholic hepatitis and acute variceal haemorrhage.

The **UKELD** score was developed to risk stratify liver transplant recipients in the UK, is based on MELD and adds serum sodium(_3_).

MELD and UKELD are primarily intended to predict waiting list mortality and therefore urgency for transplant, but perform relatively poorly at predicting survival after liver transplant(_4-6_). The **SOFT** (Survival Outcomes Following Liver Transplantation) Score was developed by at Columbia University to predict recipient survival after liver transplantation(_7_). Another score using a composite of donor and recipient characteristics is the **BAR** (Balance of Risk) score, which is based on a sample of American and European liver transplants and achieved a c-statistic of 0.7 when predicting patient  survival(_8_).

There are also two scores using donor characteristics to predict outcome, the **DRI** (Donor Risk Index) developed in the USA(_9_), and the derivative **ET-DRI** (Eurotransplant Donor Risk Index) adapted to the European donor population, which achieved a c-statistic of and 0.626 in the European population(_10_).

## Risk stratification in children

As the adult formulae do not work well at predicting outcomes in children, the **PELD** score was developed to predict waiting list mortality(_11_), and **Pedi-SOFT** to predict outcome after transplantation(_12_).

```{r setup}
library(transplantr)
library(dplyr)
```

# MELD and MELD-Na scores

The original MELD score uses serum creatinine, bilirubin and INR, but cannot be simply calculated as creatinine and bilirubin values are set to specific numbers when outside a set range. Creatinine <1mg/dl is entered as 1, or >4mg/dl as 4, and patients who are either on CVVH or have been dialysed twice in the week prior to the calculation are assigned a fixed value of 4mg/dl. Bilirubin levels less than 1mg/dl are also set to 1, as are INR values of less than 1. The final score ranges between 6 and 40.

$$MELD = 10 \times (0.957 \times log_e creatinine \times 0.378 \times log_e~bilirubin + 1.120 \times  log_e INR + 0.643)$$

To get the exact MELD score as recommended by UNOS, the part of the equation above in the brackets is rounded to the tenth decimal place before being multiplied by 10.

The MELD-Na score adds serum sodium levels into the mix if the MELD score is greater than 11. The actual sodium level is only used if sodium is between 125 and 137 mmol/l. If the actual level is less than 125, the value 125 is used in the equation, and if more than 137, a fixed value of 137 is assigned.

$$MELDNa = MELD + 1.32 \times (137 - Na) - [0.033 \times MELD \times (137 - Na)]$$

The `meld()` function in _transplantr_ calculates the MELD score with these value assignments taken into account. Creatinine and bilirubin are both calculated from their values in µmol/l by default, and can be changed to mg/dl either by setting the optional `units` parameter to `"US"` or by using the `meld_US()` wrapper function instead. It is a vectorised function and can therefore be applied to a whole series at once, for example in a _dplyr_ pipe:

```{r}
# load dataset
data("liver.pts")

# remove redundant variables and calculate MELD
oltx_data = liver.pts %>%
  select(-Patient.Age, -Patient.Sodium) %>%
  mutate(MELD = meld(INR = Patient.INR, bili = Patient.Bilirubin, 
                     creat = Patient.Creatinine, dialysis = Patient.Dialysed))

# display result
oltx_data
```

It will also work to calculate MELD score for a single case:

```{r, eval = F}
meld(INR = 2.0, bili = 3.1, creat = 1.9, dialysis = 0, units = "US")
```

The `meld_na()` function calculates the newer MELD-Na score using SI units for creatinine and bilirubin. Changing to US units can be done by setting `units` to `"US"` or using the `meld_na_US()` wrapper function. `meld_na()` is also a vectorised function and can be called from within a _dplyr_ pipe or for single cases in the same way as the `meld()` function.

It is worth noting that for liver allocation in the USA, additional points are added to the MELD score in the context of certain specified clinical conditions known as "standard MELD exceptions". These increase the MELD score by 10% every 3 months from diagnosis. Guidance on MELD, MELD-Na and PELD in US liver matching is available at the [OPTN website](https://optn.transplant.hrsa.gov).

# UKELD score

The UKELD score was developed in the UK before the MELD-Na had been published, and includes the same variables as MELD-Na: creatinine, bilirubin, INR and sodium. Although it has not been used in liver matching in the UK, a UKELD score greater than 49 has been a criterion for eligibility to join the liver transplant waiting list.

The score can be calculated with the `ukeld()` function, using µmol/l as the default unit for creatinine and bilirubin. This can be changed to mg/dl by setting the `units` parameter to `"US"` or calling the `ukeld_US()` wrapper function.

# SOFT score

The SOFT score (_7_) aims to predict post-transplant survival in adult liver recipients using 19 risk factors. There is also a pre-procurement P-SOFT score which uses the 14 risk factors known before a specific donor liver is offered for transplantation and can be used to risk stratify patients while still on the waiting list.

There are three key functions in _transplantr_ to calculate SOFT scores. The `soft()` function is a vectorised function to calculate the full 19-variable SOFT score, and the `p_soft()` function calculates the 14-variable P-SOFT score. There is also a `soft2()` function to calculate the full SOFT score for patients for whom P-SOFT has already been calculated. The functions use creatinine and albumin, which default to standard international units of µmol/l and g/l, but can be used with US units (mg/dl and g/dl) by setting the optional `Units` parameter to `"US"` or by calling any of the wrapper functions using US units by default: `soft_US()`, `p_soft_US()` and `soft2_US()`.

```{r, eval = F}
# calculate full SOFT score using international units
soft(Age = 35, BMI = 20, PrevTx = 0, AbdoSurg = 1, Albumin = 30, Dx = 0, 
     ICU = 0, Admitted = 0, MELD = 29, LifeSupport = 0, Encephalopathy = 1, 
     PVThrombosis = 0, Ascites = 1, PortalBleed = 0, DonorAge = 44, 
     DonorCVA = 0, DonorSCr = 110, National = 0, CIT = 8) 

# calculate full SOFT score using US units
soft(Age = 35, BMI = 20, PrevTx = 0, AbdoSurg = 1, Albumin = 3.0, Dx = 0, 
     ICU = 0, Admitted = 0, MELD = 29, LifeSupport = 0, Encephalopathy = 1, 
     PVThrombosis = 0, Ascites = 1, PortalBleed = 0, DonorAge = 44, 
     DonorCVA = 0, DonorSCr = 1.2, National = 0, CIT = 8, Units = "US")

# calculate P-SOFT score
p_soft(Age = 65, BMI = 36, PrevTx = 2, AbdoSurg = 1, Albumin = 29, 
       Dx = 0, ICU = 0, Admitted = 1, MELD = 32, LifeSupport = 0, 
       Encephalopathy = 1, PVThrombosis = 1, Ascites = 1)

# calculate P-SOFT with US units
p_soft_US(Age = 65, BMI = 36, PrevTx = 2, AbdoSurg = 1, Albumin = 2.9, 
          Dx = 0, ICU = 0, Admitted = 1, MELD = 32, LifeSupport = 0, 
          Encephalopathy = 1,PVThrombosis = 1, Ascites = 1)

# adding P-SOFT and SOFT as two variables to a tibble using a dplyr pipe
liver.recipients = liver.recipients %>%
  mutate(P.Soft = p_soft(age, bmi, prev.tx, abdo.surg, albumin, dialysis,
                         icu, admitted, meld.score, life.support,
                         encephalopathy, pv.thrombosis, ascites),
         Soft = soft2(P.Soft, portal.bleed, donor.age, donor.cva, donor.SCr,
                      sharing, cit))
```

# DRI and ET-DRI

The American DRI score can be calculated using the `liver_dri()` function and European ET-DRI using the `et_dri()` function.

```{r, eval = F}
# calculate DRI
liver_dri(age = 64, cod = "cva", eth = "white", dcd = 0, 
          split = 0, share = "local", cit = 14, height = 170)

# calculate ET-DRI
et_dri(age = 39, cod = "trauma", dcd = 0, split = 0, 
       share = "local", cit = 8, ggt = 50, rescue = 0)

```


# PELD score

The PELD score(_9_) is a paediatric version of MELD, and used to predict mortality in children needing liver transplants. It is based on age, bilirubin, albumin, INR and whether there is growth failure.

The `peld()` function in _transplantr_ calculates the PELD score. Bilirubin is calculated from their values in µmol/l and albumin in g/l by default, and can be changed to mg/dl and g/dl respectively either by setting the optional `units` parameter to `"US"` or by using the `peld_US()` wrapper function instead. In the event that albumin is measured locally in g/l and bilirubin in mg/dl, take care to convert it by dividing by 10. Similarly, if albumin is reported in g/dl and bilirubin in µmol/l, multiply the albumin results by 10. The conversion is easily done for a series in a vectorised way by including it in a _dplyr_ pipe:

```{r, eval = F}
# calculate PELD where lab reports albumin in g/dl and bilirubin in µmol/l
paed.oltx2 = paed.oltx %>%
  mutate(AlbuminX10 = Patient.Albumin * 10,
         PELD = peld(INR = Patient.INR, bili = Patient.Bilirubin, albumin = AlbuminX10,
                     listing_age = Patient.ListAge, growth_failure = Patient.GrowthFailure))

# calculate PELD where lab reports albumin in g/l and bilirubin in mg/dl
paed.oltx2 = paed.oltx %>%
  mutate(AlbuminDiv10 = Patient.Albumin / 10,
         PELD = peld_US(INR = Patient.INR, bili = Patient.Bilirubin, albumin = AlbuminDiv10,
                     listing_age = Patient.ListAge, growth_failure = Patient.GrowthFailure))

```

# Pedi-SOFT

The Pedi-SOFT score (_10_) is intended to predict post-transplant survival in children undergoing liver transplants, and has been demonstrated to predict survival both with infants and children aged 1-12, with c-statistic of 0.70 and 0.77 respectively.

The score is based on whether a cadaveric technical variant graft was used, recipient weight, whether recipient is on dialysis or has creatinine clearance less than 30ml/min before transplant, whether recipient required life support before transplant and number of any previous transplants.

The `pedi_soft()` function in _transplantr_ will calculate the Pedi-SOFT score, and like most other functions in the package it is a vectorised function.

```{r, eval = F}
# calculate Pedi-SOFT score
pedi_soft(CTVG = 1, Weight = 10, Dx = 0, LifeSupport = 0, PrevTx = 0) # 4
```


# References

1. Kamath PS, Wiesner RH, Malinchoc M, et al. A model to predict survival in patients with end-stage liver disease. _Hepatology_ 2001; 33:464-470. DOI: [10.1053/jhep.2001.22172](https://doi.org/10.1053/jhep.2001.22172)

2. Biggins SW, Kim WR, Terrault NA, et al. Evidence-based incorporation of serum sodium concentration into MELD. _Gastroenterology_ 2006; 130(6):1652-60. DOI: [10.1053/j.gastro.2006.02.010](https://doi.org/10.1053/j.gastro.2006.02.010)

3. Barber KM, Madden S, Allen J, et al. Elective liver transplant list mortality: development of a United Kingdom end-stage liver disease score. _Transplantation_ 2011; 92(4):469-76. DOI: [10.1097/TP.0b013e318225db4d](https://doi.org/10.1097/TP.0b013e318225db4d).

4. Wiesner R, Edwards E, Freeman R, et al. United Network for Organ Sharing Liver Disease Severity Score Committee. Model for end-stage liver disease (MELD) and allocation of donor livers. _Gastroenterology_ 2003: 124:91-96.

5. Brown RS Jr, Kumar KS, Russo MW, et al. Model for end-stage liver disease and Child-Turcotte-Pugh score as predictors of pre-transplantation disease severity, posttransplantation outcome, and resource utilization in the United Network for Organ Sharing status 2A patients. _Liver Transplant_ 2002: 8:278-284.

6. Desai NM, Mange KC, Crawford MD, et al. Predicting outcome after liver transplantation: Utility of the model of end-stage liver disease and a newly derived discrimination function. _Transplantation_ 2004; 77:99-106.

7. Rana A, Hardy MA, Halazun KJ, et al. Survival Outcomes Following Liver Transplantation (SOFT) Score: A Novel Method to Predict Patient Survival Following Liver Transplantation. _American Journal of Transplantation_ 2008: 8:2537-2546. DOI: [10.1111/j.1600-6143.2008.02400.x](https://doi.org/10.1111/j.1600-6143.2008.02400.x)

8. Dutkowski P, Oberkofler CE, Slankamenac K, et al. Are There Better Guidelines for
Allocation in Liver Transplantation? A Novel Score Targeting Justice and Utility in the
Model for End-Stage Liver Disease Era. Annals of Surgery 2011; 254:745-753. DOI: [10.1097/SLA.0b013e3182365081](https://doi.org/10.1097/SLA.0b013e3182365081)

9. Feng S, Goodrich NP, Bragg-Gresham JL, et al. Characteristics Associated with Liver Graft Failure:
The Concept of a Donor Risk Index. _American Journal of Transplantation_ 2006; 6:783–790. DOI: [10.1111/j.1600-6143.2006.01242.x](https://doi.org/10.1111/j.1600-6143.2006.01242.x)

10. Braat AE, Blok JJ, Putter H, et al. The Eurotransplant Donor Risk Index in Liver Transplantation: ET-DRI. American Journal of Transplantation 2012; 12:2789–2796. [10.1111/j.1600-6143.2012.04195.x](https://doi.org/10.1111/j.1600-6143.2012.04195.x)

11. McDiarmid SV, Anand R, Lindblad AS, et. al. Development of a pediatric end-stage liver disease score to predict poor outcome in children awaiting liver transplantation. _Transplantation_ 2002; 74(2):173-81. DOI: [10.1097/00007890-200207270-00006](https://doi.org/10.1097/00007890-200207270-00006)

12. Rana A, Pallister ZS, Guiteau JJ, et al. Survival Outcomes Following Pediatric Liver Transplantation (Pedi-SOFT) Score: A Novel Predictive Index. _American Journal of Transplantation_ 2015; 15:1855-1863. DOI: [10.1111/ajt.13190](https://doi.org/10.1111/ajt.13190)

