Skip to content

Add RdmpCohortBuildBreakdownByGroups (cohort build breakdown by groups) - #101

Open
mtinti wants to merge 3 commits into
HicServices:mainfrom
mtinti:feature/cohort-build-breakdown-by-groups
Open

Add RdmpCohortBuildBreakdownByGroups (cohort build breakdown by groups)#101
mtinti wants to merge 3 commits into
HicServices:mainfrom
mtinti:feature/cohort-build-breakdown-by-groups

Conversation

@mtinti

@mtinti mtinti commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

This ports the cohort build breakdown plugin here as its agreed long-term home. It was previously reviewed as HicServices/RDMP#2368 and that PR will be closed with a link back here once this merges.

What it does

Adds one command, ExportCohortBuildBreakDownByGroups, which reproduces the Cohort Builder's count tree (each set's and container's FinalCount plus the cumulative running totals as UNION/INTERSECT/EXCEPT are applied) split by a group column, for example Scottish health board. Output is a wide CSV: one row per count point, a Total column (RDMP's own unfiltered number), one column per group recognised by a user-supplied lookup table, then Other and NotKnown, with % of final cohort and % of reference population rows at the bottom. Groups plus Other plus NotKnown reconcile to Total on every row.

It works purely from the query cache: the cohort is built once through CohortCompiler, then every count point is recomposed from the cached per-set identifier tables with one GROUP BY per node joining the reference table on the cache server (the cohort-set source queries are never re-run). Inputs are four ColumnInfo objects (group-by column plus the lookup's key, label and optional grouping columns); the reference and lookup tables are derived from the columns, and the patient identifier is the reference table's single IsExtractionIdentifier column. A SharePreset resolves the SHARE names (SHARE_Demography.Region, z_hb_lookup.Region/HB_Name) by name at runtime for a one-click GUI menu entry; a second entry prompts for the inputs, and on deployments without those objects the preset finds nothing and the command prompts as normal.

Tests in HICPluginTests/CohortBuildBreakdownByGroupsTests.cs: unit tests (lookup validation, transformed-identifier whitelist including aliases, PostgreSQL database-name normalization, per-DBMS set operators, report projection) plus a deterministic DB-integration fixture asserting the national and per-group counts and cumulatives explicitly, that the unfiltered column equals CohortCompiler's own counts, and that groups + Other + NotKnown == Total on every row. The fixture's PostgreSql case skips where no PostgreSql connection string is configured.

The diff is purely additive (new project, referenced from Plugin/main and HICPluginTests); no existing code is touched and the RDMP submodule pin is unchanged. Full usage and preconditions are in Documentation/CohortBuildBreakdownByGroups.md.

🤖 Generated with Claude Code

https://claude.ai/code/session_0169JCnaL3fhhZjseDx2XXT2

Reproduces the Cohort Builder's count tree (per-set/per-container FinalCount
plus cumulative running totals) split by a group column (e.g. Scottish health
board), labelled by a user-supplied lookup table, written as a wide CSV with
Total / per-group / Other / NotKnown columns and % of final cohort and % of
reference population rows. Works purely from the query cache: the cohort is
built once, then every count point is recomposed from the cached per-set
identifier tables with one GROUP BY per node.

Inputs are four ColumnInfo objects (group-by column + lookup key/label/optional
grouping); the reference and lookup tables are derived from the columns and the
patient identifier is the reference table's single IsExtractionIdentifier
column. A SharePreset resolves the SHARE names by name at runtime for a
one-click GUI entry; a second entry prompts for the inputs.

New project in the solution (referenced by Plugin/main for packaging), tests in
HICPluginTests (unit + DB fixture, parameterised for SQL Server and PostgreSql),
documentation page included.

Previously reviewed as HicServices/RDMP#2368 (all review threads addressed
there); moved here as the agreed long-term home.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0169JCnaL3fhhZjseDx2XXT2
@mtinti
mtinti marked this pull request as ready for review September 9, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant