// Copyright (C) 2023 Calcarta
module Calcarta.Calculation.Wells_criteria_for_pulmonary_embolism.Code
open Calcarta.CodeResource.Standard
type Patient = {
[<Name("Clinical signs and symptoms of DVT")>]
[<Description("Objectively measured leg swelling and pain with palpation in the deep-vein region")>]
DvtSigns : bool
[<Name("Heart Rate >100bpm")>]
HeartRate : bool
[<Name("Recent history of immobilisation")>]
[<Description("Bedrest, except to access the bathroom, for ≥3 days")>]
Immobilisation : bool
[<Name("Surgery in the previous 4 weeks")>]
RecentSurgery : bool
[<Name("Previous objectively diagnosed deep venous thrombosis or pulmonary embolism")>]
PreviousDvt : bool
[<Name("Haemoptysis")>]
Haemoptysis : bool
[<Name("Malignancy")>]
[<Description("Patients with cancer who were receiving treatment, those in whom treatment had been stopped within the past 6 months, or those who were receiving palliative care")>]
Malignancy : bool
[<Name("Pulmonary embolism likelihood")>]
[<Description("Pulmonary embolism as likely as or more likely than an alternative diagnosis")>]
PulmonaryEmbolismLikelihood : bool
}
type PretestProbability =
| Low = 1
| Moderate = 2
| High = 3
type Output = {
[<Name("Wells score")>]
[<Unit("Points")>]
Score : decimal
[<Name("Pretest risk category")>]
RiskCategory : PretestProbability
[<Name("PE probability")>]
[<Description("Based on statistical analysis in original paper")>]
PeRisk : string
}
let wells_criteria_for_pulmonary_embolism (patient : Patient) =
let dvtSigns = if patient.DvtSigns then 3m else 0m
let heartRate = if patient.HeartRate then 1.5m else 0m
let immobilisation = if patient.Immobilisation || patient.RecentSurgery then 1.5m else 0m
let previousDvt = if patient.PreviousDvt then 1.5m else 0m
let haemoptysis = if patient.Haemoptysis then 1m else 0m
let malignancy = if patient.Malignancy then 1m else 0m
let pulmonaryEmbolismLikelihood = if patient.PulmonaryEmbolismLikelihood then 3m else 0m
let score =
dvtSigns +
heartRate +
immobilisation +
previousDvt +
haemoptysis +
malignancy +
pulmonaryEmbolismLikelihood
let riskCategory =
if score < 2m then PretestProbability.Low
else if score <=6m then PretestProbability.Moderate
else PretestProbability.High
let peRisk =
match riskCategory with
| PretestProbability.High -> "40.6% [CI, 28.7% to 53.7%]"
| PretestProbability.Moderate -> "16.2% [CI, 12.5% to 20.6%]"
| PretestProbability.Low -> "1.3% [CI, 0.5% to 2.7%]"
| _ -> "Not defined"
{
Score = score
RiskCategory = riskCategory
PeRisk = peRisk
}