corr-vars 2.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. corr_vars-2.1.0/.gitignore +19 -0
  2. corr_vars-2.1.0/CITATION.cff +93 -0
  3. corr_vars-2.1.0/LICENSE.md +21 -0
  4. corr_vars-2.1.0/PKG-INFO +289 -0
  5. corr_vars-2.1.0/README.md +239 -0
  6. corr_vars-2.1.0/pyproject.toml +174 -0
  7. corr_vars-2.1.0/src/corr_vars/__init__.py +174 -0
  8. corr_vars-2.1.0/src/corr_vars/concepts/__init__.py +100 -0
  9. corr_vars-2.1.0/src/corr_vars/concepts/client.py +1138 -0
  10. corr_vars-2.1.0/src/corr_vars/concepts/compile.py +339 -0
  11. corr_vars-2.1.0/src/corr_vars/concepts/files.py +280 -0
  12. corr_vars-2.1.0/src/corr_vars/concepts/resolver.py +650 -0
  13. corr_vars-2.1.0/src/corr_vars/concepts/routing.py +242 -0
  14. corr_vars-2.1.0/src/corr_vars/concepts/routing.toml +49 -0
  15. corr_vars-2.1.0/src/corr_vars/concepts/spec.py +313 -0
  16. corr_vars-2.1.0/src/corr_vars/concepts/standards.py +428 -0
  17. corr_vars-2.1.0/src/corr_vars/core/__init__.py +12 -0
  18. corr_vars-2.1.0/src/corr_vars/core/change_tracker.py +496 -0
  19. corr_vars-2.1.0/src/corr_vars/core/cohort.py +2347 -0
  20. corr_vars-2.1.0/src/corr_vars/core/file_manager.py +137 -0
  21. corr_vars-2.1.0/src/corr_vars/core/steps.py +310 -0
  22. corr_vars-2.1.0/src/corr_vars/core/variable/__init__.py +13 -0
  23. corr_vars-2.1.0/src/corr_vars/core/variable/base.py +333 -0
  24. corr_vars-2.1.0/src/corr_vars/core/variable/free_days.py +168 -0
  25. corr_vars-2.1.0/src/corr_vars/definitions/__init__.py +4 -0
  26. corr_vars-2.1.0/src/corr_vars/definitions/constants.py +26 -0
  27. corr_vars-2.1.0/src/corr_vars/definitions/exceptions.py +119 -0
  28. corr_vars-2.1.0/src/corr_vars/definitions/typing.py +371 -0
  29. corr_vars-2.1.0/src/corr_vars/plot/__init__.py +0 -0
  30. corr_vars-2.1.0/src/corr_vars/plot/movement.py +73 -0
  31. corr_vars-2.1.0/src/corr_vars/sources/__init__.py +51 -0
  32. corr_vars-2.1.0/src/corr_vars/sources/charite_demo/__init__.py +43 -0
  33. corr_vars-2.1.0/src/corr_vars/sources/charite_demo/classify/__init__.py +10 -0
  34. corr_vars-2.1.0/src/corr_vars/sources/charite_demo/classify/airway.py +492 -0
  35. corr_vars-2.1.0/src/corr_vars/sources/charite_demo/cohort.py +601 -0
  36. corr_vars-2.1.0/src/corr_vars/sources/charite_demo/config.py +111 -0
  37. corr_vars-2.1.0/src/corr_vars/sources/charite_demo/connector.py +640 -0
  38. corr_vars-2.1.0/src/corr_vars/sources/charite_demo/dataset.py +395 -0
  39. corr_vars-2.1.0/src/corr_vars/sources/charite_demo/extract.py +356 -0
  40. corr_vars-2.1.0/src/corr_vars/sources/charite_demo/helpers.py +1136 -0
  41. corr_vars-2.1.0/src/corr_vars/sources/charite_demo/mapping/__init__.py +59 -0
  42. corr_vars-2.1.0/src/corr_vars/sources/charite_demo/mapping/defaults.json +6 -0
  43. corr_vars-2.1.0/src/corr_vars/sources/charite_demo/mapping/globals.json +23 -0
  44. corr_vars-2.1.0/src/corr_vars/sources/charite_demo/mapping/loader.py +142 -0
  45. corr_vars-2.1.0/src/corr_vars/sources/charite_demo/mapping/tables.json +104 -0
  46. corr_vars-2.1.0/src/corr_vars/sources/charite_demo/py_env.py +203 -0
  47. corr_vars-2.1.0/src/corr_vars/sources/charite_demo/py_namespace.py +211 -0
  48. corr_vars-2.1.0/src/corr_vars/sources/cohort_loader.py +44 -0
  49. corr_vars-2.1.0/src/corr_vars/sources/config_loader.py +84 -0
  50. corr_vars-2.1.0/src/corr_vars/sources/local_datasource/__init__.py +24 -0
  51. corr_vars-2.1.0/src/corr_vars/sources/local_datasource/cohort.py +41 -0
  52. corr_vars-2.1.0/src/corr_vars/sources/local_datasource/config.py +51 -0
  53. corr_vars-2.1.0/src/corr_vars/sources/local_datasource/extract.py +1373 -0
  54. corr_vars-2.1.0/src/corr_vars/sources/local_datasource/helpers.py +98 -0
  55. corr_vars-2.1.0/src/corr_vars/sources/local_datasource/mapping/__init__.py +17 -0
  56. corr_vars-2.1.0/src/corr_vars/sources/local_datasource/mapping/loader.py +38 -0
  57. corr_vars-2.1.0/src/corr_vars/sources/local_datasource/mapping/variables.py +12 -0
  58. corr_vars-2.1.0/src/corr_vars/sources/local_datasource/mapping/vars.json +12 -0
  59. corr_vars-2.1.0/src/corr_vars/sources/reprodicu/__init__.py +4 -0
  60. corr_vars-2.1.0/src/corr_vars/sources/reprodicu/cohort.py +212 -0
  61. corr_vars-2.1.0/src/corr_vars/sources/reprodicu/config.py +20 -0
  62. corr_vars-2.1.0/src/corr_vars/sources/reprodicu/extract.py +191 -0
  63. corr_vars-2.1.0/src/corr_vars/sources/reprodicu/helpers.py +331 -0
  64. corr_vars-2.1.0/src/corr_vars/sources/reprodicu/mapping/__init__.py +7 -0
  65. corr_vars-2.1.0/src/corr_vars/sources/reprodicu/mapping/loader.py +21 -0
  66. corr_vars-2.1.0/src/corr_vars/sources/reprodicu/mapping/units.json +122 -0
  67. corr_vars-2.1.0/src/corr_vars/sources/reprodicu/mapping/variables.py +0 -0
  68. corr_vars-2.1.0/src/corr_vars/sources/var_loader.py +1051 -0
  69. corr_vars-2.1.0/src/corr_vars/style/matplotlibrc +1 -0
  70. corr_vars-2.1.0/src/corr_vars/utils/__init__.py +9 -0
  71. corr_vars-2.1.0/src/corr_vars/utils/base.py +84 -0
  72. corr_vars-2.1.0/src/corr_vars/utils/debug.py +98 -0
  73. corr_vars-2.1.0/src/corr_vars/utils/frames.py +1163 -0
  74. corr_vars-2.1.0/src/corr_vars/utils/helpers.py +522 -0
  75. corr_vars-2.1.0/src/corr_vars/utils/logging.py +338 -0
  76. corr_vars-2.1.0/src/corr_vars/utils/outcomes.py +569 -0
  77. corr_vars-2.1.0/src/corr_vars/utils/tableone.py +189 -0
  78. corr_vars-2.1.0/src/corr_vars/utils/time.py +579 -0
@@ -0,0 +1,19 @@
1
+ **/__editable__.corr_vars*
2
+ **/__pycache__/
3
+ **/*.log
4
+ **/corr_vars.egg-info/
5
+ **/*.pyc
6
+ .coverage
7
+ .DS_Store
8
+ .env
9
+ .hypothesis/
10
+ *.pem
11
+ .pytest_cache/
12
+ .ruff_cache/
13
+ .venv/
14
+ CLAUDE.md
15
+ dist
16
+ docs/_build/
17
+
18
+ # uv lockfile: this is a library, resolution is left to the consumer
19
+ uv.lock
@@ -0,0 +1,93 @@
1
+ cff-version: 1.2.0
2
+ message: If you use this software, please cite it as below.
3
+ title: CORR-Vars
4
+ abstract: >-
5
+ CORR-Vars is a Python library for building reproducible clinical study cohorts
6
+ from intensive-care and hospital data sources. A cohort is assembled at an
7
+ explicit observation level — patient, hospital stay, ICU stay or procedure —
8
+ and static and time-series variables are added to it from one or more
9
+ pluggable data sources. Inclusion and exclusion steps are tracked as they are
10
+ applied, so the resulting flowchart and baseline tables are generated from the
11
+ cohort itself rather than maintained alongside it. Variable definitions are not
12
+ bundled with the software: they are fetched per concept and per source from the
13
+ CORR Concepts API, which records the exact definition version served, allowing
14
+ a whole cohort — including every derived variable's dependencies — to be frozen
15
+ to a date and rebuilt later. Results export to Stata, CSV, Excel and LaTeX or
16
+ Markdown baseline tables.
17
+ type: software
18
+ authors:
19
+ - family-names: von Wedel
20
+ given-names: Dario
21
+ affiliation: 'Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Institute of Medical Informatics, Charitéplatz 1, 10117 Berlin, Germany; Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Joint Department: Infectious Diseases, Respiratory Medicine and Critical Care Medicine, Charitéplatz 1, 10117 Berlin, Germany'
22
+ - family-names: Thiele
23
+ given-names: Moritz
24
+ affiliation: Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Institute of Medical Informatics, Charitéplatz 1, 10117 Berlin, Germany
25
+ - family-names: Hardenberg
26
+ given-names: Jan-Hendrik
27
+ affiliation: Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Institute of Medical Informatics, Charitéplatz 1, 10117 Berlin, Germany; Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Department of Nephrology and Medical Intensive Care, Charitéplatz 1, 10117 Berlin, Germany
28
+ - family-names: Felber
29
+ given-names: Julian
30
+ affiliation: 'Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Institute of Medical Informatics, Charitéplatz 1, 10117 Berlin, Germany; Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Joint Department: Infectious Diseases, Respiratory Medicine and Critical Care Medicine, Charitéplatz 1, 10117 Berlin, Germany'
31
+ - family-names: Ramezani
32
+ given-names: Pedram
33
+ affiliation: 'Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Institute of Medical Informatics, Charitéplatz 1, 10117 Berlin, Germany; Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Joint Department: Infectious Diseases, Respiratory Medicine and Critical Care Medicine, Charitéplatz 1, 10117 Berlin, Germany'
34
+ - family-names: Daum
35
+ given-names: Nils
36
+ affiliation: Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Institute of Medical Informatics, Charitéplatz 1, 10117 Berlin, Germany; Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Department of Anesthesiology and Intensive Care Medicine (CCM/CVK), Charitéplatz 1, 10117 Berlin, Germany
37
+ - family-names: Grimm
38
+ given-names: Aline M.
39
+ affiliation: Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Institute of Medical Informatics, Charitéplatz 1, 10117 Berlin, Germany
40
+ - family-names: Hollerbach
41
+ given-names: Sophie
42
+ affiliation: 'Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Institute of Medical Informatics, Charitéplatz 1, 10117 Berlin, Germany; Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Joint Department: Infectious Diseases, Respiratory Medicine and Critical Care Medicine, Charitéplatz 1, 10117 Berlin, Germany'
43
+ - family-names: Nolte
44
+ given-names: Emil
45
+ affiliation: Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Institute of Medical Informatics, Charitéplatz 1, 10117 Berlin, Germany; Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Department of Nephrology and Medical Intensive Care, Charitéplatz 1, 10117 Berlin, Germany
46
+ - family-names: Kunz
47
+ given-names: Julius V.
48
+ affiliation: Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Department of Nephrology and Medical Intensive Care, Charitéplatz 1, 10117 Berlin, Germany
49
+ - family-names: Philipp
50
+ given-names: Susanne
51
+ affiliation: Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Institute of Medical Informatics, Charitéplatz 1, 10117 Berlin, Germany; Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Department of Nephrology and Medical Intensive Care, Charitéplatz 1, 10117 Berlin, Germany
52
+ - family-names: Hegermann
53
+ given-names: Henriette
54
+ affiliation: Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Institute of Medical Informatics, Charitéplatz 1, 10117 Berlin, Germany; Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Department of Anesthesiology and Intensive Care Medicine (CBF), Hindenburgdamm 30, 12203 Berlin, Germany
55
+ - family-names: Kronenberg
56
+ given-names: Noel
57
+ affiliation: Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Institute of Medical Informatics, Charitéplatz 1, 10117 Berlin, Germany
58
+ - family-names: Fassbender
59
+ given-names: Finn S.
60
+ affiliation: Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Institute of Medical Informatics, Charitéplatz 1, 10117 Berlin, Germany
61
+ - family-names: Grünewald
62
+ given-names: Elias
63
+ affiliation: Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Institute of Medical Informatics, Charitéplatz 1, 10117 Berlin, Germany
64
+ - family-names: Spies
65
+ given-names: Claudia
66
+ affiliation: Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Department of Anesthesiology and Intensive Care Medicine (CCM/CVK), Charitéplatz 1, 10117 Berlin, Germany
67
+ - family-names: Treskatsch
68
+ given-names: Sascha
69
+ affiliation: Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Department of Anesthesiology and Intensive Care Medicine (CBF), Hindenburgdamm 30, 12203 Berlin, Germany
70
+ - family-names: Witzenrath
71
+ given-names: Martin
72
+ affiliation: 'Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Joint Department: Infectious Diseases, Respiratory Medicine and Critical Care Medicine, Charitéplatz 1, 10117 Berlin, Germany'
73
+ - family-names: Eckardt
74
+ given-names: Kai-Uwe
75
+ affiliation: Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Department of Nephrology and Medical Intensive Care, Charitéplatz 1, 10117 Berlin, Germany
76
+ - family-names: Mittermaier
77
+ given-names: Mirja
78
+ affiliation: 'Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Joint Department: Infectious Diseases, Respiratory Medicine and Critical Care Medicine, Charitéplatz 1, 10117 Berlin, Germany'
79
+ - family-names: Balzer
80
+ given-names: Felix
81
+ affiliation: Charité – Universitätsmedizin Berlin, corporate member of Freie Universität Berlin and Humboldt-Universität zu Berlin, Institute of Medical Informatics, Charitéplatz 1, 10117 Berlin, Germany
82
+ - name: CORR Group
83
+ doi: 10.5281/zenodo.22346471
84
+ identifiers:
85
+ - type: doi
86
+ value: 10.5281/zenodo.22346471
87
+ description: Zenodo archive of the released versions
88
+ repository-code: https://github.com/CUB-CORR/corr_vars
89
+ url: https://docs.corr-vars.de
90
+ license: MIT
91
+ license-url: https://opensource.org/licenses/MIT
92
+ version: 2.1.0
93
+ date-released: '2026-10-22'
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Charité Outcomes Research Repository (CORR), Institut für Medizinische Informatik, Charité - Universitätsmedizin Berlin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,289 @@
1
+ Metadata-Version: 2.5
2
+ Name: corr_vars
3
+ Version: 2.1.0
4
+ Summary: Build reproducible clinical study cohorts from ICU and hospital data sources
5
+ Project-URL: Homepage, https://github.com/CUB-CORR/corr_vars
6
+ Project-URL: Documentation, https://docs.corr-vars.de
7
+ Project-URL: Bug Tracker, https://github.com/CUB-CORR/corr_vars/issues
8
+ Project-URL: Source, https://github.com/CUB-CORR/corr_vars
9
+ Author-email: Moritz Thiele <moritz.thiele@charite.de>, Pedram Ramezani <pedram.ramezani@charite.de>
10
+ Maintainer-email: noel.kronenberg@charite.de, dario.von-wedel@charite.de
11
+ License-Expression: MIT
12
+ License-File: LICENSE.md
13
+ Keywords: ICU,clinical research,cohort,electronic health records,epidemiology
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Classifier: Intended Audience :: Healthcare Industry
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
25
+ Requires-Python: >=3.10
26
+ Requires-Dist: corr-vars-widget>=0.0.8
27
+ Requires-Dist: duckdb<1.5,>=1.1
28
+ Requires-Dist: graphviz>=0.21
29
+ Requires-Dist: httpx>=0.27
30
+ Requires-Dist: ibis-framework[duckdb]>=10.0
31
+ Requires-Dist: matplotlib>=3.10.8
32
+ Requires-Dist: networkx>=3.4.1
33
+ Requires-Dist: numpy>=2.0.0
34
+ Requires-Dist: pandas<3.0.0,>=2.2.0
35
+ Requires-Dist: plotly>=5.0.0
36
+ Requires-Dist: polars==1.44.1
37
+ Requires-Dist: scikit-learn<1.7,>=1.6.1
38
+ Requires-Dist: scipy>=1.10.0
39
+ Requires-Dist: seaborn>=0.13.2
40
+ Requires-Dist: tableone>=0.7.10
41
+ Requires-Dist: tomli>=2.0; python_full_version < '3.11'
42
+ Requires-Dist: tqdm>=4.65
43
+ Requires-Dist: xlsxwriter>=3.2.5
44
+ Requires-Dist: zstandard>=0.23.0
45
+ Provides-Extra: charite-demo
46
+ Requires-Dist: pycomorb>=0.5.2; extra == 'charite-demo'
47
+ Provides-Extra: stata
48
+ Requires-Dist: stata-setup>=0.1.3; extra == 'stata'
49
+ Description-Content-Type: text/markdown
50
+
51
+ # CORR-VARS – Streamlining Real-World Evidence Studies and Bedside Use <img src="docs/_static/corr_favicon.png" align="right" width="100"/>
52
+ [![CI](https://img.shields.io/github/actions/workflow/status/CUB-CORR/corr_vars/tests.yml?branch=main)](https://github.com/CUB-CORR/corr_vars/actions/workflows/tests.yml)
53
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.22346471.svg)](https://doi.org/10.5281/zenodo.22346471)
54
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
55
+
56
+ Build and manage clinical study cohorts from ICU and hospital data sources. Add, filter and export variables whose definitions are served — and versioned — by the CORR Concepts API.
57
+
58
+ ## Installation
59
+
60
+ ```shell
61
+ uv add git+https://github.com/CUB-CORR/corr_vars.git
62
+ ```
63
+
64
+ Requires Python ≥ 3.10.
65
+
66
+ ## Quick Start
67
+
68
+ ```python
69
+ from corr_vars import Cohort
70
+
71
+ cohort = Cohort(
72
+ obs_level="icu_stay", # "patient" | "hospital_stay" | "icu_stay" | "procedure"
73
+ sources={"reprodicu": {"path": "/path/to/reprodICU_files"}},
74
+ project="my_project", # project on the Concepts API
75
+ # api_key="corr_..." # or set CORR_CONCEPTS_API_KEY
76
+ )
77
+
78
+ # Add a pre-defined variable
79
+ cohort.add_variable("blood_sodium")
80
+
81
+ # Apply inclusion criteria and visualise the flowchart
82
+ cohort.include_list([
83
+ {"variable": "age_on_admission", "operation": ">= 18", "label": "Adults"},
84
+ {"variable": "icu_length_of_stay", "operation": "> 2", "label": "ICU stay > 2 days"},
85
+ ])
86
+ cohort.figureone
87
+
88
+ # Export
89
+ cohort.save("my_cohort.corr3")
90
+ cohort.to_csv("output/")
91
+ ```
92
+
93
+ ### Try it with the demo dataset
94
+
95
+ The `charite_demo` source reads a public, fully synthetic ICU dataset (20'000 ICU
96
+ stays), and the public demo Concepts API serves its variable definitions, so you can
97
+ try `corr_vars` without data access or an account:
98
+
99
+ ```python
100
+ cohort = Cohort(
101
+ obs_level="icu_stay",
102
+ sources={"charite_demo": {}},
103
+ project="demo",
104
+ api_key="cak_demo_0d2b53ac", # public demo key
105
+ )
106
+ ```
107
+
108
+ Install with the extra (`uv add "corr_vars[charite-demo] @ git+https://github.com/CUB-CORR/corr_vars.git"`)
109
+ and follow the [demo tutorial](https://docs.corr-vars.de/tutorials/charite_demo.html).
110
+ For a hands-on notebook to run yourself, see [`examples/`](examples/).
111
+
112
+ ## Observation Levels
113
+
114
+ | `obs_level` | Primary key | One row per … |
115
+ |------------------|------------------|-----------------------|
116
+ | `"patient"` | `patient_id` | patient |
117
+ | `"hospital_stay"` | `case_id` | hospitalisation |
118
+ | `"icu_stay"` | `icu_stay_id` | ICU admission |
119
+ | `"procedure"` | `procedure_id` | surgical procedure |
120
+
121
+ ## Data Sources
122
+
123
+ Sources are plugins: each is a package under `src/corr_vars/sources/` that
124
+ supplies cohort data and, optionally, variable extraction. Multiple sources can
125
+ be combined in a single `Cohort` call.
126
+
127
+ Two sources ship with the package: `reprodicu`, a ready-to-use example, and
128
+ `local_datasource`, a skeleton you bind to your own store.
129
+
130
+ ### ReprodICU
131
+
132
+ The plug-and-play example source. Download the
133
+ [reprodICU](https://github.com/cub-corr/reprodicu) parquet files and pass their
134
+ folder as `path` — nothing else to configure.
135
+
136
+ ```python
137
+ sources = {
138
+ "reprodicu": {
139
+ "path": "/path/to/reprodICU_files",
140
+ "include_datasets": [],
141
+ "exclude_datasets": [],
142
+ }
143
+ }
144
+ ```
145
+
146
+ ### Local data source (`local_datasource`)
147
+
148
+ A source skeleton, pinned local in `routing.toml`: it ships the variable
149
+ classes (`NativeStatic`, `DerivedStatic`, `DerivedDynamic`, `NativeDynamic`,
150
+ `ComplexVariable`) and the extraction pipeline, but no store. Bind it to your
151
+ own data in two places:
152
+
153
+ 1. Replace `cohort.load_data(obs_level, source_kwargs)` so it returns the
154
+ observation frame (primary key plus the level's `t_min`/`t_max` anchors).
155
+ 2. Subclass `NativeExtractor`, implement `extract(cohort, id_column)`, and set
156
+ `NativeDynamic.extractor_class` to your subclass.
157
+
158
+ Then fill `mapping/vars.json` and `mapping/variables.py` with your variable
159
+ definitions, or route the source to a Concepts API endpoint instead. See the
160
+ [local_datasource API reference](https://docs.corr-vars.de/api/local_datasource.html).
161
+
162
+ ### Custom variables
163
+
164
+ The aggregation classes are source-agnostic — construct one directly and add it
165
+ to any cohort, including a reprodICU one:
166
+
167
+ ```python
168
+ from corr_vars import Cohort
169
+ from corr_vars.sources.local_datasource import DerivedStatic, NativeStatic
170
+
171
+ cohort = Cohort(
172
+ obs_level="icu_stay",
173
+ sources={"reprodicu": {"path": "/path/to/reprodICU_files"}},
174
+ project="my_project",
175
+ )
176
+
177
+ cohort.add_variable(NativeStatic(
178
+ var_name="max_sodium_icu",
179
+ select="!max value",
180
+ base_var="blood_sodium",
181
+ tmin="icu_admission",
182
+ tmax="icu_discharge",
183
+ ))
184
+ cohort.add_variable(DerivedStatic(
185
+ var_name="hypernatremia",
186
+ requires=["max_sodium_icu"],
187
+ expression="max_sodium_icu > 145",
188
+ ))
189
+ ```
190
+
191
+ `base_var` and `requires` resolve through the cohort's own sources. Pass
192
+ `tmin`/`tmax` inside the constructor, not to `add_variable`. Full reference:
193
+ [aggregation variables](https://docs.corr-vars.de/api/aggregation.html).
194
+
195
+ ## Variable Definitions
196
+
197
+ Variable definitions are not bundled with this package. They are fetched per
198
+ concept and per source from the CORR Concepts API, which also records the exact
199
+ version that was served. Routing is declared in
200
+ `src/corr_vars/concepts/routing.toml`:
201
+
202
+ ```toml
203
+ [local]
204
+ sources = ["local_datasource"]
205
+
206
+ [[endpoint]]
207
+ url = "https://concepts.example.edu/api"
208
+ sources = ["*"]
209
+ ```
210
+
211
+ A cohort authenticates against that endpoint on construction, so a missing
212
+ `project` or a bad key fails before the (slow) data load:
213
+
214
+ ```python
215
+ cohort = Cohort(project="my_project", api_key="corr_...")
216
+ cohort = Cohort(project="my_project", date="2025-06-30") # freeze to a day
217
+ cohort.add_variable("blood_sodium::v3") # pin one variable
218
+ ```
219
+
220
+ Point a cohort at a different endpoint with `Cohort(concepts_api_url=...)`.
221
+ Sources listed under `[local]` in `routing.toml` are never fetched; their
222
+ definitions are read from the source's bundled `mapping` module and keep working
223
+ with no network and no API key. `local_datasource` is the one bundled source
224
+ listed there.
225
+
226
+ ## Development
227
+
228
+ ### Setup
229
+
230
+ ```shell
231
+ git clone https://github.com/CUB-CORR/corr_vars.git
232
+ cd corr_vars
233
+ uv sync --group dev
234
+ uv run pre-commit install
235
+ ```
236
+
237
+ Pre-commit hooks enforce uniform formatting and catch common errors. When a hook modifies a file, stage the change and commit again.
238
+
239
+ ### Running Tests
240
+
241
+ If you have developed new features, please add relevant tests to the `tests/` folder.
242
+
243
+ ```shell
244
+ uv run pytest
245
+ ```
246
+
247
+ Integration tests (`tests/integration`) run automatically once a pull request to `main` is opened. Results are attached to the pull request and a test report will be generated. Do not merge until tests pass.
248
+
249
+ `tests/sources` is hand-run: it needs the source's own data files plus a Concepts API project and key, skips when they are missing, and runs only when named (`uv run pytest tests/sources`). A bare `uv run pytest` runs `tests/integration` only, like CI, which needs neither.
250
+
251
+ ### Building the Documentation
252
+
253
+ ```shell
254
+ cd docs
255
+ make clean && make html
256
+ # or: rm -rf _build && uv run sphinx-build -M html . _build
257
+ ```
258
+
259
+ The HTML output is written to `docs/_build/html/`. Documentation is automatically published to [docs.corr-vars.de](https://docs.corr-vars.de) on merge to `main`.
260
+
261
+ ### Releasing
262
+
263
+ Releases are published to PyPI as `corr_vars` by [`.github/workflows/release.yml`](.github/workflows/release.yml) using [Trusted Publishing](https://docs.pypi.org/trusted-publishers/) (OIDC). No API token is stored anywhere.
264
+
265
+ **One-time setup**
266
+
267
+ 1. On [PyPI](https://pypi.org/manage/account/publishing/), add a *pending* trusted publisher. Use PyPI project name `corr_vars`, owner `CUB-CORR`, repository `corr_vars`, workflow `release.yml` and environment `pypi`. The first successful publish creates the project.
268
+ 2. In the GitHub repository, under *Settings → Environments*, create the environment `pypi`. You can optionally add required reviewers to `pypi` and restrict it to `v*` tags.
269
+
270
+ **Release procedure**
271
+
272
+ 1. Bump `__version__` in `src/corr_vars/__init__.py` and `version` / `date-released` in `CITATION.cff`, then merge to `main`.
273
+ 2. Tag and push: `git tag v2.0.3 && git push origin v2.0.3`.
274
+
275
+ The workflow first checks that the tag, `__version__` and `CITATION.cff` agree. It then runs the tests, builds and checks the sdist and wheel, publishes to PyPI and creates the GitHub release with the built files attached.
276
+
277
+ ### Contributing
278
+
279
+ See the [Contributing Variables](https://docs.corr-vars.de/contributing_variables.html) guide for variable contributions in the documentation.
280
+
281
+ 1. Create an issue or feature request on GitHub.
282
+ 2. Branch off `main` using the naming convention `IssueNumber-IssueTitle`.
283
+ 3. Commit your changes and push to your branch (i.e. variables or new features)
284
+ 4. Run unit tests as described [above](#running-tests) by opening a pull request or running them manually.
285
+ 5. If you have changed anything relevant to the documentation update the documentation as described [above](#building-the-documentation). **This is not done automatically!**
286
+
287
+ ## License
288
+
289
+ MIT — see [LICENSE.md](LICENSE.md).
@@ -0,0 +1,239 @@
1
+ # CORR-VARS – Streamlining Real-World Evidence Studies and Bedside Use <img src="docs/_static/corr_favicon.png" align="right" width="100"/>
2
+ [![CI](https://img.shields.io/github/actions/workflow/status/CUB-CORR/corr_vars/tests.yml?branch=main)](https://github.com/CUB-CORR/corr_vars/actions/workflows/tests.yml)
3
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.22346471.svg)](https://doi.org/10.5281/zenodo.22346471)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ Build and manage clinical study cohorts from ICU and hospital data sources. Add, filter and export variables whose definitions are served — and versioned — by the CORR Concepts API.
7
+
8
+ ## Installation
9
+
10
+ ```shell
11
+ uv add git+https://github.com/CUB-CORR/corr_vars.git
12
+ ```
13
+
14
+ Requires Python ≥ 3.10.
15
+
16
+ ## Quick Start
17
+
18
+ ```python
19
+ from corr_vars import Cohort
20
+
21
+ cohort = Cohort(
22
+ obs_level="icu_stay", # "patient" | "hospital_stay" | "icu_stay" | "procedure"
23
+ sources={"reprodicu": {"path": "/path/to/reprodICU_files"}},
24
+ project="my_project", # project on the Concepts API
25
+ # api_key="corr_..." # or set CORR_CONCEPTS_API_KEY
26
+ )
27
+
28
+ # Add a pre-defined variable
29
+ cohort.add_variable("blood_sodium")
30
+
31
+ # Apply inclusion criteria and visualise the flowchart
32
+ cohort.include_list([
33
+ {"variable": "age_on_admission", "operation": ">= 18", "label": "Adults"},
34
+ {"variable": "icu_length_of_stay", "operation": "> 2", "label": "ICU stay > 2 days"},
35
+ ])
36
+ cohort.figureone
37
+
38
+ # Export
39
+ cohort.save("my_cohort.corr3")
40
+ cohort.to_csv("output/")
41
+ ```
42
+
43
+ ### Try it with the demo dataset
44
+
45
+ The `charite_demo` source reads a public, fully synthetic ICU dataset (20'000 ICU
46
+ stays), and the public demo Concepts API serves its variable definitions, so you can
47
+ try `corr_vars` without data access or an account:
48
+
49
+ ```python
50
+ cohort = Cohort(
51
+ obs_level="icu_stay",
52
+ sources={"charite_demo": {}},
53
+ project="demo",
54
+ api_key="cak_demo_0d2b53ac", # public demo key
55
+ )
56
+ ```
57
+
58
+ Install with the extra (`uv add "corr_vars[charite-demo] @ git+https://github.com/CUB-CORR/corr_vars.git"`)
59
+ and follow the [demo tutorial](https://docs.corr-vars.de/tutorials/charite_demo.html).
60
+ For a hands-on notebook to run yourself, see [`examples/`](examples/).
61
+
62
+ ## Observation Levels
63
+
64
+ | `obs_level` | Primary key | One row per … |
65
+ |------------------|------------------|-----------------------|
66
+ | `"patient"` | `patient_id` | patient |
67
+ | `"hospital_stay"` | `case_id` | hospitalisation |
68
+ | `"icu_stay"` | `icu_stay_id` | ICU admission |
69
+ | `"procedure"` | `procedure_id` | surgical procedure |
70
+
71
+ ## Data Sources
72
+
73
+ Sources are plugins: each is a package under `src/corr_vars/sources/` that
74
+ supplies cohort data and, optionally, variable extraction. Multiple sources can
75
+ be combined in a single `Cohort` call.
76
+
77
+ Two sources ship with the package: `reprodicu`, a ready-to-use example, and
78
+ `local_datasource`, a skeleton you bind to your own store.
79
+
80
+ ### ReprodICU
81
+
82
+ The plug-and-play example source. Download the
83
+ [reprodICU](https://github.com/cub-corr/reprodicu) parquet files and pass their
84
+ folder as `path` — nothing else to configure.
85
+
86
+ ```python
87
+ sources = {
88
+ "reprodicu": {
89
+ "path": "/path/to/reprodICU_files",
90
+ "include_datasets": [],
91
+ "exclude_datasets": [],
92
+ }
93
+ }
94
+ ```
95
+
96
+ ### Local data source (`local_datasource`)
97
+
98
+ A source skeleton, pinned local in `routing.toml`: it ships the variable
99
+ classes (`NativeStatic`, `DerivedStatic`, `DerivedDynamic`, `NativeDynamic`,
100
+ `ComplexVariable`) and the extraction pipeline, but no store. Bind it to your
101
+ own data in two places:
102
+
103
+ 1. Replace `cohort.load_data(obs_level, source_kwargs)` so it returns the
104
+ observation frame (primary key plus the level's `t_min`/`t_max` anchors).
105
+ 2. Subclass `NativeExtractor`, implement `extract(cohort, id_column)`, and set
106
+ `NativeDynamic.extractor_class` to your subclass.
107
+
108
+ Then fill `mapping/vars.json` and `mapping/variables.py` with your variable
109
+ definitions, or route the source to a Concepts API endpoint instead. See the
110
+ [local_datasource API reference](https://docs.corr-vars.de/api/local_datasource.html).
111
+
112
+ ### Custom variables
113
+
114
+ The aggregation classes are source-agnostic — construct one directly and add it
115
+ to any cohort, including a reprodICU one:
116
+
117
+ ```python
118
+ from corr_vars import Cohort
119
+ from corr_vars.sources.local_datasource import DerivedStatic, NativeStatic
120
+
121
+ cohort = Cohort(
122
+ obs_level="icu_stay",
123
+ sources={"reprodicu": {"path": "/path/to/reprodICU_files"}},
124
+ project="my_project",
125
+ )
126
+
127
+ cohort.add_variable(NativeStatic(
128
+ var_name="max_sodium_icu",
129
+ select="!max value",
130
+ base_var="blood_sodium",
131
+ tmin="icu_admission",
132
+ tmax="icu_discharge",
133
+ ))
134
+ cohort.add_variable(DerivedStatic(
135
+ var_name="hypernatremia",
136
+ requires=["max_sodium_icu"],
137
+ expression="max_sodium_icu > 145",
138
+ ))
139
+ ```
140
+
141
+ `base_var` and `requires` resolve through the cohort's own sources. Pass
142
+ `tmin`/`tmax` inside the constructor, not to `add_variable`. Full reference:
143
+ [aggregation variables](https://docs.corr-vars.de/api/aggregation.html).
144
+
145
+ ## Variable Definitions
146
+
147
+ Variable definitions are not bundled with this package. They are fetched per
148
+ concept and per source from the CORR Concepts API, which also records the exact
149
+ version that was served. Routing is declared in
150
+ `src/corr_vars/concepts/routing.toml`:
151
+
152
+ ```toml
153
+ [local]
154
+ sources = ["local_datasource"]
155
+
156
+ [[endpoint]]
157
+ url = "https://concepts.example.edu/api"
158
+ sources = ["*"]
159
+ ```
160
+
161
+ A cohort authenticates against that endpoint on construction, so a missing
162
+ `project` or a bad key fails before the (slow) data load:
163
+
164
+ ```python
165
+ cohort = Cohort(project="my_project", api_key="corr_...")
166
+ cohort = Cohort(project="my_project", date="2025-06-30") # freeze to a day
167
+ cohort.add_variable("blood_sodium::v3") # pin one variable
168
+ ```
169
+
170
+ Point a cohort at a different endpoint with `Cohort(concepts_api_url=...)`.
171
+ Sources listed under `[local]` in `routing.toml` are never fetched; their
172
+ definitions are read from the source's bundled `mapping` module and keep working
173
+ with no network and no API key. `local_datasource` is the one bundled source
174
+ listed there.
175
+
176
+ ## Development
177
+
178
+ ### Setup
179
+
180
+ ```shell
181
+ git clone https://github.com/CUB-CORR/corr_vars.git
182
+ cd corr_vars
183
+ uv sync --group dev
184
+ uv run pre-commit install
185
+ ```
186
+
187
+ Pre-commit hooks enforce uniform formatting and catch common errors. When a hook modifies a file, stage the change and commit again.
188
+
189
+ ### Running Tests
190
+
191
+ If you have developed new features, please add relevant tests to the `tests/` folder.
192
+
193
+ ```shell
194
+ uv run pytest
195
+ ```
196
+
197
+ Integration tests (`tests/integration`) run automatically once a pull request to `main` is opened. Results are attached to the pull request and a test report will be generated. Do not merge until tests pass.
198
+
199
+ `tests/sources` is hand-run: it needs the source's own data files plus a Concepts API project and key, skips when they are missing, and runs only when named (`uv run pytest tests/sources`). A bare `uv run pytest` runs `tests/integration` only, like CI, which needs neither.
200
+
201
+ ### Building the Documentation
202
+
203
+ ```shell
204
+ cd docs
205
+ make clean && make html
206
+ # or: rm -rf _build && uv run sphinx-build -M html . _build
207
+ ```
208
+
209
+ The HTML output is written to `docs/_build/html/`. Documentation is automatically published to [docs.corr-vars.de](https://docs.corr-vars.de) on merge to `main`.
210
+
211
+ ### Releasing
212
+
213
+ Releases are published to PyPI as `corr_vars` by [`.github/workflows/release.yml`](.github/workflows/release.yml) using [Trusted Publishing](https://docs.pypi.org/trusted-publishers/) (OIDC). No API token is stored anywhere.
214
+
215
+ **One-time setup**
216
+
217
+ 1. On [PyPI](https://pypi.org/manage/account/publishing/), add a *pending* trusted publisher. Use PyPI project name `corr_vars`, owner `CUB-CORR`, repository `corr_vars`, workflow `release.yml` and environment `pypi`. The first successful publish creates the project.
218
+ 2. In the GitHub repository, under *Settings → Environments*, create the environment `pypi`. You can optionally add required reviewers to `pypi` and restrict it to `v*` tags.
219
+
220
+ **Release procedure**
221
+
222
+ 1. Bump `__version__` in `src/corr_vars/__init__.py` and `version` / `date-released` in `CITATION.cff`, then merge to `main`.
223
+ 2. Tag and push: `git tag v2.0.3 && git push origin v2.0.3`.
224
+
225
+ The workflow first checks that the tag, `__version__` and `CITATION.cff` agree. It then runs the tests, builds and checks the sdist and wheel, publishes to PyPI and creates the GitHub release with the built files attached.
226
+
227
+ ### Contributing
228
+
229
+ See the [Contributing Variables](https://docs.corr-vars.de/contributing_variables.html) guide for variable contributions in the documentation.
230
+
231
+ 1. Create an issue or feature request on GitHub.
232
+ 2. Branch off `main` using the naming convention `IssueNumber-IssueTitle`.
233
+ 3. Commit your changes and push to your branch (i.e. variables or new features)
234
+ 4. Run unit tests as described [above](#running-tests) by opening a pull request or running them manually.
235
+ 5. If you have changed anything relevant to the documentation update the documentation as described [above](#building-the-documentation). **This is not done automatically!**
236
+
237
+ ## License
238
+
239
+ MIT — see [LICENSE.md](LICENSE.md).