CohortGenerator module

Cohort Generator Module

This module manages code for defining and materializing cohorts of patients for medical prediction tasks.

class Generators.CohortGenerator.Cohort(schema_name='', cohort_table_name=None, cohort_generation_script=None, cohort_generation_kwargs=None, first=None, verbose=True, outcome_col_name='y')

Bases: object

An object to hold cohort definitions and materialize cohort tables.

This class serves two purposes. First, by setting cohort_generation_script and cohort_generation_kwargs, the rules by which a cohort is defined are laid out. Second, by calling the build method and passing in a OMOP standard database, these rules are applied to retrieve an actual table of cohort members and outcomes which can be used for downstream tasks

Parameters
  • cohort_generation_script (str) – A path to a SQL file containing a script to generate the cohort. This script may contain templated terms in the form {param}.

  • cohort_generation_kwargs (dict) – Keyword arguments to format any templated terms in the SQL script found at cohort_generation_script.

  • first (int) – Limit the cohort to the first first patients satisfying the cohort definition. This allows for faster prototyping.

build(db, replace=False)

Materialize the cohort table in database db using the script provided at initialization.

Parameters

db (Utils.dbutils.Database) – The database on which queries are to be run

Returns

None

get_num_examples()

Get the size of the cohort.

Returns

The number of patients in the cohort, returns a value of 0 if the cohort has not yet been materialized.

Return type

int

is_built()

Checks whether or not the cohort has been materialized yet.

Returns

A boolean representing whether or not the cohort has been materialized yet

Return type

bool