Functional Weave
Code in Python

health.waiting-time@1.0.1

README.md

4,514 bytes · view raw

# health.waiting-time

How long a patient has waited on an NHS England consultant-led
referral-to-treatment (RTT) pathway, the way NHS England counts it: days from
the clock start to the clock stop (or to the measuring date while the patient
is still waiting), the weekly reporting band, and whether the 18-week standard
has been breached.

Patients in England have the right to start consultant-led non-emergency
treatment within a maximum of 18 weeks from referral. 18 weeks is 126 days,
and a patient who has waited exactly 126 days is still within it (they are
reported in the 17-18 week band); 127 days is a breach. `eighteenWeekDate` is
the clock start plus 126 days, the last day on which treatment still meets the
standard.

**Week bands.** RTT returns put each pathway in a weekly time band, ">n-1 to
n weeks", and `weekBand` is that n. The first band, 0-1 weeks, holds eight
days (0 to 7), every later band seven: 8-14 days is band 2, 120-126 days band
18, 127 days band 19. NHS England's last band is "104+ weeks", 729 days and
more; `weekBand` keeps counting above 104 (729 days is 105) so a caller can
still tell long waits apart, and a return should put anything above 104 in the
>104 band. `completedWeeks` is simply whole weeks (days divided by 7, rounded
down), for display. A clock that starts and stops on the same day is a real
pathway of zero days.

**No clock pauses.** Earlier versions of the rules allowed "patient-initiated
clock pauses". NHS England removed them in 2015 with the admitted pathway
standard: "there is no longer any provision to report pauses or suspensions in
RTT waiting time clocks ... under any circumstances". This capability
therefore takes a clock start and an optional clock stop and nothing else,
deliberately. Events that the rules do recognise are the caller's to apply:

- a clock stop (rules 4 and 5: first definitive treatment, a decision not to
  treat, active monitoring, a patient declining treatment, and so on) is the
  `clockStop` date;
- a DNA of the first appointment nullifies the clock (rule 5e, footnote 10),
  and when the patient rebooks a new clock starts (rule 3e), so pass the
  rebooking date as a new `clockStart`;
- other new clock starts (rule 3: a second bilateral procedure, a new
  treatment, the end of active monitoring) are likewise new pathways.

**Errors.** A measuring date before the clock start, a clock stop before the
clock start, and a clock stop after the measuring date (a stop that has not
happened yet) are errors. Dates are ISO `YYYY-MM-DD`, and the measuring date is
always an argument, never the clock.

## Source

NHS England, "Recording and reporting referral to treatment (RTT) waiting
times for consultant-led elective care", version 5.2, February 2025:
section 2.2 reproduces the "Referral to treatment consultant-led waiting times
rules suite" (clock starts, rules 1-3; clock stops, rules 4-5), the
introduction records the removal of clock pauses, and section 10.1.7
"Measuring the length of RTT pathways" defines the time bands.
https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2025/10/Recording-and-reporting-RTT-waiting-times-guidance-v5.2-Feb25.pdf

## Before you rely on this

**Not professional advice.** This capability calculates health figures from published rules. It is a software component for developers, not medical advice. Rules change and every rate here has an effective date. Check that the dates cover your case. Verify results against the official sources listed above, and have a clinician review how you use it, before anyone relies on the output. Provided "as is" under its licence, without warranty.

**Not a medical device.** It is not intended to diagnose, treat or support clinical decisions about any individual. Anyone building it into clinical software is responsible for that software's regulatory status, and must validate it under their own clinical governance.

**Unreviewed.** This capability's implementations agree in every language and pass its published test vectors, which were worked out from the official sources cited. But no qualified clinician has yet checked those vectors, or confirmed that the capability covers the cases it claims. Treat it as a draft. Do not use it for real people, money or decisions without your own expert review. Once a qualified reviewer signs off, this notice is replaced with their name, qualification and the date. Each new version needs fresh sign-off.

1.0.1 marks it unreviewed. The code and the tests are unchanged.