onconova.interoperability.parsers
T
module-attribute
¶
BundleParser(bundle)
¶
Source code in onconova/interoperability/parsers.py
bundle
instance-attribute
¶
key_map
instance-attribute
¶
list_fields
instance-attribute
¶
nested_resources
instance-attribute
¶
users_map
instance-attribute
¶
get_or_create_user(user)
staticmethod
¶
Retrieves an existing User object by username or creates a new one if it does not exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
User | str
|
A User instance containing user details, or a string representing the username. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
User |
User
|
The retrieved or newly created User object, or None if the input is invalid. |
Notes
- If a string is provided, a new user is created with default inactive and external access level.
- If a User is provided, user details are imported and the user is created as inactive and external.
Source code in onconova/interoperability/parsers.py
import_bundle(case=None)
¶
Imports a patient case bundle into the database, including all related resources and data completion statuses.
This method performs the import within a database transaction to ensure atomicity and prevent partial imports in case of errors. It validates and imports the main patient case, then iterates through all related resource lists, importing each resource and its nested subresources. Finally, it records the completion status for each data category associated with the case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
PatientCase
|
An existing PatientCase instance to update. If None, a new instance is created. |
None
|
Returns:
| Type | Description |
|---|---|
PatientCase
|
models.PatientCase: The imported or updated PatientCase instance. |
Source code in onconova/interoperability/parsers.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 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 | |
import_history_events(orm_instance, resourceId)
¶
Imports history events associated with a specific resource into the ORM instance.
This method filters events from the bundle's history that match the given resourceId, imports the user (actor) for each event if present, creates event records in the ORM, manually sets the event timestamp, and finally adds a manual event indicating the import.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Model
|
The ORM instance to which events will be imported. |
required |
|
str
|
The identifier of the resource whose events are to be imported. |
required |
Source code in onconova/interoperability/parsers.py
import_resource(resource, instance=None, **fields)
¶
Imports a resource into the database, resolving foreign keys and associating related events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Schema
|
The resource object to import, which must have an 'id' attribute. |
required |
|
T | None
|
An existing ORM instance to update, or None to create a new one. |
None
|
|
dict
|
Additional fields to pass to the model's dump method. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the resource does not have an 'id'. |
Returns:
| Type | Description |
|---|---|
T
|
The ORM instance created or updated from the resource. |
Side Effects
- Resolves foreign keys in the resource.
- Creates or updates the database entry for the resource.
- Deletes the latest creation event for the ORM instance.
- Updates the external-to-internal foreign key mapping.
- Imports related history events for the resource.
Source code in onconova/interoperability/parsers.py
resolve_foreign_keys(schema_instance)
¶
Resolves foreign key fields in a schema instance by converting external keys to internal keys.
Iterates over the fields of the provided schema instance, excluding 'externalSourceId'. For fields ending with 'Id', replaces the external key value with its corresponding internal key. For fields ending with 'Ids', replaces the list of external key values with a list of corresponding internal keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Schema
|
The schema instance containing foreign key fields to resolve. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Schema |
Schema
|
The schema instance with foreign key fields resolved to internal keys. |