FHIR Model Factory
Main class and utilities for dynamically constructing FHIR resource models.
get_type_choice_value_by_base
Retrieve the value of a type-choice field in an instance based on the field name starting with a specific base string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
object
|
The instance object to retrieve the value from. |
required |
base
|
str
|
The base string that the field name should start with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
value |
Any
|
The value of the first field found in the instance that starts with the specified base string,
or |
Source code in fhircraft/fhir/resources/validators.py
validate_FHIR_element_fixed_value
validate_FHIR_element_fixed_value(cls: Any, element: Union[FHIRBaseModel, List[FHIRBaseModel], Any], constant: Union[FHIRBaseModel, List[FHIRBaseModel], Any]) -> Any
Validate the FHIR element against a specified constant value and return the element if it fulfills the constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
Any
|
Placeholder for an argument that is not used in the function. |
required |
element
|
Union[FHIRBaseModel, List[FHIRBaseModel]]
|
The FHIR element to validate against the constant. |
required |
constant
|
Union[FHIRBaseModel, List[FHIRBaseModel]]
|
The constant value to validate the element against. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Union[FHIRBaseModel, List[FHIRBaseModel]]: The validated FHIR element. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the element does not fulfill the specified constant. |
Source code in fhircraft/fhir/resources/validators.py
validate_FHIR_element_pattern
validate_FHIR_element_pattern(cls: Any, element: Union[FHIRBaseModel, List[FHIRBaseModel], Any], pattern: Union[FHIRBaseModel, List[FHIRBaseModel], Any]) -> Any
Validate the FHIR element against a specified pattern and return the element if it fulfills the pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
Any
|
Placeholder for an argument that is not used in the function. |
required |
element
|
Union[FHIRBaseModel, List[FHIRBaseModel]]
|
The FHIR element to validate against the pattern. |
required |
pattern
|
Union[FHIRBaseModel, List[FHIRBaseModel]]
|
The pattern to validate the element against. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Union[FHIRBaseModel, List[FHIRBaseModel]]: The validated FHIR element. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the element does not fulfill the specified pattern. |
Source code in fhircraft/fhir/resources/validators.py
validate_FHIR_model_fixed_value
validate_FHIR_model_fixed_value(model: Union[FHIRBaseModel, List[FHIRBaseModel], Any], constant: Union[FHIRBaseModel, List[FHIRBaseModel], Any]) -> Any
Validate the FHIR model against a specified constant value and return the model if it fulfills the constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Union[FHIRBaseModel, List[FHIRBaseModel]]
|
The FHIR model to validate against the constant. |
required |
constant
|
Union[FHIRBaseModel, List[FHIRBaseModel]]
|
The constant value to validate the model against. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Union[FHIRBaseModel, List[FHIRBaseModel]]: The validated FHIR element. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the element does not fulfill the specified constant. |
Source code in fhircraft/fhir/resources/validators.py
validate_FHIR_model_pattern
validate_FHIR_model_pattern(model: Union[FHIRBaseModel, List[FHIRBaseModel], Any], pattern: Union[FHIRBaseModel, List[FHIRBaseModel], Any]) -> Any
Validate the FHIR model against a specified pattern and return the model if it fulfills the pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Union[FHIRBaseModel, List[FHIRBaseModel]]
|
The FHIR model to validate against the pattern. |
required |
pattern
|
Union[FHIRBaseModel, List[FHIRBaseModel]]
|
The pattern to validate the model against. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Union[FHIRBaseModel, List[FHIRBaseModel]]: The validated FHIR model. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the model does not fulfill the specified pattern. |
Source code in fhircraft/fhir/resources/validators.py
validate_element_constraint
validate_element_constraint(instance: T, elements: Sequence[str], expression: str, human: str, key: str, severity: str) -> T
Validates a FHIR element constraint based on a FHIRPath expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
T
|
The instance to be validated. |
required |
elements
|
Sequence[str]
|
The elements to be validated. |
required |
expression
|
str
|
The FHIRPath expression to evaluate. |
required |
human
|
str
|
A human-readable description of the constraint. |
required |
key
|
str
|
The key associated with the constraint. |
required |
severity
|
str
|
The severity level of the constraint ('warning' or 'error'). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
T
|
The validated value. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the validation fails and severity is not |
Warning
|
If the validation fails and severity is |
Source code in fhircraft/fhir/resources/validators.py
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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
validate_model_constraint
Validates a FHIR model constraint based on a FHIRPath expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
T
|
Instance of the model to be validated. |
required |
expression
|
str
|
The FHIRPath expression to evaluate. |
required |
human
|
str
|
A human-readable description of the constraint. |
required |
key
|
str
|
The key associated with the constraint. |
required |
severity
|
str
|
The severity level of the constraint ('warning' or 'error'). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
instance |
type[T]
|
The validated model instance. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the validation fails and severity is not |
Warning
|
If the validation fails and severity is |
Source code in fhircraft/fhir/resources/validators.py
validate_slicing_cardinalities
validate_slicing_cardinalities(cls: Any, values: List[Any] | None, field_name: str) -> List[FHIRSliceModel] | None
Validates the cardinalities of FHIR slices for a specific field within a FHIR resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
Any
|
The Pydantic FHIR model class. |
required |
values
|
List[Any]
|
List of values for the field. |
required |
field_name
|
str
|
The name of the field to validate. |
required |
Returns:
| Type | Description |
|---|---|
List[FHIRSliceModel] | None
|
List[FHIRSliceModel]: The validated list of values. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If cardinality constraints are violated for any slice. |
Source code in fhircraft/fhir/resources/validators.py
validate_type_choice_element
validate_type_choice_element(instance: T, field_types: List[Any], field_name_base: str, required: bool = False, non_allowed_types=[]) -> T
Validate the type choice element for a given instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
T
|
The instance to validate. |
required |
field_types
|
List[Any]
|
List of field types to check. |
required |
field_name_base
|
str
|
Base name of the field. |
required |
required
|
bool
|
Whether the type choice element is required. |
False
|
non_allowed_types
|
List[Any] | None
|
List of types that are not allowed for this element (for negative checks). |
[]
|
Returns:
| Name | Type | Description |
|---|---|---|
T |
T
|
The validated instance. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If more than one value is set for the type choice element or if a non-allowed type is set. |
Source code in fhircraft/fhir/resources/validators.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | |