imednet.validation package¶
Validation utilities for iMednet data.
This package provides tools for validating record data against study schemas, including caching of variable metadata and data dictionary management.
- class imednet.validation.AsyncSchemaCache[source]¶
Bases:
BaseSchemaCache[AsyncImednetFacade]Asynchronous implementation of the schema cache.
- class imednet.validation.AsyncSchemaValidator[source]¶
Bases:
BaseSchemaValidator[AsyncImednetFacade]Validate record payloads using variable metadata from the API (Asynchronous).
- __init__(sdk)[source]¶
Initialize the asynchronous schema validator.
- Parameters:
sdk (AsyncImednetFacade) –
- Return type:
None
- async refresh(study_key)[source]¶
Populate the schema cache for
study_keyfrom the Variables endpoint.This method never raises
ValidationError; any API errors bubble up asApiError.- Return type:
None- Parameters:
study_key (str) –
- class imednet.validation.BaseSchemaCache[source]¶
Bases:
Generic[_TClient]Cache of variables by form key with optional async refresh.
- __init__(is_async)[source]¶
Initialize the schema cache.
- Parameters:
is_async (
bool) – Whether this cache is used in an asynchronous context.- Return type:
None
- form_key_from_id(form_id)[source]¶
Resolve a form key from a form ID.
- Parameters:
form_id (
int) – The form ID to look up.- Returns:
The form key if found, else None.
- Return type:
Optional[str]
- property forms: dict[str, dict[str, imednet.models.engine.Variable]]¶
Return cached variables grouped by form key.
- populate(variables)[source]¶
Populate the cache with the given variables.
- Return type:
None- Parameters:
variables (Iterable[Variable]) –
- refresh(forms, variables, study_key=None)[source]¶
Refresh the cache, using the appropriate sync or async implementation.
- Parameters:
forms (
FormsEndpoint|AsyncFormsEndpoint) – The forms endpoint (sync or async).variables (
VariablesEndpoint|AsyncVariablesEndpoint) – The variables endpoint (sync or async).study_key (
Optional[str]) – The study key to refresh variables for.
- Returns:
An awaitable if async, else None.
- Return type:
Any
- class imednet.validation.BaseSchemaValidator[source]¶
Bases:
_ValidatorMixin,Generic[_TClient]Base validator sharing logic between sync and async implementations.
- class imednet.validation.DataDictionary[source]¶
Bases:
objectContainer for data dictionary CSV content.
- __init__(business_logic, choices, forms, questions)¶
- Parameters:
business_logic (list[dict[str, str]]) –
choices (list[dict[str, str]]) –
forms (list[dict[str, str]]) –
questions (list[dict[str, str]]) –
- Return type:
None
- class imednet.validation.DataDictionaryLoader[source]¶
Bases:
objectLoad data dictionary files from various sources.
- classmethod from_directory(directory)[source]¶
Load all required CSV files from
directory.- Return type:
- Parameters:
directory (Path | str) –
- classmethod from_files(*, business_logic, choices, forms, questions)[source]¶
Load a data dictionary from individual CSV files.
- Return type:
- Parameters:
business_logic (Path | TextIO) –
choices (Path | TextIO) –
forms (Path | TextIO) –
questions (Path | TextIO) –
- class imednet.validation.SchemaCache[source]¶
Bases:
BaseSchemaCache[ImednetFacade]Synchronous implementation of the schema cache.
- class imednet.validation.SchemaValidator[source]¶
Bases:
BaseSchemaValidator[ImednetFacade]Validate record payloads using variable metadata from the API (Synchronous).
- __init__(sdk, *, is_async=False)[source]¶
Initialize the synchronous schema validator.
- Parameters:
sdk (ImednetFacade) –
is_async (bool) –
- Return type:
None
- static __new__(cls, sdk, *args, **kwargs)[source]¶
Create a new instance of the validator, handling deprecation of is_async.
- Parameters:
sdk (
ImednetFacade) – The iMednet facade instance.*args (
Any) – Positional arguments.**kwargs (
Any) – Keyword arguments.
- Returns:
A SchemaValidator or AsyncSchemaValidator instance.
- Return type:
Any
- refresh(study_key)[source]¶
Populate the schema cache for
study_keyfrom the Variables endpoint.This method never raises
ValidationError; any API errors bubble up asApiError.- Return type:
None- Parameters:
study_key (str) –
- imednet.validation.validate_record_data(schema, form_key, data)[source]¶
Validate
dataforform_keyusing the provided schema cache.- Raises:
ValidationError – If the form key is not present in the schema or the data fails validation checks.
- Return type:
None- Parameters:
schema (BaseSchemaCache[Any]) –
form_key (str) –
data (dict[str, Any]) –
Submodules¶
imednet.validation.cache module¶
Caching and validation logic for iMednet variable schemas.
- class imednet.validation.cache.AsyncSchemaCache[source]¶
Bases:
BaseSchemaCache[AsyncImednetFacade]Asynchronous implementation of the schema cache.
- class imednet.validation.cache.AsyncSchemaValidator[source]¶
Bases:
BaseSchemaValidator[AsyncImednetFacade]Validate record payloads using variable metadata from the API (Asynchronous).
- __init__(sdk)[source]¶
Initialize the asynchronous schema validator.
- Parameters:
sdk (AsyncImednetFacade) –
- Return type:
None
- async refresh(study_key)[source]¶
Populate the schema cache for
study_keyfrom the Variables endpoint.This method never raises
ValidationError; any API errors bubble up asApiError.- Return type:
None- Parameters:
study_key (str) –
- class imednet.validation.cache.BaseSchemaCache[source]¶
Bases:
Generic[_TClient]Cache of variables by form key with optional async refresh.
- __init__(is_async)[source]¶
Initialize the schema cache.
- Parameters:
is_async (
bool) – Whether this cache is used in an asynchronous context.- Return type:
None
- form_key_from_id(form_id)[source]¶
Resolve a form key from a form ID.
- Parameters:
form_id (
int) – The form ID to look up.- Returns:
The form key if found, else None.
- Return type:
Optional[str]
- property forms: dict[str, dict[str, imednet.models.engine.Variable]]¶
Return cached variables grouped by form key.
- populate(variables)[source]¶
Populate the cache with the given variables.
- Return type:
None- Parameters:
variables (Iterable[Variable]) –
- refresh(forms, variables, study_key=None)[source]¶
Refresh the cache, using the appropriate sync or async implementation.
- Parameters:
forms (
FormsEndpoint|AsyncFormsEndpoint) – The forms endpoint (sync or async).variables (
VariablesEndpoint|AsyncVariablesEndpoint) – The variables endpoint (sync or async).study_key (
Optional[str]) – The study key to refresh variables for.
- Returns:
An awaitable if async, else None.
- Return type:
Any
- class imednet.validation.cache.BaseSchemaValidator[source]¶
Bases:
_ValidatorMixin,Generic[_TClient]Base validator sharing logic between sync and async implementations.
- class imednet.validation.cache.SchemaCache[source]¶
Bases:
BaseSchemaCache[ImednetFacade]Synchronous implementation of the schema cache.
- class imednet.validation.cache.SchemaValidator[source]¶
Bases:
BaseSchemaValidator[ImednetFacade]Validate record payloads using variable metadata from the API (Synchronous).
- __init__(sdk, *, is_async=False)[source]¶
Initialize the synchronous schema validator.
- Parameters:
sdk (ImednetFacade) –
is_async (bool) –
- Return type:
None
- static __new__(cls, sdk, *args, **kwargs)[source]¶
Create a new instance of the validator, handling deprecation of is_async.
- Parameters:
sdk (
ImednetFacade) – The iMednet facade instance.*args (
Any) – Positional arguments.**kwargs (
Any) – Keyword arguments.
- Returns:
A SchemaValidator or AsyncSchemaValidator instance.
- Return type:
Any
- refresh(study_key)[source]¶
Populate the schema cache for
study_keyfrom the Variables endpoint.This method never raises
ValidationError; any API errors bubble up asApiError.- Return type:
None- Parameters:
study_key (str) –
- imednet.validation.cache.calculate_readiness_score(schema, form_key, data)[source]¶
Calculate the schema readiness score for a record’s data.
- Return type:
tuple[float,list[str]]- Returns:
A tuple of (score, list of validation failure reasons).
- Parameters:
schema (BaseSchemaCache[Any]) –
form_key (str) –
data (dict[str, Any]) –
- imednet.validation.cache.validate_record_data(schema, form_key, data)[source]¶
Validate
dataforform_keyusing the provided schema cache.- Raises:
ValidationError – If the form key is not present in the schema or the data fails validation checks.
- Return type:
None- Parameters:
schema (BaseSchemaCache[Any]) –
form_key (str) –
data (dict[str, Any]) –
- imednet.validation.cache.validate_record_entry(schema, record)[source]¶
Validate a single record entry against the schema.
Resolves the form key from “formKey”, “form_key”, “formId”, or “form_id”.
- Parameters:
schema (
BaseSchemaCache[Any]) – The schema cache to use for validation.record (
dict[str,Any]) – The record data dictionary.
- Raises:
ValidationError – If the form key is not present in the schema or the data fails validation checks.
- Return type:
None
- imednet.validation.cache.validator(value)¶
Validate that the value is a string.
- Parameters:
value (
Any) – The value to validate.- Raises:
ValidationError – If the value is not a string.
- Return type:
None
imednet.validation.data_dictionary module¶
Loading and container for iMednet Data Dictionary files.
- class imednet.validation.data_dictionary.DataDictionary[source]¶
Bases:
objectContainer for data dictionary CSV content.
- __init__(business_logic, choices, forms, questions)¶
- Parameters:
business_logic (list[dict[str, str]]) –
choices (list[dict[str, str]]) –
forms (list[dict[str, str]]) –
questions (list[dict[str, str]]) –
- Return type:
None
- class imednet.validation.data_dictionary.DataDictionaryLoader[source]¶
Bases:
objectLoad data dictionary files from various sources.
- classmethod from_directory(directory)[source]¶
Load all required CSV files from
directory.- Return type:
- Parameters:
directory (Path | str) –
- classmethod from_files(*, business_logic, choices, forms, questions)[source]¶
Load a data dictionary from individual CSV files.
- Return type:
- Parameters:
business_logic (Path | TextIO) –
choices (Path | TextIO) –
forms (Path | TextIO) –
questions (Path | TextIO) –