Skip to content

Stage 6: Test-patient filter

EHR exports sometimes include training, quality-assurance and test patients. Stage 6 removes any patient matching an exclusion rule, together with all of that patient's records and documents. The bundle before filtering is kept as dashboard_data.prefilter.json so a removal can be checked.

Sources of exclusion rules

Rules come from two places, and both are applied:

  1. HARDCODED_TEST_EXCLUSIONS, a list near the top of run_pipeline.py, for rules that stay the same between runs and belong under version control.
  2. test_patients.txt in the working directory, for rules that change between runs or that someone other than the developer maintains. A template is available.

The log line Total active exclusion rules: N shows how many were loaded.

Rule syntax

One rule per line. Lines starting with # are comments, and blank lines are ignored.

Rule Example Removes
id id: a1b2c3d4-... The patient with that exact ID
name name: Test Patient An exact full-name match, ignoring case
name_contains name_contains: zztest Any patient whose first or last name contains the text, ignoring case
mrn_contains mrn_contains: 99999 Any patient whose MRN contains the text, ignoring case

A line without a rule type is read as name_contains.

Example

# near the top of run_pipeline.py
HARDCODED_TEST_EXCLUSIONS = [
    'name: Zztest Patient',
    'name_contains: training',
]
# test_patients.txt
mrn_contains: 99999
name: Demo User

These rules remove anyone named exactly "Zztest Patient" or "Demo User", anyone whose first or last name contains "training", and anyone whose MRN contains "99999".

What to check

The log reports how many patients and records were removed. Compare it with the list of test accounts from each health system before every run, and check that name_contains rules are specific enough not to catch a real person.