Skip to content

onconova.interoperability.schemas

ExportMetadata

Bases: BaseModel

Represents metadata information for an exported resource.

Attributes:

Name Type Description
exportedAt datetime

The datetime when the resource was exported.

exportedBy str

Username of the user who performed the export.

exportVersion str

Version tag of the exporting system.

checksum str

Checksum (e.g., SHA256) of the exported content for integrity verification.

checksum class-attribute instance-attribute

exportVersion class-attribute instance-attribute

exportedAt class-attribute instance-attribute

exportedBy class-attribute instance-attribute

PatientCaseBundle

Bases: PatientCase

PatientCaseBundle aggregates all relevant patient case data for interoperability and import/export operations.

This schema extends PatientCase and organizes multiple related entities, such as neoplastic entities, stagings, tumor markers, risk assessments, therapies, surgeries, adverse events, treatment responses, performance status, comorbidities, genomic variants, genomic signatures, vitals, lifestyles, family history, tumor boards, completed data categories, and history events.

The order of properties is significant for import tools that rely on reference trees.

Attributes:

Name Type Description
neoplasticEntities List[NeoplasticEntity]

List of neoplastic entities associated with the patient case.

stagings List[Union[...]]

List of staging schemas (e.g., TNM, FIGO, Binet, etc.).

tumorMarkers List[TumorMarkerSchema]

List of tumor marker schemas.

riskAssessments List[RiskAssessment]

List of risk assessment schemas.

therapyLines List[TherapyLine]

List of therapy line schemas.

systemicTherapies List[SystemicTherapy]

List of systemic therapy schemas.

surgeries List[Surgery]

List of surgery schemas.

radiotherapies List[Radiotherapy]

List of radiotherapy schemas.

adverseEvents List[AdverseEvent]

List of adverse event schemas.

treatmentResponses List[TreatmentResponse]

List of treatment response schemas.

performanceStatus List[PerformanceStatus]

List of performance status schemas.

comorbidities List[ComorbiditiesAssessment]

List of comorbidities assessment schemas.

genomicVariants List[GenomicVariant]

List of genomic variant schemas.

genomicSignatures List[Union[...]]

List of genomic signature schemas (e.g., TMB, MSI, LOH, etc.).

vitals List[Vitals]

List of vitals schemas.

lifestyles List[Lifestyle]

List of lifestyle schemas.

familyHistory List[FamilyHistory]

List of family history schemas.

tumorBoards List[Union[UnspecifiedTumorBoard, MolecularTumorBoard]]

List of tumor board schemas.

completedDataCategories Dict[PatientCaseDataCategories, PatientCaseDataCompletionStatus]

Mapping of data categories to their completion status.

history List[HistoryEvent]

List of history events related to the patient case.

Methods:

Name Description
resolve_stagings

Resolves and serializes staging data for the patient case.

resolve_genomicSignatures

Resolves and serializes genomic signature data.

resolve_tumorBoards

Resolves and serializes tumor board data.

resolve_completedDataCategories

Resolves completion status for each data category.

resolve_history

Resolves and retrieves history events for the patient case.

Config

model_config: Serialization configuration (serialize_by_alias=False).

adverseEvents class-attribute instance-attribute

comorbidities class-attribute instance-attribute

completedDataCategories instance-attribute

contributorsDetails class-attribute instance-attribute

familyHistory class-attribute instance-attribute

genomicSignatures class-attribute instance-attribute

genomicVariants class-attribute instance-attribute

history class-attribute instance-attribute

lifestyles class-attribute instance-attribute

model_config class-attribute instance-attribute

neoplasticEntities class-attribute instance-attribute

performanceStatus class-attribute instance-attribute

radiotherapies class-attribute instance-attribute

riskAssessments class-attribute instance-attribute

stagings class-attribute instance-attribute

surgeries class-attribute instance-attribute

systemicTherapies class-attribute instance-attribute

therapyLines class-attribute instance-attribute

treatmentResponses class-attribute instance-attribute

tumorBoards class-attribute instance-attribute

tumorMarkers class-attribute instance-attribute

vitals class-attribute instance-attribute

anonymize_users(obj) classmethod

Source code in onconova/interoperability/schemas.py
@model_validator(mode='after')
@classmethod
def anonymize_users(cls, obj):
    def recursively_replace(obj, original_value, new_value, visited=None):
        if visited is None:
            visited = set()
        # Don't recurse into primitive types
        if isinstance(obj, (str, int, float, bool, type(None))):
            return
        # Avoid cycles
        obj_id = id(obj)
        if obj_id in visited:
            return
        visited.add(obj_id)

        if isinstance(obj, dict):
            for key, value in obj.items():
                if value == original_value:
                    obj[key] = new_value
                else:
                    recursively_replace(value, original_value, new_value, visited)
        elif isinstance(obj, list):
            for idx, item in enumerate(obj):
                if item == original_value:
                    obj[idx] = new_value
                else:
                    recursively_replace(item, original_value, new_value, visited)
        elif hasattr(obj, '__dict__'):
            for attr in vars(obj):
                value = getattr(obj, attr)
                if value == original_value:
                    setattr(obj, attr, new_value)
                else:
                    recursively_replace(value, original_value, new_value, visited)

    for user in obj.contributorsDetails:
        if not user.anonymized:
            continue
        original_username = user.username
        # Anonymize user details
        user.firstName = 'Anonymous'
        user.lastName = 'External User'
        user.username = f"user-{str(user.id)[:5]}" # type: ignore
        user.email = 'anonymized@mail.com'
        # Replace all existing instances of the username throughout the bundle and replace it
        recursively_replace(obj, original_username, user.username)

    return obj 

resolve_completedDataCategories(obj) staticmethod

Source code in onconova/interoperability/schemas.py
@staticmethod
def resolve_completedDataCategories(obj):
    from onconova.oncology.models.patient_case import PatientCase

    return {
        category: sc.PatientCaseDataCompletionStatus(
            status=completion is not None,
            username=completion.created_by if completion else None,
            timestamp=completion.created_at if completion else None,
        )
        for category in PatientCaseDataCategoryChoices.values
        for completion in (
            (
                list(obj.completed_data_categories.filter(category=category)) # type: ignore
                if isinstance(obj, PatientCase)
                else obj.get("completed_data_categories")
            )
            or [None]
        )
    }

resolve_contributorsDetails(obj) staticmethod

Source code in onconova/interoperability/schemas.py
@staticmethod
def resolve_contributorsDetails(obj):
    if isinstance(obj, dict):
        return obj.get("contributorsDetails")
    else:
        return [
            UserExport.model_validate(user)
            for contributor_username in obj.contributors 
            for user in User.objects.filter(username=contributor_username)
        ]   

resolve_genomicSignatures(obj) staticmethod

Source code in onconova/interoperability/schemas.py
@staticmethod
def resolve_genomicSignatures(obj):
    from onconova.oncology.controllers.genomic_signature import (
        RESPONSE_SCHEMAS,
        cast_to_model_schema,
    )

    return [
        cast_to_model_schema(
            staging.get_discriminated_genomic_signature(), RESPONSE_SCHEMAS
        )
        for staging in obj.genomic_signatures.all()
    ]

resolve_history(obj) staticmethod

Source code in onconova/interoperability/schemas.py
@staticmethod
def resolve_history(obj):
    if isinstance(obj, dict):
        return obj.get("history")
    else:
        return (
            pghistory.models.Events.objects.tracks(obj) # type: ignore
            .all()
            .union(
                pghistory.models.Events.objects.references(obj).filter( # type: ignore
                    pgh_model__icontains="oncology"
                )
            )
        )

resolve_stagings(obj) staticmethod

Source code in onconova/interoperability/schemas.py
@staticmethod
def resolve_stagings(obj):
    from onconova.oncology.controllers.staging import (
        RESPONSE_SCHEMAS,
        cast_to_model_schema,
    )

    return [
        cast_to_model_schema(staging.get_domain_staging(), RESPONSE_SCHEMAS)
        for staging in obj.stagings.all()
    ]

resolve_tumorBoards(obj) staticmethod

Source code in onconova/interoperability/schemas.py
@staticmethod
def resolve_tumorBoards(obj):
    from onconova.oncology.controllers.tumor_board import (
        RESPONSE_SCHEMAS,
        cast_to_model_schema,
    )

    return [
        cast_to_model_schema(staging.specialized_tumor_board, RESPONSE_SCHEMAS)
        for staging in obj.tumor_boards.all()
    ]
runner