Body Mass Index (BMI)

A function of mass and height used to determine if someone is within a healthy weight range

Description

Sourced from Wikipedia, see https://en.wikipedia.org/wiki/body%20mass%20index ยท Text under CC BY-SA license

Body mass index (BMI) is a value derived from the mass (weight) and height of a person. The BMI is defined as the body mass divided by the square of the body height, and is expressed in units of kg/m2, resulting from mass in kilograms and height in metres. The BMI may be determined using a table or chart which displays BMI as a function of mass and height using contour lines or colours for different BMI categories, and which may use other units of measurement (converted to metric units for the calculation).The BMI is a convenient rule of thumb used to broadly categorize a person as underweight, normal weight, overweight, or obese based on tissue mass (muscle, fat, and bone) and height. Major adult BMI classifications are underweight (under 18.5 kg/m2), normal weight (18.5 to 24.9), overweight (25 to 29.9), and obese (30 or more). When used to predict an individual's health, rather than as a statistical measurement for groups, the BMI has limitations that can make it less useful than some of the alternatives, especially when applied to individuals with abdominal obesity, short stature, or unusually high muscle mass. BMIs under 20 and over 25 have been associated with higher all-cause mortality, with the risk increasing with distance from the 20–25 range.
Code Version Id
3cf37b92-8f8c-4c48-a004-c1e073517555
// 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
        }