Chapter 20

Health data, medical software, and security

When code becomes a device, why the data are special, and why availability is safety

Human Biology for the Medical Maker

Four things change in health software

What changesWhy it matters
Software can be a medical deviceDecided by what you say it is for; then IEC 62304 applies
The data are specialProtected by law everywhere; de-identification is hard
Systems must interoperateHL7, FHIR, DICOM — and codes and units carry the meaning
Security failures harm patientsRansomware has closed emergency departments

Orientation, not legal or regulatory advice. What applies is decided with the host's specialists.

When is software a medical device?

Intended use decides

One algorithm, three products

Marketed asStatus
"Track your workouts"General wellness — generally not a device
"Notifies you of an irregular rhythm suggestive of atrial fibrillation"A medical device
Used in hospital to decide who gets anticoagulationA higher-risk device still

"For educational purposes only" in a footer does not neutralise a screen that says "Diagnosis: atrial fibrillation".

SaMD and SiMD

Software as a Medical Device

  • Is the device, on general-purpose hardware
  • Retinopathy grading from photographs
  • Haemorrhage flagging on CT; insulin dose calculators

Software in a Medical Device

  • Drives or is part of a hardware device
  • Infusion pump firmware
  • CT reconstruction; ventilator control loops

"Not a device" does not mean "not a safety question" — England's DCB0129 and DCB0160 apply to health IT anyway.

The IMDRF risk framework

Healthcare situationTreat or diagnoseDrive managementInform management
CriticalIVIIIII
SeriousIIIIII
Non-seriousIIII

Two questions: how serious is the situation, and how much does anyone rely on the output?

The shape of the main regimes

JurisdictionIn outline
United StatesFDA "device software functions"; Cures Act exclusions incl. some clinical decision support; quality regulation incorporates ISO 13485 from February 2026
European UnionMDR Rule 11: decision-informing software at least Class IIa; little clinical software is Class I. EU AI Act phasing in to 2027
United KingdomMHRA regulation under reform; NHS adds DCB0129, DCB0160, and DTAC

Clinical decision support is the grey zone you are most likely to wander into. Settle it before writing the rule.

The software lifecycle — IEC 62304

What you must plan, do, and record

The IEC 62304 lifecycle

Development activities, maintenance, and the supporting processes that run throughout

Development activities, maintenance, and the supporting processes that run throughout

Software safety classes

ClassWorst outcome if the software failsProcess burden
ANo injury possiblePlanning, requirements, release, configuration, problem resolution
BNon-serious injury possibleAdds architecture, unit, integration, and system testing
CDeath or serious injury possibleAdds detailed design and the most rigorous unit verification

An independent hardware control can lower the class. Segregation can confine class C to a small component.

SOUP, configuration, and problem resolution

  • SOUP: software of unknown provenance — every dependency you did not build
  • Record version, what you rely on it for, and its published bugs
  • Be able to reproduce exactly what was in a release
  • Every reported problem recorded, assessed for safety, resolved, verified

You already know this — you are responsible for what you ship, including what you imported.

What goes wrong

Lessons written in harm

Therac-25 as a fault tree

A software fault AND no hardware interlock AND a routinely overridden error — with an organisation that let it recur

A software fault AND no hardware interlock AND a routinely overridden error — with an organisation that let it recur

The lessons of Therac-25

  • Do not replace an independent interlock with software
  • Concurrency faults can depend on operator speed
  • Frequent cryptic errors train users to override them
  • Reused code is not proven safe by another system's history
  • Investigate incident reports; do not reassure them away

Required reading: Leveson and Turner's investigation.

Pumps, units, and alarms

Infusion pump failures

  • 1.0 entered as 10: a tenfold overdose
  • mg versus micrograms; per hour versus per minute
  • Silent clamping; mode confusion
  • Response: drug libraries with hard and soft limits

Units and alarms

  • Glucose units differ by a factor of 18
  • Mars Climate Orbiter lost to pound-force versus newtons
  • Most monitor alarms are false or irrelevant
  • An alarm is a test with a prevalence problem

The identifiability spectrum

Identified, pseudonymised, de-identified, anonymous — pseudonymised data are still personal data

Identified, pseudonymised, de-identified, anonymous — pseudonymised data are still personal data

Quasi-identifiers combine: ZIP code, sex, and full birth date identify about 87 percent of Americans.

Medical data's own traps

  • Free text: notes mention names, relatives, employers, places
  • Dates: strongly identifying; shift consistently per patient
  • Images: burned-in text, reconstructable faces, DICOM headers and private tags
  • Rare conditions and small numbers
  • Linkage with another dataset — including one that does not exist yet

The legal frameworks in outline

FrameworkWhat a builder needs to know
GDPR and UK GDPRHealth data are special category: a lawful basis and an Article 9 condition; DPIA for high-risk processing; data protection by design
Caldicott principles (UK)Justify the purpose; minimum necessary; need-to-know; the duty to share matters too
HIPAA (US)Covered entities and business associates; minimum necessary; de-identify by Safe Harbor (18 identifiers) or Expert Determination

Never put real patient data into a tool the organisation has not approved — including a chat assistant or a bug report.

The standards

StandardWhat to know
HL7 version 2Pipe-delimited messages; still carries most hospital traffic; every site customises it
FHIRResources as JSON over REST; R4 widely deployed; SMART on FHIR for app launch
DICOMFile format and network protocol for images; DICOMweb over HTTP
TerminologiesSNOMED CT findings; LOINC what was measured; ICD diagnoses; UCUM units

A number without a code and a unit is not clinical data.

Security

Availability is a safety property

Why hospitals are targets

EventWhat happened
WannaCry (2017)Unpatched Windows worldwide; a third of NHS trusts in England disrupted, ambulances diverted
Change Healthcare (2024)US claims and pharmacy processing disrupted for weeks; largest reported US health data breach
Synnovis (2024)London pathology halted; operations cancelled; appeals for O-type blood donors

A system that is confidential and intact but down is a system whose patients are not being treated.

What regulators expect, and secure development applied

Regulators

  • US cyber devices since March 2023: vulnerability plan, coordinated disclosure, SBOM
  • EU MDR: IT security in safety requirements
  • IEC 81001-5-1 secure lifecycle; MDS2 form

Applied

  • Threat model the clinical workflow: gloves, 3 a.m., emergencies
  • Plan for patching: signed updates, rollback
  • Embedded: close debug ports, no hard-coded secrets, a defined safe state

AI and machine learning

  • Dataset shift: a widely used sepsis model performed far worse at a new site
  • Shortcut learning: a pneumonia model learned which hospital took the X-ray
  • Subgroup performance hidden by the average
  • Labels are often one opinion or a billing code
  • Leakage and prevalence mismatch inflate results

Locked versus adaptive algorithms; predetermined change control plans (FDA, December 2024).

Units, validation, and audit trails

  • Unit is part of the type; convert once at the boundary; reject ambiguous input
  • Validation that respects the user: say what is wrong and what to do
  • Impossible means hard stop; unusual means deliberate, logged confirmation
  • Never auto-correct a clinical value; read back with the unit
  • Hash-chained audit logs make tampering detectable

k-anonymity arithmetic

k = 1

1,000 people × sex, birth year, postcode district = 8,000 cells — most people are alone in theirs

Generalise to 10-year bands and regions: 80 cells, about 12 per cell. k is a floor, not a guarantee.

Threat modelling with STRIDE

  • Spoofing — authentication
  • Tampering — integrity
  • Repudiation — who changed what
  • Information disclosure — confidentiality
  • Denial of service — availability
  • Elevation of privilege — authorisation

Tools you can use today

ToolUse
SyntheaSynthetic patient records as FHIR — never develop against real data
HAPI FHIR, InfernoLocal FHIR server; conformance testing
pydicom, defacing toolsInspect and de-identify DICOM, including private tags
ARX, sdcMicrok-anonymity and re-identification risk metrics
Threat Dragon; Syft, CycloneDX, OSV-ScannerThreat models; SBOMs and vulnerability matching
PhysioNet, TCIAPublic data — honour any credentialing exactly

Worked example: the companion app that grew

VersionThe requestWhat changes
1Learners scan a QR code, answer three questions, results to the educatorNot a device; minimal personal data; ordinary security
2Also record whether the learner has joint hypermobilitySpecial category health data; a study — stop, ask, do not add the field
3Patients measure elbow angle at home with the phone cameraVery probably a device; IEC 62304; accuracy validation; a sponsor and regulatory decision

In software, scope creep is regulatory creep. Keep the intended-use statement in the README.

Workshop exercise and exit criteria

  • Classify five apps on the IMDRF table and name the deciding question
  • Build a synthetic FHIR pipeline that handles codes and units explicitly
  • De-identify a public DICOM file and document what remained
  • Compute k for three generalisations of a Synthea table
  • Threat-model the mock monitor; produce an SBOM for a project of yours

What this chapter does not establish

  • You cannot determine regulatory status
  • You are not compliant with IEC 62304 or any other standard
  • This is not legal advice
  • De-identification is specialist work
  • Security testing of clinical systems needs written authorisation
  • A model's metrics are not its clinical value

Next — Making a model that teaches.