# Clinical data integration contracts

Which integration checks keep patient identity, clinical meaning, time, provenance and consent intact when clinical
messages, lab results, device readings, enrollment files and claims about the same people are joined, and what does each
failure do to four published metrics if nothing catches it? Everything is synthetic: made-up people on fixed seeds, with
feeds shaped after public HL7 version 2, FHIR R4 and X12 layouts. The page is `index.html`; the design, committed before
any code ran, is `DESIGN.md` (sha256 aae10fb37331fba30d3bd299ef39e904210b1c4ed534b3f8133b12ad5969b7be, also pinned in
`design-declaration.json`).

## What is here

| File | What it is |
|---|---|
| `index.html` | The study page, built by `cdc/report.py` from `results/results.json` |
| `DESIGN.md`, `design-declaration.json` | The design, the fault schedule, the checks' thresholds and six predictions, as committed before any code ran |
| `cdc/world.py` | The synthetic population and its truth: people, coverage, care, labs, device readings, consent |
| `cdc/feeds.py` | The six feeds as envelopes: HL7 v2 ADT and ORU, FHIR Observation and Consent, X12 834 and 837P layouts |
| `cdc/faults.py` | The twelve declared faults |
| `cdc/parse.py` | The parser front end every arm shares, with the schema checks |
| `cdc/contracts.py`, `cdc/pipeline.py` | The semantic checks and the pipeline: landing, checks, identity, tables, metrics |
| `cdc/metrics.py` | Truth: the four metrics computed from the generator |
| `cdc/run.py`, `cdc/summarize.py` | The study run (one file per year and scenario in `results/stages/`) and the summary |
| `blind/` | What the independent author saw (`INSTRUCTIONS.md`, `samples.jsonl`) and the faults the author wrote (`faults.py`) |
| `results/results.json` | Every aggregate the page shows; `results/page-numbers.json` ties each page number to it |
| `tools/check_numbers.py` | Every number on the page must come from `results.json` |
| `tests/` | Unit tests on small cases, a replay of the summary and the page from the stored run files, and a seeded check of the generator |
| `NOTICE.txt` | Standards, codes and the licence terms followed |

`blind/faults.py` here is a reading copy of the author's file: the author's strings wrote number ranges with en dashes,
and the copy writes each one as "to". Nothing else differs, and no string it changes reaches a result.

## Reproduce

Python 3.12, standard library only (pytest for the tests):

```
python -B -m cdc.run
python -B -m cdc.summarize
python -B -m cdc.report
python -B -m pytest tests -q -p no:cacheprovider
python -I tools/check_numbers.py
```

The full run is 255 scenario runs: five years, each with no fault, the 12 faults alone, all together, 10 ablations, the
share sweep and the 10 blind faults. The tests need no run: they replay the stored files.

## Data and licence

No real person, record or organisation is in this study. Lab and device results carry LOINC codes; see `NOTICE.txt` for
the LOINC notice and the HL7 trademark note. The code may be reused for reading and reproduction.

Some files are packed in clinical-data-contracts-data-1.zip; unzip it here to restore the full export, which the manifest lists file by file.
