Skip to content

LK009 — duplicate_subjects

Subjects that look like the same person under two ids.

default severity warning
injector ehrlint.inject.inject_lk009

Why this matters

Patients get duplicate records across registrations, sites, and merges. Two ids for one person defeat a subject-level split in exactly the way LK005 guards against, but invisibly -- the split is disjoint by id while not being disjoint by person.

What it looks like in practice

A patient registered twice -- at two sites, or before and after a record merge. The split is disjoint by id while not being disjoint by person, so LK005 is clean and the leak is invisible.

A note on severity

Deterministic, not probabilistic, and it skips rather than guessing when the demographics in your data distinguish too few profiles for a collision to be evidence. Reporting arithmetic as a finding would be the fabricated statistic this project forbids.

The query it runs

WITH sig AS (
  SELECT subject_id, STRING_AGG(DISTINCT code, '|' ORDER BY code) AS signature
  FROM events WHERE time IS NULL GROUP BY subject_id
)
SELECT signature, COUNT(DISTINCT subject_id) AS n_subject_ids
FROM sig GROUP BY signature HAVING n_subject_ids > 1

Worked example

On the clean synthetic cohort, which is clean by construction:

$ ehrlint audit --data clean/ --task task.yaml --checks LK009

LK009 did not fire.
  No two subject ids share an identical demographic signature.
exit code 0

With the matching leak planted by ehrlint.inject.inject_lk009:

$ ehrlint audit --data leaky/ --task task.yaml --checks LK009

LK009 duplicate_subjects  [warning]
  4 group(s) covering 8 subject id(s) share an identical static demographic signature and may be the same person under multiple ids.
  affected: 8 of 124 subject(s) (6.5%), 8 row(s)

  example rows:
    subject_id   signature                 subject_ids          n_subject_ids
    S000050      BORN_1990s|BORN_ON_00000  S000050,S000050-DUP  2            
    S000050-DUP  BORN_1990s|BORN_ON_00000  S000050,S000050-DUP  2            
    S000098      BORN_1950s|BORN_ON_00000  S000098,S000098-DUP  2            

exit code 0

Reproduce both:

ehrlint synth --out clean/ --n-subjects 120 --seed 0
ehrlint synth --out leaky/ --n-subjects 120 --seed 0 --inject LK009
ehrlint audit --data leaky/ --task leaky/task.yaml \
  --labels leaky/labels.parquet --splits leaky/splits.json --checks LK009

What to do about it

Resolve the duplicates before splitting. A shared signature is a candidate for review, not a confirmed duplicate: twins and sparse demographics both produce collisions.

When it skips

A skip is not a pass. This check reports a skip, with the reason, when its inputs are not available — see reading a report.