Functional Weave
Code in Rust

health.qrisk-inputs-validate@1.0.0

README.md

4,105 bytes · view raw

# health.qrisk-inputs-validate

Status: needs review and sign-off by a qualified clinician before it is published. Not a medical device; for decision support only; always follow local clinical guidelines.

Checks that a set of inputs is fit to be given to the QRISK3 cardiovascular
risk calculator. **It does NOT compute risk.** QRISK3 itself is a licensed
algorithm (ClinRisk / Endeavour Predict); use an accredited implementation
for the score. This capability catches the data problems before the call:
missing required values, values outside the ranges the calculator accepts,
a height without a weight, and people QRISK3 is not valid for.

Every problem is reported, not just the first, in the order of the
`QriskInputs` fields and then `existingCvd` and `onStatins`, each with the
field name, a reason code and a message in the calculator's own wording where
it has one. The result is `valid` only when there are none.

## The published input definitions

From the QRISK3 calculator form at https://qrisk.org and its client-side
validation script https://qrisk.org/form.v003.js:

| Field | Required | Accepted |
|---|---|---|
| age | yes | whole years, 25 to 84 |
| sex | yes | `female`, `male` |
| ethnicity | yes | `white-or-not-stated`, `indian`, `pakistani`, `bangladeshi`, `chinese`, `other-asian`, `black-caribbean`, `black-african`, `other` |
| postcode | no ("leave blank if unknown") | a valid UK postcode (checked with validation.uk-postcode) |
| smoking | yes | `non-smoker`, `ex-smoker`, `light` (under 10 a day), `moderate` (10 to 19), `heavy` (20 or more) |
| diabetes | yes | `none`, `type-1`, `type-2` |
| cholesterolHdlRatio | no | 1.0 to 11.0 |
| systolicBp | no | whole mmHg, 70 to 210 |
| systolicBpSd | no | 0.0 to 40.0 (SD of at least two recent systolic readings) |
| heightCm, weightKg | no, but both or neither | whole cm 140 to 210; whole kg 40 to 180 |

The eleven yes/no conditions (family history, CKD 3-5, AF, treated
hypertension, migraine, rheumatoid arthritis, SLE, severe mental illness,
atypical antipsychotics, regular steroid tablets, erectile dysfunction) are
booleans and cannot be invalid.

The calculator states that it "is only valid if you do not already have a
diagnosis of coronary heart disease (including angina or heart attack) or
stroke/transient ischaemic attack, and not on statins", so `existingCvd` or
`onStatins` being true is reported as `not-applicable`.

The codes for the categorical fields are this capability's own lower-case
spellings of the calculator's options; the fields are plain strings, not
enums, because the point is to check raw recorded values.

## Edge cases and decisions

- **Height and weight are whole numbers** in the published form ("enter an
  integer"). Round a recorded 172.5 cm before calling; a fractional height is
  refused with an error (it is a type error, thrown in every language, not a
  reported clinical problem), as is a fractional age or systolic pressure.
  A whole number sent as 170.0 is accepted.
- **A lone height or weight** is reported against the missing one, with the
  calculator's "only entered one of height and weight" message.
- **A blank postcode** (empty or spaces) is treated as unknown, as on the
  form.
- **Units are not converted.** A height of 2 (metres) is out of range, not
  200 cm. A total cholesterol typed into the ratio field cannot be told apart
  from a ratio if it is between 1 and 11: that is for the caller.
- **Erectile dysfunction** is, as far as we know, a term of the male QRISK3
  equation only (BMJ 2017; the paper's tables were not re-read for this
  package); the calculator's form does not reject it for women and neither
  does this.
- The ranges are the calculator's input limits, not clinical normal ranges.

## Sources

- QRISK3 risk calculator, https://qrisk.org, and its form validation
  https://qrisk.org/form.v003.js (both read September 2026).
- Hippisley-Cox J, Coupland C, Brindle P. Development and validation of
  QRISK3 risk prediction algorithms to estimate future risk of cardiovascular
  disease: prospective cohort study. BMJ 2017;357:j2099.