Concepts API
============

.. automodule:: corr_vars.concepts

Routing
-------

``src/corr_vars/concepts/routing.toml`` ships with the package and decides, per
source, where definitions come from. It is not user-scoped: there is no config
file or environment variable that rewrites it.

.. list-table::
   :header-rows: 1
   :widths: 25 75

   * - Source
     - Definitions
   * - ``charite_demo``, ``reprodicu``
     - The public demo Concepts API (``https://demo-concepts.corr.icu/api``)
   * - ``local_datasource``
     - Pinned local: the source's bundled ``mapping`` module, no network, no key
   * - any other source
     - The wildcard endpoint; point a cohort at your own with
       ``Cohort(concepts_api_url=...)``

Selecting a version
-------------------

A cohort authenticates against its endpoint on construction, so a missing
``project`` or a bad key fails before the data load. Every variable records the
exact version it was served in ``cohort.concept_versions``.

.. code-block:: python

   from corr_vars import Cohort

   cohort = Cohort(
       obs_level="icu_stay",
       sources={"charite_demo": {}},
       project="demo",
       api_key="cak_demo_0d2b53ac",
       date="2025-06-30",          # freeze every definition to a day
   )
   cohort.add_variable("blood_sodium::v3")   # pin one variable
   cohort.add_variable("corr_v1/heart_rate") # explicit taxonomy

A reference has the form ``[taxonomy/]var_name[::version]``, where the version is
``latest``, ``vN``, ``YYYY-MM-DD`` or ``draftNNNN``. The key comes from
``api_key=``, else the ``CORR_CONCEPTS_API_KEY`` environment variable (``corr
login`` stores it for you, see :doc:`../cli`).

Reference
---------

.. currentmodule:: corr_vars.concepts.routing

.. autofunction:: load_routing

.. autoclass:: ConceptRouting
   :members:

.. currentmodule:: corr_vars.concepts.spec

.. autofunction:: parse_variable_spec

.. autofunction:: parse_version_selector

.. currentmodule:: corr_vars.concepts.client

.. autoclass:: ConceptsApiClient
   :members:

.. autoclass:: Concept
   :members:

.. currentmodule:: corr_vars.concepts.resolver

.. autoclass:: ConceptResolver
   :members:

.. currentmodule:: corr_vars.concepts.standards

.. autofunction:: check_source

.. autofunction:: format_findings
