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
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. |