Core API Reference¶
Core classes and functions for ccdakit.
Configuration¶
CDAConfig
dataclass
¶
Global configuration for C-CDA generation.
OrganizationInfo
dataclass
¶
Organization/custodian information.
configure(config)
¶
Set global configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
CDAConfig
|
CDAConfig instance |
required |
get_config()
¶
Get current configuration.
Returns:
| Type | Description |
|---|---|
CDAConfig
|
Current CDAConfig instance |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If not configured |
Source code in ccdakit/core/config.py
reset_config()
¶
Base Classes¶
CDAElement
¶
Bases: ABC
Base class for all CDA elements.
All builders inherit from this class and implement the build() method.
Source code in ccdakit/core/base.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
Functions¶
__init__(version=CDAVersion.R2_1, schema=None)
¶
Initialize CDA element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
CDAVersion
|
C-CDA version to generate |
R2_1
|
schema
|
Optional[XSDValidator]
|
Optional XSD validator |
None
|
Source code in ccdakit/core/base.py
build()
abstractmethod
¶
Build and return the XML element.
This method must be implemented by subclasses.
Returns:
| Type | Description |
|---|---|
_Element
|
lxml Element representing this CDA component |
to_element()
¶
Build element with optional validation.
Returns:
| Type | Description |
|---|---|
_Element
|
lxml Element representing this CDA component |
Raises:
| Type | Description |
|---|---|
DocumentInvalid
|
If validation fails |
Source code in ccdakit/core/base.py
to_string(pretty=True, encoding='unicode')
¶
Convert to XML string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pretty
|
bool
|
Whether to pretty-print XML |
True
|
encoding
|
str
|
Output encoding ('unicode' or 'utf-8') |
'unicode'
|
Returns:
| Type | Description |
|---|---|
str
|
XML string representation |
Source code in ccdakit/core/base.py
get_templates()
¶
Get templateIds for current version.
Returns:
| Type | Description |
|---|---|
List[TemplateConfig]
|
List of TemplateConfig for this version |
Raises:
| Type | Description |
|---|---|
ValueError
|
If version not supported |
Source code in ccdakit/core/base.py
add_template_ids(parent)
¶
Add all templateIds for current version to parent element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
_Element
|
Parent element to add templateIds to |
required |
Source code in ccdakit/core/base.py
CDAVersion
¶
TemplateConfig
¶
Template identifier configuration.
Source code in ccdakit/core/base.py
Functions¶
__init__(root, extension=None, description=None)
¶
Initialize template configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
str
|
Template OID |
required |
extension
|
Optional[str]
|
Version extension (e.g., '2015-08-01') |
None
|
description
|
Optional[str]
|
Human-readable description |
None
|
Source code in ccdakit/core/base.py
to_element()
¶
Convert to templateId XML element.
Returns:
| Type | Description |
|---|---|
_Element
|
lxml Element for templateId |
Source code in ccdakit/core/base.py
Validation¶
ValidationResult
dataclass
¶
Result of validation with errors, warnings, and info.
Source code in ccdakit/core/validation.py
Attributes¶
is_valid
property
¶
Check if validation passed (no errors).
has_warnings
property
¶
Check if there are warnings.
all_issues
property
¶
Get all issues in order: errors, warnings, infos.
Functions¶
raise_if_invalid()
¶
Raise ValidationError if validation failed.
Raises:
| Type | Description |
|---|---|
ValidationError
|
If there are any errors |
to_dict()
¶
Convert to dictionary for JSON serialization.
Source code in ccdakit/core/validation.py
__str__()
¶
String representation of validation result.
Source code in ccdakit/core/validation.py
ValidationIssue
dataclass
¶
A validation issue (error, warning, or info).
Source code in ccdakit/core/validation.py
ValidationLevel
¶
ValidationError
¶
Bases: Exception
Exception raised when validation fails.
Source code in ccdakit/core/validation.py
Functions¶
__init__(result)
¶
Initialize with validation result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
ValidationResult
|
ValidationResult containing errors |
required |
Null Flavors¶
NullFlavor
¶
Bases: Enum
Standard HL7 null flavors.
Used when data is missing or not applicable.
Source code in ccdakit/core/null_flavor.py
get_null_flavor_for_missing(asked=False)
¶
Get appropriate null flavor for missing data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asked
|
bool
|
Whether the data was asked for but not provided |
False
|
Returns:
| Type | Description |
|---|---|
NullFlavor
|
Appropriate NullFlavor |
Source code in ccdakit/core/null_flavor.py
is_null_flavor(value)
¶
Check if a string is a valid null flavor code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Optional[str]
|
String to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if value is a null flavor code |