imednet.datadict package

iMednet Data Dictionary module.

Provides canonical modeling, 4-file CSV loading, live SDK extraction, deterministic JSON emission, structural diffing, and schema validation.

Subpackages

Submodules

imednet.datadict.cdisc_builders module

Builders, PHI redactors, and schema validators for CDISC ODM 1.3.2 and Dataset-JSON v1.1.

imednet.datadict.cdisc_builders.build_datadict_from_sdk_metadata(study_key, *, forms=(), variables=(), intervals=(), study_name=None, study_description=None, protocol_name=None)[source]

Construct a canonical DataDictionary from SDK Form/Variable/Interval objects.

Parameters:
  • study_key (str) –

  • forms (Sequence[Any]) –

  • variables (Sequence[Any]) –

  • intervals (Sequence[Any]) –

  • study_name (str | None) –

  • study_description (str | None) –

  • protocol_name (str | None) –

Return type:

DataDictionary

imednet.datadict.cdisc_builders.build_dataset_json_bundle(study_key, *, records=(), forms=(), variables=(), visits=(), data_dictionary=None, as_sdtm=None, sdtm_domain=None, form_key=None, use_labels_as_columns=False, variable_whitelist=None, form_whitelist=None, naming_convention=None, preserve_record_id=False, include_deleted=False, mask_phi=True, custom_phi_keys=None, enrichment_pipeline=<object object>, metadata_version_oid='MDV.001', file_oid=None, creation_datetime=None, source_system_version=None, seq_counters=None, domain_seq_counters=None, seq_overrides=None, lineage_out=None)[source]

Build a multi-dataset DatasetJsonBundle of flat CDISC Dataset-JSON v1.1 envelopes.

Parameters:
  • study_key (str) –

  • records (Iterable[Any]) –

  • forms (Sequence[Any]) –

  • variables (Sequence[Any]) –

  • visits (Iterable[Any]) –

  • data_dictionary (DataDictionary | None) –

  • as_sdtm (bool | None) –

  • sdtm_domain (str | None) –

  • form_key (str | None) –

  • use_labels_as_columns (bool) –

  • variable_whitelist (Collection[str] | None) –

  • form_whitelist (Collection[int] | None) –

  • naming_convention (str | None) –

  • preserve_record_id (bool) –

  • include_deleted (bool) –

  • mask_phi (bool) –

  • custom_phi_keys (Collection[str] | None) –

  • enrichment_pipeline (Any) –

  • metadata_version_oid (str) –

  • file_oid (str | None) –

  • creation_datetime (str | None) –

  • source_system_version (str | None) –

  • seq_counters (dict[str, int] | None) –

  • domain_seq_counters (dict[str, dict[str, int]] | None) –

  • seq_overrides (Mapping[str, int] | None) –

  • lineage_out (dict[str, dict[str, Any]] | None) –

Return type:

DatasetJsonBundle

imednet.datadict.cdisc_builders.build_dataset_json_envelope(study_key, *, records=(), forms=(), variables=(), visits=(), data_dictionary=None, as_sdtm=None, sdtm_domain=None, form_key=None, use_labels_as_columns=False, variable_whitelist=None, form_whitelist=None, naming_convention=None, preserve_record_id=False, include_deleted=False, mask_phi=True, custom_phi_keys=None, enrichment_pipeline=<object object>, metadata_version_oid='MDV.001', file_oid=None, creation_datetime=None, source_system_version=None, seq_counters=None, domain_seq_counters=None, seq_overrides=None, lineage_out=None)[source]

Build a flat CDISC Dataset-JSON v1.1 single-dataset envelope.

Parameters:
  • study_key (str) –

  • records (Iterable[Any]) –

  • forms (Sequence[Any]) –

  • variables (Sequence[Any]) –

  • visits (Iterable[Any]) –

  • data_dictionary (DataDictionary | None) –

  • as_sdtm (bool | None) –

  • sdtm_domain (str | None) –

  • form_key (str | None) –

  • use_labels_as_columns (bool) –

  • variable_whitelist (Collection[str] | None) –

  • form_whitelist (Collection[int] | None) –

  • naming_convention (str | None) –

  • preserve_record_id (bool) –

  • include_deleted (bool) –

  • mask_phi (bool) –

  • custom_phi_keys (Collection[str] | None) –

  • enrichment_pipeline (Any) –

  • metadata_version_oid (str) –

  • file_oid (str | None) –

  • creation_datetime (str | None) –

  • source_system_version (str | None) –

  • seq_counters (dict[str, int] | None) –

  • domain_seq_counters (dict[str, dict[str, int]] | None) –

  • seq_overrides (Mapping[str, int] | None) –

  • lineage_out (dict[str, dict[str, Any]] | None) –

Return type:

DatasetJsonEnvelope

imednet.datadict.cdisc_builders.build_odm_archive(study_key, *, study=None, data_dictionary=None, forms=(), variables=(), intervals=(), subjects=(), visits=(), records=(), revisions=(), queries=(), sites=(), users=(), reference_data=(), metadata_version_oid='MDV.001', metadata_version_name=None, file_oid=None, file_type='Snapshot', creation_datetime=None, mask_phi=True, custom_phi_keys=None, enrichment_pipeline=None, include_deleted=False)[source]

Build a complete, deterministic CDISC ODM 1.3.2 OdmArchive snapshot.

Parameters:
  • study_key (str) –

  • study (Any) –

  • data_dictionary (DataDictionary | None) –

  • forms (Sequence[Any]) –

  • variables (Sequence[Any]) –

  • intervals (Sequence[Any]) –

  • subjects (Iterable[Any]) –

  • visits (Iterable[Any]) –

  • records (Iterable[Any]) –

  • revisions (Iterable[Any]) –

  • queries (Iterable[Any]) –

  • sites (Iterable[Any]) –

  • users (Iterable[Any]) –

  • reference_data (Sequence[OdmReferenceData]) –

  • metadata_version_oid (str) –

  • metadata_version_name (str | None) –

  • file_oid (str | None) –

  • file_type (Literal['Snapshot', 'Transactional']) –

  • creation_datetime (str | None) –

  • mask_phi (bool) –

  • custom_phi_keys (Collection[str] | None) –

  • enrichment_pipeline (Any) –

  • include_deleted (bool) –

Return type:

OdmArchive

imednet.datadict.cdisc_builders.get_dataset_json_schema()[source]

Load the bundled official CDISC Dataset-JSON v1.1 JSON Schema.

Return type:

dict[str, Any]

imednet.datadict.cdisc_builders.load_dataset_json(source)[source]

Load and validate a CDISC Dataset-JSON v1.1 envelope from JSON text, path, or dict.

Parameters:

source (str | Path | Mapping[str, Any]) –

Return type:

DatasetJsonEnvelope

imednet.datadict.cdisc_builders.make_location_oid(site_token)[source]

Return a deterministic ODM LocationOID for site_token.

Parameters:

site_token (Any) –

Return type:

str

imednet.datadict.cdisc_builders.make_oid_slug(raw, fallback='UNKNOWN')[source]

Normalize an arbitrary token into a deterministic CDISC OID segment.

Parameters:
  • raw (Any) –

  • fallback (str) –

Return type:

str

imednet.datadict.cdisc_builders.make_study_event_oid(visit_token)[source]

Return a deterministic ODM StudyEventOID for visit_token.

Parameters:

visit_token (Any) –

Return type:

str

imednet.datadict.cdisc_builders.make_user_oid(user_token)[source]

Return a deterministic ODM UserOID for user_token.

Parameters:

user_token (Any) –

Return type:

str

imednet.datadict.cdisc_builders.make_xml_ncname(prefix, *parts, used_ids=None)[source]

Construct a valid XML xs:ID NCName token starting with an ASCII letter.

Parameters:
  • prefix (str) –

  • parts (Any) –

  • used_ids (set[str] | None) –

Return type:

str

imednet.datadict.cdisc_builders.map_queries_to_annotations(queries, *, mask_phi=True, custom_phi_keys=None, used_xml_ids=None)[source]

Map iMednet Query and QueryComment histories into ODM <Annotation> objects.

Returns (by_record_and_var, by_record_only, by_subject_only, unattached_annotations).

Parameters:
  • queries (Iterable[Any]) –

  • mask_phi (bool) –

  • custom_phi_keys (Collection[str] | None) –

  • used_xml_ids (set[str] | None) –

Return type:

tuple[dict[tuple[int, str], list[OdmAnnotation]], dict[int, list[OdmAnnotation]], dict[str, list[OdmAnnotation]], list[OdmAnnotation]]

imednet.datadict.cdisc_builders.map_revisions_to_audit_records(revisions, *, default_location_oid=None, site_oid_by_record_id=None, mask_phi=True, custom_phi_keys=None, used_xml_ids=None)[source]

Map iMednet RecordRevision items into ODM <AuditRecord> objects.

Returns (by_record_id, all_ordered_audit_records).

Parameters:
  • revisions (Iterable[Any]) –

  • default_location_oid (str | None) –

  • site_oid_by_record_id (Mapping[int, str] | None) –

  • mask_phi (bool) –

  • custom_phi_keys (Collection[str] | None) –

  • used_xml_ids (set[str] | None) –

Return type:

tuple[dict[int, list[OdmAuditRecord]], list[OdmAuditRecord]]

imednet.datadict.cdisc_builders.map_sites_and_users_to_admin_data(study_key, *, sites=(), users=(), inferred_site_tokens=(), inferred_user_tokens=(), metadata_version_oid='MDV.001', effective_date='1970-01-01', mask_phi=True, custom_phi_keys=None)[source]

Map iMednet Site and User metadata into a deterministic OdmAdminData model.

Parameters:
  • study_key (str) –

  • sites (Iterable[Any]) –

  • users (Iterable[Any]) –

  • inferred_site_tokens (Iterable[tuple[Any, str | None]]) –

  • inferred_user_tokens (Iterable[Any]) –

  • metadata_version_oid (str) –

  • effective_date (str) –

  • mask_phi (bool) –

  • custom_phi_keys (Collection[str] | None) –

Return type:

OdmAdminData

imednet.datadict.cdisc_builders.normalize_odm_datetime(value, *, fallback='1970-01-01T00:00:00Z', strict=False)[source]

Format temporal scalars or EDC date strings into deterministic UTC ISO-8601 timestamps.

Parameters:
  • value (Any) –

  • fallback (str) –

  • strict (bool) –

Return type:

str

imednet.datadict.cdisc_builders.to_dataset_json(envelope, *, indent=2)[source]

Serialize a validated DatasetJsonEnvelope to deterministic UTF-8 JSON text.

Parameters:
Return type:

str

imednet.datadict.cdisc_builders.to_dataset_json_file(envelope, file_path, *, indent=2)[source]

Write a DatasetJsonEnvelope deterministically to file_path.

Parameters:
Return type:

None

imednet.datadict.cdisc_builders.validate_dataset_json(target)[source]

Validate a flat CDISC Dataset-JSON v1.1 document against JSON Schema and tuple invariants.

Parameters:

target (DatasetJsonEnvelope | Mapping[str, Any] | str | Path) –

Return type:

list[str]

imednet.datadict.cdisc_builders.validate_odm_xml(source)[source]

Validate an ODM 1.3.2 XML document safely using defusedxml and cdisc-odm-1.3.2.xsd.

Parameters:

source (str | bytes | Path) –

Return type:

list[str]

imednet.datadict.diff module

Structural comparison and diffing for DataDictionary instances.

class imednet.datadict.diff.DiffItem[source]

Bases: object

A single change item.

action: str

Required.

path: str

Required.

old_value: Any = None
new_value: Any = None
to_dict()[source]

Convert diff item to dict.

Return type:

dict[str, Any]

class imednet.datadict.diff.DiffReport[source]

Bases: object

Structural diff report between two DataDictionary models.

items: list[DiffItem] = list()
add(action, path, old_val=None, new_val=None)[source]

Add a diff item.

Parameters:
  • action (str) –

  • path (str) –

  • old_val (Any) –

  • new_val (Any) –

Return type:

None

property has_changes: bool

Return True if any changes exist between the two dictionaries.

to_dict()[source]

Convert report to a dictionary.

Return type:

dict[str, Any]

to_json(*, indent=2)[source]

Convert report to formatted JSON.

Parameters:

indent (int) –

Return type:

str

to_markdown()[source]

Convert report to Markdown.

Return type:

str

to_text()[source]

Convert report to human-readable text.

Return type:

str

imednet.datadict.diff.diff(old_dict, new_dict)[source]

Compute structural differences between two DataDictionary instances.

Parameters:
Returns:

DiffReport summarizing additions, removals, and modifications.

Return type:

DiffReport

imednet.datadict.emit module

Canonical JSON and CDISC ODM XML emission for iMednet Data Dictionary.

imednet.datadict.emit.sort_data_dictionary(datadict)[source]

Return a deep copy of DataDictionary with deterministic ordering.

Ordering guarantees: - Forms sorted by formKey. - Variables on each form sorted by sequence, then variableName. - Choices on each variable sorted by position, then choiceValue. - Business logic rules sorted by sequence, then id.

Parameters:

datadict (DataDictionary) –

Return type:

DataDictionary

imednet.datadict.emit.to_file(datadict, file_path, *, indent=2, exclude_generated_at=False)[source]

Write canonical DataDictionary JSON to a UTF-8 encoded file.

Parameters:
  • datadict (DataDictionary) – DataDictionary instance.

  • file_path (Path | str) – Destination file path.

  • indent (int) – Indentation level.

  • exclude_generated_at (bool) – If True, omit metadata.generatedAt.

Return type:

None

imednet.datadict.emit.to_json(datadict, *, indent=2, exclude_generated_at=False)[source]

Serialize DataDictionary to canonical, deterministic JSON.

Parameters:
  • datadict (DataDictionary) – DataDictionary instance.

  • indent (int) – Indentation level (default: 2 spaces).

  • exclude_generated_at (bool) – If True, omit metadata.generatedAt for deterministic diffs/tests.

Returns:

Canonical JSON string encoded with UTF-8 representation.

Return type:

str

imednet.datadict.emit.to_odm_file(datadict, file_path, *, file_oid=None, creation_datetime=None, meta_data_version_oid='MDV.001', meta_data_version_name=None, indent='  ', odm_version=None, file_type=None, originator=None, source_system=None, source_system_version=None, admin_data=(), reference_data=(), clinical_data=(), mask_phi=True, custom_phi_keys=None, validate_xsd=True)[source]

Write CDISC ODM 1.3 / 1.3.2 XML content to a UTF-8 encoded file.

Parameters:
  • datadict (DataDictionary | OdmArchive) –

  • file_path (Path | str) –

  • file_oid (str | None) –

  • creation_datetime (str | None) –

  • meta_data_version_oid (str) –

  • meta_data_version_name (str | None) –

  • indent (str) –

  • odm_version (str | None) –

  • file_type (str | None) –

  • originator (str | None) –

  • source_system (str | None) –

  • source_system_version (str | None) –

  • admin_data (Sequence[OdmAdminData]) –

  • reference_data (Sequence[OdmReferenceData]) –

  • clinical_data (Sequence[OdmClinicalData]) –

  • mask_phi (bool) –

  • custom_phi_keys (Collection[str] | None) –

  • validate_xsd (bool) –

Return type:

None

imednet.datadict.emit.to_odm_xml(datadict, *, file_oid=None, creation_datetime=None, meta_data_version_oid='MDV.001', meta_data_version_name=None, indent='  ', odm_version=None, file_type=None, originator=None, source_system=None, source_system_version=None, admin_data=(), reference_data=(), clinical_data=(), mask_phi=True, custom_phi_keys=None, validate_xsd=True)[source]

Serialize DataDictionary or OdmArchive to CDISC ODM 1.3 / 1.3.2 XML format.

This function does not mutate the input DataDictionary or OdmArchive instance.

Parameters:
  • datadict (DataDictionary | OdmArchive) –

  • file_oid (str | None) –

  • creation_datetime (str | None) –

  • meta_data_version_oid (str) –

  • meta_data_version_name (str | None) –

  • indent (str) –

  • odm_version (str | None) –

  • file_type (str | None) –

  • originator (str | None) –

  • source_system (str | None) –

  • source_system_version (str | None) –

  • admin_data (Sequence[OdmAdminData]) –

  • reference_data (Sequence[OdmReferenceData]) –

  • clinical_data (Sequence[OdmClinicalData]) –

  • mask_phi (bool) –

  • custom_phi_keys (Collection[str] | None) –

  • validate_xsd (bool) –

Return type:

str

imednet.datadict.emit.write_odm_xml_stream(datadict, target, *, file_oid=None, creation_datetime=None, meta_data_version_oid='MDV.001', meta_data_version_name=None, indent='  ', odm_version=None, file_type=None, originator=None, source_system=None, source_system_version=None, admin_data=(), reference_data=(), clinical_data=(), subject_stream=None, mask_phi=True, custom_phi_keys=None, validate_xsd=True)[source]

Stream CDISC ODM XML (1.3 or 1.3.2) incrementally without materializing all SubjectData.

Parameters:
  • datadict (DataDictionary | OdmArchive) –

  • target (TextIO | BinaryIO | Path | str) –

  • file_oid (str | None) –

  • creation_datetime (str | None) –

  • meta_data_version_oid (str) –

  • meta_data_version_name (str | None) –

  • indent (str) –

  • odm_version (str | None) –

  • file_type (str | None) –

  • originator (str | None) –

  • source_system (str | None) –

  • source_system_version (str | None) –

  • admin_data (Sequence[OdmAdminData]) –

  • reference_data (Sequence[OdmReferenceData]) –

  • clinical_data (Sequence[OdmClinicalData]) –

  • subject_stream (Iterable[OdmSubjectData] | None) –

  • mask_phi (bool) –

  • custom_phi_keys (Collection[str] | None) –

  • validate_xsd (bool) –

Return type:

None

imednet.datadict.exchange module

Canonical read-only exchange models for CDISC ODM 1.3.2 and Dataset-JSON v1.1.

class imednet.datadict.exchange.DatasetJsonBundle[source]

Bases: object

Typed multi-dataset Python bundle mapping itemGroupOID keys to v1.1 envelopes.

study_oid: str

Required. API field studyOID.

metadata_version_oid: str = 'MDV.001'

API field metaDataVersionOID.

dataset_json_creation_datetime: str

Required. API field datasetJSONCreationDateTime.

datasets: dict[str, DatasetJsonEnvelope] = dict()
get(key, default=None)[source]

Return dataset envelope for key if present, else default.

Parameters:
Return type:

DatasetJsonEnvelope | None

items()[source]

Return view of (itemGroupOID, DatasetJsonEnvelope) pairs.

Return type:

ItemsView[str, DatasetJsonEnvelope]

keys()[source]

Return view of itemGroupOID keys.

Return type:

KeysView[str]

values()[source]

Return view of DatasetJsonEnvelope values.

Return type:

ValuesView[DatasetJsonEnvelope]

class imednet.datadict.exchange.DatasetJsonColumn[source]

Bases: object

CDISC Dataset-JSON v1.1 column definition inside top-level columns.

item_oid: str

Required. API field itemOID.

name: str

Required.

label: str

Required.

data_type: Literal['string', 'integer', 'float', 'double', 'decimal', 'boolean', 'date', 'time', 'datetime', 'URI']

Required. API field dataType.

target_data_type: Literal['integer', 'decimal'] | None = None

API field targetDataType.

length: int | None = None
display_format: str | None = None

API field displayFormat.

key_sequence: int | None = None

API field keySequence.

property oid: str

Return item_oid for ergonomic Python inspection.

property type: Literal['string', 'integer', 'float', 'double', 'decimal', 'boolean', 'date', 'time', 'datetime', 'URI']

Return data_type for ergonomic Python inspection.

class imednet.datadict.exchange.DatasetJsonEnvelope[source]

Bases: object

Canonical read-only flat CDISC Dataset-JSON v1.1 single-dataset envelope.

dataset_json_creation_datetime: str

Required. API field datasetJSONCreationDateTime.

dataset_json_version: Literal['1.1.0'] = '1.1.0'

API field datasetJSONVersion.

file_oid: str | None = None

API field fileOID.

db_last_modified_datetime: str | None = None

API field dbLastModifiedDateTime.

originator: str | None = None
source_system: DatasetJsonSourceSystem | None = None

API field sourceSystem.

study_oid: str | None = None

API field studyOID.

metadata_version_oid: str | None = None

API field metaDataVersionOID.

metadata_ref: str | None = None

API field metaDataRef.

item_group_oid: str

Required. API field itemGroupOID.

is_reference_data: bool | None = None

API field isReferenceData.

records: int

Required.

name: str

Required.

label: str

Required.

columns: tuple[DatasetJsonColumn, ...] = ()
rows: tuple[tuple[str | int | float | bool | None, ...], ...] = ()
to_json_dict()[source]

Serialize to a clean CDISC Dataset-JSON v1.1 dictionary omitting null optional keys.

Return type:

dict[str, Any]

imednet.datadict.exchange.DatasetJsonItem

alias of DatasetJsonColumn

class imednet.datadict.exchange.DatasetJsonSourceSystem[source]

Bases: object

CDISC Dataset-JSON v1.1 sourceSystem metadata descriptor.

name: str

Required.

version: str

Required.

class imednet.datadict.exchange.OdmAdminData[source]

Bases: object

CDISC ODM 1.3.2 <AdminData> container for study users and locations.

study_oid: str | None = None

API field studyOID.

users: tuple[OdmUser, ...] = ()
locations: tuple[OdmLocation, ...] = ()
extra_attributes: dict[str, Any] = dict()

API field extraAttributes.

class imednet.datadict.exchange.OdmAnnotation[source]

Bases: object

CDISC ODM 1.3.2 <Annotation> element for EDC queries and query comments.

seq_num: int

Required. API field seqNum.

id: str | None = None
transaction_type: str | None = None

API field transactionType.

comment: str | None = None
sponsor_or_site: str | None = None

API field sponsorOrSite.

flags: tuple[OdmFlag, ...] = ()
class imednet.datadict.exchange.OdmArchive[source]

Bases: object

Canonical read-only CDISC ODM 1.3.2 archive snapshot extending DataDictionary.

file_oid: str = 'IMEDNET_ODM_EXPORT'

API field fileOID.

file_type: Literal['Snapshot', 'Transactional'] = 'Snapshot'

API field fileType.

odm_version: str = '1.3.2'

API field odmVersion.

creation_datetime: str | None = None

API field creationDateTime.

as_of_datetime: str | None = None

API field asOfDateTime.

originator: str | None = None
source_system: str | None = None

API field sourceSystem.

source_system_version: str | None = None

API field sourceSystemVersion.

description: str | None = None
metadata_version_oid: str = 'MDV.001'

API field metaDataVersionOID.

metadata_version_name: str | None = None

API field metaDataVersionName.

data_dictionary: DataDictionary

Required. API field dataDictionary.

admin_data: tuple[OdmAdminData, ...] = ()

API field adminData.

reference_data: tuple[OdmReferenceData, ...] = ()

API field referenceData.

clinical_data: tuple[OdmClinicalData, ...] = ()

API field clinicalData.

validation_warnings: tuple[str, ...] = ()

API field validationWarnings.

class imednet.datadict.exchange.OdmAuditRecord[source]

Bases: object

CDISC ODM 1.3.2 <AuditRecord> element for 21 CFR Part 11 revision trails.

id: str | None = None
edit_point: str | None = None

API field editPoint.

used_imputation_method: str | None = None

API field usedImputationMethod.

user_oid: str

Required. API field userOID.

location_oid: str

Required. API field locationOID.

datetime_stamp: str

Required. API field dateTimeStamp.

reason_for_change: str | None = None

API field reasonForChange.

source_id: str | None = None

API field sourceID.

class imednet.datadict.exchange.OdmClinicalData[source]

Bases: object

CDISC ODM 1.3.2 <ClinicalData> container for clinical, audit, and query records.

study_oid: str

Required. API field studyOID.

metadata_version_oid: str

Required. API field metaDataVersionOID.

subjects: tuple[OdmSubjectData, ...] = ()
audit_records: tuple[OdmAuditRecord, ...] = ()

API field auditRecords.

annotations: tuple[OdmAnnotation, ...] = ()
class imednet.datadict.exchange.OdmFlag[source]

Bases: object

CDISC ODM 1.3.2 <Flag> child of <Annotation>.

flag_value: str

Required. API field flagValue.

flag_value_codelist_oid: str = 'CL.IMEDNET_FLAG_VALUE'

API field flagValueCodeListOID.

flag_type: str | None = None

API field flagType.

flag_type_codelist_oid: str | None = None

API field flagTypeCodeListOID.

class imednet.datadict.exchange.OdmFormData[source]

Bases: object

CDISC ODM 1.3.2 <FormData> container.

form_oid: str

Required. API field formOID.

form_repeat_key: str | None = None

API field formRepeatKey.

transaction_type: str | None = None

API field transactionType.

audit_record: OdmAuditRecord | None = None

API field auditRecord.

annotations: tuple[OdmAnnotation, ...] = ()
item_groups: tuple[OdmItemGroupData, ...] = ()

API field itemGroups.

property item_group_data: tuple[imednet.datadict.exchange.OdmItemGroupData, ...]

Alias for item_groups matching ODM ItemGroupData terminology.

class imednet.datadict.exchange.OdmItemData[source]

Bases: object

CDISC ODM 1.3.2 <ItemData> value cell.

item_oid: str

Required. API field itemOID.

value: str | None = None
is_null: bool = False

API field isNull.

transaction_type: str | None = None

API field transactionType.

audit_record_id: str | None = None

API field auditRecordID.

annotation_id: str | None = None

API field annotationID.

measurement_unit_oid: str | None = None

API field measurementUnitOID.

audit_record: OdmAuditRecord | None = None

API field auditRecord.

annotations: tuple[OdmAnnotation, ...] = ()
class imednet.datadict.exchange.OdmItemGroupData[source]

Bases: object

CDISC ODM 1.3.2 <ItemGroupData> record container.

item_group_oid: str

Required. API field itemGroupOID.

item_group_repeat_key: str | None = None

API field itemGroupRepeatKey.

transaction_type: str | None = None

API field transactionType.

audit_record: OdmAuditRecord | None = None

API field auditRecord.

annotations: tuple[OdmAnnotation, ...] = ()
items: tuple[OdmItemData, ...] = ()
property audit_records: tuple[imednet.datadict.exchange.OdmAuditRecord, ...]

Return inline AuditRecord as a read-only tuple.

class imednet.datadict.exchange.OdmLocation[source]

Bases: object

CDISC ODM 1.3.2 <Location> site/institution definition.

oid: str

Required.

name: str

Required.

location_type: str = 'Site'

API field locationType.

metadata_version_refs: tuple[OdmMetaDataVersionRef, ...] = ()

API field metaDataVersionRefs.

extra_attributes: dict[str, Any] = dict()

API field extraAttributes.

class imednet.datadict.exchange.OdmMetaDataVersionRef[source]

Bases: object

CDISC ODM 1.3.2 <MetaDataVersionRef> child of <Location>.

study_oid: str

Required. API field studyOID.

metadata_version_oid: str

Required. API field metaDataVersionOID.

effective_date: str = '1970-01-01'

API field effectiveDate.

class imednet.datadict.exchange.OdmReferenceData[source]

Bases: object

CDISC ODM 1.3.2 <ReferenceData> container for non-subject reference tables.

study_oid: str

Required. API field studyOID.

metadata_version_oid: str

Required. API field metaDataVersionOID.

item_groups: tuple[OdmItemGroupData, ...] = ()

API field itemGroups.

property item_group_data: tuple[imednet.datadict.exchange.OdmItemGroupData, ...]

Alias for item_groups matching ODM ItemGroupData terminology.

class imednet.datadict.exchange.OdmStudyEventData[source]

Bases: object

CDISC ODM 1.3.2 <StudyEventData> scheduled or unscheduled visit container.

study_event_oid: str

Required. API field studyEventOID.

study_event_repeat_key: str | None = None

API field studyEventRepeatKey.

transaction_type: str | None = None

API field transactionType.

audit_record: OdmAuditRecord | None = None

API field auditRecord.

annotations: tuple[OdmAnnotation, ...] = ()
forms: tuple[OdmFormData, ...] = ()
class imednet.datadict.exchange.OdmSubjectData[source]

Bases: object

CDISC ODM 1.3.2 <SubjectData> subject clinical hierarchy.

subject_key: str

Required. API field subjectKey.

transaction_type: str | None = None

API field transactionType.

investigator_user_oid: str | None = None

API field investigatorUserOID.

site_location_oid: str | None = None

API field siteLocationOID.

audit_record: OdmAuditRecord | None = None

API field auditRecord.

annotations: tuple[OdmAnnotation, ...] = ()
study_events: tuple[OdmStudyEventData, ...] = ()

API field studyEvents.

forms: tuple[OdmFormData, ...] = ()
class imednet.datadict.exchange.OdmUser[source]

Bases: object

CDISC ODM 1.3.2 <User> administrative definition.

oid: str

Required.

user_type: str | None = None

API field userType.

login_name: str | None = None

API field loginName.

display_name: str | None = None

API field displayName.

full_name: str | None = None

API field fullName.

first_name: str | None = None

API field firstName.

last_name: str | None = None

API field lastName.

organization: str | None = None
email: str | None = None
phone: str | None = None
location_refs: tuple[str, ...] = ()

API field locationRefs.

extra_attributes: dict[str, Any] = dict()

API field extraAttributes.

imednet.datadict.logic module

Business logic XML parsing and AST evaluation for iMednet data dictionary.

class imednet.datadict.logic.ExtractedCondition[source]

Bases: object

Flattened representation of a single XML condition leaf.

variable: str

Required.

operator: str = '=='
value: Any = ''
expected_truth: bool = True
form: str | None = None
compare_variable: str | None = None
class imednet.datadict.logic.ExtractedRuleMetadata[source]

Bases: object

Structured metadata extracted from a BusinessLogicRule AST.

rule_id: str | int | None

Required.

rule_name: str

Required.

form: str | None

Required.

rule_type: str | None

Required.

severity: Literal['error', 'warning', 'none']

Required.

logical_operator: Literal['AND', 'OR']

Required.

conditions: list[ExtractedCondition] = list()
message: str | None = None
is_cross_scope: bool = False
is_ui_only: bool = False
class imednet.datadict.logic.LogicEvaluationReport[source]

Bases: object

Aggregated results of evaluating multiple BusinessLogicRules.

results: list[RuleEvaluationResult] = list()
property errors: list[imednet.datadict.logic.RuleEvaluationResult]

Blocking rule violations (e.g. Form or Required edit checks).

property has_errors: bool

Return True when one or more blocking rules triggered.

property skipped: list[imednet.datadict.logic.RuleEvaluationResult]

Rules skipped due to inactive status, missing logic, UI actions, or cross-scope refs.

property warnings: list[imednet.datadict.logic.RuleEvaluationResult]

Non-blocking rule triggers (e.g. Query or Auto Query rules).

class imednet.datadict.logic.LogicTreeEvaluator[source]

Bases: object

Deterministic, non-eval evaluator for parsed BusinessLogicRule XML ASTs.

evaluate_rule(rule, data, *, form_key=None)[source]

Evaluate a single BusinessLogicRule or dict against data.

Parameters:
  • rule (Any) –

  • data (Mapping[str, Any]) –

  • form_key (str | None) –

Return type:

RuleEvaluationResult

evaluate_rules(rules, data, *, form_key=None)[source]

Evaluate a sequence of BusinessLogicRule instances or dicts against data.

Parameters:
  • rules (Iterable[Any]) –

  • data (Mapping[str, Any]) –

  • form_key (str | None) –

Return type:

LogicEvaluationReport

evaluate_tree(logic_tree, data, *, form_key=None, rule_type=None)[source]

Evaluate an unwrapped logic AST against data.

Returns:

(triggered, is_cross_scope, skip_reason)

Parameters:
  • logic_tree (Mapping[str, Any]) –

  • data (Mapping[str, Any]) –

  • form_key (str | None) –

  • rule_type (str | None) –

Return type:

tuple[bool, bool, str | None]

extract_rule_metadata(rule, *, default_form=None)[source]

Extract structured condition and target metadata from an XML BusinessLogicRule.

Parameters:
  • rule (Any) –

  • default_form (str | None) –

Return type:

ExtractedRuleMetadata | None

validate_rule_regex_patterns(rule)[source]

Return validation error descriptions for invalid or unsafe static regex conditions.

Parameters:

rule (Any) –

Return type:

list[str]

class imednet.datadict.logic.RangeCheckConstraint[source]

Bases: object

Normalized CDISC ODM RangeCheck comparator, check values, and SoftHard severity.

comparator: Literal['LT', 'LE', 'GT', 'GE', 'EQ', 'NE', 'IN', 'NOTIN']

Required.

check_values: tuple[str, ...]

Required.

soft_hard: Literal['Soft', 'Hard'] = 'Hard'
error_message: str | None = None
class imednet.datadict.logic.RuleEvaluationResult[source]

Bases: object

Outcome of evaluating a single BusinessLogicRule against a Record.

rule_id: str | int | None

Required.

rule_name: str

Required.

rule_type: str | None

Required.

severity: Literal['error', 'warning', 'none']

Required.

triggered: bool

Required.

message: str

Required.

skipped: bool = False
skip_reason: str | None = None
is_cross_scope: bool = False
class imednet.datadict.logic.VariableConstraints[source]

Bases: object

Normalized validation constraints extracted from a DataDictionary Variable.

choices: list[str] = list()
required_policy: Literal['yes', 'auto_query', 'no'] = 'no'
min_value: float | None = None
max_value: float | None = None
min_length: int | None = None
max_length: int | None = None
range_checks: tuple[RangeCheckConstraint, ...] = ()
imednet.datadict.logic.extract_variable_constraints(var)[source]

Extract choices, required policy, numeric bounds, and string lengths from a Variable.

Parameters:

var (Any) –

Return type:

VariableConstraints

imednet.datadict.logic.parse_logic_xml(xml_content)[source]

Parse BusinessLogic XML into a structured AST dictionary.

Parameters:

xml_content (str | None) – Verbatim XML string, or None.

Returns:

Structured dictionary representation of the rule logic, or None if input is empty.

Raises:

ValueError – If XML parsing fails due to invalid syntax.

Return type:

dict[str, Any] | None

imednet.datadict.logic.validate_regex_pattern(pattern)[source]

Validate that pattern is syntactically valid and safe against ReDoS.

Parameters:

pattern (str) – Regular expression string to inspect.

Raises:

ValueError – If pattern exceeds length limits, fails syntax parsing, or contains backtracking-prone constructs.

Return type:

None

imednet.datadict.models module

Canonical Pydantic v2 data models for iMednet Data Dictionary.

class imednet.datadict.models.BusinessLogicRule[source]

Bases: DictCompatMixin, BaseModel

An edit check, workflow trigger, or business logic rule.

id: str | int | None = None

Unique rule identifier

name: str | None = None

Descriptive name of the rule

type: str | None = None

Rule category: Form, Workflow, Query, Approval, Required

status: str | None = None

Rule status (Active, Inactive)

form: str | None = None

Form key if rule is form-scoped or attached

sequence: int | None = None

Execution sequence

logic: dict[str, Any] | None = None

Structured parsed AST of the business logic

logicRawXml: str | None = None

Verbatim XML string (optional, omitted with –no-raw-xml)

extraAttributes: dict[str, Any] = dict()

Additional rule properties or unknown columns

get(key, default=None)

Return value for key or default if absent.

Parameters:
  • key (str) –

  • default (Any) –

Return type:

Any

items()

Return list of (key, value) pairs.

Return type:

list[tuple[str, Any]]

keys()

Return list of accessible keys.

Return type:

list[str]

class imednet.datadict.models.Choice[source]

Bases: DictCompatMixin, BaseModel

A choice option for single-select or multi-select variables.

choiceText: str

Required. Display text of the choice

choiceValue: str

Required. Coded value of the choice

position: int | None = None

Display order sequence

extraAttributes: dict[str, Any] = dict()

Unknown columns for this choice

get(key, default=None)

Return value for key or default if absent.

Parameters:
  • key (str) –

  • default (Any) –

Return type:

Any

items()

Return list of (key, value) pairs.

Return type:

list[tuple[str, Any]]

keys()

Return list of accessible keys.

Return type:

list[str]

class imednet.datadict.models.DataDictionary[source]

Bases: DictCompatMixin, BaseModel

Canonical root data dictionary container.

metadata: Metadata = Metadata()
forms: list[Form] = list()
unassignedBusinessLogic: list[BusinessLogicRule] = list()

Business logic not tied to a single form (Workflow, Query, Approval, Required)

property business_logic: list[Any]

Backward-compatible access to all business logic rules.

property choices: list[imednet.datadict.models.Choice]

Backward-compatible access to all choices.

form_for_key(form_key)[source]

Return the Form model matching form_key, or None if absent.

Parameters:

form_key (str) –

Return type:

Form | None

form_key_from_id(form_id)[source]

Resolve a formKey from a numeric or string formId.

Parameters:

form_id (int | str) –

Return type:

str | None

get(key, default=None)

Return value for key or default if absent.

Parameters:
  • key (str) –

  • default (Any) –

Return type:

Any

items()

Return list of (key, value) pairs.

Return type:

list[tuple[str, Any]]

keys()

Return list of accessible keys.

Return type:

list[str]

property questions: list[imednet.datadict.models.Variable]

Backward-compatible access to all variables as questions.

rules_for_form(form_key)[source]

Return all business logic rules scoped or attached to form_key.

Parameters:

form_key (str) –

Return type:

list[BusinessLogicRule]

variables_for_form(form_key)[source]

Return a mapping of variable names to Variable definitions for form_key.

Parameters:

form_key (str) –

Return type:

dict[str, Variable]

class imednet.datadict.models.DictCompatMixin[source]

Bases: object

Provides dictionary-like interface for legacy callers.

get(key, default=None)[source]

Return value for key or default if absent.

Parameters:
  • key (str) –

  • default (Any) –

Return type:

Any

items()[source]

Return list of (key, value) pairs.

Return type:

list[tuple[str, Any]]

keys()[source]

Return list of accessible keys.

Return type:

list[str]

class imednet.datadict.models.Form[source]

Bases: DictCompatMixin, BaseModel

A form defining data fields and rules for clinical data entry.

formKey: str

Required. Unique short code/mnemonic for the form

formName: str | None = None

Human-readable form title

formId: str | int | None = None

Unique form identifier

formType: str | None = None

Type of form (Subject, Study, Admin, etc.)

variables: list[Variable] = list()

Variables defined on this form

businessLogic: list[BusinessLogicRule] = list()

Form-scoped business logic rules

extraAttributes: dict[str, Any] = dict()

Unknown columns for this form

get(key, default=None)

Return value for key or default if absent.

Parameters:
  • key (str) –

  • default (Any) –

Return type:

Any

items()

Return list of (key, value) pairs.

Return type:

list[tuple[str, Any]]

keys()

Return list of accessible keys.

Return type:

list[str]

class imednet.datadict.models.Metadata[source]

Bases: BaseModel

Metadata envelope for the study data dictionary.

schemaVersion: str = '1.0.0'

Data dictionary schema version

studyKey: str | None = None

Study key

generatedAt: str | None = None

Timestamp of data dictionary generation

source: str | None = None

Source of generation (csv, api)

validationWarnings: list[str] = list()

Warnings generated during loading/validation

extraAttributes: dict[str, Any] = dict()

Unknown metadata columns or properties

classmethod create(study_key=None, source=None, validation_warnings=None, **extra)[source]

Create a Metadata envelope with current UTC timestamp.

Parameters:
  • study_key (str | None) –

  • source (str | None) –

  • validation_warnings (list[str] | None) –

  • extra (Any) –

Return type:

Metadata

class imednet.datadict.models.Variable[source]

Bases: DictCompatMixin, BaseModel

A clinical data variable (data point) on a form.

variableName: str

Required. Unique identifier for variable within form

label: str | None = None

Display prompt/label on the Form for a Subject

variableType: str | None = None

Field type (Text, Radio, Date/Time Precision, etc.)

sequence: int | None = None

Display order within form

required: str | None = None

Required policy (e.g. ‘Yes’, ‘No’, ‘Auto Query’)

format: str | None = None

Format mask or pattern

precision: str | None = None

Date/Time or number precision

choices: list[Choice] = list()

Allowed choices for categorical variables

extraAttributes: dict[str, Any] = dict()

Unknown columns for this variable

get(key, default=None)

Return value for key or default if absent.

Parameters:
  • key (str) –

  • default (Any) –

Return type:

Any

items()

Return list of (key, value) pairs.

Return type:

list[tuple[str, Any]]

keys()

Return list of accessible keys.

Return type:

list[str]

property variable_name: str

Snake-case alias for variableName matching core Variable models.

property variable_type: str | None

Snake-case alias for variableType matching core Variable models.

imednet.datadict.normalize module

Field normalization and date policy for data dictionary.

imednet.datadict.normalize.normalize_form_id(form_id, form_key=None)[source]

Normalize formId values, stripping synthetic formKey fallbacks and coercing numeric IDs.

Parameters:
  • form_id (Any) – Raw formId value from a loader or model.

  • form_key (str | None) – Associated formKey to detect synthetic formId == formKey defaults.

Returns:

Normalized integer or string formId, or None if unset or synthetic.

Return type:

int | str | None

imednet.datadict.normalize.normalize_form_type(value, *, default=None)[source]

Normalize formType values across loaders using canonical ‘Subject’ terminology.

Legacy ‘Patient’ (and ‘CRF’/’Participant’) values normalize to ‘Subject’.

Parameters:
  • value (str | None) – Raw formType value.

  • default (str | None) – Default canonical formType when value is empty or None.

Returns:

Normalized formType string or default.

Return type:

str | None

imednet.datadict.normalize.normalize_measurement_units(extra_attrs)[source]

Extract and normalize measurement unit definitions from extraAttributes.

Parameters:

extra_attrs (dict[str, Any] | None) – Dictionary of extra attributes on Metadata or Variable.

Returns:

List of normalized unit dictionaries containing ‘oid’, ‘name’, and ‘symbol’.

Return type:

list[dict[str, str]]

imednet.datadict.normalize.normalize_row_data(row, known_camel_fields, source_name='CSV')[source]

Normalize a CSV row: map known headers to camelCase and isolate unknown attributes.

Parameters:
  • row (dict[str, str]) – Raw dictionary of CSV header to string value.

  • known_camel_fields (set[str]) – Set of known fields in camelCase.

  • source_name (str) – Name of the source file for warning messages.

Returns:

Tuple of (known_fields_dict, extra_attributes_dict, warning_messages).

Return type:

tuple[dict[str, Any], dict[str, Any], list[str]]

imednet.datadict.normalize.normalize_variable_bounds(extra_attrs)[source]

Extract and normalize validation bounds or ODM RangeChecks from extraAttributes.

Parameters:

extra_attrs (dict[str, Any] | None) – Variable extraAttributes dictionary.

Returns:

List of normalized range check dictionaries ready for ODM serialization.

Return type:

list[dict[str, Any]]

imednet.datadict.normalize.normalize_variable_type(value, *, precision=None)[source]

Normalize variableType values across CSV, ODM, REDCap, and SDK sources.

Parameters:
  • value (str | None) – Raw variableType string.

  • precision (str | None) – Optional precision string to disambiguate generic ‘Number’ types.

Returns:

Canonical variableType string, or None if empty.

Return type:

str | None

imednet.datadict.normalize.to_camel_case(text)[source]

Strict lexical camelCasing for headers without semantic renames.

Examples

‘Patient Record Report’ -> ‘patientRecordReport’ ‘Special Patient ID’ -> ‘specialPatientId’ ‘Form Key’ -> ‘formKey’ ‘Form ID’ -> ‘formId’ ‘BUSINESS_LOGIC’ -> ‘businessLogic’ ‘variableName’ -> ‘variableName’ ‘Form’ -> ‘form’

Parameters:

text (str) – The string to convert.

Returns:

The camelCased string.

Return type:

str

imednet.datadict.normalize.validate_timestamp(timestamp_str)[source]

Assert that a timestamp string adheres strictly to the MM-DD-YYYY format.

Parameters:

timestamp_str (str) – The timestamp string to validate.

Returns:

The validated timestamp string.

Raises:

ValueError – If the timestamp does not adhere to MM-DD-YYYY or has invalid calendar date.

Return type:

str

imednet.datadict.schema module

JSON Schema generation and validation for iMednet Data Dictionary.

imednet.datadict.schema.get_schema()[source]

Generate or retrieve the canonical JSON Schema for DataDictionary.

Returns:

JSON Schema dictionary.

Return type:

dict[str, Any]

imednet.datadict.schema.validate(target, schema=None)[source]

Validate a data dictionary against the canonical model or an optional JSON schema.

Parameters:
  • target (dict[str, Any] | str | Path | DataDictionary) – DataDictionary instance, dict, JSON string, or path to JSON file.

  • schema (dict[str, Any] | None) – Optional JSON Schema to validate against via jsonschema.

Returns:

List of error strings (empty if valid).

Return type:

list[str]