Reversible, encrypted de-identification of clinical notes
- Project
- ReDACT-HW, university capstone
- Team
- 4 people
- My part
- Rule-based PHI detector, manual PHI review, the whole frontend, and the rule-based evaluation. I also contributed to the LLM detector.
- Tags
Overview
ReDACT-HW lets clinicians use cloud LLMs on patient notes without exposing anyone's identity. Personal data is detected, replaced and encrypted on the local machine, so only de-identified text ever leaves the trusted environment. An authorised key holder can still recover the original if needed.
The problem
Clinicians want AI to summarise and analyse patient notes, but sending the real notes to cloud LLMs creates big HIPAA and privacy risks. Scrubbing identifiers (PHI) by hand is slow and easy to get wrong, so a lot of healthcare teams simply can't use modern AI tools safely.
- Sending the raw note means names, dates of birth, record numbers and addresses all go to a third party.
- Just deleting the identifiers, the way normal de-identification does, strips out useful context and makes it impossible to get the original back.
- Our approach is to replace each identifier with a consistent, encrypted look-alike. The note still reads naturally, is safe to share, and can only be reversed with the key.
example
My contribution
This was a team of four. The parts I worked on were:
- Rule-based PHI detector – built on Microsoft Presidio with the spaCy NLP model and regex patterns, plus custom recognizers for Australian identifiers.
- Manual PHI review – the step where a reviewer checks and corrects the detected spans.
- All of the frontend, including the step-by-step processing flow.
- Evaluation of the rule-based detector.
- Contributions to the LLM detector.
How the system fits together
The system is split into a trusted local environment, where PHI is present, and an open environment, where only de-identified text exists. The trust boundary between them is the core security property.
Processing a note
The Process a note page works a bit like a checkout – one step at a time, carrying the result of the previous step forward. There's an optional first step that turns a handwritten note into the text file used for the rest.
- Upload the clinical note as a plain text file. Nothing leaves the local environment at this point.
- Two detectors run on the note: a rule-based one (regex patterns plus an NLP model) and a local LLM. Each finds PHI on its own and labels it against about 30 identifier categories.
- Inspect each detector's output. Every result is shown on its own screen with the note highlighted and every span tagged, so you can compare the two side by side.
- Manual PHI review. Both lists are merged into one view. The reviewer can add, remove or relabel any span – the whole point is to catch every identifier before anything goes to the LLM.
- Preview the surrogate note. Original and surrogated versions are shown next to each other.
- Download the de-identified note, now safe to give to a cloud LLM.
What's in the app
| Page | What it does |
|---|---|
| Process a note | The guided flow above: upload, detect, review, surrogate and download |
| Re-identify | Upload a de-identified note to recover the original from the surrogate values |
| History | Browse processed notes next to their de-identified versions, and generate a summary |
| Evaluation | Measured results for the rule-based detector, the LLM, pseudonymisation and the threat model |
| Settings | Change passwords and create accounts |
PHI detection
Rule-based detector
The rule-based service looks for identifiers that have a recognisable structure or a well-known vocabulary. It sits on Microsoft Presidio, which runs independent recognizers over the note and pools everything into one list of typed spans.
- Pattern recognizers: regex and structural checks for fixed formats like phone numbers, emails, Medicare numbers and record numbers – places where a pattern is cheaper and more reliable than a language model.
- NLP recognizer: spaCy's
en_core_web_lgmodel reads the sentence to pick up people, organisations and places that don't have a fixed format. - Custom Australian recognizers: added because clinical notes contain identifiers Presidio doesn't know out of the box.
| Recognizer | Covers |
|---|---|
| AHPRA | Health practitioner registration numbers |
| HPI-I | Healthcare Provider Identifier, Individual |
| HPI-O | Healthcare Provider Identifier, Organisation |
| IHI | Individual Healthcare Identifier |
| Suburb / postcode | Built from the full list of Australian suburbs and postcodes |
I evaluated this detector on 100+ synthetic notes with planted identifiers, scored at three different strictness levels and split by recognizer type, so you can see what the rules contributed versus the NLP model.
Local LLM detector
The LLM service finds the identifiers that need context – patient, relative and clinician names, hospitals and
clinics, and whether a date is a birth date or a clinical one. It runs gemma4:e4b locally through
Ollama, so the note never leaves the machine.
- Prompt versions: five were built and scored on the same synthetic notes. Adding more rules actually made the small models worse, so version 4 keeps the original prompt plus six short rules – each one only stayed because it improved a scored run.
- A second pass for repeated names: the model often catches a name in the header but misses later mentions like "Mrs Kaur". A short second call asks for every other mention of the people already found. On 15 notes that lifted patient-name recall from 0.45 to 0.85.
- Structured, repeatable output: the answer is locked to a JSON list using only the PHI categories, with a fixed seed so the same note always gives the same result.
- Exact positions: the model copies each identifier word for word, then code finds where it sits in the note and marks every occurrence.
Five local models were tried on 15 notes, and the three strongest were run on 100:
| Model | F1 | Decoys wrongly flagged | Notes with nothing missed |
|---|---|---|---|
| gemma4:e4b | 0.948 | 0 of 452 | 27 / 100 |
| llama3.1:8b | 0.933 | 31 | 15 / 100 |
| qwen2.5:7b | 0.898 | 49 | 6 / 100 |
On a held-out set of 20 notes not used while building the prompt, it found 95% of identifiers (recall 0.951) with no false alarms (precision 1.000). It still misses some, which is why its spans are merged with the rule-based detector's and checked in the manual review step.
Manual review
A missed identifier is the critical error. The target is PHI recall of at least 0.98. So after the automated detection there's a review step where a person can add, remove or relabel spans before anything is surrogated. Where the two detectors disagree, a span can carry several labels for the reviewer to sort out.
De-identification, encryption and the key vault
Once the reviewer confirms the spans, each identifier is replaced with a surrogate of the same format. Different kinds of identifier are handled differently, because what makes them reversible decides what has to be stored.
- Numbers are encrypted. Record, phone and Medicare numbers use FF3-1 format-preserving encryption (NIST SP 800-38G Rev 1), so a 7-digit record number becomes another 7-digit number. Reversing it is just decryption – nothing extra is stored per note.
- Names and places get look-alikes. A keyed hash picks a realistic surrogate from pools of names, institutions, streets and cities, so the same person always gets the same surrogate. Because a hash can't be reversed, the mapping is stored in the encrypted vault.
- Dates move together. Every date in a note is shifted by the same offset (derived from the key and a multiple of seven days) so intervals and weekdays stay the same.
- One root key. A single 32-byte root key is the only secret. Separate keys are derived from it for each purpose, and the vault is sealed with AES-256-GCM, which also detects any tampering.
- Fail closed. If a span has a type with no surrogate strategy, the run stops with an error. Letting an unrecognised identifier through would look like success while still leaking PHI.
Other components
- Handwriting transcription: an optional step that reads a photo or scan of a handwritten
note with a local vision model (
qwen2.5vl:7bvia Ollama). The prompt is set up so it transcribes rather than interprets, and a repeat penalty plus an output cap stop the model from looping. - History and summaries: every processed note is kept, with access controlled by role. Edits are saved as new versions. Cloud summaries are generated only from the server's own copy of the de-identified text, so an original can't be sent to the cloud by mistake.
Design choices
- Local-first trust boundary: transcription, detection, surrogation and the key vault all run locally. The cloud LLM only ever sees de-identified text.
- Reversible pseudonymisation, not redaction – so context is kept and recovery is still possible with the key.
- Hybrid detection: rules handle the structured identifiers, language understanding handles the free-text ones. Both are run and the results are pooled.
- A human in the loop, because a missed identifier is the critical error.
- Privacy and utility are measured – detection recall and precision, whether the pseudonymisation is correct, round-trip recovery, and resistance to attacks from three different adversary classes.
- Local files only, no external database – it's a single-site tool and nothing is deployed to the cloud.
Tech stack
| Frontend | React, TypeScript, shadcn/ui, Tailwind CSS, Recharts |
| Backend | Python, Flask |
| PHI detection | Presidio, spaCy (en_core_web_lg), custom AU recognizers, local LLM via Ollama |
| Encryption | FF3 format-preserving encryption, cryptography, encrypted key vault |
| Storage | File system |
| Testing | pytest, plus an evaluation harness over synthetic notes |