FHIRPath Calculation Gallery for FHIR Questionnaires
Writing a clinical calculation in FHIRPath by hand — item references, unit conversions, edge cases — is slow and error-prone. The FHIR Questionnaire Builder ships a gallery of ready-made calculations: choose one, say which questionnaire item supplies each input, and the builder inserts a working calculatedExpression you can keep editing.
How it works
- In the Builder, open an item's expression editor and choose Choose from gallery.
- Pick a calculation and select the questionnaire item for each input (with unit conversion where it applies).
- Insert it — the result is ordinary FHIRPath, exported in the standard SDC calculated-expression extension.
Calculations give no result until their inputs are answered, rather than guessing a value. They are reference calculations to save authoring effort, not medical advice — check each formula against its source for your use case.
Calculations in the gallery
BMI (Body Mass Index)
weight ÷ height² — pick the weight and height items, with optional unit conversion.
Inputs
- Weight item (Already in kg / Convert from lb)
- Height item (Already in m / Convert from cm)
Source: Quetelet index (weight kg ÷ height m²)
BMI (imperial: lb, inches)
weight(lb) × 703 ÷ height(in)² — the standard US imperial BMI formula.
Inputs
- Weight item (Already in lb / Convert from kg)
- Height item (Already in inches / Convert from cm)
Source: Imperial BMI formula (weight lb × 703 ÷ height in²)
BMI Category (WHO)
BMI mapped to its WHO weight category — pick the weight and height items, with optional unit conversion.
Result: Underweight · Normal weight · Overweight · Obese
Inputs
- Weight item (Already in kg / Convert from lb)
- Height item (Already in m / Convert from cm)
Source: WHO adult BMI classification
Age from birthdate (whole years)
Whole years since a birthdate item — correctly handles a birthday not yet reached this year.
Inputs
- Birthdate item
Source: Calendar-year difference with birthday adjustment
Unit conversion
Convert a single numeric item between common clinical units.
Inputs
- Item to convert (lb → kg / kg → lb / cm → m / m → cm / °F → °C / °C → °F)
Source: Standard unit conversion factors
GAD-7 total + severity
Sums the 7 GAD-7 items (each scored 0–3) and maps the total to its anxiety severity band.
Result: Minimal anxiety · Mild anxiety · Moderate anxiety · Severe anxiety
Inputs
- Q1 — feeling nervous, anxious, on edge
- Q2 — unable to stop/control worrying
- Q3 — worrying too much
- Q4 — trouble relaxing
- Q5 — restless
- Q6 — easily annoyed/irritable
- Q7 — feeling afraid something awful might happen
Source: Spitzer et al. 2006, Arch Intern Med 166:1092
PHQ-9 total + severity
Sums the 9 PHQ-9 items (each scored 0–3) and maps the total to its depression severity band.
Result: Minimal depression · Mild depression · Moderate depression · Moderately severe depression · Severe depression
Inputs
- Q1 — little interest or pleasure
- Q2 — feeling down, depressed, hopeless
- Q3 — sleep trouble
- Q4 — tired / little energy
- Q5 — poor appetite or overeating
- Q6 — feeling bad about yourself
- Q7 — trouble concentrating
- Q8 — moving/speaking slowly, or restless
- Q9 — thoughts of self-harm
Source: Kroenke, Spitzer & Williams 2001, J Gen Intern Med 16:606
CHA₂DS₂-VASc stroke risk score
Stroke risk score for atrial fibrillation — pick the yes/no item for each criterion (max 9 points).
Inputs
- Congestive heart failure / LV dysfunction (+1)
- Hypertension (+1)
- Age ≥75 (+2)
- Diabetes mellitus (+1)
- Prior stroke/TIA/thromboembolism (+2)
- Vascular disease (+1)
- Age 65–74 (+1)
- Sex category female (+1)
Source: Lip et al. 2010, Chest 137:263
Sum of items
Add as many numeric items as you need — their values (with optional unit conversion) are added together.
Inputs
- Item to include (add as many rows as needed) (As-is / lb → kg / kg → lb / cm → m / m → cm / °F → °C / °C → °F)
Source: Plain sum of the picked items
Charlson Comorbidity Index
Add one row per comorbidity the patient has — each contributes its fixed weight (1–6), plus an automatic age-based bonus.
Inputs
- Comorbidity present (add as many rows as needed) (Myocardial infarction (+1) / Congestive heart failure (+1) / Peripheral vascular disease (+1) / Cerebrovascular disease (+1) / Dementia (+1) / Chronic pulmonary disease (+1) / Rheumatologic disease (+1) / Peptic ulcer disease (+1) / Liver disease — mild (+1) / Diabetes — controlled (+1) / Hemiplegia or paraplegia (+2) / Renal disease (+2) / Diabetes — uncontrolled (end-organ damage) (+2) / Malignancy — localized (+2) / Leukemia (+2) / Lymphoma (+2) / Liver disease — moderate/severe (+3) / Malignancy — metastatic (+6) / AIDS (+6))
- Age (years)
Source: Charlson et al. 1987, J Chronic Dis 40:373 (with the Charlson/Deyo age adjustment)
Count of Yes answers
How many of the picked yes/no items are answered Yes — add one row per item.
Inputs
- Yes/no item (add as many rows as needed)
Source: Plain count of the picked items answered Yes
Percent change
(new − baseline) ÷ baseline × 100, rounded to 1 decimal — e.g. weight change since the first visit.
Inputs
- Baseline value item
- New value item
Source: Standard relative change: (new − baseline) ÷ baseline × 100
PHQ-2 screen
Sums the 2 PHQ-2 items (each scored 0–3); a total of 3 or more is a positive depression screen.
Result: Negative screen · Positive screen
Inputs
- Q1 — little interest or pleasure
- Q2 — feeling down, depressed, hopeless
Source: Kroenke, Spitzer & Williams 2003, Med Care 41:1284
Glasgow Coma Scale
Adds the eye (1–4), verbal (1–5) and motor (1–6) responses and maps the total (3–15) to its severity band.
Result: Severe (GCS 3–8) · Moderate (GCS 9–12) · Mild (GCS 13–15)
Inputs
- Eye response (1–4)
- Verbal response (1–5)
- Motor response (1–6)
Source: Teasdale & Jennett 1974, Lancet 2:81
Apgar score
Sums the 5 Apgar criteria (each scored 0–2) and maps the total (0–10) to its band.
Result: Low (0–3) · Moderately abnormal (4–6) · Reassuring (7–10)
Inputs
- Appearance — skin colour (0–2)
- Pulse — heart rate (0–2)
- Grimace — reflex irritability (0–2)
- Activity — muscle tone (0–2)
- Respiration — breathing effort (0–2)
Source: Apgar 1953; AAP/ACOG score bands
qSOFA sepsis screen
Counts the 3 qSOFA criteria that are present; 2 or more means high risk of poor outcome.
Result: Lower risk · High risk
Inputs
- Respiratory rate ≥22/min
- Altered mentation
- Systolic BP ≤100 mmHg
Source: Singer et al. 2016 (Sepsis-3), JAMA 315:801
Body surface area (Mosteller)
√(height cm × weight kg ÷ 3600), in m² — pick the height and weight items, with optional unit conversion.
Inputs
- Height item (Already in cm / Convert from inches / Convert from m)
- Weight item (Already in kg / Convert from lb)
Source: Mosteller 1987, N Engl J Med 317:1098
Mean arterial pressure
(systolic + 2 × diastolic) ÷ 3 in mmHg, rounded to 1 decimal.
Inputs
- Systolic BP item
- Diastolic BP item
Source: Standard estimate: (systolic + 2 × diastolic) ÷ 3
Serum anion gap
Na − (Cl + HCO₃), all in mEq/L — pick the three lab items.
Inputs
- Sodium item
- Chloride item
- Bicarbonate item
Source: Standard potassium-free form: Na − (Cl + HCO₃)
eGFR (CKD-EPI 2021)
Estimated GFR in mL/min/1.73 m² from creatinine, age and sex — set the answer code that means female if your sex item does not use “female”.
Inputs
- Serum creatinine item (Already in mg/dL / Convert from µmol/L)
- Age in years item
- Sex item (single choice)
- Answer code for Female (default
female)
Source: Inker et al. 2021, N Engl J Med 385:1737 (race-free CKD-EPI)
Creatinine clearance (Cockcroft–Gault)
(140 − age) × weight ÷ (72 × creatinine), × 0.85 if female, in mL/min — set the answer code that means female if your sex item does not use “female”.
Inputs
- Age in years item
- Weight item (Already in kg / Convert from lb)
- Serum creatinine item (Already in mg/dL / Convert from µmol/L)
- Sex item (single choice)
- Answer code for Female (default
female)
Source: Cockcroft & Gault 1976, Nephron 16:31
Expected delivery date (LMP + 280 days)
Last menstrual period + 280 days (40 weeks), assuming a regular 28-day cycle.
Inputs
- Last menstrual period item
Source: Naegele's rule, 280-day form (regular 28-day cycle)
Date plus interval
A date item plus a fixed interval — e.g. a follow-up or next-due date.
Inputs
- Start date item (+ 1 week / + 2 weeks / + 4 weeks / + 1 month / + 3 months / + 6 months / + 1 year)
Source: FHIRPath calendar arithmetic
Age at a date (whole years)
Whole years between a birthdate and another date item — e.g. age at the visit or at diagnosis.
Inputs
- Birthdate item
- Date to measure age at
Source: Calendar-year difference with birthday adjustment
Age in months at a date
Whole months between a birthdate and another date item — for infant and paediatric questionnaires.
Inputs
- Birthdate item
- Date to measure age at
Source: Calendar-month difference with day-of-month adjustment
Corrected calcium (albumin)
Total calcium adjusted for low albumin, in mg/dL: Ca + 0.8 × (4.0 − albumin).
Inputs
- Total calcium item (Already in mg/dL / Convert from mmol/L)
- Albumin item (Already in g/dL / Convert from g/L)
Source: Payne et al. 1973, BMJ 4:643
LDL cholesterol (Friedewald)
Total − HDL − triglycerides ÷ 5, in mg/dL; no result when triglycerides are 400 mg/dL or more.
Inputs
- Total cholesterol item (Already in mg/dL / Convert from mmol/L)
- HDL cholesterol item (Already in mg/dL / Convert from mmol/L)
- Triglycerides item (Already in mg/dL / Convert from mmol/L)
Source: Friedewald et al. 1972, Clin Chem 18:499
HOMA-IR (insulin resistance)
Fasting glucose × fasting insulin ÷ 405 (glucose in mg/dL, insulin in µU/mL), rounded to 2 decimals.
Inputs
- Fasting glucose item (Already in mg/dL / Convert from mmol/L)
- Fasting insulin item (µU/mL)
Source: Matthews et al. 1985, Diabetologia 28:412
FIB-4 liver fibrosis index
Age × AST ÷ (platelets × √ALT), mapped to low / indeterminate / high risk of advanced fibrosis (cut-offs 1.3 and 2.67).
Result: Low risk (< 1.3) · Indeterminate (1.3–2.67) · High risk (> 2.67)
Inputs
- Age in years item
- AST item (U/L)
- ALT item (U/L)
- Platelets item (×10⁹/L)
Source: Shah et al. 2009, Clin Gastroenterol Hepatol 7:1104 (cut-offs 1.3 / 2.67)
QTc (Bazett)
QT interval corrected for heart rate: QT ÷ √RR, in ms — over-corrects at fast heart rates.
Inputs
- QT interval item (ms)
- Heart rate item (bpm)
Source: Bazett 1920
QTc (Fridericia)
QT interval corrected for heart rate: QT ÷ RR¹ᐟ³, in ms — steadier than Bazett at fast or slow rates.
Inputs
- QT interval item (ms)
- Heart rate item (bpm)
Source: Fridericia 1920
Ideal body weight (Devine)
Male 50 kg / female 45.5 kg + 2.3 kg per inch over 5 feet — set the answer code that means female if your sex item does not use “female”.
Inputs
- Height item (Already in inches / Convert from cm)
- Sex item (single choice)
- Answer code for Female (default
female)
Source: Devine 1974, Drug Intell Clin Pharm 8:650
Waist-to-hip ratio
Waist circumference ÷ hip circumference (same unit), rounded to 2 decimals.
Inputs
- Waist circumference item
- Hip circumference item
Source: WHO Expert Consultation 2008, Waist circumference and waist–hip ratio (Geneva)
Days between two dates
Whole days from a start date item to an end date item — e.g. length of stay. Negative if the end is before the start.
Inputs
- Start date item
- End date item
Source: Calendar day count (Gregorian calendar, leap years included)
Gestational age (completed weeks)
Completed weeks from the last menstrual period to a visit date item; no result if the visit is before the LMP.
Inputs
- Last menstrual period item
- Visit date item
Source: Standard LMP dating (completed weeks since the first day of the last period)