Sourced from Wikipedia, see https://en.wikipedia.org/wiki/body%20mass%20index ยท Text under CC BY-SA license
// Copyright (C) 2023 Calcarta
module Calcarta.Calculation.``Body_mass_index_(bmi)``.Code
open Calcarta.CodeResource.Standard
open Calcarta.CodeResource.Units.QuantitiesOfMechanics.Mass
open Calcarta.CodeResource.Units.SpaceAndTime.Length
type Patient = {
[<Description("Remove any heavy items or clothing before weighing")>]
[<Unit(Kilogram)>]
Weight : decimal
[<Description("Should be measured without shoes, standing on a hard surface with the back against a wall")>]
[<Unit(Centimetre)>]
Height : decimal
}
type BmiOutput = {
[<Name("Body Mass Index (BMI)")>]
[<Unit("kg m⁻²")>]
BmiValue : decimal
[<Name("Classification")>]
BmiClassification : string
}
let calculateBmi patient =
let bmiValue = patient.Weight / (patient.Height * patient.Height / 10000m)
let bmiClassification =
match bmiValue with
| bmi when bmi < 18.5m -> "Underweight"
| bmi when bmi < 25m -> "Normal range"
| bmi when bmi < 30m -> "Overweight"
| bmi when bmi < 35m -> "Obese class 1"
| bmi when bmi < 40m -> "Obese class 2"
| _ -> "Obese class 3"
{
BmiValue = bmiValue
BmiClassification = bmiClassification
}