Skip to content

Add cohort scripting commands: ExportCohortAsScript / BuildCohortFromScript#2360

Draft
mtinti wants to merge 3 commits into
HicServices:developfrom
mtinti:feature/cohort-script-commands
Draft

Add cohort scripting commands: ExportCohortAsScript / BuildCohortFromScript#2360
mtinti wants to merge 3 commits into
HicServices:developfrom
mtinti:feature/cohort-script-commands

Conversation

@mtinti

@mtinti mtinti commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Proposed Change

Adds two CLI commands under CommandExecution/AtomicCommands/CohortScript:

  • ExportCohortAsScript — decompiles a CohortIdentificationConfiguration into a portable,
    data-free folder: requirement.md (placeholder), build.script.yaml (a runnable command
    script that recreates the cohort), query.sql (the SQL RDMP would run; if the cohort cannot be expressed as one query - sets span servers/credentials with no QueryCache - this falls back to a best-effort per-set decomposition plus notes) and
    catalogue-manifest.yaml (the extractable columns, patient-identifier column(s) and published
    filters of only the catalogues this cohort uses). The build script captures set operations,
    nested cohort sub-containers + child order, published-filter imports with parameters,
    hand-written filters, global (cohort-level) and aggregate-level parameters, nested AND/OR filter
    containers, patient index tables (joinables) with their joins/filters/parameters + the ix####
    alias, forced joins, disabled sets and sub-containers, customised dimension SQL, and the Project
    association. No patient data is emitted — only catalogue/table/column names and filter logic.
  • BuildCohortFromScript — the inverse: replays a build.script.yaml to rebuild an identical cohort.

The captured set was cross-checked against RDMP's native "clone Cohort Identification Configuration"
cascade so that an export → file → rebuild reproduces the same object graph the clone would, for
every aspect that affects cohort membership.

Notes for reviewers: CLI-only — the commands also appear in the GUI "Run…" palette automatically,
but there's no right-click wiring in this PR. No database migration; metadata only (no data processing).
A CHANGELOG entry will be added before this leaves draft.

The query.sql cross-server fallback is verified with a two-server docker fixture: the real "different server ... no QueryCache" error is captured, each set's SQL is emitted individually and executes against its own server, while a single-server cohort still produces the real combined query.

Type of change

  • Bugfix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation-Only Update
  • Other (if none of the other choices apply)

Checklist

  • Ensured that the PR branch is in sync with the target branch (i.e. it is automatically merge-able)
  • Created or updated any tests if relevant
  • Have validated this change against the Test Plan
  • Requested a review by one of the repository maintainers
  • Have written new documentation or updated existing documentation to detail any new or updated functionality and how to use it
  • Have added an entry into the changelog

@mtinti mtinti changed the title Feature/cohort script commands Add cohort scripting commands: ExportCohortAsScript / BuildCohortFromScript Jun 8, 2026
Comment thread Rdmp.Core.Tests/CommandExecution/TestCohortScriptRoundTrip.cs Fixed
Comment thread Rdmp.Core.Tests/CommandExecution/TestCohortScriptRoundTrip.cs Fixed
@mtinti mtinti force-pushed the feature/cohort-script-commands branch 9 times, most recently from e161219 to 70920bf Compare June 9, 2026 20:39
mtinti and others added 3 commits June 20, 2026 11:00
Two CLI commands under CommandExecution/AtomicCommands/CohortScript:

- ExportCohortAsScript: decompiles a CohortIdentificationConfiguration into a
  portable, data-free folder: requirement.md placeholder, build.script.yaml,
  query.sql, and catalogue-manifest.yaml (the extractable columns, patient
  identifier column(s) and published filters of ONLY the catalogues this cohort
  uses). The build script captures set operations, nested cohort sub-containers
  and child order, published-filter imports with parameters, hand-written
  filters, global and aggregate-level parameters, nested AND/OR filter
  containers, patient index tables (joinables) with their joins/filters/params,
  forced joins, disabled sets and sub-containers, customised dimension SQL, and
  the Project association. No patient data leaves - only catalogue/table/column
  names and filter logic.

- BuildCohortFromScript: the inverse - replays a build.script.yaml in-process to
  recreate an identical cohort (binds handles via NewObjectPool, restores child
  order, rebuilds patient index tables and rewrites their instance-specific alias).

Round-trip verified on a fixture exercising all of the above: export -> rebuild
-> re-export -> execute returns identical cohort membership.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
TestCohortScriptRoundTrip builds a cohort in the in-memory MemoryDataExportRepository
(set operation, nested AND/OR filter containers, an aggregate-level parameter and a
patient index table with an Inner join-use), runs ExportCohortAsScript then
BuildCohortFromScript, and asserts the rebuilt object graph matches the original.
No database required.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…rial

Adds an "Exporting and rebuilding a cohort" section to RdmpCommandLine.md
covering both commands and what the build script captures.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mtinti mtinti force-pushed the feature/cohort-script-commands branch from 70920bf to 1701d3c Compare June 20, 2026 10:01
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.

2 participants