The Lawfare Academy

Lawfare Group → Knowledge Institute → Lawfare Academy

← RHIA Foundations: Health Information, Analytics and Administration

Unit 10

Relational data, query logic and denominator integrity

Learning objectives

  • Design a small relational schema and detect duplicated measures.
  • Explain how filtering changes a report’s population.

Define the grain of every table

The grain is what one row represents. A person table, encounter table and charge-line table have different grains. A person can have several encounters and an encounter several charges. A primary key should identify a row; a foreign key expresses a relationship. A name is not necessarily a unique or stable key.

Before joining, predict row counts. An inner join retains matching combinations; a left join retains rows from the left even without a match. A filter on a right-side field after a left join can unintentionally exclude the unmatched rows. Null is not automatically zero, and comparisons involving missing values require explicit treatment.

Aggregate at the intended level

Count distinct encounter identifiers when the measure is encounters, but do not use DISTINCT as a universal repair for a flawed query. Two legitimate encounters may share other values. Aggregate charge-line amounts at their own grain, then join the encounter-level total if appropriate. Check expected key uniqueness and reconcile totals with a small synthetic dataset.

For every report, document inclusion criteria, period, statuses and cutoff. A query that runs without errors may answer the wrong question. Use fictional tables only; the exercise does not require querying patient systems or learner data.

Worked example

Synthetic encounters E1 and E2 each have one patient. E1 has charges 20 and 30; E2 has a charge 40. A join produces three rows. What are the encounter count, charge count and total charges? What happens if each joined row is treated as an encounter?

Work through the reasoning

There are two encounters, three charge lines and total charges 90. Counting joined rows as encounters incorrectly gives three. If a separate encounter-level measure is repeated on E1’s two charge rows, summing it can inflate the result. Check the grain and keys rather than merely accepting the join’s row count.

Check understanding

How many encounters are in the original synthetic dataset?

  1. 2
    Feedback

    Correct: E1 and E2 are distinct encounters.

  2. 3
    Feedback

    That is the joined charge-row count.

  3. 90
    Feedback

    That is the monetary total.

  4. 1
    Feedback

    There are two identifiers.

Why can a right-side filter after a left join matter?

  1. It can exclude unmatched rows and change the denominator
    Feedback

    Correct: inspect the population actually retained.

  2. It always fixes duplicates
    Feedback

    Filtering is not a universal duplicate repair.

  3. It guarantees privacy compliance
    Feedback

    Query structure alone does not establish compliance.

  4. It changes every null into zero
    Feedback

    Null handling must be explicit.

Further reading

    My learning →