Test data that is realistic and contains no patient
The reason teams copy production into staging is that synthetic data is usually too clean to find bugs. That is a solvable problem, and solving it is cheaper than the alternative.
Every engineer who has worked on a billing system has had the thought: it would be so much easier to debug this against real data.
It would. It is also a disclosure of protected health information to an environment that is not covered by the controls production is covered by, usually to a database with weaker access rules, frequently onto a laptop, and occasionally into a backup that outlives the investigation by four years.
The argument for copying production is not laziness. It is that synthetic test data is normally too tidy to be useful: one payer, one plan, names without apostrophes, every claim paid in full, no reversals, no twins sharing an address and a surname. A test suite built on that passes cheerfully while the real pipeline falls over.
So the task is not to forbid realistic data. It is to generate data that is realistic in the ways that break software.
What makes test data realistic
Not plausible names. Plausible awkwardness. A generator worth having produces, deliberately and in known proportions:
- Names with apostrophes, hyphens, two spaces, accented characters, a single-letter surname, a name longer than the field the standard allows.
- Patients who share a surname and an address; patients who share a date of birth and a first name; a junior and a senior at the same address.
- Encounters with one line and encounters with sixty.
- Claims with twelve diagnosis codes and claims with one.
- Secondary coverage, tertiary coverage, coverage that terminated mid-month, retroactive termination.
- Remittances that pay in full, pay nothing, pay partially, reverse a previous payment, carry a provider-level adjustment, and arrive out of order.
- A deposit covering two remittances, and a remittance paid across two deposits.
- Dates that are awkward: a service on 29 February, a date of birth that makes the patient a newborn, a date of birth that makes them 94.
- Amounts that are awkward: a seventy-cent amount across three lines, a claim that balances to zero, a negative balance.
Each of those is a bug somebody has already shipped. A generator that emits them by construction turns a category of production incident into a test that fails on a laptop.
Where the data should come from
Three routes, in descending order of preference.
Generated from scratch, by a seeder that composes the awkward cases above. This is the one to build, because it is reproducible from a seed value, contains nothing real by construction, and can be committed.
Published sample files for the format work. The implementation guides and the trading partners provide example transactions, and these are the right thing to parse first because they are what the specification authors considered canonical.
De-identified extracts, if an extract genuinely has to come from production. This is a last resort and it is not a sanitising pass over a copy: it is a deliberate transformation with a defined standard behind it. The safe-harbour method names the identifiers that have to come out — names, geography below state level, all date elements other than the year, contact details, every identifying number, and ages over 89 which have to be aggregated rather than shifted. Note what that leaves: the dates are gone, which usually removes most of what you wanted the extract for. That is a feature of the standard, not a shortcoming of the implementation.
The honest conclusion is that de-identification rarely helps a developer, which is why the generator is worth the investment.
Keeping the environments apart
Generated data is only half of it. The other half is making sure that a test environment cannot do anything real:
- Distinct identifiers. Use the reserved example ranges for national provider and plan identifiers rather than real ones, so a file that escapes cannot be mistaken for a live claim.
- Outbound paths that go nowhere. No test environment should hold credentials for a production clearinghouse endpoint. The failure here is not hypothetical and it is embarrassing in a way that reaches the practice's payer relationships.
- Email and messaging disabled at the transport, not by a flag in the application. A flag can be wrong; a mail server that does not exist cannot send.
- Visibly different. A banner, a colour, something that makes it obvious which environment a screenshot came from. This prevents the support conversation where nobody can tell whether the broken screen is real.
If production data must be used to investigate something, the control that works is a narrow, time-boxed, audited access path into production itself rather than a copy somewhere else. A copy is a new system holding PHI, with its own access list, retention, and risk analysis, and almost nobody who makes one treats it that way.
What bites once it is live
A generator with no seed is not reproducible. When a bug appears against generated data, somebody needs to regenerate exactly that data. Seed it, print the seed, and put the seed in the failure output.
Too realistic becomes a problem of its own. If the generated data is good enough that nobody can tell it from real, it will eventually be treated as real. Keep the surnames obviously fictional — a consistent convention is enough — and keep every identifier in a reserved range.
Demo data is a different product. The data a salesperson shows a prospect wants to be tidy and attractive, which is the opposite of what a test suite wants. Two generators, or one with two profiles, and never the test fixtures in a demo.
Fixtures drift away from the formats. A trading partner changes what it sends and the fixture library keeps testing last year's shape. Refresh from current published samples on a schedule, and keep each fixture's provenance in a comment at the top of the file.
How to test it
- The generator, run twice with the same seed, produces identical output.
- Every provider and plan identifier in the generated set is in the reserved example range. Assert this in a test, not in a convention.
- The awkward cases are present in a fresh generated set: the apostrophe, the same-name-same-address pair, the sixty-line encounter, the reversal, the many-to-many deposit, the 29 February service date.
- The full pipeline runs end to end on generated data — claim built, acknowledgment parsed, remittance posted, statement produced — with no fixture that was ever derived from a real patient.
- A check in continuous integration that the fixture directory contains no file whose provenance is unstated.
What we do
We build the fixture set from a seeded generator that emits the awkward cases on purpose, keep every identifier in the reserved example ranges so nothing we generate can be mistaken for a live claim, and investigate production problems through a narrow audited path into production rather than by making another copy of it somewhere with weaker controls.
Building something that has to talk to a payer?
If any of the above is a problem you currently have, describe it and we will tell you what we would do about it.