core

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateBMI

func CalculateBMI(h Height, w Weight) (float64, error)

CalculateBMI computes the Body Mass Index (BMI) from a Height and Weight.

Supported unit pairs:

  • Height in centimeters (Unit_cm) and Weight in kilograms (Unit_kg)
  • Height in inches (Unit_inch) and Weight in pounds (Unit_lbs)

Returns the BMI rounded to one decimal place. If either numeric value is zero an error is returned. If the provided units are not one of the supported pairs an error is returned.

func ConvertLength

func ConvertLength(length float64, from Unit, to Unit) float64

ConvertLength converts length between inches and centimeters. If the units are identical the input is returned. Only inch<->cm conversions are supported; other combinations are returned unchanged.

func ConvertTemperature

func ConvertTemperature(temp float64, from Unit, to Unit) float64

ConvertTemperature converts temperature values between Fahrenheit and Celsius. If the units are identical the input is returned. Only the two directions Fahrenheit<->Celsius are supported; other combinations return the input unmodified.

func ConvertWeight

func ConvertWeight(weight float64, from Unit, to Unit) float64

ConvertWeight converts weight between pounds and kilograms. If the 'from' and 'to' units are the same the input value is returned unmodified. Only lbs<->kg conversions are supported by this helper; other unit combos are returned unchanged.

Types

type BloodPressure

type BloodPressure struct {
	Systolic  int // systolic pressure in BPUnit (mmHg)
	Diastolic int // diastolic pressure in BPUnit (mmHg)
	BPUnit    Unit
	MAP       float64 // mean arterial pressure in BPUnit (mmHg)
}

BloodPressure represents a standard blood pressure measurement. Systolic and Diastolic are stored as integer mmHg values and BPUnit indicates the unit used (currently Unit_mmHg).

func NewBloodPressure

func NewBloodPressure(systolic int, diastolic int, mapValue ...float64) (BloodPressure, error)

NewBloodPressure constructs a BloodPressure value and validates that systolic and diastolic are positive and systolic >= diastolic. Returns an error when validation fails. NewBloodPressure takes an optional mapValue parameter. If no mapValue is provided, it calculates MAP using the common clinical approximation: MAP = (Diastolic * 2 + Systolic) / 3

type Height

type Height struct {
	Height     float64
	HeightUnit Unit
}

Height represents a person's height and the unit used to record it. Height is a plain numeric value; the interpretation of the value depends on HeightUnit (for example, cm or inch).

func NewHeight

func NewHeight(height float64, system UnitSystem) Height

NewHeight creates a Height using a UnitSystem. For UnitSystemSI the unit is centimeters, for UnitSystemUS the unit is inches.

type Respiratory

type Respiratory struct {
	RespiratoryRate int // breaths per minute
	SpO2            SpO2
}

Respiratory groups a respiratory rate and SpO2 measurement.

type SpO2

type SpO2 struct {
	Value int // percent oxygen saturation (0-100)
	Unit  Unit
}

SpO2 represents oxygen saturation as an integer percentage and its unit.

type Temperature

type Temperature struct {
	Temp     float64 // temperature numeric value
	TempUnit Unit    // unit, e.g. Unit_celsius or Unit_fahrenheit
}

Temperature holds a numeric temperature value and its unit. Use NewTemperature to create a Temperature with a UnitSystem (SI/US).

func NewTemperature

func NewTemperature(temp float64, system UnitSystem) (Temperature, error)

NewTemperature creates a Temperature using a UnitSystem. For UnitSystemSI the Temperature unit will be Celsius; for UnitSystemUS the unit will be Fahrenheit.

type Unit

type Unit string

Unit is a type alias for unit strings used across the medkit package. Examples include "kg", "lbs", "cm", "inch", and various laboratory units such as "mg/dL" or "mmol/L".

const (
	// Weight
	Unit_lbs   Unit = "lbs"
	Unit_kg    Unit = "kg"
	Unit_kg_m2 Unit = "kg/m²"

	// Length
	Unit_inch Unit = "inch"
	Unit_cm   Unit = "cm"

	// Temperature
	Unit_fahrenheit Unit = "fahrenheit"
	Unit_celsius    Unit = "celsius"

	// Blood Pressure
	Unit_mmHg Unit = "mmHg"

	// Blood Work - units commonly used in the US (conventional)
	Unit_mg_dL Unit = "mg/dL"
	Unit_g_dL  Unit = "g/dL"
	Unit_ng_dL Unit = "ng/dL"

	// Blood Work - units commonly used in SI
	Unit_mmolL    Unit = "mmol/L"
	Unit_umol_L   Unit = "µmol/L"
	Unit_mEq_L    Unit = "mEq/L"
	Unit_mmol_mol Unit = "mmol/mol"
	Unit_mIU_L    Unit = "mIU/L"
	Unit_mg_L     Unit = "mg/L"

	// Enzyme / activity / counts (shared across systems)
	Unit_U_L     Unit = "U/L"
	Unit_fL      Unit = "fL"
	Unit_pg      Unit = "pg"
	Unit_percent Unit = "%"
	Unit_second  Unit = "s"
	Unit_mm_hr   Unit = "mm/hr"
	Unit_ng_mL   Unit = "ng/mL"
	Unit_none    Unit = "" // for unitless values

	// Cell Counts (shared)
	Unit_K_uL Unit = "K/µL"
	Unit_M_uL Unit = "M/µL"
)

type UnitSystem

type UnitSystem int

UnitSystem represents a measurement system. Use UnitSystemSI for the International System of Units (metric) and UnitSystemUS for common United States customary units.

const (
	// UnitSystemSI indicates metric/SI units (e.g., cm, kg).
	UnitSystemSI UnitSystem = iota
	// UnitSystemUS indicates US customary units (e.g., inch, lbs).
	UnitSystemUS
)

type Vitals

type Vitals struct {
	HeartRate     int
	Respiratory   Respiratory
	BloodPressure BloodPressure
	Temperature   Temperature
}

Vitals aggregates common vital signs measured in clinical settings. It includes heart rate, respiratory measurements, blood pressure, and temperature.

func NewVitals

func NewVitals(hr int, respRate int, spo2 int, bp BloodPressure, temp Temperature) (Vitals, error)

NewVitals constructs a Vitals record and validates basic fields. It returns an error for non-positive heart rate or respiratory rate. SpO2 is populated with Unit_percent automatically.

type Weight

type Weight struct {
	Weight     float64
	WeightUnit Unit
}

Weight represents a person's weight and the unit used to record it. Weight is a plain numeric value; the interpretation depends on WeightUnit (for example, kg or lbs).

func NewWeight

func NewWeight(weight float64, system UnitSystem) Weight

NewWeight creates a Weight using a UnitSystem. For UnitSystemSI the unit is kilograms, for UnitSystemUS the unit is pounds.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL