# Account signals from linked claims: design

Written before any world was generated or any pipeline was run. Every number below is in
`linkedclaims/protocol.json`, which this note explains; if the two disagree, the protocol is the record.

## What this part adds

The retargeting holdout study asks one question in several settings: what a report can and cannot tell a team about
who is growing and why, and what would settle it.

- Rounds 1 and 2 use a simulated software company: attribution credit against a holdout, then a media mix model checked
  against both.
- Round 3 (`life-sciences-signals.html`) uses public payment and prescribing records for one state. It works on
  aggregates only and makes no patient-level claim: the link from a payment to a prescriber is an exact clinician id, and
  the account is the clinician.
- This part goes under that page. Commercial and research teams in life sciences build clinician (HCP) and organisation
  (HCO) signals from patient-level claims and EHR records. Before any signal exists, someone chooses how to link a
  patient's records, which clinician gets credit for a start, which organisation a clinician rolls up to, and which
  codes define the product and the condition. No published page measures what those choices do to the answer. Here the
  records are synthetic, so the true patient, the true deciding clinician and the true organisation behind every record
  are known, and each choice can be scored against them.

Overlap with other published studies, checked before this design: the identity resolution study compares stitching
rules for user counts on a synthetic shop, and the clinical data integration contracts study compares feed contracts
for clinical quality figures. Neither builds account signals, ranks accounts, credits clinicians or rolls clinicians
up to organisations. This part reuses the general idea of deterministic against probabilistic linkage only as one of
four choices, and asks a different question: which accounts look like they are growing.

## The question

When account signals for clinicians and organisations are built from linked claims and EHR records, how much do
linkage, de-duplication, terminology mapping and affiliation choices change which accounts look like they are growing,
and which acceptance checks would let a commercial team and a research team each trust the dataset?

## Data: a synthetic market

One synthetic market per seed, 24 months. Months 1 to 12 are the lookback; months 13 to 24 are the measured year,
split into a first and second half.

- **Organisations:** 4 health systems on an EHR network with their own pharmacies, 12 group practices and 40 small
  practices, in 6 regions.
- **Clinicians:** primary care physicians, specialists, and nurse practitioners or physician assistants (NP/PA), each
  NP/PA with a supervising physician in the same organisation. Ids are 10 digits with a check digit, shaped like a
  national clinician id, and all start with 9, which no real id does. Each clinician has a preference for product A
  against B and C; some adopt A during the measured year (true growers) and some move away from it. Some clinicians move
  organisations, and two small practices and one group are acquired by a system. The affiliation history records each
  change up to three months late.
- **Patients:** 36,000 with the indication and 3,600 with a related condition that shares the diagnosis category (it is
  not the indication). Patients have no names: demographic fields are codes (surname code, given-name code, date of
  birth, sex, region). Twins exist. Patients switch health plans, which gives them a new member id; part of the switches
  come with a plan crosswalk from the old id to the new one.
- **Records:** pharmacy claims (member id, fill date, package code, prescriber id), medical claims (member id, visit
  date, diagnosis code, procedure code, rendering id) and, at the four systems only, EHR encounters (record number, date,
  diagnosis code, attending id). Every enrolment and EHR registration carries its own copy of the demographics, with
  typing errors, name variants and date-of-birth slips at stated rates.
- **Terminology:** a fixture of invented code values in the formats of public diagnosis, procedure and drug code
  systems. Mid-period, the diagnosis system gets a new version (one code splits into two children and a new, more
  specific code appears) and product A gets new package codes that health-system pharmacies adopt first.
- **Truth:** the generator keeps the true patient, the true deciding clinician, that clinician's true organisation on the
  date, and the true product behind every record.

## The choices (the arms)

36 pipelines: every combination of

1. **Patient linkage:** deterministic tokens (records that share an exact hash of surname, given name, date of birth and
   sex) against probabilistic scoring (field-by-field agreement weights over pairs from two blocking passes, a declared
   threshold, connected groups).
2. **Clinician attribution:** the prescriber on the start fill, the rendering clinician on the latest medical claim with
   the indication in the 90 days before, or the attending clinician on the latest EHR encounter with the indication in
   the 90 days before.
3. **Organisation roll-up:** the clinician's organisation on the service date, or the organisation recorded at the end.
4. **Terminology:** the exact codes listed at the start of the measured year, a grouped value set (every code under the
   indication category and every package of each ingredient, by the version in force on the date), or the grouped set
   with its documented exclusions (the related condition's code), pinned to one release.

Reference pipeline: probabilistic, prescribing, service date, curated. Clinician lists depend on linkage, attribution
and terminology only.

## Measures, against truth

- A **start** is a fill of product A in the measured year with no fill of A in the 12 months before, for a person with
  an indication code in the 12 months up to the fill. Growth is second-half starts minus first-half starts. The top 20
  clinicians and top 10 organisations are ranked by growth.
- Names common to all six linkage and attribution clinician lists, and their pairwise overlaps (headline).
- Each pipeline's overlap with the true top 20 clinicians and top 10 organisations, and the members of its lists with
  no true growth.
- Starts against truth: total error, false starts, missed starts, and false starts from one patient split into two.
- Clinician-level start error, organisation share of class error, and the research cohort count per quarter.
- A noise floor: the true top 20 in two draws of the same market (same clinicians and preferences, new patients). It
  says how much a top-grower list moves with perfect data.

## Acceptance checks, for two consumers

Each check uses only what a team holds (the records, the reference files, the plan crosswalk, a second build), so it
can run on real data. Here each is also scored against truth.

- **Commercial (rank accounts and act on the list):** C1 the ranking survives a re-linkage; C2 every class package is
  mapped; C3 starts are credited to individual clinicians; C4 last half's organisation counts do not change when the
  data is rebuilt later.
- **Research-ready (count a cohort and publish it):** R1 counts are reproducible with the code-set release pinned
  (bookkeeping: it fails only for a build that reads the latest release, used as its planted control); R2 every code of
  the condition and the class seen in the data is in the set or documented as excluded; R3 every diagnosis code in the
  set is mostly carried with another code of the set (a code that stands alone may be a different population); R4
  linkage error is bounded, from the crosswalk pairs and from linked persons whose records disagree on sex.

The thresholds are in the protocol. The faults these checks look for were built into the generator by the same author,
so their pass and fail rates are a self-test. What is not a self-test: how far the top-grower lists move, and whether
passing the checks goes with a list closer to the truth.

## Runs, spread and stopping rule

20 markets (seeds 1 to 20), each with all 36 pipelines; a redraw of each for the noise floor; a sweep of the main
assumed inputs at half and double, one at a time, on 6 markets each. No sampling interval: every error is against the
generator's truth, and the spread is the median with the lowest and highest market. A direction or ranking between
choices is stated only when at least 18 of the 20 markets agree. The number of markets is fixed; none is added or
dropped after results. A pilot seed (0, not one of the 20) may change only the patient count, by the rule in the
protocol, before any pipeline is compared with truth.

## Predictions (written before any run)

- P1: In the median market, fewer than 10 of the 20 top-growing clinicians appear in all six linkage and attribution
  lists.
- P2: Attribution moves the clinician list more than linkage does.
- P3: The reference pipeline matches at least 14 of the true top 20 clinicians.
- P4: Current-affiliation roll-up puts at least 2 organisations with no true growth into the top 10.
- P5: The exact code set misses more than 5% of true second-half starts.
- P6: Pipelines that pass all four commercial checks match more of the true top 20 than pipelines that fail one.
- P7: Two draws of the same market share fewer than 15 of their true top 20 clinicians.
- P8: Only probabilistic linkage with curated codes passes all four research checks, in at least 18 of 20 markets.

## Limits, stated before the results

Synthetic records with assumed rates; the sizes show how each choice can fail, not how far a real dataset drifts. No
clinical validity. No real code value, clinician id, organisation or data source is used or named. The study shows a
method; it claims no healthcare or life-sciences employment.

## Reproduction

The generator uses only the Python standard library and string-seeded random streams, so a world replays byte for byte
on Python 3.12. `python3 -B -m linkedclaims.run --out DIR` rebuilds every result file and refuses an existing folder;
the tests compare the replay with the published files.
