Skip to main content

Serialisation utilities for OMOP CDM cohorts and CQI builder

Project description

OA Cohorts – Reporting & Cohort Execution Engine

This package provides the core machinery for defining, executing, and inspecting cohort-based reports over OMOP-style clinical data. It’s designed to support building real-world evidence reports from composable clinical rules, measures, cohorts, and indicators, with both programmatic APIs and lightweight HTML rendering for debugging and exploration.

The framework implemented here supports configuration-driven clinical quality indicators over OMOP-harmonised data, with explicit support for disease and treatment episodes, temporality, and combinatorial logic. Measures can be defined in terms of diagnoses, treatments, procedures, observations, measurements, and demographics, and composed into clinically interpretable cohorts and indicators.

This enables the same indicator definitions to support bulk benchmarking, trend analysis over time, and patient-level drill-down, without rewriting query logic for each use case. In practice, this provides a bridge between formal indicator specifications and the operational reality of multidisciplinary care.

At a high level, the system lets you:

  • Define query rules (exact, hierarchical, scalar thresholds, phenotypes, etc.)
  • Combine rules into subqueries
  • Build measures from subqueries (including composite measures with AND/OR/EXCEPT logic)
  • Group measures into dash cohorts and cohort definitions
  • Define indicators (numerator/denominator pairs)
  • Assemble everything into a report
  • Execute the report against a database session and materialise results as in-memory member sets
  • Inspect SQL, executability, and structure via HTML renderers (handy in notebooks)

This is intentionally object-centric: once a report is executed, downstream payloads are assembled from the resolved cohort and indicator member sets, with report-level demography fetched only for the in-scope cohort person_ids.

Diagnosis target semantics

The diagnosis layer now distinguishes between two common clinical questions:

  • dx_any: any diagnosis row attached to the current disease episode
  • dx_primary: diagnosis rows restricted to the patient's primary diagnosis episode anchor

In practice, dx_primary is the safer target when a cohort or indicator should be defined by the diagnosis present at the start of the primary episode of care, rather than by later progression or metastatic episodes that may carry related diagnosis coding.

That distinction matters most for report definitions that need to answer questions like "was this a lung primary cohort?" rather than the broader question "did this episode ever carry a lung-related diagnosis code?"

What’s here (roughly)

  • Report / ReportCohortMap: Top-level report definition, linking cohorts and indicators.
  • DashCohort / DashCohortDef: User-facing cohort groupings backed by executable measures.
  • Measure / MeasureSQLCompiler / MeasureExecutor: The core executable units. Measures compile to SQL, execute against a session, and materialise member sets with dating and episode context.
  • Indicator: Numerator/denominator semantics over measures, including optional indicator-level relative date windows anchored to report cohort membership.
  • QueryRule (+ subclasses): The rule DSL: exact matches, hierarchies, exclusions, scalar thresholds, phenotypes, substring matches, etc.
  • HTMLRenderable mixins: Lightweight visualisation of structure, SQL previews, and executability for debugging and exploration.

Execution model

report.execute(session)
report.assert_executed()

rows = report.members(executor)    # all cohort members
indicators = report.indicators     # output rows are built per denominator member within the report cohort

Indicator-relative date windows

Indicators can optionally define dynamic numerator and denominator date windows using:

  • numerator_max_days_prior
  • numerator_max_days_post
  • denominator_max_days_prior
  • denominator_max_days_post

These windows are evaluated relative to the report cohort membership date, not globally on the reusable measure definition. This keeps measures portable while allowing the same measure to participate in different indicators with different timing requirements.

Execution semantics:

  • measures still execute broadly and materialise their full MeasureMember sets
  • indicator row assembly then narrows numerator and denominator rows relative to the in-scope report cohort membership date
  • when the denominator is the full report cohort (measure_id = 0), filtering is still evaluated per cohort membership row so different in-scope episodes for the same person can qualify differently
  • if a window is configured and either the anchor date or candidate member date is missing, that candidate does not satisfy the dated comparison

Status

This is a working internal engine under active development. APIs may shift.

Docker

The repo includes a lightweight CLI container under docker/docker-compose.yaml that joins the external cava-network and expects an ENGINE SQLAlchemy URL.

Example:

cd docker
docker compose up -d oa-cohorts
docker compose exec oa-cohorts oa-cohorts --help
docker compose exec oa-cohorts oa-cohorts import-config /app/dash_config

The database host in ENGINE should be reachable on cava-network, for example postgresql+psycopg2://user:password@postgres:5432/dbname.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oa_cohorts-0.7.3.tar.gz (50.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oa_cohorts-0.7.3-py3-none-any.whl (67.1 kB view details)

Uploaded Python 3

File details

Details for the file oa_cohorts-0.7.3.tar.gz.

File metadata

  • Download URL: oa_cohorts-0.7.3.tar.gz
  • Upload date:
  • Size: 50.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for oa_cohorts-0.7.3.tar.gz
Algorithm Hash digest
SHA256 51aa105eb16da6653146446d35f2fa50487b05226589947b175bb4c475350a7f
MD5 4cd4b7948e6d084175400ca14f3e6980
BLAKE2b-256 d120b6347836f271c5e22a96aacc96a3cfe9f38a79694fa02e63e95fcbc04d1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for oa_cohorts-0.7.3.tar.gz:

Publisher: pypi.yml on AustralianCancerDataNetwork/oa-cohorts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file oa_cohorts-0.7.3-py3-none-any.whl.

File metadata

  • Download URL: oa_cohorts-0.7.3-py3-none-any.whl
  • Upload date:
  • Size: 67.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for oa_cohorts-0.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 054f87f7be71cd12a308abd45ffcf169eec0b4105cf0f3b591db8cb7020f46f3
MD5 3f372ee74dbb859d5e59207ac6855e22
BLAKE2b-256 94575ce21868c9eb2039a50ed1a45ee4e4c0eced999a40b34a2f18fcb0318da4

See more details on using hashes here.

Provenance

The following attestation bundles were made for oa_cohorts-0.7.3-py3-none-any.whl:

Publisher: pypi.yml on AustralianCancerDataNetwork/oa-cohorts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page