Skip to content

onconova.oncology.controllers.patient_case

OthersController

Bases: ControllerBase

get_clinical_centers(query='')

Source code in onconova/oncology/controllers/patient_case.py
@route.get(
    path="/clinical-centers",
    response={
        200: list[str],
        **COMMON_HTTP_ERRORS,
        501: None,
    },
    operation_id="getClinicalCenters",
)
def get_clinical_centers(self, query: str = ""):
    queryset = orm.PatientCase.objects.all()
    if query:
        queryset = queryset.filter(clinical_center__icontains=query)
    return queryset.values_list("clinical_center", flat=True).distinct()

PatientCaseController

Bases: ControllerBase

create_patient_case(payload)

Source code in onconova/oncology/controllers/patient_case.py
@route.post(
    path="",
    response={201: ModifiedResourceSchema, **COMMON_HTTP_ERRORS},
    permissions=[perms.CanManageCases],
    operation_id="createPatientCase",
)
def create_patient_case(self, payload: scm.PatientCaseCreate):
    return 201, payload.model_dump_django()

create_patient_case_data_completion(caseId, category)

Source code in onconova/oncology/controllers/patient_case.py
@route.post(
    path="/{caseId}/data-completion/{category}",
    response={201: ModifiedResourceSchema, 404: None, **COMMON_HTTP_ERRORS},
    permissions=[perms.CanManageCases],
    operation_id="createPatientCaseDataCompletion",
)
def create_patient_case_data_completion(
    self, caseId: str, category: orm.PatientCaseDataCompletion.PatientCaseDataCategories
):
    return 201, orm.PatientCaseDataCompletion.objects.create(
        case=get_object_or_404(orm.PatientCase, id=caseId), category=category
    )

delete_patient_case(caseId)

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

delete_patient_case_data_completion(caseId, category)

Source code in onconova/oncology/controllers/patient_case.py
@route.delete(
    path="/{caseId}/data-completion/{category}",
    response={204: None, 404: None, **COMMON_HTTP_ERRORS},
    permissions=[perms.CanManageCases],
    operation_id="deletePatientCaseDataCompletion",
)
def delete_patient_case_data_completion(
    self, caseId: str, category: orm.PatientCaseDataCompletion.PatientCaseDataCategories
):
    instance = get_object_or_404(
        orm.PatientCaseDataCompletion, case__id=caseId, category=category
    )
    instance.delete()
    return 204, None

get_all_patient_case_history_events(caseId)

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

get_all_patient_cases_matching_the_query(query, idSearch=None)

Source code in onconova/oncology/controllers/patient_case.py
@route.get(
    path="",
    response={200: Paginated[scm.PatientCase], **COMMON_HTTP_ERRORS},
    permissions=[perms.CanViewCases],
    operation_id="getPatientCases",
)
@paginate()
@ordering()
@anonymize()
def get_all_patient_cases_matching_the_query(
    self,
    query: Query[PatientCaseFilters],
    idSearch: Nullable[str] = None,
):  # type: ignore
    queryset = orm.PatientCase.objects.all()
    if idSearch:
        id_query = Q(pseudoidentifier__icontains=idSearch) | Q(
            id__icontains=idSearch
        )
        if (
            self.context
            and self.context.request
            and perms.CanManageCases().check_user_permission(
                self.context.request.user  # type: ignore
            )
        ):
            id_query = id_query | Q(clinical_identifier__icontains=idSearch)
        queryset = queryset.filter(id_query)
    return query.filter(queryset)  # type: ignore

get_patient_case_by_id(caseId, type=PatientCaseIdentifier.ID, clinicalCenter=None)

Source code in onconova/oncology/controllers/patient_case.py
@route.get(
    path="/{caseId}",
    response={200: scm.PatientCase, 404: None, **COMMON_HTTP_ERRORS},
    permissions=[perms.CanViewCases],
    operation_id="getPatientCaseById",
)
@anonymize()
def get_patient_case_by_id(
    self,
    caseId: str,
    type: PatientCaseIdentifier = PatientCaseIdentifier.ID,
    clinicalCenter: str | None = None,
):
    if type == PatientCaseIdentifier.ID:
        return get_object_or_404(orm.PatientCase, id=caseId.strip())
    elif type == PatientCaseIdentifier.PSEUDO:
        return get_object_or_404(orm.PatientCase, pseudoidentifier=caseId.strip())
    elif type == PatientCaseIdentifier.CLINICAL:
        if (
            self.context
            and self.context.request
            and not perms.CanManageCases().check_user_permission(
                self.context.request.user  # type: ignore
            )
        ):
            return 403, None
        if not clinicalCenter:
            raise ValueError(
                "Clinical center must also be provided along the clinical identifier."
            )
        return get_object_or_404(
            orm.PatientCase,
            clinical_identifier=caseId.strip(),
            clinical_center=clinicalCenter.strip(),
        )

get_patient_case_data_completion_status(caseId, category)

Source code in onconova/oncology/controllers/patient_case.py
@route.get(
    path="/{caseId}/data-completion/{category}",
    response={
        200: scm.PatientCaseDataCompletionStatus,
        404: None,
        **COMMON_HTTP_ERRORS,
    },
    permissions=[perms.CanViewCases],
    operation_id="getPatientCaseDataCompletionStatus",
)
def get_patient_case_data_completion_status(
    self, caseId: str, category: orm.PatientCaseDataCompletion.PatientCaseDataCategories
):
    category_completion = orm.PatientCaseDataCompletion.objects.filter(
        case__id=caseId, category=category
    ).first()
    return scm.PatientCaseDataCompletionStatus.model_validate(
        dict(
            status=category_completion is not None,
            username=(
                category_completion.created_by if category_completion else None
            ),
            timestamp=(
                category_completion.created_at if category_completion else None
            ),
        )
    )

get_patient_case_history_event_by_id(caseId, eventId)

Source code in onconova/oncology/controllers/patient_case.py
@route.get(
    path="/{caseId}/history/events/{eventId}",
    response={
        200: HistoryEvent.bind_schema(scm.PatientCaseCreate),
        404: None,
        **COMMON_HTTP_ERRORS,
    },
    permissions=[perms.CanViewCases],
    operation_id="getPatientCaseHistoryEventById",
)
def get_patient_case_history_event_by_id(self, caseId: str, eventId: str):
    instance = get_object_or_404(orm.PatientCase, id=caseId)
    return get_object_or_404(
        pghistory.models.Events.objects.tracks(instance), pgh_id=eventId  # type: ignore
    )

revert_patient_case_to_history_event(caseId, eventId)

Source code in onconova/oncology/controllers/patient_case.py
@route.put(
    path="/{caseId}/history/events/{eventId}/reversion",
    response={201: ModifiedResourceSchema, 404: None, **COMMON_HTTP_ERRORS},
    permissions=[perms.CanManageCases],
    operation_id="revertPatientCaseToHistoryEvent",
)
def revert_patient_case_to_history_event(self, caseId: str, eventId: str):
    instance = get_object_or_404(orm.PatientCase, id=caseId)
    return 201, get_object_or_404(instance.events, pgh_id=eventId).revert()

update_patient_case(caseId, payload)

Source code in onconova/oncology/controllers/patient_case.py
@route.put(
    path="/{caseId}",
    response={200: ModifiedResourceSchema, 404: None, **COMMON_HTTP_ERRORS},
    permissions=[perms.CanManageCases],
    operation_id="updatePatientCaseById",
)
def update_patient_case(self, caseId: str, payload: scm.PatientCaseCreate):  # type: ignore
    instance = get_object_or_404(orm.PatientCase, id=caseId)
    return scm.PatientCaseCreate.model_validate(payload).model_dump_django(
        instance=instance
    )

PatientCaseFilters

Bases: PatientCaseFilters

morphology class-attribute instance-attribute

primarySite class-attribute instance-attribute

filter_morphology(value)

Source code in onconova/oncology/controllers/patient_case.py
def filter_morphology(self, value: bool) -> Q | Exists:
    return (
        Exists(
            orm.NeoplasticEntity.objects.filter(
                case_id=OuterRef("pk"),
                morphology__code=value,
                relationship="primary",
            )
        )
        if value
        else Q()
    )

filter_primarySite(value)

Source code in onconova/oncology/controllers/patient_case.py
def filter_primarySite(self, value: bool) -> Q | Exists:
    return (
        Exists(
            orm.NeoplasticEntity.objects.filter(
                case_id=OuterRef("pk"),
                topography_group__code=value,
                relationship="primary",
            )
        )
        if value
        else Q()
    )

PatientCaseIdentifier

Bases: str, Enum

CLINICAL class-attribute instance-attribute

ID class-attribute instance-attribute

PSEUDO class-attribute instance-attribute

runner