Add RdmpCohortBuildBreakdownByGroups (cohort build breakdown by groups) - #101
Open
mtinti wants to merge 3 commits into
Open
Add RdmpCohortBuildBreakdownByGroups (cohort build breakdown by groups)#101mtinti wants to merge 3 commits into
mtinti wants to merge 3 commits into
Conversation
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
marked this pull request as ready for review
September 9, 2026 11:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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