imednet_workflows package¶
Workflow helpers built on top of the iMednet SDK.
Subpackages¶
- imednet_workflows.uat package
- Submodules
- imednet_workflows.uat.engine module
- imednet_workflows.uat.generator module
- imednet_workflows.uat.inspector module
AsyncStudySchemaInspectorStudySchemaInspectorStudySnapshotStudySnapshot.study_keyStudySnapshot.captured_atStudySnapshot.formsStudySnapshot.variablesStudySnapshot.intervalsStudySnapshot.sitesStudySnapshot.forms_by_keyStudySnapshot.variables_by_formStudySnapshot.intervals_by_nameStudySnapshot.active_sites()StudySnapshot.enrollment_forms()StudySnapshot.from_data_dictionary()StudySnapshot.model_post_init()StudySnapshot.scheduled_forms()StudySnapshot.unscheduled_forms()
- imednet_workflows.uat.models module
InvalidUATStateTransitionErrorRecordTestTypeUATFormSpecUATFormSpec.form_keyUATFormSpec.form_nameUATFormSpec.form_typeUATFormSpec.test_typeUATFormSpec.interval_nameUATFormSpec.subject_countUATFormSpec.variablesUATFormSpec.required_variable_namesUATFormSpec.enabledUATFormSpec.notesUATFormSpec.validate_subject_count()UATFormSpec.validate_unique_variable_names()
UATSpecificationUATSpecification.spec_versionUATSpecification.study_keyUATSpecification.study_nameUATSpecification.generated_atUATSpecification.generated_byUATSpecification.subject_specsUATSpecification.form_specsUATSpecification.global_date_valueUATSpecification.global_text_lengthUATSpecification.forms_snapshot_countUATSpecification.variables_snapshot_countUATSpecification.intervals_snapshot_countUATSpecification.sites_snapshot_countUATSpecification.seedUATSpecification.enabled_forms()UATSpecification.forms_by_type()UATSpecification.from_json()UATSpecification.validate_spec_version()
UATSubjectSpecUATVariableSpecUATVariableSpec.variable_nameUATVariableSpec.variable_keyUATVariableSpec.variable_typeUATVariableSpec.form_keyUATVariableSpec.strategyUATVariableSpec.fixed_valueUATVariableSpec.min_valueUATVariableSpec.max_valueUATVariableSpec.max_lengthUATVariableSpec.coded_valuesUATVariableSpec.requiredUATVariableSpec.notesUATVariableSpec.validate_fixed_strategy()
UATWorkflowStateUATWorkflowState.PENDINGUATWorkflowState.INSPECTINGUATWorkflowState.BUILDING_SPECUATWorkflowState.GENERATINGUATWorkflowState.SUBMITTINGUATWorkflowState.MONITORINGUATWorkflowState.COMPLETEDUATWorkflowState.FAILEDUATWorkflowState.allowed_transitionsUATWorkflowState.can_transition_to()UATWorkflowState.is_terminalUATWorkflowState.validate_transition_to()
VariableTestStrategyis_valid_uat_transition()normalize_uat_state()validate_uat_transition()
- imednet_workflows.uat.orchestrator module
AsyncUATWorkflowAsyncUATWorkflow.__init__()AsyncUATWorkflow.build_spec()AsyncUATWorkflow.generate()AsyncUATWorkflow.inspect()AsyncUATWorkflow.last_resultAsyncUATWorkflow.monitor()AsyncUATWorkflow.reset()AsyncUATWorkflow.run()AsyncUATWorkflow.stateAsyncUATWorkflow.state_historyAsyncUATWorkflow.submit()AsyncUATWorkflow.transition_to()
UATRunPhaseUATRunResultUATRunResult.study_keyUATRunResult.run_idUATRunResult.started_atUATRunResult.completed_atUATRunResult.stateUATRunResult.state_historyUATRunResult.failure_phaseUATRunResult.error_messageUATRunResult.specUATRunResult.record_setsUATRunResult.submission_resultUATRunResult.poll_summaryUATRunResult.dry_runUATRunResult.validation_reportUATRunResult.phase_durationsUATRunResult.failed_phaseUATRunResult.is_terminalUATRunResult.overall_successUATRunResult.summary()
UATSpecificationBuilderUATWorkflow
- imednet_workflows.uat.submission module
AsyncBulkRecordSubmissionWorkflowBatchSubmissionBulkRecordSubmissionWorkflowBulkSubmissionErrorInvalidSubmissionPhaseTransitionErrorSubmissionPhaseSubmissionPhase.PENDINGSubmissionPhase.REGISTRATIONSubmissionPhase.AWAITING_REGISTRATIONSubmissionPhase.DATASubmissionPhase.COMPLETEDSubmissionPhase.FAILEDSubmissionPhase.allowed_transitionsSubmissionPhase.can_transition_to()SubmissionPhase.is_terminalSubmissionPhase.validate_transition_to()
SubmissionResultSubmissionResult.study_keySubmissionResult.started_atSubmissionResult.completed_atSubmissionResult.registration_batchesSubmissionResult.data_batchesSubmissionResult.enrolled_subject_keysSubmissionResult.skipped_formsSubmissionResult.warningsSubmissionResult.all_batch_idsSubmissionResult.all_batchesSubmissionResult.total_records_submitted
is_valid_submission_transition()normalize_submission_phase()validate_submission_transition()
Submodules¶
imednet_workflows.cached_loader module¶
Workflow for loading study records with local SQLite caching for performance.
- class imednet_workflows.cached_loader.CachedRecordsLoader[source]¶
Bases:
objectLoad study records through a local SQLite cache with origin-scoped incremental sync.
- __init__(sdk, *, cache_dir=None, database_name='records_cache.sqlite3', retry_attempts=3, lock_timeout_seconds=30, lock=None)[source]¶
Initialize the cached records loader.
- Parameters:
sdk (ImednetFacade) – An instance of the iMednet SDK facade.
cache_dir (str | Path | None) – Directory to store the SQLite cache. Defaults to ~/.imednet/cache.
database_name (str) – Name of the SQLite database file.
retry_attempts (int) – Number of API retry attempts for facade implementations without SDK retry policy.
lock_timeout_seconds (int) – Number of seconds to wait when acquiring the cache file lock.
lock (UnixFileLock | None) – Optional FileLock instance for synchronizing write transactions.
- Return type:
None
- property base_url: str¶
Return the normalized SDK origin URL partitioning this loader’s cache state.
- count_cached_records(study_key, *, conn=None)[source]¶
Return the count of cached records for
study_keywithout materialising rows.- Parameters:
study_key (str) –
conn (Connection | None) –
- Return type:
int
- get_cached_records(study_key, *, conn=None)[source]¶
Return cached records for
study_keywithout contacting the API.- Parameters:
study_key (str) –
conn (Connection | None) –
- Return type:
list[Record]
- get_study_sync_state(study_key, *, conn=None)[source]¶
Return the stored sync epoch, watermark, and status metadata for
study_key.- Parameters:
study_key (str) –
conn (Connection | None) –
- Return type:
- iter_cached_records(study_key, *, conn=None, chunk_size=5000, order_by_subject=False)[source]¶
Yield cached records for
study_keyin bounded chunks.- Parameters:
study_key (str) –
conn (Connection | None) –
chunk_size (int) –
order_by_subject (bool) –
- Return type:
Iterator[Record]
- load_records(study_key, *, reconcile=True, lock_timeout_seconds=None)[source]¶
Synchronise the cache for
study_keyand return cached records.- Parameters:
study_key (str) –
reconcile (bool) –
lock_timeout_seconds (float | None) –
- Return type:
list[Record]
- property lock: UnixFileLock¶
Return the inter-process file lock protecting cache write operations.
- class imednet_workflows.cached_loader.StudySyncState[source]¶
Bases:
objectSnapshot of synchronization epoch and watermark metadata for a study.
- study_key: str¶
Required.
- sync_epoch: int = 0¶
- high_water_mark: str | None = None¶
- initial_sync_complete: bool = False¶
- status: StudySyncStatus = <StudySyncStatus.IDLE: 'idle'>¶
- last_synced_at: str | None = None¶
- error_message: str | None = None¶
- class imednet_workflows.cached_loader.StudySyncStatus[source]¶
Bases:
StrEnumLifecycle status for per-study SQLite cache synchronization.
- IDLE: str = 'idle'¶
- SYNCING: str = 'syncing'¶
- SYNCED: str = 'synced'¶
- FAILED: str = 'failed'¶
imednet_workflows.chunked_pipeline module¶
Utilities for processing large datasets in memory-bounded chunks.
- class imednet_workflows.chunked_pipeline.ChunkedRecordPipeline[source]¶
Bases:
objectChunked iteration utilities for large-study workflows.
- __init__(*, chunk_size=5000)[source]¶
Initialize the chunked record pipeline.
- Parameters:
chunk_size (int) – The number of items per chunk.
- Return type:
None
imednet_workflows.cli module¶
CLI commands for iMednet workflows.
This module provides the Typer/argparse integration for common clinical data workflows, including record extraction, cache synchronization, standards readiness validation, and state ledger management.
- imednet_workflows.cli.setup_parser(subparsers)[source]¶
Set up the workflows argparse subparsers.
- Parameters:
subparsers (argparse._SubParsersAction[Any]) –
- Return type:
None
imednet_workflows.config_version_control module¶
SQLite-backed version control ledger for study configurations.
Provides immutable, append-only commit history with SHA-256 content hashing, diff capability, and safe rollback. History blocks are read-only once written.
- class imednet_workflows.config_version_control.ConfigVersionStore[source]¶
Bases:
objectImmutable append-only store for
StudyConfigurationversions.Each call to
commit_config()creates a new entry signed with a SHA-256 digest of the serialised configuration body. History is strictly read-only — individual commit rows may never be edited or deleted.- Parameters:
db_path – Filesystem path for the SQLite database. Defaults to
~/.imednet/config_versions.sqlite3.
- __init__(db_path=None, *, base_url=None, sdk=None)[source]¶
Initialize the configuration version store.
- Parameters:
db_path (str | Path | None) – Path to the SQLite database file.
base_url (str | None) – Optional explicit API origin URL to pin this store to.
sdk (Any) – Optional SDK instance to extract pinned origin and session credentials from.
- Return type:
None
- commit_config(study_key, config, desc, *, sdk=None)[source]¶
Serialise config, compute its SHA-256 hash, and persist the commit.
- Parameters:
study_key (str) – Identifies the study this configuration belongs to.
config (StudyConfiguration) – The
StudyConfigurationto store.desc (str) – Human-readable description of what changed.
sdk (Any) – The SDK instance used to verify server-side permissions.
- Returns:
The
commit_id(SHA-256 hex digest of the serialised JSON body).- Raises:
ValueError – If a commit with the same content hash already exists.
PermissionError – If an authenticated SDK session is not provided, or if the authenticated session does not have manager/admin role.
- Return type:
str
- classmethod current_store_state_token()[source]¶
Return a fast in-memory state token capturing active store path, context, and write generation.
- Return type:
tuple[Any, …]
- property db_path: Path¶
Return the dynamically selected database file path based on pinned or active base URL.
- diff_configs(commit_a, commit_b)[source]¶
Compute a property-level diff between two commits.
Compares the flat JSON key space of the two commits. Returns a dict with three sub-keys:
added— keys present in b but not in a.removed— keys present in a but not in b.changed— keys present in both but with different values.
- Parameters:
commit_a (str) – SHA-256 commit ID of the before state.
commit_b (str) – SHA-256 commit ID of the after state.
- Returns:
Dict with
added,removed, andchangedsub-dicts.- Raises:
KeyError – If either commit ID is not found in the store.
- Return type:
dict[str, Any]
- get_head(study_key)[source]¶
Return the current head
commit_idfor study_key, orNoneif empty.- Parameters:
study_key (str) –
- Return type:
str | None
- get_history(study_key)[source]¶
Return all commits for study_key, ordered oldest-first.
- Parameters:
study_key (str) – The study whose history should be retrieved.
- Returns:
A list of dicts, each with keys
commit_id,study_key,version_tag,modified_by,description,timestamp,parent_commit_id, andcontent_hash. Theconfig_databody is intentionally omitted to keep the payload small — userollback_config()to retrieve the full body for a specific commit.- Return type:
list[dict[str, Any]]
- classmethod resolve_committed_config(study_key)[source]¶
Read the latest committed
StudyConfigurationwithout creating empty DB files.- Parameters:
study_key (str) –
- Return type:
StudyConfiguration | None
- classmethod resolve_committed_study_keys()[source]¶
Return
(state_token, known_study_keys)across active SQLite/legacy paths, orNoneif mocked.- Return type:
tuple[tuple[Any, …], frozenset[str]] | None
- classmethod resolve_legacy_committed_config(study_key)[source]¶
Read latest committed StudyConfiguration from legacy study-partitioned SQLite paths.
- Parameters:
study_key (str) –
- Return type:
StudyConfiguration | None
- rollback_config(study_key, commit_id)[source]¶
Restore and return the
StudyConfigurationstored at commit_id.This method is non-destructive — it does not modify any existing history rows. The caller is responsible for creating a new commit via
commit_config()if they wish to record the rollback.- Parameters:
study_key (str) – The study the commit must belong to.
commit_id (str) – The SHA-256 commit ID to restore.
- Returns:
The deserialised
StudyConfiguration.- Raises:
KeyError – If the commit is not found or does not belong to the requested study.
- Return type:
imednet_workflows.data_extraction module¶
Provides workflows for extracting specific datasets from iMednet studies.
- class imednet_workflows.data_extraction.AsyncDataExtractionWorkflow[source]¶
Bases:
objectCanonical asynchronous workflow for multi-endpoint clinical data extraction.
- __init__(sdk)[source]¶
Initialize the asynchronous data extraction workflow.
- Parameters:
sdk (AsyncImednetFacade) –
- Return type:
None
- async extract_audit_trail(study_key, start_date=None, end_date=None, user_filter=None, **filters)[source]¶
Asynchronously extract the audit trail (record revisions) based on filters.
- Parameters:
study_key (str) –
start_date (str | None) –
end_date (str | None) –
user_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
filters (Any) –
- Return type:
list[RecordRevision]
- async extract_odm_audit_records(study_key, start_date=None, end_date=None, user_filter=None, *, default_location_oid=None, mask_phi=True, phi_keys=None, **filters)[source]¶
Asynchronously extract study RecordRevision audit history mapped to ODM 1.3.2
<AuditRecord>models.- Parameters:
study_key (str) –
start_date (str | None) –
end_date (str | None) –
user_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
default_location_oid (str | None) –
mask_phi (bool) –
phi_keys (Collection[str] | None) –
filters (Any) –
- Return type:
list[OdmAuditRecord]
- async extract_records_by_criteria(study_key, record_filter=None, subject_filter=None, visit_filter=None, on_progress=None, *, include_deleted=False, record_data_filter=None, **other_filters)[source]¶
Asynchronously extract records matching combined subject, visit, and record filters.
- Parameters:
study_key (str) –
record_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
subject_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
visit_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
on_progress (Callable[[str], None] | None) –
include_deleted (bool) –
record_data_filter (str | None) –
other_filters (Any) –
- Return type:
list[Record]
- class imednet_workflows.data_extraction.DataExtractionWorkflow[source]¶
Bases:
objectProvides methods for complex data extraction tasks involving multiple iMednet endpoints.
- Parameters:
sdk – An instance of the synchronous ImednetSDK.
- __init__(sdk)[source]¶
Initialize the data extraction workflow.
- Parameters:
sdk (ImednetFacade) – An instance of the synchronous iMednet SDK facade.
- Return type:
None
- extract_audit_trail(study_key, start_date=None, end_date=None, user_filter=None, **filters)[source]¶
Extracts the audit trail (record revisions) based on specified filters.
- Parameters:
study_key (str) –
start_date (str | None) –
end_date (str | None) –
user_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
filters (Any) –
- Return type:
list[RecordRevision]
- extract_odm_audit_records(study_key, start_date=None, end_date=None, user_filter=None, *, default_location_oid=None, mask_phi=True, phi_keys=None, **filters)[source]¶
Extract study RecordRevision audit history mapped to ODM 1.3.2
<AuditRecord>models.- Parameters:
study_key (str) –
start_date (str | None) –
end_date (str | None) –
user_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
default_location_oid (str | None) –
mask_phi (bool) –
phi_keys (Collection[str] | None) –
filters (Any) –
- Return type:
list[OdmAuditRecord]
- extract_records_by_criteria(study_key, record_filter=None, subject_filter=None, visit_filter=None, on_progress=None, *, include_deleted=False, record_data_filter=None, **other_filters)[source]¶
Extracts records based on criteria spanning subjects, visits, and records.
- Parameters:
study_key (str) –
record_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
subject_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
visit_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
on_progress (Callable[[str], None] | None) –
include_deleted (bool) –
record_data_filter (str | None) –
other_filters (Any) –
- Return type:
list[Record]
- iter_records_by_criteria(study_key, record_filter=None, subject_filter=None, visit_filter=None, on_progress=None, *, include_deleted=False, record_data_filter=None, **other_filters)[source]¶
Lazily yield records matching combined subject, visit, and record filters.
- Parameters:
study_key (str) –
record_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
subject_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
visit_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
on_progress (Callable[[str], None] | None) –
include_deleted (bool) –
record_data_filter (str | None) –
other_filters (Any) –
- Return type:
Iterator[Record]
imednet_workflows.duckdb_centralizer module¶
DuckDB ingestion workflow for incremental form centralization.
Provides an incremental record centralization pipeline using DuckDB.
- class imednet_workflows.duckdb_centralizer.AsyncDuckDBIngestionWorkflow[source]¶
Bases:
objectAsynchronous incremental record centralization pipeline using DuckDB.
- __init__(sdk, db_path=':memory:', *, mask_phi=True)[source]¶
Initialize the asynchronous DuckDB ingestion workflow.
- Parameters:
sdk (AsyncImednetFacade) –
db_path (str) –
mask_phi (bool) –
- Return type:
None
- async build_silver_view(study_key, *, include_deleted=False)[source]¶
Asynchronously create or replace per-Study and combined silver views.
- Parameters:
study_key (str) –
include_deleted (bool) –
- Return type:
None
- close()¶
Close the underlying DuckDB connection idempotently.
- Return type:
None
- async ingest_revisions(study_key, *, start_date=None, end_date=None, mode='append', mask_phi=None, validate_chain=False, allow_partial=None)[source]¶
Asynchronously fetch RecordRevisions and write to the bronze_revisions table.
- Parameters:
study_key (str) –
start_date (str | None) –
end_date (str | None) –
mode (Literal['append', 'replace']) –
mask_phi (bool | None) –
validate_chain (bool) –
allow_partial (bool | None) –
- Return type:
int
- class imednet_workflows.duckdb_centralizer.DuckDBIngestionWorkflow[source]¶
Bases:
objectIncremental record centralization pipeline using a bronze/silver DuckDB layout.
- __init__(sdk, db_path=':memory:', *, mask_phi=True)[source]¶
Initialize the DuckDB ingestion workflow.
- Parameters:
sdk (ImednetFacade) – An instance of the synchronous iMednet SDK facade.
db_path (str) – Path to the DuckDB database file or “:memory:”. Defaults to “:memory:”.
mask_phi (bool) – Redact sensitive clinical and Study-configured PHI values by default.
- Return type:
None
- build_silver_view(study_key, *, include_deleted=False)[source]¶
Create or replace per-Study and combined silver current-state and history views.
- Parameters:
study_key (str) –
include_deleted (bool) –
- Return type:
None
- close()¶
Close the underlying DuckDB connection idempotently.
- Return type:
None
- ingest_revisions(study_key, *, start_date=None, end_date=None, mode='append', mask_phi=None, validate_chain=False, allow_partial=None)[source]¶
Fetch RecordRevisions and write to the bronze_revisions table.
- Parameters:
study_key (str) –
start_date (str | None) –
end_date (str | None) –
mode (Literal['append', 'replace']) –
mask_phi (bool | None) –
validate_chain (bool) –
allow_partial (bool | None) –
- Return type:
int
imednet_workflows.extraction_engine module¶
Canonical data extraction engine for iMednet.
This module provides the logic to map raw EDC records into standardized clinical models (Adverse Events, Protocol Deviations, etc.) based on study-specific mapping rules.
- class imednet_workflows.extraction_engine.ExtractionResult[source]¶
Bases:
BaseModelCanonical extraction output grouped by reporting domain.
- adverse_events: list[AdverseEvent] = list()¶
- protocol_deviations: list[ProtocolDeviation] = list()¶
- device_deficiencies: list[DeviceDeficiency] = list()¶
- adsl_records: list[SubjectLevelAnalysis] = list()¶
- adae_records: list[AnalysisAdverseEvent] = list()¶
- adlb_records: list[AnalysisLabResult] = list()¶
- validation_errors: list[dict[str, Any]] = list()¶
- imednet_workflows.extraction_engine.extract_canonical_records(records, study_configuration, *, include_deleted=False)[source]¶
Extract canonical models from raw records using study mappings.
- Parameters:
records (Iterable[Record]) –
study_configuration (StudyConfiguration) –
include_deleted (bool) –
- Return type:
imednet_workflows.namespace module¶
Namespace for accessing workflow classes.
- class imednet_workflows.namespace.AsyncWorkflows[source]¶
Bases:
objectNamespace for accessing asynchronous workflow classes.
- __init__(sdk_instance)[source]¶
Initialize the async workflows namespace.
- Parameters:
sdk_instance (AsyncImednetFacade) –
- property duckdb_centralizer: AsyncDuckDBIngestionWorkflow¶
Asynchronous incremental record centralization pipeline using DuckDB.
- class imednet_workflows.namespace.Workflows[source]¶
Bases:
objectNamespace for accessing workflow classes.
- __init__(sdk_instance)[source]¶
Initialize the workflows namespace.
- Parameters:
sdk_instance (ImednetFacade) –
- property duckdb_centralizer: DuckDBIngestionWorkflow¶
Incremental record centralization pipeline using DuckDB.
imednet_workflows.query_management module¶
Provides workflows for managing queries within iMednet studies.
- class imednet_workflows.query_management.AsyncQueryManagementWorkflow[source]¶
Bases:
objectCanonical asynchronous workflow for clinical discrepancy management.
- __init__(sdk)[source]¶
Initialize the asynchronous query management workflow.
- Parameters:
sdk (AsyncImednetFacade) –
- Return type:
None
- async extract_odm_annotations(study_key, additional_filter=None, *, open_only=False, include_answered=False, mask_phi=True, phi_keys=None, **kwargs)[source]¶
Asynchronously extract study Query histories mapped to ODM 1.3.2
<Annotation>models.- Parameters:
study_key (str) –
additional_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
open_only (bool) –
include_answered (bool) –
mask_phi (bool) –
phi_keys (Collection[str] | None) –
kwargs (Any) –
- Return type:
list[OdmAnnotation]
- async get_open_queries(study_key, additional_filter=None, include_answered=False, **kwargs)[source]¶
Asynchronously retrieve open queries (and optionally answered queries).
- Parameters:
study_key (str) –
additional_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
include_answered (bool) –
kwargs (Any) –
- Return type:
list[Query]
- async get_queries_by_site(study_key, site_key, additional_filter=None, **kwargs)[source]¶
Asynchronously retrieve all queries for active, keyed subjects at a site.
- Parameters:
study_key (str) –
site_key (str) –
additional_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
kwargs (Any) –
- Return type:
list[Query]
- async get_queries_for_subject(study_key, subject_key, additional_filter=None, **kwargs)[source]¶
Asynchronously retrieve all queries for a specific subject within a study.
- Parameters:
study_key (str) –
subject_key (str) –
additional_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
kwargs (Any) –
- Return type:
list[Query]
- async get_query_state_counts(study_key, **kwargs)[source]¶
Asynchronously count queries grouped by their current QueryStatus values.
- Parameters:
study_key (str) –
kwargs (Any) –
- Return type:
dict[str, int]
- async get_unresolved_queries(study_key, additional_filter=None, **kwargs)[source]¶
Asynchronously retrieve all unresolved (OPEN and ANSWERED) queries.
- Parameters:
study_key (str) –
additional_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
kwargs (Any) –
- Return type:
list[Query]
- async list_queries(study_key, *, status=None, unresolved_only=False, subject_key=None, site_key=None, additional_filter=None, **kwargs)[source]¶
Asynchronously list queries filtered by status, unresolved state, subject, or site.
- Parameters:
study_key (str) –
status (QueryStatus | str | None) –
unresolved_only (bool) –
subject_key (str | None) –
site_key (str | None) –
additional_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
kwargs (Any) –
- Return type:
list[Query]
- async sync_queries_to_triage(study_key, store=None, *, additional_filter=None, unresolved_only=False, default_severity='medium', **kwargs)[source]¶
Asynchronously synchronize clinical queries into a local TriageStore queue.
- Parameters:
study_key (str) –
store (TriageStoreProtocol | str | Path | None) –
additional_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
unresolved_only (bool) –
default_severity (str) –
kwargs (Any) –
- Return type:
list[TriageItem]
- class imednet_workflows.query_management.QueryManagementWorkflow[source]¶
Bases:
objectProvides methods for common query management tasks.
- Parameters:
sdk – An instance of the synchronous ImednetSDK.
- __init__(sdk)[source]¶
Initialize the query management workflow.
- Parameters:
sdk (ImednetFacade) –
- Return type:
None
- extract_odm_annotations(study_key, additional_filter=None, *, open_only=False, include_answered=False, mask_phi=True, phi_keys=None, **kwargs)[source]¶
Extract study Query and QueryComment histories mapped to ODM 1.3.2
<Annotation>models.- Parameters:
study_key (str) –
additional_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
open_only (bool) –
include_answered (bool) –
mask_phi (bool) –
phi_keys (Collection[str] | None) –
kwargs (Any) –
- Return type:
list[OdmAnnotation]
- get_open_queries(study_key, additional_filter=None, include_answered=False, **kwargs)[source]¶
Retrieves open queries for a given study, optionally including answered queries.
- Parameters:
study_key (str) –
additional_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
include_answered (bool) –
kwargs (Any) –
- Return type:
list[Query]
- get_queries_by_site(study_key, site_key, additional_filter=None, **kwargs)[source]¶
Retrieves all queries for active, keyed subjects at a specific site within a study.
- Parameters:
study_key (str) –
site_key (str) –
additional_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
kwargs (Any) –
- Return type:
list[Query]
- get_queries_for_subject(study_key, subject_key, additional_filter=None, **kwargs)[source]¶
Retrieves all queries for a specific subject within a study.
- Parameters:
study_key (str) –
subject_key (str) –
additional_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
kwargs (Any) –
- Return type:
list[Query]
- get_query_state_counts(study_key, **kwargs)[source]¶
Counts queries grouped by their current QueryStatus values.
- Parameters:
study_key (str) –
kwargs (Any) –
- Return type:
dict[str, int]
- get_unresolved_queries(study_key, additional_filter=None, **kwargs)[source]¶
Retrieves all unresolved (
OPENandANSWERED) queries for a given study.- Parameters:
study_key (str) –
additional_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
kwargs (Any) –
- Return type:
list[Query]
- list_queries(study_key, *, status=None, unresolved_only=False, subject_key=None, site_key=None, additional_filter=None, **kwargs)[source]¶
List queries filtered by status, unresolved state, subject, or site.
- Parameters:
study_key (str) –
status (QueryStatus | str | None) –
unresolved_only (bool) –
subject_key (str | None) –
site_key (str | None) –
additional_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
kwargs (Any) –
- Return type:
list[Query]
- sync_queries_to_triage(study_key, store=None, *, additional_filter=None, unresolved_only=False, default_severity='medium', **kwargs)[source]¶
Synchronize clinical queries for a study into a local TriageStore queue.
- Parameters:
study_key (str) –
store (TriageStoreProtocol | str | Path | None) –
additional_filter (dict[str, Any | tuple[str, Any] | list[Any]] | None) –
unresolved_only (bool) –
default_severity (str) –
kwargs (Any) –
- Return type:
list[TriageItem]
imednet_workflows.record_mapper module¶
Record-to-DataFrame mapping workflow for iMednet.
This module provides the RecordMapper which handles fetching,
filtering, and parsing EDC records into tabular formats like pandas
DataFrames, including support for dynamic Pydantic model validation.
- class imednet_workflows.record_mapper.AsyncRecordMapper[source]¶
Bases:
RecordMapperAsynchronous EDC record-to-DataFrame and SDTM mapping workflow.
- __init__(sdk, *, loader=None, chunk_size=5000, mask_phi=True, include_deleted=False)[source]¶
Initialize with an
AsyncImednetSDKorAsyncImednetFacade.- Parameters:
sdk (AsyncImednetFacade) –
loader (CachedRecordsLoader | None) –
chunk_size (int) –
mask_phi (bool) –
include_deleted (bool) –
- Return type:
None
- async build_hierarchy(study_key, visit_key=None, use_labels_as_keys=False, variable_whitelist=None, form_whitelist=None, *, naming_convention=None, domain=None, mask_phi=None, include_deleted=None, records=None)[source]¶
Asynchronously generate a nested JSON tree structure up to three levels deep.
- Parameters:
study_key (str) –
visit_key (str | None) –
use_labels_as_keys (bool) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
naming_convention (str | None) –
domain (str | None) –
mask_phi (bool | None) –
include_deleted (bool | None) –
- Return type:
list[dict[str, Any]]
- async dataframe(study_key, visit_key=None, use_labels_as_columns=True, variable_whitelist=None, form_whitelist=None, *, as_sdtm=False, domain=None, naming_convention=None, preserve_record_id=False, mask_phi=None, include_deleted=None)[source]¶
Asynchronously return a
pandas.DataFrameof records for a study.- Parameters:
study_key (str) –
visit_key (str | None) –
use_labels_as_columns (bool) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
as_sdtm (bool) –
domain (str | None) –
naming_convention (str | None) –
preserve_record_id (bool) –
mask_phi (bool | None) –
include_deleted (bool | None) –
- Return type:
DataFrame
- async iter_dataframes(study_key, visit_key=None, use_labels_as_columns=True, variable_whitelist=None, form_whitelist=None, *, as_sdtm=False, domain=None, naming_convention=None, mask_phi=None, include_deleted=None)[source]¶
Asynchronously yield mapped record DataFrames in bounded chunks.
- Parameters:
study_key (str) –
visit_key (str | None) –
use_labels_as_columns (bool) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
as_sdtm (bool) –
domain (str | None) –
naming_convention (str | None) –
mask_phi (bool | None) –
include_deleted (bool | None) –
- Return type:
AsyncIterator[DataFrame]
- async iter_sdtm_dataframes(study_key, domain, visit_key=None, variable_whitelist=None, form_whitelist=None, *, naming_convention=None, preserve_record_id=False, mask_phi=None, include_deleted=None)[source]¶
Asynchronously yield chunked pandas DataFrames transformed into an SDTM domain.
- Parameters:
study_key (str) –
domain (str) –
visit_key (str | None) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
naming_convention (str | None) –
preserve_record_id (bool) –
mask_phi (bool | None) –
include_deleted (bool | None) –
- Return type:
AsyncIterator[DataFrame]
- async sdtm_dataframe(study_key, domain, visit_key=None, variable_whitelist=None, form_whitelist=None, *, naming_convention=None, preserve_record_id=False, mask_phi=None, include_deleted=None)[source]¶
Asynchronously return a DataFrame transformed into a CDISC SDTM domain dataset.
- Parameters:
study_key (str) –
domain (str) –
visit_key (str | None) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
naming_convention (str | None) –
preserve_record_id (bool) –
mask_phi (bool | None) –
include_deleted (bool | None) –
- Return type:
DataFrame
- async sdtm_dataset_json(study_key, domain, visit_key=None, variable_whitelist=None, form_whitelist=None, *, naming_convention=None, preserve_record_id=False, mask_phi=None, include_deleted=None, metadata_version_oid='MDV.001', file_oid=None, creation_datetime=None)[source]¶
Asynchronously emit a CDISC Dataset-JSON v1.1 envelope for a specific SDTM domain.
- Parameters:
study_key (str) –
domain (str) –
visit_key (str | None) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
naming_convention (str | None) –
preserve_record_id (bool) –
mask_phi (bool | None) –
include_deleted (bool | None) –
metadata_version_oid (str) –
file_oid (str | None) –
creation_datetime (str | None) –
- Return type:
- async to_dataset_json(study_key, visit_key=None, use_labels_as_columns=False, variable_whitelist=None, form_whitelist=None, *, form_key=None, as_sdtm=None, domain=None, naming_convention=None, preserve_record_id=False, mask_phi=None, include_deleted=None, metadata_version_oid='MDV.001', file_oid=None, creation_datetime=None, records=None)[source]¶
Asynchronously emit a CDISC Dataset-JSON v1.1 envelope for CDASH Forms or SDTM domains.
- Parameters:
study_key (str) –
visit_key (str | None) –
use_labels_as_columns (bool) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
form_key (str | None) –
as_sdtm (bool | None) –
domain (str | None) –
naming_convention (str | None) –
preserve_record_id (bool) –
mask_phi (bool | None) –
include_deleted (bool | None) –
metadata_version_oid (str) –
file_oid (str | None) –
creation_datetime (str | None) –
records (Iterable[Any] | AsyncIterable[Any] | None) –
- Return type:
- async to_dataset_json_bundle(study_key, visit_key=None, use_labels_as_columns=False, variable_whitelist=None, form_whitelist=None, *, form_key=None, as_sdtm=None, domain=None, naming_convention=None, preserve_record_id=False, mask_phi=None, include_deleted=None, metadata_version_oid='MDV.001', file_oid=None, creation_datetime=None, records=None)[source]¶
Asynchronously emit a
DatasetJsonBundlefor CDASH Forms or SDTM domains.- Parameters:
study_key (str) –
visit_key (str | None) –
use_labels_as_columns (bool) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
form_key (str | None) –
as_sdtm (bool | None) –
domain (str | None) –
naming_convention (str | None) –
preserve_record_id (bool) –
mask_phi (bool | None) –
include_deleted (bool | None) –
metadata_version_oid (str) –
file_oid (str | None) –
creation_datetime (str | None) –
records (Iterable[Any] | AsyncIterable[Any] | None) –
- Return type:
- transform_to_sdtm(records, domain, study_key, *, mask_phi=None, include_deleted=None, seq_counters=None, record_seqs=None, preserve_record_id=False)¶
Transform an iterable of records into a normalized SDTM domain DataFrame.
- Parameters:
records (Iterable[Any]) –
domain (str) –
study_key (str) –
mask_phi (bool | None) –
include_deleted (bool | None) –
seq_counters (dict[str, int] | None) –
record_seqs (dict[str, int] | None) –
preserve_record_id (bool) –
- Return type:
DataFrame
- class imednet_workflows.record_mapper.RecordMapper[source]¶
Bases:
objectMaps EDC records for a study into a pandas DataFrame.
- Features:
Fetches variable definitions for column mapping.
Dynamically creates a Pydantic model for type validation of record data.
Fetches records, applying server-side filtering where possible.
Merges metadata and record data.
Offers choice between variable names or labels for column headers.
Handles parsing errors gracefully for individual records.
Example
sdk = ImednetSDK(api_key, security_key, base_url) mapper = RecordMapper(sdk) # Get DataFrame with labels as columns, filtered by visit df_labels = mapper.dataframe(study_key=”MYSTUDY”, visit_key=”VISIT1”) # Get DataFrame with variable names as columns df_names = mapper.dataframe(study_key=”MYSTUDY”, use_labels_as_columns=False)
- __init__(sdk, *, loader=None, chunk_size=5000, mask_phi=True, include_deleted=False)[source]¶
Initialize with an
ImednetSDKinstance.loaderenables cache-backed streaming for large-study workflows.chunk_sizecontrols the maximum number of records parsed into each yielded batch when using chunked mapping helpers.mask_phicontrols whether sensitive clinical fields are masked at mapper ingress by default.include_deletedcontrols whether voided (deleted=True) records are retained (defaults toFalse).- Parameters:
sdk (ImednetFacade) –
loader (CachedRecordsLoader | None) –
chunk_size (int) –
mask_phi (bool) –
include_deleted (bool) –
- Return type:
None
- build_hierarchy(study_key, visit_key=None, use_labels_as_keys=False, variable_whitelist=None, form_whitelist=None, *, naming_convention=None, domain=None, mask_phi=None, include_deleted=None, records=None)[source]¶
Generate a nested JSON tree structure up to three levels deep.
- Parameters:
study_key (str) –
visit_key (str | None) –
use_labels_as_keys (bool) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
naming_convention (str | None) –
domain (str | None) –
mask_phi (bool | None) –
include_deleted (bool | None) –
records (Iterable[Record] | None) –
- Return type:
list[dict[str, Any]]
- dataframe(study_key, visit_key=None, use_labels_as_columns=True, variable_whitelist=None, form_whitelist=None, *, as_sdtm=False, domain=None, naming_convention=None, preserve_record_id=False, mask_phi=None, include_deleted=None)[source]¶
Return a
pandas.DataFrameof records for a study.- Parameters:
study_key (str) –
visit_key (str | None) –
use_labels_as_columns (bool) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
as_sdtm (bool) –
domain (str | None) –
naming_convention (str | None) –
preserve_record_id (bool) –
mask_phi (bool | None) –
include_deleted (bool | None) –
- Return type:
DataFrame
- iter_dataframes(study_key, visit_key=None, use_labels_as_columns=True, variable_whitelist=None, form_whitelist=None, *, as_sdtm=False, domain=None, naming_convention=None, mask_phi=None, include_deleted=None)[source]¶
Yield mapped record DataFrames in bounded chunks.
- Parameters:
study_key (str) –
visit_key (str | None) –
use_labels_as_columns (bool) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
as_sdtm (bool) –
domain (str | None) –
naming_convention (str | None) –
mask_phi (bool | None) –
include_deleted (bool | None) –
- Return type:
Iterator[DataFrame]
- iter_sdtm_dataframes(study_key, domain, visit_key=None, variable_whitelist=None, form_whitelist=None, *, naming_convention=None, preserve_record_id=False, mask_phi=None, include_deleted=None)[source]¶
Yield chunked pandas DataFrames transformed into an SDTM domain dataset.
- Parameters:
study_key (str) –
domain (str) –
visit_key (str | None) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
naming_convention (str | None) –
preserve_record_id (bool) –
mask_phi (bool | None) –
include_deleted (bool | None) –
- Return type:
Iterator[DataFrame]
- sdtm_dataframe(study_key, domain, visit_key=None, variable_whitelist=None, form_whitelist=None, *, naming_convention=None, preserve_record_id=False, mask_phi=None, include_deleted=None)[source]¶
Return a
pandas.DataFrametransformed into a CDISC SDTM domain dataset.- Parameters:
study_key (str) –
domain (str) –
visit_key (str | None) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
naming_convention (str | None) –
preserve_record_id (bool) –
mask_phi (bool | None) –
include_deleted (bool | None) –
- Return type:
DataFrame
- sdtm_dataset_json(study_key, domain, visit_key=None, variable_whitelist=None, form_whitelist=None, *, naming_convention=None, preserve_record_id=False, mask_phi=None, include_deleted=None, metadata_version_oid='MDV.001', file_oid=None, creation_datetime=None)[source]¶
Emit a CDISC Dataset-JSON v1.1 envelope for a specific SDTM domain.
- Parameters:
study_key (str) –
domain (str) –
visit_key (str | None) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
naming_convention (str | None) –
preserve_record_id (bool) –
mask_phi (bool | None) –
include_deleted (bool | None) –
metadata_version_oid (str) –
file_oid (str | None) –
creation_datetime (str | None) –
- Return type:
- to_dataset_json(study_key, visit_key=None, use_labels_as_columns=False, variable_whitelist=None, form_whitelist=None, *, form_key=None, as_sdtm=None, domain=None, naming_convention=None, preserve_record_id=False, mask_phi=None, include_deleted=None, metadata_version_oid='MDV.001', file_oid=None, creation_datetime=None, records=None)[source]¶
Emit a CDISC Dataset-JSON v1.1 envelope for CDASH Forms or SDTM domains.
- Parameters:
study_key (str) –
visit_key (str | None) –
use_labels_as_columns (bool) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
form_key (str | None) –
as_sdtm (bool | None) –
domain (str | None) –
naming_convention (str | None) –
preserve_record_id (bool) –
mask_phi (bool | None) –
include_deleted (bool | None) –
metadata_version_oid (str) –
file_oid (str | None) –
creation_datetime (str | None) –
records (Iterable[Any] | None) –
- Return type:
- to_dataset_json_bundle(study_key, visit_key=None, use_labels_as_columns=False, variable_whitelist=None, form_whitelist=None, *, form_key=None, as_sdtm=None, domain=None, naming_convention=None, preserve_record_id=False, mask_phi=None, include_deleted=None, metadata_version_oid='MDV.001', file_oid=None, creation_datetime=None, records=None)[source]¶
Emit a
DatasetJsonBundlemapping each Form or SDTM domain to a flat v1.1 envelope.- Parameters:
study_key (str) –
visit_key (str | None) –
use_labels_as_columns (bool) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
form_key (str | None) –
as_sdtm (bool | None) –
domain (str | None) –
naming_convention (str | None) –
preserve_record_id (bool) –
mask_phi (bool | None) –
include_deleted (bool | None) –
metadata_version_oid (str) –
file_oid (str | None) –
creation_datetime (str | None) –
records (Iterable[Any] | None) –
- Return type:
- transform_to_sdtm(records, domain, study_key, *, mask_phi=None, include_deleted=None, seq_counters=None, record_seqs=None, preserve_record_id=False)[source]¶
Transform an iterable of records into a normalized SDTM domain DataFrame.
- Parameters:
records (Iterable[Any]) –
domain (str) –
study_key (str) –
mask_phi (bool | None) –
include_deleted (bool | None) –
seq_counters (dict[str, int] | None) –
record_seqs (dict[str, int] | None) –
preserve_record_id (bool) –
- Return type:
DataFrame
- imednet_workflows.record_mapper.transform_records_to_dataset_json(records, study_key, *, forms=(), variables=(), as_sdtm=None, domain=None, use_labels_as_columns=False, variable_whitelist=None, form_whitelist=None, form_key=None, naming_convention=None, preserve_record_id=False, include_deleted=False, mask_phi=True, enrichment_pipeline=<object object>, phi_keys=None, metadata_version_oid='MDV.001', file_oid=None, creation_datetime=None)[source]¶
Transform clinical records into a CDISC Dataset-JSON v1.1 envelope.
- Parameters:
records (Iterable[Any]) –
study_key (str) –
forms (Iterable[Any]) –
variables (Iterable[Any]) –
as_sdtm (bool | None) –
domain (str | None) –
use_labels_as_columns (bool) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
form_key (str | None) –
naming_convention (str | None) –
preserve_record_id (bool) –
include_deleted (bool) –
mask_phi (bool) –
enrichment_pipeline (EnrichmentPipeline | None) –
phi_keys (Iterable[str] | None) –
metadata_version_oid (str) –
file_oid (str | None) –
creation_datetime (str | None) –
- Return type:
- imednet_workflows.record_mapper.transform_records_to_dataset_json_bundle(records, study_key, *, forms=(), variables=(), as_sdtm=None, domain=None, use_labels_as_columns=False, variable_whitelist=None, form_whitelist=None, form_key=None, naming_convention=None, preserve_record_id=False, include_deleted=False, mask_phi=True, enrichment_pipeline=<object object>, phi_keys=None, metadata_version_oid='MDV.001', file_oid=None, creation_datetime=None)[source]¶
Transform clinical records across multiple Forms or SDTM domains into a
DatasetJsonBundle.- Parameters:
records (Iterable[Any]) –
study_key (str) –
forms (Iterable[Any]) –
variables (Iterable[Any]) –
as_sdtm (bool | None) –
domain (str | None) –
use_labels_as_columns (bool) –
variable_whitelist (list[str] | None) –
form_whitelist (list[int] | None) –
form_key (str | None) –
naming_convention (str | None) –
preserve_record_id (bool) –
include_deleted (bool) –
mask_phi (bool) –
enrichment_pipeline (EnrichmentPipeline | None) –
phi_keys (Iterable[str] | None) –
metadata_version_oid (str) –
file_oid (str | None) –
creation_datetime (str | None) –
- Return type:
- imednet_workflows.record_mapper.transform_records_to_sdtm(records, domain, study_key, *, include_deleted=False, mask_phi=True, enrichment_pipeline=<object object>, pipeline=<object object>, seq_counters=None, record_seqs=None, preserve_record_id=False, phi_keys=None, registry=None)[source]¶
Transform clinical records into a normalized CDISC SDTM domain DataFrame.
Delegates normalization, ISO 8601
BRTHDTCyear redaction, subject-group sorting, and<DOM>SEQassignment (omittingDMSEQonDM) to the coreimednet.spi.modelsSDTM engine while resolving study enrichment rules throughresolve_enrichment_pipelinewhen not explicitly provided.- Parameters:
records (Iterable[Any]) –
domain (str) –
study_key (str) –
include_deleted (bool) –
mask_phi (bool) –
enrichment_pipeline (EnrichmentPipeline | None) –
pipeline (EnrichmentPipeline | None) –
seq_counters (dict[str, int] | None) –
record_seqs (dict[str, int] | None) –
preserve_record_id (bool) –
phi_keys (Iterable[str] | None) –
registry (Any | None) –
- Return type:
DataFrame
imednet_workflows.record_update module¶
Utilities for submitting and updating records in iMedNet studies.
- class imednet_workflows.record_update.AsyncRecordUpdateWorkflow[source]¶
Bases:
objectAsynchronous workflow for creating or updating records on
AsyncImednetSDK.- __init__(sdk, *, batch_size=100, schema=None)[source]¶
Initialize the asynchronous record update workflow.
- Parameters:
sdk (AsyncImednetFacade) –
batch_size (int) –
schema (ValidationSchemaProtocol | None) –
- Return type:
None
- async_create_new_record(study_key, form_identifier, subject_identifier, data, form_identifier_type='key', subject_identifier_type='key', wait_for_completion=False, timeout=300, poll_interval=5, *, record_status=None, reason_for_change=None, email_notify=None, schema=None, resolve_results=True)[source]¶
Deprecated alias for
create_new_record().- Parameters:
study_key (str) –
form_identifier (str | int) –
subject_identifier (str | int) –
data (dict[str, Any]) –
form_identifier_type (Literal['key', 'id']) –
subject_identifier_type (Literal['key', 'id', 'oid']) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
record_status (RecordStatus | str | None) –
reason_for_change (str | None) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
resolve_results (bool) –
- Return type:
- async_create_or_update_records(study_key, records_data, wait_for_completion=False, timeout=300, poll_interval=5, *, email_notify=None, schema=None, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True)[source]¶
Deprecated alias for
create_or_update_records().- Parameters:
study_key (str) –
records_data (Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –
dry_run (bool) –
collect_errors (bool) –
resolve_results (bool) –
- Return type:
- async_create_or_update_records_batch(study_key, records_data, wait_for_completion=False, timeout=300, poll_interval=5, *, email_notify=None, chunk_size=None, schema=None, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True, _single_job_method=None)[source]¶
Deprecated alias for
create_or_update_records_batch().- Parameters:
study_key (str) –
records_data (Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
email_notify (bool | str | None) –
chunk_size (int | None) –
schema (ValidationSchemaProtocol | None) –
on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –
dry_run (bool) –
collect_errors (bool) –
resolve_results (bool) –
_single_job_method (tuple[str, str] | None) –
- Return type:
- async_register_subject(study_key, form_identifier, site_identifier, data, form_identifier_type='key', site_identifier_type='name', wait_for_completion=False, timeout=300, poll_interval=5, *, subject_key=None, subject_oid=None, record_status=None, reason_for_change=None, email_notify=None, schema=None, resolve_results=True)[source]¶
Deprecated alias for
register_subject().- Parameters:
study_key (str) –
form_identifier (str | int) –
site_identifier (str | int) –
data (dict[str, Any]) –
form_identifier_type (Literal['key', 'id']) –
site_identifier_type (Literal['name', 'id']) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
subject_key (str | None) –
subject_oid (str | None) –
record_status (RecordStatus | str | None) –
reason_for_change (str | None) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
resolve_results (bool) –
- Return type:
- async_update_record(study_key, data=None, *, record_id=None, record_oid=None, visit_id=None, form_identifier=None, form_identifier_type='key', subject_identifier=None, subject_identifier_type='key', interval_identifier=None, interval_identifier_type='name', site_identifier=None, site_identifier_type='name', record_status=None, reason_for_change=None, wait_for_completion=False, timeout=300, poll_interval=5, email_notify=None, schema=None, resolve_results=True)[source]¶
Deprecated alias for
update_record().- Parameters:
study_key (str) –
data (dict[str, Any] | None) –
record_id (int | None) –
record_oid (str | None) –
visit_id (int | None) –
form_identifier (str | int | None) –
form_identifier_type (Literal['key', 'id']) –
subject_identifier (str | int | None) –
subject_identifier_type (Literal['key', 'id', 'oid']) –
interval_identifier (str | int | None) –
interval_identifier_type (Literal['name', 'id']) –
site_identifier (str | int | None) –
site_identifier_type (Literal['name', 'id']) –
record_status (RecordStatus | str | None) –
reason_for_change (str | None) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
resolve_results (bool) –
- Return type:
- async_update_scheduled_record(study_key, form_identifier, subject_identifier, interval_identifier, data, form_identifier_type='key', subject_identifier_type='key', interval_identifier_type='name', wait_for_completion=False, timeout=300, poll_interval=5, *, record_status=None, reason_for_change=None, email_notify=None, schema=None, resolve_results=True)[source]¶
Deprecated alias for
update_scheduled_record().- Parameters:
study_key (str) –
form_identifier (str | int) –
subject_identifier (str | int) –
interval_identifier (str | int) –
data (dict[str, Any]) –
form_identifier_type (Literal['key', 'id']) –
subject_identifier_type (Literal['key', 'id', 'oid']) –
interval_identifier_type (Literal['name', 'id']) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
record_status (RecordStatus | str | None) –
reason_for_change (str | None) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
resolve_results (bool) –
- Return type:
- async create_new_record(study_key, form_identifier, subject_identifier, data, form_identifier_type='key', subject_identifier_type='key', wait_for_completion=False, timeout=300, poll_interval=5, *, record_status=None, reason_for_change=None, email_notify=None, schema=None, resolve_results=True)[source]¶
Asynchronously create a new (unscheduled) record for an existing subject.
- Parameters:
study_key (str) –
form_identifier (str | int) –
subject_identifier (str | int) –
data (dict[str, Any]) –
form_identifier_type (Literal['key', 'id']) –
subject_identifier_type (Literal['key', 'id', 'oid']) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
record_status (RecordStatus | str | None) –
reason_for_change (str | None) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
resolve_results (bool) –
- Return type:
- async create_or_update_records(study_key, records_data, wait_for_completion=False, timeout=300, poll_interval=5, *, email_notify=None, schema=None, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True)[source]¶
Asynchronously submit a single-chunk record payload and return its Job.
- Parameters:
study_key (str) –
records_data (Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –
dry_run (bool) –
collect_errors (bool) –
resolve_results (bool) –
- Return type:
- async create_or_update_records_batch(study_key, records_data, wait_for_completion=False, timeout=300, poll_interval=5, *, email_notify=None, chunk_size=None, schema=None, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True, _single_job_method=None)[source]¶
Asynchronously validate once, submit chunks, and return a batch summary.
- Parameters:
study_key (str) –
records_data (Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
email_notify (bool | str | None) –
chunk_size (int | None) –
schema (ValidationSchemaProtocol | None) –
on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –
dry_run (bool) –
collect_errors (bool) –
resolve_results (bool) –
_single_job_method (tuple[str, str] | None) –
- Return type:
- async register_subject(study_key, form_identifier, site_identifier, data, form_identifier_type='key', site_identifier_type='name', wait_for_completion=False, timeout=300, poll_interval=5, *, subject_key=None, subject_oid=None, record_status=None, reason_for_change=None, email_notify=None, schema=None, resolve_results=True)[source]¶
Asynchronously register a new subject by submitting a single record.
- Parameters:
study_key (str) –
form_identifier (str | int) –
site_identifier (str | int) –
data (dict[str, Any]) –
form_identifier_type (Literal['key', 'id']) –
site_identifier_type (Literal['name', 'id']) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
subject_key (str | None) –
subject_oid (str | None) –
record_status (RecordStatus | str | None) –
reason_for_change (str | None) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
resolve_results (bool) –
- Return type:
- async update_record(study_key, data=None, *, record_id=None, record_oid=None, visit_id=None, form_identifier=None, form_identifier_type='key', subject_identifier=None, subject_identifier_type='key', interval_identifier=None, interval_identifier_type='name', site_identifier=None, site_identifier_type='name', record_status=None, reason_for_change=None, wait_for_completion=False, timeout=300, poll_interval=5, email_notify=None, schema=None, resolve_results=True)[source]¶
Asynchronously update an existing record by recordId, recordOid, visitId, or interval.
- Parameters:
study_key (str) –
data (dict[str, Any] | None) –
record_id (int | None) –
record_oid (str | None) –
visit_id (int | None) –
form_identifier (str | int | None) –
form_identifier_type (Literal['key', 'id']) –
subject_identifier (str | int | None) –
subject_identifier_type (Literal['key', 'id', 'oid']) –
interval_identifier (str | int | None) –
interval_identifier_type (Literal['name', 'id']) –
site_identifier (str | int | None) –
site_identifier_type (Literal['name', 'id']) –
record_status (RecordStatus | str | None) –
reason_for_change (str | None) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
resolve_results (bool) –
- Return type:
- async update_scheduled_record(study_key, form_identifier, subject_identifier, interval_identifier, data, form_identifier_type='key', subject_identifier_type='key', interval_identifier_type='name', wait_for_completion=False, timeout=300, poll_interval=5, *, record_status=None, reason_for_change=None, email_notify=None, schema=None, resolve_results=True)[source]¶
Asynchronously update an existing scheduled record for a subject.
- Parameters:
study_key (str) –
form_identifier (str | int) –
subject_identifier (str | int) –
interval_identifier (str | int) –
data (dict[str, Any]) –
form_identifier_type (Literal['key', 'id']) –
subject_identifier_type (Literal['key', 'id', 'oid']) –
interval_identifier_type (Literal['name', 'id']) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
record_status (RecordStatus | str | None) –
reason_for_change (str | None) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
resolve_results (bool) –
- Return type:
- class imednet_workflows.record_update.RecordUpdateWorkflow[source]¶
Bases:
objectProvides synchronous workflows for creating or updating records over the shared async core.
- Parameters:
sdk – An instance of the ImednetFacade (or AsyncImednetFacade for legacy direct usage).
batch_size – Maximum number of records per API POST chunk (default: 100).
schema – Optional offline or pre-populated ValidationSchemaProtocol (e.g. DataDictionary or SchemaCache).
- __init__(sdk, *, batch_size=100, schema=None)[source]¶
Initialize the record update workflow with an SDK instance.
- Parameters:
sdk (ImednetFacade | AsyncImednetFacade) –
batch_size (int) –
schema (ValidationSchemaProtocol | None) –
- Return type:
None
- async_create_new_record(study_key, form_identifier, subject_identifier, data, form_identifier_type='key', subject_identifier_type='key', wait_for_completion=False, timeout=300, poll_interval=5, *, record_status=None, reason_for_change=None, email_notify=None, schema=None, resolve_results=True)[source]¶
Deprecated asynchronous alias for
create_new_record().- Parameters:
study_key (str) –
form_identifier (str | int) –
subject_identifier (str | int) –
data (dict[str, Any]) –
form_identifier_type (Literal['key', 'id']) –
subject_identifier_type (Literal['key', 'id', 'oid']) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
record_status (RecordStatus | str | None) –
reason_for_change (str | None) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
resolve_results (bool) –
- Return type:
- async_create_or_update_records(study_key, records_data, wait_for_completion=False, timeout=300, poll_interval=5, *, email_notify=None, schema=None, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True)[source]¶
Deprecated asynchronous variant of
create_or_update_records().- Parameters:
study_key (str) –
records_data (Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –
dry_run (bool) –
collect_errors (bool) –
resolve_results (bool) –
- Return type:
- async_create_or_update_records_batch(study_key, records_data, wait_for_completion=False, timeout=300, poll_interval=5, *, email_notify=None, chunk_size=None, schema=None, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True, _single_job_method=None)[source]¶
Deprecated asynchronous alias for batch record submission.
- Parameters:
study_key (str) –
records_data (Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
email_notify (bool | str | None) –
chunk_size (int | None) –
schema (ValidationSchemaProtocol | None) –
on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –
dry_run (bool) –
collect_errors (bool) –
resolve_results (bool) –
_single_job_method (tuple[str, str] | None) –
- Return type:
- async_register_subject(study_key, form_identifier, site_identifier, data, form_identifier_type='key', site_identifier_type='name', wait_for_completion=False, timeout=300, poll_interval=5, *, subject_key=None, subject_oid=None, record_status=None, reason_for_change=None, email_notify=None, schema=None, resolve_results=True)[source]¶
Deprecated asynchronous alias for
register_subject().- Parameters:
study_key (str) –
form_identifier (str | int) –
site_identifier (str | int) –
data (dict[str, Any]) –
form_identifier_type (Literal['key', 'id']) –
site_identifier_type (Literal['name', 'id']) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
subject_key (str | None) –
subject_oid (str | None) –
record_status (RecordStatus | str | None) –
reason_for_change (str | None) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
resolve_results (bool) –
- Return type:
- async_update_record(study_key, data=None, *, record_id=None, record_oid=None, visit_id=None, form_identifier=None, form_identifier_type='key', subject_identifier=None, subject_identifier_type='key', interval_identifier=None, interval_identifier_type='name', site_identifier=None, site_identifier_type='name', record_status=None, reason_for_change=None, wait_for_completion=False, timeout=300, poll_interval=5, email_notify=None, schema=None, resolve_results=True)[source]¶
Deprecated asynchronous alias for
update_record().- Parameters:
study_key (str) –
data (dict[str, Any] | None) –
record_id (int | None) –
record_oid (str | None) –
visit_id (int | None) –
form_identifier (str | int | None) –
form_identifier_type (Literal['key', 'id']) –
subject_identifier (str | int | None) –
subject_identifier_type (Literal['key', 'id', 'oid']) –
interval_identifier (str | int | None) –
interval_identifier_type (Literal['name', 'id']) –
site_identifier (str | int | None) –
site_identifier_type (Literal['name', 'id']) –
record_status (RecordStatus | str | None) –
reason_for_change (str | None) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
resolve_results (bool) –
- Return type:
- async_update_scheduled_record(study_key, form_identifier, subject_identifier, interval_identifier, data, form_identifier_type='key', subject_identifier_type='key', interval_identifier_type='name', wait_for_completion=False, timeout=300, poll_interval=5, *, record_status=None, reason_for_change=None, email_notify=None, schema=None, resolve_results=True)[source]¶
Deprecated asynchronous alias for
update_scheduled_record().- Parameters:
study_key (str) –
form_identifier (str | int) –
subject_identifier (str | int) –
interval_identifier (str | int) –
data (dict[str, Any]) –
form_identifier_type (Literal['key', 'id']) –
subject_identifier_type (Literal['key', 'id', 'oid']) –
interval_identifier_type (Literal['name', 'id']) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
record_status (RecordStatus | str | None) –
reason_for_change (str | None) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
resolve_results (bool) –
- Return type:
- create_new_record(study_key, form_identifier, subject_identifier, data, form_identifier_type='key', subject_identifier_type='key', wait_for_completion=False, timeout=300, poll_interval=5, *, record_status=None, reason_for_change=None, email_notify=None, schema=None, resolve_results=True)[source]¶
Create a new unscheduled record for an existing subject.
- Parameters:
study_key (str) –
form_identifier (str | int) –
subject_identifier (str | int) –
data (dict[str, Any]) –
form_identifier_type (Literal['key', 'id']) –
subject_identifier_type (Literal['key', 'id', 'oid']) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
record_status (RecordStatus | str | None) –
reason_for_change (str | None) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
resolve_results (bool) –
- Return type:
- create_or_update_records(study_key, records_data, wait_for_completion=False, timeout=300, poll_interval=5, *, email_notify=None, schema=None, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True)[source]¶
Submit a single-chunk record payload and return its Job.
- Parameters:
study_key (str) –
records_data (Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –
dry_run (bool) –
collect_errors (bool) –
resolve_results (bool) –
- Return type:
- create_or_update_records_batch(study_key, records_data, wait_for_completion=False, timeout=300, poll_interval=5, *, email_notify=None, chunk_size=None, schema=None, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True, _single_job_method=None)[source]¶
Validate once, submit records in bounded chunks, and return a batch summary.
- Parameters:
study_key (str) –
records_data (Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
email_notify (bool | str | None) –
chunk_size (int | None) –
schema (ValidationSchemaProtocol | None) –
on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –
dry_run (bool) –
collect_errors (bool) –
resolve_results (bool) –
_single_job_method (tuple[str, str] | None) –
- Return type:
- register_subject(study_key, form_identifier, site_identifier, data, form_identifier_type='key', site_identifier_type='name', wait_for_completion=False, timeout=300, poll_interval=5, *, subject_key=None, subject_oid=None, record_status=None, reason_for_change=None, email_notify=None, schema=None, resolve_results=True)[source]¶
Register a new subject by submitting a single enrollment record.
- Parameters:
study_key (str) –
form_identifier (str | int) –
site_identifier (str | int) –
data (dict[str, Any]) –
form_identifier_type (Literal['key', 'id']) –
site_identifier_type (Literal['name', 'id']) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
subject_key (str | None) –
subject_oid (str | None) –
record_status (RecordStatus | str | None) –
reason_for_change (str | None) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
resolve_results (bool) –
- Return type:
- update_record(study_key, data=None, *, record_id=None, record_oid=None, visit_id=None, form_identifier=None, form_identifier_type='key', subject_identifier=None, subject_identifier_type='key', interval_identifier=None, interval_identifier_type='name', site_identifier=None, site_identifier_type='name', record_status=None, reason_for_change=None, wait_for_completion=False, timeout=300, poll_interval=5, email_notify=None, schema=None, resolve_results=True)[source]¶
Update an existing record by recordId, recordOid, visitId, or interval.
- Parameters:
study_key (str) –
data (dict[str, Any] | None) –
record_id (int | None) –
record_oid (str | None) –
visit_id (int | None) –
form_identifier (str | int | None) –
form_identifier_type (Literal['key', 'id']) –
subject_identifier (str | int | None) –
subject_identifier_type (Literal['key', 'id', 'oid']) –
interval_identifier (str | int | None) –
interval_identifier_type (Literal['name', 'id']) –
site_identifier (str | int | None) –
site_identifier_type (Literal['name', 'id']) –
record_status (RecordStatus | str | None) –
reason_for_change (str | None) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
resolve_results (bool) –
- Return type:
- update_scheduled_record(study_key, form_identifier, subject_identifier, interval_identifier, data, form_identifier_type='key', subject_identifier_type='key', interval_identifier_type='name', wait_for_completion=False, timeout=300, poll_interval=5, *, record_status=None, reason_for_change=None, email_notify=None, schema=None, resolve_results=True)[source]¶
Update an existing scheduled visit record for a subject.
- Parameters:
study_key (str) –
form_identifier (str | int) –
subject_identifier (str | int) –
interval_identifier (str | int) –
data (dict[str, Any]) –
form_identifier_type (Literal['key', 'id']) –
subject_identifier_type (Literal['key', 'id', 'oid']) –
interval_identifier_type (Literal['name', 'id']) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
record_status (RecordStatus | str | None) –
reason_for_change (str | None) –
email_notify (bool | str | None) –
schema (ValidationSchemaProtocol | None) –
resolve_results (bool) –
- Return type:
imednet_workflows.register_subjects module¶
Workflow for registering subjects in iMedNet via the Records API.
- class imednet_workflows.register_subjects.AsyncRegisterSubjectsWorkflow[source]¶
Bases:
objectAsynchronous workflow for bulk subject registration on
AsyncImednetSDK.- __init__(sdk, *, batch_size=100, filter_enrolled=False)[source]¶
Initialize the asynchronous subject registration workflow.
- Parameters:
sdk (AsyncImednetFacade) –
batch_size (int) –
filter_enrolled (bool) –
- Return type:
None
- async_register_subjects(study_key, subjects, email_notify=None, wait_for_completion=False, timeout=300, poll_interval=5, *, filter_enrolled=None, skip_existing=False, subject_key_field=None, schema=None, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True)[source]¶
Deprecated alias for
register_subjects().- Parameters:
study_key (str) –
subjects (Sequence[RegisterSubjectRequest | dict[str, Any]] | Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –
email_notify (str | None) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
filter_enrolled (bool | None) –
skip_existing (bool) –
subject_key_field (str | None) –
schema (ValidationSchemaProtocol | None) –
on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –
dry_run (bool) –
collect_errors (bool) –
resolve_results (bool) –
- Return type:
- async_register_subjects_batch(study_key, subjects, email_notify=None, wait_for_completion=False, timeout=300, poll_interval=5, *, chunk_size=None, filter_enrolled=None, skip_existing=False, subject_key_field=None, schema=None, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True, _single_job_method=None)[source]¶
Deprecated alias for
register_subjects_batch().- Parameters:
study_key (str) –
subjects (Sequence[RegisterSubjectRequest | dict[str, Any]] | Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –
email_notify (str | None) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
chunk_size (int | None) –
filter_enrolled (bool | None) –
skip_existing (bool) –
subject_key_field (str | None) –
schema (ValidationSchemaProtocol | None) –
on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –
dry_run (bool) –
collect_errors (bool) –
resolve_results (bool) –
_single_job_method (tuple[str, str] | None) –
- Return type:
- async register_subjects(study_key, subjects, email_notify=None, wait_for_completion=False, timeout=300, poll_interval=5, *, filter_enrolled=None, skip_existing=False, subject_key_field=None, schema=None, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True)[source]¶
Asynchronously register a single-chunk batch of subjects and return its Job.
- Parameters:
study_key (str) –
subjects (Sequence[RegisterSubjectRequest | dict[str, Any]] | Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –
email_notify (str | None) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
filter_enrolled (bool | None) –
skip_existing (bool) –
subject_key_field (str | None) –
schema (ValidationSchemaProtocol | None) –
on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –
dry_run (bool) –
collect_errors (bool) –
resolve_results (bool) –
- Return type:
- async register_subjects_batch(study_key, subjects, email_notify=None, wait_for_completion=False, timeout=300, poll_interval=5, *, chunk_size=None, filter_enrolled=None, skip_existing=False, subject_key_field=None, schema=None, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True, _single_job_method=None)[source]¶
Asynchronously validate sites, filter enrolled subjects, and submit in bounded chunks.
- Parameters:
study_key (str) –
subjects (Sequence[RegisterSubjectRequest | dict[str, Any]] | Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –
email_notify (str | None) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
chunk_size (int | None) –
filter_enrolled (bool | None) –
skip_existing (bool) –
subject_key_field (str | None) –
schema (ValidationSchemaProtocol | None) –
on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –
dry_run (bool) –
collect_errors (bool) –
resolve_results (bool) –
_single_job_method (tuple[str, str] | None) –
- Return type:
- class imednet_workflows.register_subjects.RegisterSubjectsWorkflow[source]¶
Bases:
objectManages synchronous registration of subjects over the shared async execution engine.
- __init__(sdk, *, batch_size=100, filter_enrolled=False)[source]¶
Initialize the RegisterSubjectsWorkflow.
- Parameters:
sdk (ImednetFacade | AsyncImednetFacade) – An instance of
ImednetFacadeorAsyncImednetFacade.batch_size (int) – Maximum number of records per chunked POST request (default: 100).
filter_enrolled (bool) – If True, filter out subjects already enrolled in the study.
- Return type:
None
- async_register_subjects(study_key, subjects, email_notify=None, wait_for_completion=False, timeout=300, poll_interval=5, *, filter_enrolled=None, skip_existing=False, subject_key_field=None, schema=None, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True)[source]¶
Deprecated asynchronous alias for single-chunk subject registration.
- Parameters:
study_key (str) –
subjects (Sequence[RegisterSubjectRequest | dict[str, Any]] | Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –
email_notify (str | None) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
filter_enrolled (bool | None) –
skip_existing (bool) –
subject_key_field (str | None) –
schema (ValidationSchemaProtocol | None) –
on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –
dry_run (bool) –
collect_errors (bool) –
resolve_results (bool) –
- Return type:
- async_register_subjects_batch(study_key, subjects, email_notify=None, wait_for_completion=False, timeout=300, poll_interval=5, *, chunk_size=None, filter_enrolled=None, skip_existing=False, subject_key_field=None, schema=None, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True, _single_job_method=None)[source]¶
Deprecated asynchronous alias for subject batch registration.
- Parameters:
study_key (str) –
subjects (Sequence[RegisterSubjectRequest | dict[str, Any]] | Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –
email_notify (str | None) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
chunk_size (int | None) –
filter_enrolled (bool | None) –
skip_existing (bool) –
subject_key_field (str | None) –
schema (ValidationSchemaProtocol | None) –
on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –
dry_run (bool) –
collect_errors (bool) –
resolve_results (bool) –
_single_job_method (tuple[str, str] | None) –
- Return type:
- register_subjects(study_key, subjects, email_notify=None, wait_for_completion=False, timeout=300, poll_interval=5, *, filter_enrolled=None, skip_existing=False, subject_key_field=None, schema=None, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True)[source]¶
Register a single-chunk batch of subjects synchronously and return its Job.
- Parameters:
study_key (str) –
subjects (Sequence[RegisterSubjectRequest | dict[str, Any]] | Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –
email_notify (str | None) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
filter_enrolled (bool | None) –
skip_existing (bool) –
subject_key_field (str | None) –
schema (ValidationSchemaProtocol | None) –
on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –
dry_run (bool) –
collect_errors (bool) –
resolve_results (bool) –
- Return type:
- register_subjects_batch(study_key, subjects, email_notify=None, wait_for_completion=False, timeout=300, poll_interval=5, *, chunk_size=None, filter_enrolled=None, skip_existing=False, subject_key_field=None, schema=None, on_progress=None, dry_run=False, collect_errors=False, resolve_results=True, _single_job_method=None)[source]¶
Validate sites once, optionally filter enrolled subjects, and submit in bounded chunks.
- Parameters:
study_key (str) –
subjects (Sequence[RegisterSubjectRequest | dict[str, Any]] | Sequence[BaseRecordRequest | Mapping[str, Any]] | DataFrameLike | str | PathLike[str]) –
email_notify (str | None) –
wait_for_completion (bool) –
timeout (int) –
poll_interval (int) –
chunk_size (int | None) –
filter_enrolled (bool | None) –
skip_existing (bool) –
subject_key_field (str | None) –
schema (ValidationSchemaProtocol | None) –
on_progress (JobProgressCallback | Callable[[JobStatusEvent], None] | None) –
dry_run (bool) –
collect_errors (bool) –
resolve_results (bool) –
_single_job_method (tuple[str, str] | None) –
- Return type:
imednet_workflows.schema_profiler module¶
Workflow for profiling form and record-data population across cached records.
- class imednet_workflows.schema_profiler.FieldProfile[source]¶
Bases:
BaseModelSummary statistics for a single form field.
- variable_name: str¶
Required.
- label: str¶
Required.
- population_rate: float¶
Required.
- inferred_type: str¶
Required.
- unique_count: int = 0¶
- unique_values: list[str] = list()¶
- class imednet_workflows.schema_profiler.FormProfile[source]¶
Bases:
BaseModelSummary statistics for a single form.
- form_key: str¶
Required.
- form_name: str¶
Required.
- record_count: int¶
Required.
- fields: dict[str, FieldProfile] = dict()¶
- class imednet_workflows.schema_profiler.SchemaProfiler[source]¶
Bases:
objectProfile form and record-data population across cached records.
- __init__(sdk, loader=None)[source]¶
Initialize the schema profiler.
- Parameters:
sdk (ImednetFacade) – An instance of the iMednet SDK facade.
loader (CachedRecordsLoader | None) – Optional cached records loader. If not provided, one will be created.
- Return type:
None
- profile_records(study_key, *, records=None)[source]¶
Return per-form field profiling statistics for
study_key.- Parameters:
study_key (str) –
records (Iterable[Record] | None) –
- Return type:
dict[str, FormProfile]
imednet_workflows.standards_validation module¶
Backward-compatible re-exports of core CDISC standards validation models.
imednet_workflows.state_ledger module¶
Stateful incremental high-water mark tracker for workflow streams.
- class imednet_workflows.state_ledger.AirflowStateProvider[source]¶
Bases:
BaseStateProviderManage transactional stream checkpoints using Airflow Variables.
- __init__(variable_prefix='imednet_state', *, lease_ttl_seconds=3600.0)[source]¶
Initialize the Airflow Variable state provider.
- Parameters:
variable_prefix (str) – Prefix namespace for Airflow
Variablecheckpoint keys.lease_ttl_seconds (float) – Duration in seconds before an active
RUNNINGlease expires.
- Return type:
None
- batch_transaction(study_key, stream_names, fallback_timestamp=None, *, lease_ttl_seconds=None)[source]¶
Context manager for batched transactional tracking across multiple Study streams.
- Parameters:
study_key (str) –
stream_names (Sequence[str]) –
fallback_timestamp (datetime | None) –
lease_ttl_seconds (float | None) –
- Return type:
Generator[dict[str, dict[str, Any]], None, None]
- delete_entry(study_key, stream_name=None, *, force=False)[source]¶
Delete a Study or specific stream checkpoint from Airflow Variables.
- Parameters:
study_key (str) –
stream_name (str | None) –
force (bool) –
- Return type:
bool
- get_last_status(study_key, stream_name)[source]¶
Return the execution status for a Study and stream from Airflow Variables.
- Parameters:
study_key (str) –
stream_name (str) –
- Return type:
StreamExecutionStatus | None
- get_last_timestamp(study_key, stream_name)[source]¶
Return the high-water mark timestamp for a Study and stream from Airflow Variables.
- Parameters:
study_key (str) –
stream_name (str) –
- Return type:
datetime | None
- get_sdtm_lineage(study_key, stream_name)[source]¶
Return persisted SDTM sidecar lineage and sequence watermarks from Airflow Variables.
- Parameters:
study_key (str) –
stream_name (str) –
- Return type:
dict[str, Any]
- read_state()[source]¶
Read and validate the full ledger state across all Study checkpoints.
- Return type:
- record_sdtm_lineage(study_key, stream_name, lineage_updates=None, seq_watermarks=None)[source]¶
Persist SDTM sidecar lineage and monotonic sequence watermarks in Airflow Variables.
- Parameters:
study_key (str) –
stream_name (str) –
lineage_updates (Mapping[str, dict[str, Any] | None] | None) –
seq_watermarks (Mapping[str, int] | None) –
- Return type:
None
- set_last_timestamp(study_key, stream_name, timestamp, records_processed=0, status=StreamExecutionStatus.SUCCESS, error_message=None, metadata=None, force=False, *, owner_pid=None, owner_host=None, lease_expires_at=None, lease_id=None, _preserve_existing_lineage=True)[source]¶
Persist the high-water mark checkpoint for a Study and stream in Airflow Variables.
- Parameters:
study_key (str) –
stream_name (str) –
timestamp (datetime | None) –
records_processed (int) –
status (StreamExecutionStatus | str) –
error_message (str | None) –
metadata (dict[str, Any] | None) –
force (bool) –
owner_pid (int | None) –
owner_host (str | None) –
lease_expires_at (datetime | None) –
lease_id (str | None) –
_preserve_existing_lineage (bool) –
- Return type:
None
- transaction(study_key, stream_name, fallback_timestamp=None, *, lease_ttl_seconds=None)[source]¶
Context manager for transactional state tracking backed by Airflow Variables.
- Parameters:
study_key (str) –
stream_name (str) –
fallback_timestamp (datetime | None) –
lease_ttl_seconds (float | None) –
- Return type:
Generator[dict[str, Any], None, None]
- class imednet_workflows.state_ledger.BaseStateProvider[source]¶
Bases:
ABCAbstract interface for managing high-water marks and state transactions.
- batch_transaction(study_key, stream_names, fallback_timestamp=None, *, lease_ttl_seconds=None)[source]¶
Context manager for transactional state tracking across multiple streams in one study.
- Parameters:
study_key (str) –
stream_names (Sequence[str]) –
fallback_timestamp (datetime | None) –
lease_ttl_seconds (float | None) –
- Return type:
Generator[dict[str, dict[str, Any]], None, None]
- abstract delete_entry(study_key, stream_name=None, *, force=False)[source]¶
Deletes a study or specific stream entry from the state.
Returns
Trueif the entry existed and was removed,Falseotherwise.- Parameters:
study_key (str) –
stream_name (str | None) –
force (bool) –
- Return type:
bool
- get_last_status(study_key, stream_name)[source]¶
Returns the last execution status for a given study and stream.
- Parameters:
study_key (str) –
stream_name (str) –
- Return type:
StreamExecutionStatus | None
- abstract get_last_timestamp(study_key, stream_name)[source]¶
Returns the high-water mark timestamp for a given study and stream.
- Parameters:
study_key (str) –
stream_name (str) –
- Return type:
datetime | None
- get_sdtm_lineage(study_key, stream_name)[source]¶
Return persisted SDTM sidecar lineage and monotonic sequence watermarks.
- Parameters:
study_key (str) –
stream_name (str) –
- Return type:
dict[str, Any]
- abstract read_state()[source]¶
Reads and validates the current full state (for CLI display).
- Return type:
- record_sdtm_lineage(study_key, stream_name, lineage_updates=None, seq_watermarks=None)[source]¶
Persist SDTM sidecar lineage and monotonic sequence watermarks.
- Parameters:
study_key (str) –
stream_name (str) –
lineage_updates (Mapping[str, dict[str, Any] | None] | None) –
seq_watermarks (Mapping[str, int] | None) –
- Return type:
None
- abstract set_last_timestamp(study_key, stream_name, timestamp, records_processed=0, status=StreamExecutionStatus.SUCCESS, error_message=None, metadata=None, force=False)[source]¶
Sets the high-water mark timestamp atomically.
- Parameters:
study_key (str) –
stream_name (str) –
timestamp (datetime | None) –
records_processed (int) –
status (StreamExecutionStatus | str) –
error_message (str | None) –
metadata (dict[str, Any] | None) –
force (bool) –
- Return type:
None
- abstract transaction(study_key, stream_name, fallback_timestamp=None, *, lease_ttl_seconds=None)[source]¶
Context manager for transactional state tracking.
- Parameters:
study_key (str) –
stream_name (str) –
fallback_timestamp (datetime | None) –
lease_ttl_seconds (float | None) –
- Return type:
Generator[dict[str, Any], None, None]
- imednet_workflows.state_ledger.ExtractionStateLedger¶
alias of
FileStateProvider
- class imednet_workflows.state_ledger.FileStateProvider[source]¶
Bases:
BaseStateProviderManages transactional state bookmarks per study using a local JSON file.
- __init__(ledger_path='/home/runner/.imednet/pipeline_ledger.json', *, lease_ttl_seconds=3600.0)[source]¶
Initialize the extraction state ledger.
- Parameters:
ledger_path (str | Path) – Path to the JSON file where state is persisted.
lease_ttl_seconds (float) – Lease duration in seconds for active RUNNING transactions.
- Return type:
None
- batch_transaction(study_key, stream_names, fallback_timestamp=None, *, lease_ttl_seconds=None)[source]¶
Context manager for transactional state tracking across multiple streams in one study.
- Parameters:
study_key (str) –
stream_names (Sequence[str]) –
fallback_timestamp (datetime | None) –
lease_ttl_seconds (float | None) –
- Return type:
Generator[dict[str, dict[str, Any]], None, None]
- delete_entry(study_key, stream_name=None, *, force=False)[source]¶
Deletes a study or specific stream entry from the ledger under the file lock.
Returns
Trueif the entry existed and was removed,Falseotherwise.- Parameters:
study_key (str) –
stream_name (str | None) –
force (bool) –
- Return type:
bool
- get_last_status(study_key, stream_name)[source]¶
Returns the last execution status for a given study and stream.
- Parameters:
study_key (str) –
stream_name (str) –
- Return type:
StreamExecutionStatus | None
- get_last_timestamp(study_key, stream_name)[source]¶
Returns the high-water mark timestamp for a given study and stream.
- Parameters:
study_key (str) –
stream_name (str) –
- Return type:
datetime | None
- get_sdtm_lineage(study_key, stream_name)[source]¶
Return persisted SDTM sidecar lineage and sequence watermarks under file lock.
- Parameters:
study_key (str) –
stream_name (str) –
- Return type:
dict[str, Any]
- record_sdtm_lineage(study_key, stream_name, lineage_updates=None, seq_watermarks=None)[source]¶
Atomically merge SDTM sidecar lineage and monotonic sequence watermarks into the ledger.
- Parameters:
study_key (str) –
stream_name (str) –
lineage_updates (Mapping[str, dict[str, Any] | None] | None) –
seq_watermarks (Mapping[str, int] | None) –
- Return type:
None
- set_last_timestamp(study_key, stream_name, timestamp, records_processed=0, status=StreamExecutionStatus.SUCCESS, error_message=None, metadata=None, force=False)[source]¶
Sets the high-water mark timestamp atomically.
- Parameters:
study_key (str) –
stream_name (str) –
timestamp (datetime | None) –
records_processed (int) –
status (StreamExecutionStatus | str) –
error_message (str | None) –
metadata (dict[str, Any] | None) –
force (bool) –
- Return type:
None
- transaction(study_key, stream_name, fallback_timestamp=None, *, lease_ttl_seconds=None)[source]¶
Context manager for transactional state tracking.
Yields a dict where user can record ‘records_processed’, ‘new_timestamp’, and ‘metadata’. Saves automatically upon exiting the context with no exceptions.
- Parameters:
study_key (str) –
stream_name (str) –
fallback_timestamp (datetime | None) –
lease_ttl_seconds (float | None) –
- Return type:
Generator[dict[str, Any], None, None]
- write_state(state)[source]¶
Writes the ledger state atomically using a temporary file.
- Parameters:
state (LedgerState) –
- Return type:
None
- exception imednet_workflows.state_ledger.InvalidStateTransitionError[source]¶
Bases:
ValueErrorRaised when an invalid stream execution state transition is requested.
- class imednet_workflows.state_ledger.LedgerState[source]¶
Bases:
BaseModelSchema for the entire ledger file containing all studies.
- studies: dict[str, StudyState] = dict()¶
- class imednet_workflows.state_ledger.StreamExecutionStatus[source]¶
Bases:
str,EnumExecution status for workflow stream checkpoints.
- PENDING: str = 'pending'¶
- RUNNING: str = 'running'¶
- SUCCESS: str = 'success'¶
- FAILED: str = 'failed'¶
- class imednet_workflows.state_ledger.StreamState[source]¶
Bases:
BaseModelSchema for individual stream execution checkpoints.
- last_timestamp: datetime | None = None¶
- records_processed: int = 0¶
- last_run_status: StreamExecutionStatus = <StreamExecutionStatus.SUCCESS: 'success'>¶
- error_message: str | None = None¶
- metadata: dict[str, Any] = dict()¶
- owner_pid: int | None = None¶
- owner_host: str | None = None¶
- lease_expires_at: datetime | None = None¶
- lease_id: str | None = None¶
- class imednet_workflows.state_ledger.StudyState[source]¶
Bases:
BaseModelSchema for all streams in a given study context.
- streams: dict[str, StreamState] = dict()¶
- imednet_workflows.state_ledger.get_state_provider(ledger_path='/home/runner/.imednet/pipeline_ledger.json')[source]¶
Factory to get the appropriate state provider based on environment.
- Parameters:
ledger_path (str | Path) –
- Return type:
- imednet_workflows.state_ledger.is_valid_transition(current_status, target_status)[source]¶
Checks whether transitioning from current_status to target_status is permitted.
- Parameters:
current_status (StreamExecutionStatus | str | None) –
target_status (StreamExecutionStatus | str) –
- Return type:
bool
- imednet_workflows.state_ledger.validate_transition(current_status, target_status)[source]¶
Validates and returns target_status if valid, or raises InvalidStateTransitionError.
- Parameters:
current_status (StreamExecutionStatus | str | None) –
target_status (StreamExecutionStatus | str) –
- Return type:
imednet_workflows.study_structure module¶
Workflow for retrieving and aggregating study structural metadata.
- async imednet_workflows.study_structure.async_get_study_structure(sdk, study_key)[source]¶
Canonical asynchronous implementation for retrieving study structural metadata.
- Parameters:
sdk (AsyncImednetFacade) –
study_key (str) –
- Return type:
- imednet_workflows.study_structure.get_study_structure(sdk, study_key)[source]¶
Fetches and aggregates study structure information (intervals, forms, variables).
- Parameters:
sdk (ImednetFacade) – An initialized synchronous ImednetSDK instance.
study_key (str) – The key of the study to fetch structure for.
- Returns:
A StudyStructure object containing nested intervals, forms, and variables.
- Raises:
TypeError – If an asynchronous SDK is passed.
ImednetError – If fetching any part of the structure fails.
- Return type:
imednet_workflows.subject_data module¶
Provides a workflow to retrieve comprehensive data for a specific subject.
- class imednet_workflows.subject_data.AsyncSubjectDataWorkflow[source]¶
Bases:
objectCanonical asynchronous workflow to retrieve comprehensive data for a subject.
- __init__(sdk)[source]¶
Initialize the asynchronous subject data workflow.
- Parameters:
sdk (AsyncImednetFacade) –
- Return type:
None
- class imednet_workflows.subject_data.SubjectComprehensiveData[source]¶
Bases:
ImednetBaseModelStructure to hold aggregated data for a subject.
- class imednet_workflows.subject_data.SubjectDataWorkflow[source]¶
Bases:
objectProvides methods to retrieve comprehensive data related to a specific subject.
- Parameters:
sdk – An instance of the synchronous ImednetFacade.
- __init__(sdk)[source]¶
Initialize the subject data workflow.
- Parameters:
sdk (ImednetFacade) –
- Return type:
None
imednet_workflows.sync_worker module¶
Background worker for maintaining a local record cache via incremental synchronization.
- class imednet_workflows.sync_worker.SyncWorker[source]¶
Bases:
objectBackground cache refresher that runs incremental record sync loops.
- __init__(loader, *, config, stop_event=None, on_error=None, max_consecutive_failures=None)[source]¶
Initialize the sync worker.
- Parameters:
loader (CachedRecordsLoader) – The cached records loader to use for synchronization.
config (SyncWorkerConfig) – Worker configuration including study key and interval.
stop_event (Event | None) – Optional threading event to control worker termination.
on_error (Callable[[Exception, int], None] | Callable[[Exception], None] | None) – Optional callback invoked when a sync cycle raises an exception.
max_consecutive_failures (int | None) – Optional limit overriding
config.max_consecutive_failures.
- Return type:
None
- property consecutive_failures: int¶
Return the number of consecutive failed sync cycles.
- property last_error: Exception | None¶
Return the exception raised by the most recent failed sync cycle, if any.
- property max_consecutive_failures: int | None¶
Return the configured maximum consecutive failures before stopping as FAILED.
- run_forever(on_cycle=None, on_sleep_tick=None, on_error=None)[source]¶
Run sync cycles until stopped or failed.
- Parameters:
on_cycle (Callable[[int, int], None] | None) –
on_sleep_tick (Callable[[int, int], None] | None) –
on_error (Callable[[Exception, int], None] | Callable[[Exception], None] | None) –
- Return type:
None
- run_once()[source]¶
Run one idempotent cache sync cycle, preserving terminal FAILED state.
- Return type:
int
- property state: SyncWorkerState¶
Return the current lifecycle state of the worker.
- class imednet_workflows.sync_worker.SyncWorkerConfig[source]¶
Bases:
objectConfiguration for a synchronization worker.
- study_key: str¶
Required.
- interval_seconds: int = 900¶
- reconcile: bool = True¶
- reconcile_every_n_cycles: int = 1¶
- lock_timeout_seconds: float = 30¶
- max_consecutive_failures: int | None = None¶
imednet_workflows.triage_store module¶
Workflow for managing a triage queue of records using a local SQLite database.
- class imednet_workflows.triage_store.TriageStore[source]¶
Bases:
objectThread-safe SQLite-backed triage queue and decision store.
- __init__(db_path=None, *, base_url=None, sdk=None, timeout=30.0, retry_attempts=3)[source]¶
Initialize the triage store.
- Parameters:
db_path (str | Path | None) – Path to the SQLite database file. Defaults to
IMEDNET_TRIAGE_DB_PATHor~/.imednet/<origin>/triage.sqlite3.base_url (str | None) – Optional EDC origin URL to scope the store directory under.
sdk (Any) – Optional SDK or facade instance supplying origin and governance context.
timeout (float) – Maximum time to wait for a database connection.
retry_attempts (int) – Number of write retry attempts.
- Return type:
None
- add_annotation(item_id, user_id, comment)[source]¶
Add a comment/annotation to a triage item.
- Parameters:
item_id (str) –
user_id (str) –
comment (str) –
- Return type:
None
- assign_item(item_id, assignee)[source]¶
Assign a triage item to a specific user.
- Parameters:
item_id (str) –
assignee (str) –
- Return type:
None
- delete_item(item_id)[source]¶
Delete a triage item and its cascaded annotations and history.
- Parameters:
item_id (str) – Identifier of the triage item to delete.
- Returns:
True if the item existed and was deleted, False otherwise.
- Return type:
bool
- get_item_last_updated(item_id)[source]¶
Get the last updated timestamp for a triage item.
- Parameters:
item_id (str) –
- Return type:
datetime | None
- get_queue(study_key, status=None)[source]¶
Fetch the triage queue for a study, optionally filtered by status.
- Parameters:
study_key (str) –
status (TriageStatus | None) –
- Return type:
list[TriageItem]
- get_status_counts(study_key)[source]¶
Count triage items for a study grouped by
TriageStatus.- Parameters:
study_key (str) –
- Return type:
dict[str, int]
- get_triage_item(item_id)[source]¶
Fetch a single triage item by ID.
- Parameters:
item_id (str) –
- Return type:
TriageItem | None
- update_status(item_id, to_status, user_id, comment)[source]¶
Update the status of a triage item and record the transition in history.
- Parameters:
item_id (str) –
to_status (TriageStatus) –
user_id (str) –
comment (str | None) –
- Return type:
None
- upsert_item(item)[source]¶
Insert or update a triage item while preserving prior annotations and history.
- Parameters:
item (TriageItem) –
- Return type:
None
imednet_workflows.wizard module¶
Interactive console wizard and parameter validator for iMednet workflows.
Provides step-by-step interactive prompts, live parameter validation, and stderr progress reporting to preserve clean stdout stream outputs.
- imednet_workflows.wizard.display_ledger_streams(ledger_path='/home/runner/.imednet/pipeline_ledger.json', study_key=None, *, state_provider=None)[source]¶
Display active ledger streams to stderr for interactive inspection.
- Parameters:
ledger_path (str) – Path to the pipeline ledger JSON file.
study_key (str | None) – Optional study key to filter displayed streams.
state_provider (BaseStateProvider | None) – Optional pre-initialized state provider to reuse.
- Returns:
The loaded
LedgerStatewhen readable, orNoneon error.- Return type:
LedgerState | None
- imednet_workflows.wizard.ensure_interactive_stdin(*, force_non_interactive=False)[source]¶
Ensure interactive stdin prompts are permitted, exiting with code 1 otherwise.
- Parameters:
force_non_interactive (bool) –
- Return type:
None
- imednet_workflows.wizard.print_progress(message)[source]¶
Print a progress or status message to stderr and flush.
This ensures stdout remains clean for structured data piping.
- Parameters:
message (str) –
- Return type:
None
- imednet_workflows.wizard.prompt_confirm(prompt_text, default=False)[source]¶
Prompt the user for a boolean confirmation on stderr.
- Parameters:
prompt_text (str) – Description of the confirmation action.
default (bool) – Default boolean choice if user presses Enter.
- Returns:
True if confirmed, False otherwise.
- Raises:
SystemExit – If stdin is non-interactive or end-of-file (EOF) is encountered.
- Return type:
bool
- imednet_workflows.wizard.prompt_email_notify(prompt_text="Enter email notification ('true', 'false', email address, '-' to clear, or leave blank)", default=None)[source]¶
Prompt for and validate an optional
--email-notifyvalue before Study inspection.- Parameters:
prompt_text (str) –
default (str | bool | None) –
- Return type:
bool | str | None
- imednet_workflows.wizard.prompt_filters(category_name, example, existing_filters=None, *, model=None)[source]¶
Interactively prompt and validate key-value filters for a category.
- Parameters:
category_name (str) – Name of the filter category (e.g., ‘subject filter’).
example (str) – An illustrative example string (e.g., ‘subject_status=Screened’).
existing_filters (list[str] | None) – Filters already supplied on the command line.
model (type[Any] | None) – Optional endpoint resource model class used to validate filter keys.
- Returns:
A list of validated filter strings.
- Return type:
list[str]
- imednet_workflows.wizard.prompt_input(prompt_text, default=None, *, allow_clear=True)[source]¶
Prompt the user for input on stderr and read from stdin.
- Parameters:
prompt_text (str) – Prompt message describing the expected input.
default (str | None) – Optional default value if the user provides an empty line.
allow_clear (bool) – When True, typing
-clears any default and returns"".
- Returns:
The stripped string provided by the user, or the default.
- Raises:
SystemExit – If stdin is non-interactive or end-of-file (EOF) is encountered.
- Return type:
str
- imednet_workflows.wizard.prompt_iso8601_timestamp(prompt_text="Enter ISO-8601 UTC timestamp (e.g., '2026-05-22T12:00:00Z')", default=None)[source]¶
Interactively prompt for and validate an ISO-8601 UTC timestamp until valid.
- Parameters:
prompt_text (str) – Message describing the timestamp prompt.
default (str | None) – Optional default timestamp string.
- Returns:
A tuple of (raw_timestamp_string, parsed_datetime_utc).
- Return type:
tuple[str, datetime]
- imednet_workflows.wizard.prompt_non_negative_int(prompt_text, default=0)[source]¶
Prompt for a non-negative integer with immediate validation.
- Parameters:
prompt_text (str) – Message describing the expected number.
default (int) – Default non-negative integer value.
- Returns:
Validated non-negative integer (>= 0).
- Return type:
int
- imednet_workflows.wizard.prompt_positive_int(prompt_text, default=1)[source]¶
Prompt for a positive integer with immediate validation.
- Parameters:
prompt_text (str) – Message describing the expected number.
default (int) – Default positive integer value.
- Returns:
Validated positive integer (> 0).
- Return type:
int
- imednet_workflows.wizard.prompt_stream_name(stream=None)[source]¶
Ensure a valid non-empty stream name, prompting if needed.
- Parameters:
stream (str | None) – Existing stream name from CLI arguments.
- Returns:
Non-empty stream name string.
- Return type:
str
- imednet_workflows.wizard.prompt_study_key(study_key=None)[source]¶
Ensure a valid non-empty study key, prompting if needed.
- Parameters:
study_key (str | None) – Existing study key from CLI arguments.
- Returns:
Non-empty study key string.
- Return type:
str
- imednet_workflows.wizard.prompt_subject_count(prompt_text='Enter number of test subjects', default=2)[source]¶
Prompt for a UAT subject count bounded within 1..100 before Study inspection.
- Parameters:
prompt_text (str) –
default (int) –
- Return type:
int
- imednet_workflows.wizard.validate_filter_syntax(filter_str, *, model=None)[source]¶
Validate a filter parameter string via the shared SPI parser.
- Parameters:
filter_str (str) – Raw filter string (single clause or compound ‘;’ / ‘,’ clauses).
model (type[Any] | None) – Optional endpoint resource model class used to validate filter keys.
- Returns:
A tuple of (is_valid, key, parsed_value, error_message).
- Return type:
tuple[bool, str | None, Any | None, str | None]
- imednet_workflows.wizard.validate_iso8601_timestamp(ts)[source]¶
Validate that a string is a valid ISO-8601 UTC timestamp.
- Parameters:
ts (str) – Input timestamp string (e.g. ‘2026-05-22T12:00:00Z’).
- Returns:
A tuple of (is_valid, parsed_datetime_utc, error_message).
- Return type:
tuple[bool, datetime | None, str | None]