Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
4620980
Fluent api for working with LLMs and Capr API for allowing power user…
azimov Jan 21, 2026
e440739
Missing functionality added to fluent api
azimov Jan 21, 2026
e64fb14
Updated skill and added a system prompt for usage with GPT-4o
azimov Jan 21, 2026
7b2fb9d
Updated api and skill to cover complex nested cases with toy secondar…
azimov Jan 21, 2026
beecd7d
Updated gpt system prompt
azimov Jan 22, 2026
6980fd5
Fixes for crazy prompt hallucinations
azimov Jan 22, 2026
2669c41
Merge remote-tracking branch 'origin/fluent-api-tooling' into fluent-…
azimov Jan 22, 2026
8241626
Added automatic skill update (deterministic from codebase, not via llm)
azimov Jan 22, 2026
40bcea1
Prompt added to prompts dir
azimov Jan 22, 2026
e285968
Prompt types and examples suited to different model classes
azimov Jan 22, 2026
ba2d921
Prompt builder utility function
azimov Jan 22, 2026
111c01b
Prompt builder refactor
azimov Jan 22, 2026
618ae06
Merge branch 'develop' into fluent-api-tooling
azimov Jan 27, 2026
3d018ab
Removed cohort definition from index
azimov Jan 27, 2026
5781486
Merge branch 'develop' into fluent-api-tooling
azimov Jan 27, 2026
4821dcd
Simplified the skill and LLM usage by exploiting context managers whi…
azimov Jan 27, 2026
1370c2d
Updated the skill to help the dumbest of models
azimov Jan 27, 2026
fe92d16
removed skill file commit hooks
azimov Jan 29, 2026
33a9483
Default list behaviour for cohort elements prevents some downstream m…
azimov Jan 29, 2026
832aa93
Updated markdown skill to refine phenotype builder
azimov Feb 3, 2026
80c12c6
Validation utilities for more inline checking
azimov Feb 3, 2026
df1f160
Utility functions for making modifications to existing cohorts
azimov Feb 3, 2026
4d17deb
cleaned up artifact
azimov Feb 3, 2026
1761b99
Code cleanup
azimov Feb 3, 2026
2fa408b
validators and tests
azimov Feb 3, 2026
41bc11c
Cohort builder skill exposed as command line tool
azimov Feb 5, 2026
7a97316
Evaluation rubric example
azimov Feb 5, 2026
e985bc3
Evaluation rubric working model that uses circe criteria
azimov Feb 5, 2026
f399b5d
Actually insert rules into a rubric table, similar to a cohort table
azimov Feb 5, 2026
ec6c952
Ddl syntax
azimov Feb 5, 2026
c7f9c6b
Evaluation API for simpler usage
azimov Feb 5, 2026
01c8685
skill refined
azimov Feb 5, 2026
c7cc3ca
api fix
azimov Feb 5, 2026
ff56e0b
Gender concepts in api
azimov Feb 6, 2026
345fb30
Concept set inclusion
azimov Feb 6, 2026
f63c001
Parameterize index date fields
azimov Feb 6, 2026
0ea7ea4
Expanded criteria and markdown output
azimov Feb 6, 2026
692495d
Refinement of time windows
azimov Feb 6, 2026
ff840e1
Code cleanup
azimov Feb 6, 2026
3f68f80
Adding comments to see rules in sql
azimov Feb 6, 2026
44b9ebf
Fix - only allow distinct index events in score table
azimov Feb 6, 2026
f9777e3
Joins still seem broken with internal weirdness. This needs to be re-…
azimov Feb 6, 2026
b0eac91
Only allow a run on one cohort at a time, always require cohort id
azimov Feb 6, 2026
76a9457
Whitespace
azimov Feb 6, 2026
a7e972d
Whitespace for markdown output
azimov Feb 10, 2026
6f7ef9e
Fix for missing templates when installed
azimov Feb 12, 2026
6eb7e62
Merge remote-tracking branch 'origin/cohort-evaluation-metrics' into …
azimov Feb 12, 2026
4696b21
concept set display issues
azimov Feb 13, 2026
867ef75
cohort deletion on multi execute
azimov Feb 13, 2026
427a21f
Altered temporal windows for skill to help the llm do asymetric windo…
azimov Feb 17, 2026
455813f
row line by line output
azimov Feb 18, 2026
d89d936
Merge remote-tracking branch 'origin/cohort-evaluation-metrics' into …
azimov Feb 18, 2026
16a3fa0
Added descriptions to evaluation builders
azimov Feb 19, 2026
cfd32d6
Removed bad string ```
azimov Feb 20, 2026
d4ae110
added cohort modifier utility functions
azimov Feb 24, 2026
30ed1a2
refined cohort modifier utility functions
azimov Feb 25, 2026
17562f1
Merge remote-tracking branch 'egill/develop' into fluent-api-tooling
azimov Mar 16, 2026
c6e64c9
Merge remote-tracking branch 'origin/develop' into fluent-api-tooling
azimov Mar 16, 2026
25767e3
Replaced with_ methods using meta-programming from domain registration
azimov Mar 17, 2026
2d42a73
Merge branch 'fluent-api-tooling' into cohort-evaluation-metrics
azimov Mar 17, 2026
1cce4ab
merge
azimov Mar 18, 2026
35b6c03
fixed tests after merge
azimov Mar 18, 2026
a00abbd
ruff changes
azimov Mar 18, 2026
005ec25
Merge branch 'features/ibis-new-design-develop' into cohort-evaluatio…
azimov Mar 20, 2026
5cee0b5
including metrics for calculation
azimov Mar 20, 2026
d5a8be9
Merge branch 'develop' into cohort-evaluation-metrics
azimov Mar 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
227 changes: 0 additions & 227 deletions .agent/cohort_builder_enhancements.md

This file was deleted.

3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ include CONTRIBUTING.md
include requirements.txt
include pyproject.toml

# Include all Python files in the circe package
# Include all Python files and Jinja2 templates in the circe package
recursive-include circe *.py
recursive-include circe *.j2

# Include type hints marker
include circe/py.typed
Expand Down
104 changes: 66 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,57 +87,85 @@ circe process cohort.json --validate --sql --markdown

See the [CLI Documentation](#command-line-interface) section below for more details.

### Python API
## High-Level Building APIs

CIRCE Python provides two high-level APIs for building cohorts without manually constructing complex JSON/Pydantic models.

### 1. Context Manager API (`circe.cohort_builder`)
**Best for: LLMs, beginners, and interactive development.**
This Pythonic API uses `with` blocks and auto-builds on exit.

```python
from circe.cohort_builder import CohortBuilder
from circe.vocabulary import concept_set, descendants
from circe.api import build_cohort_query

# 1. Define concept sets
t2dm = concept_set(descendants(201826), id=1, name="T2DM")
metformin = concept_set(descendants(1503297), id=2, name="Metformin")

# 2. Build cohort using context manager
with CohortBuilder("New Metformin Users with T2DM") as cohort:
cohort.with_concept_sets(t2dm, metformin)
cohort.with_drug(concept_set_id=2) # Entry: metformin exposure
cohort.first_occurrence() # First exposure only
cohort.with_observation_window(prior_days=365) # 365 days prior
cohort.min_age(18) # Adults only
cohort.require_condition(concept_set_id=1, within_days_before=365)

with cohort.include_rule("No Prior Insulin") as rule:
rule.exclude_drug(3, anytime_before=True)

# 3. Access the built expression and generate SQL
sql = build_cohort_query(cohort.expression)
```

### 2. Capr-style API (`circe.capr`)
**Best for: Power users familiar with the R `Capr` package.**
A functional, declarative API for programmatic cohort definition.

```python
from circe.capr import (
cohort, entry, condition_occurrence, drug_exposure,
at_least, exactly, with_all, during_interval, event_starts
)

# Build using functional composition
my_cohort = cohort(
title="T2DM on Metformin",
entry=entry(
drug_exposure(concept_set_id=2, first_occurrence=True),
observation_window=(365, 0)
),
attrition=attrition(
has_t2dm=with_all(
at_least(1, condition_occurrence(1),
during_interval(event_starts(before=365)))
)
)
).build()
```

## Advanced Usage: Raw Pydantic Models

For full control, you can use the underlying Pydantic models that replicate the Java CIRCE-BE internal structure.

```python
from circe import CohortExpression
from circe.cohortdefinition import PrimaryCriteria, ConditionOccurrence
from circe.cohortdefinition.core import ObservationFilter, ResultLimit
from circe.vocabulary import ConceptSet, ConceptSetExpression, ConceptSetItem, Concept

# Create a cohort expression
# Create a cohort expression using raw models
cohort = CohortExpression(
title="Type 2 Diabetes Cohort",
title="Raw Model Example",
primary_criteria=PrimaryCriteria(
criteria_list=[
ConditionOccurrence(
codeset_id=1,
first=True
)
],
criteria_list=[ConditionOccurrence(codeset_id=1, first=True)],
observation_window=ObservationFilter(prior_days=0, post_days=0),
primary_limit=ResultLimit(type="All")
),
concept_sets=[
ConceptSet(
id=1,
name="Type 2 Diabetes",
expression=ConceptSetExpression(
items=[
ConceptSetItem(
concept=Concept(
concept_id=201826,
concept_name="Type 2 diabetes mellitus"
),
include_descendants=True
)
]
)
)
]
concept_sets=[...]
)

# Generate SQL using the API
from circe.api import build_cohort_query
from circe.cohortdefinition import BuildExpressionQueryOptions

options = BuildExpressionQueryOptions()
options.cdm_schema = 'cdm'
options.vocabulary_schema = 'cdm'
options.cohort_id = 1
options.target_table = 'scratch.cohort'
sql = build_cohort_query(cohort, options)
print(sql)
```

### Experimental Ibis Execution API
Expand Down
3 changes: 3 additions & 0 deletions circe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,7 @@ def get_json_schema() -> dict:
"safe_model_rebuild",
# I/O helpers
"load_expression",
"get_cohort_builder_skill",
"get_skill",
"list_skills",
]
Loading
Loading