Skip to content

onconova.oncology.controllers.staging

AnyPayloadSchemas module-attribute

AnyResponseSchemas module-attribute

PAYLOAD_SCHEMAS module-attribute

RESPONSE_SCHEMAS module-attribute

StagingController

Bases: ControllerBase

create_staging(payload)

Source code in onconova/oncology/controllers/staging.py
@route.post(
    path="",
    response={201: ModifiedResourceSchema, **COMMON_HTTP_ERRORS},
    permissions=[perms.CanManageCases],
    operation_id="createStaging",
)
def create_staging(self, payload: AnyPayloadSchemas):  # type: ignore
    return 201, payload.model_dump_django()

delete_staging(stagingId)

Source code in onconova/oncology/controllers/staging.py
@route.delete(
    path="/{stagingId}",
    response={204: None, 404: None, **COMMON_HTTP_ERRORS},
    permissions=[perms.CanManageCases],
    operation_id="deleteStagingById",
)
def delete_staging(self, stagingId: str):
    instance = get_object_or_404(orm.Staging, id=stagingId)
    instance.delete()
    return 204, None

get_all_staging_history_events(stagingId)

Source code in onconova/oncology/controllers/staging.py
@route.get(
    path="/{stagingId}/history/events",
    response={200: Paginated[HistoryEvent], 404: None, **COMMON_HTTP_ERRORS},
    permissions=[perms.CanViewCases],
    operation_id="getAllStagingHistoryEvents",
)
@paginate()
@ordering()
def get_all_staging_history_events(self, stagingId: str):
    instance = get_object_or_404(orm.Staging, id=stagingId)
    return pghistory.models.Events.objects.tracks(instance).all()  # type: ignore

get_all_stagings_matching_the_query(query)

Source code in onconova/oncology/controllers/staging.py
@route.get(
    path="",
    response={
        200: Paginated[AnyResponseSchemas],
        **COMMON_HTTP_ERRORS,
    },
    permissions=[perms.CanViewCases],
    exclude_none=True,
    operation_id="getStagings",
)
@paginate()
@ordering()
@anonymize()
def get_all_stagings_matching_the_query(self, query: Query[scm.StagingFilters]):  # type: ignore
    queryset = orm.Staging.objects.all().order_by("-date")
    return [
        cast_to_model_schema(staging.get_domain_staging(), RESPONSE_SCHEMAS)
        for staging in query.filter(queryset)
    ]

get_staging_by_id(stagingId)

Source code in onconova/oncology/controllers/staging.py
@route.get(
    path="/{stagingId}",
    response={200: AnyResponseSchemas, 404: None},
    permissions=[perms.CanViewCases],
    exclude_none=True,
    operation_id="getStagingById",
)
@anonymize()
def get_staging_by_id(self, stagingId: str):
    instance = get_object_or_404(orm.Staging, id=stagingId)
    return cast_to_model_schema(instance.get_domain_staging(), RESPONSE_SCHEMAS)

get_staging_history_event_by_id(stagingId, eventId)

Source code in onconova/oncology/controllers/staging.py
@route.get(
    path="/{stagingId}/history/events/{eventId}",
    response={200: HistoryEvent, 404: None, **COMMON_HTTP_ERRORS},
    permissions=[perms.CanViewCases],
    operation_id="getStagingHistoryEventById",
)
def get_staging_history_event_by_id(self, stagingId: str, eventId: str):
    instance = get_object_or_404(orm.Staging, id=stagingId)
    event = instance.parent_events.filter(pgh_id=eventId).first()  # type: ignore
    if not event and hasattr(instance, "events"):
        event = instance.events.filter(pgh_id=eventId).first()
    if not event:
        return 404, None
    return get_object_or_404(
        pghistory.models.Events.objects.tracks(instance), pgh_id=eventId  # type: ignore
    )

revert_staging_to_history_event(stagingId, eventId)

Source code in onconova/oncology/controllers/staging.py
@route.put(
    path="/{stagingId}/history/events/{eventId}/reversion",
    response={201: ModifiedResourceSchema, 404: None, **COMMON_HTTP_ERRORS},
    permissions=[perms.CanManageCases],
    operation_id="revertStagingToHistoryEvent",
)
def revert_staging_to_history_event(self, stagingId: str, eventId: str):
    instance = get_object_or_404(orm.Staging, id=stagingId)
    instance = instance.get_domain_staging()
    try:
        return 201, revert_multitable_model(instance, eventId)
    except ObjectDoesNotExist:
        return 404, None

update_staging(stagingId, payload)

Source code in onconova/oncology/controllers/staging.py
@route.put(
    path="/{stagingId}",
    response={200: ModifiedResourceSchema, 404: None, **COMMON_HTTP_ERRORS},
    permissions=[perms.CanManageCases],
    operation_id="updateStagingById",
)
def update_staging(self, stagingId: str, payload: AnyPayloadSchemas):  # type: ignore
    instance = get_object_or_404(orm.Staging, id=stagingId)
    return cast_to_model_schema(
        instance.get_domain_staging(), PAYLOAD_SCHEMAS, payload
    ).model_dump_django(instance=instance.get_domain_staging()) 

cast_to_model_schema(model_instance, schemas, payload=None)

Source code in onconova/oncology/controllers/staging.py
def cast_to_model_schema(model_instance, schemas, payload=None):
    return next(
        (
            schema.model_validate(payload or model_instance)
            for schema in schemas
            if (
                payload
                and payload.stagingDomain
                == schema.model_fields["stagingDomain"].default
            )
            or (
                model_instance
                and model_instance.staging_domain
                == schema.model_fields["stagingDomain"].default
            )
        )
    )
runner