Skip to content

onconova.oncology.models.comorbidities

CharlsonPanelDetails() dataclass

Class that provides comorbidity categories and scoring logic for the Charlson Comorbidity Index.

References
  • C. N. Klabunde et al., Annals of Epidemiology,Volume 17, Issue 8, 2007, 584-590
  • Quan H et al., Medical Care 2005; 43(11):1130-1139.

acute_mi class-attribute instance-attribute

aids class-attribute instance-attribute

chf class-attribute instance-attribute

cpd class-attribute instance-attribute

cvd class-attribute instance-attribute

dementia class-attribute instance-attribute

diabates_complications class-attribute instance-attribute

diabetes class-attribute instance-attribute

history_mi class-attribute instance-attribute

liver_disease class-attribute instance-attribute

mild_liver_disease class-attribute instance-attribute

paralysis class-attribute instance-attribute

pvd class-attribute instance-attribute

renal_disease class-attribute instance-attribute

rheumatic_disease class-attribute instance-attribute

ulcers class-attribute instance-attribute

get_score_annotation() classmethod

Constructs a Django ORM annotation that calculates the total comorbidity score for a patient based on the presence of specific condition codes. Each condition code is mapped to a weight, and the sum of these weights is computed using conditional logic.

Returns:

Type Description
Sum

An annotation expression that can be used in queryset aggregation

Sum

to compute the total comorbidity score for each patient.

Source code in onconova/oncology/models/comorbidities.py
@classmethod
def get_score_annotation(cls) -> Sum:
    """
    Constructs a Django ORM annotation that calculates the total comorbidity score for a patient
    based on the presence of specific condition codes. Each condition code is mapped to a weight,
    and the sum of these weights is computed using conditional logic.

    Returns:
        (django.db.models.Sum): An annotation expression that can be used in queryset aggregation
        to compute the total comorbidity score for each patient.
    """
    return Sum(
        Case(
            When(
                present_conditions__code__in=cls.acute_mi.codes
                + cls.history_mi.codes,
                then=Case(
                    When(
                        present_conditions__code__in=cls.acute_mi.codes,
                        then=cls.acute_mi.weight,
                    ),
                    When(
                        present_conditions__code__in=cls.history_mi.codes,
                        then=cls.history_mi.weight,
                    ),
                    default=0,
                ),
            ),
            When(present_conditions__code__in=cls.chf.codes, then=cls.chf.weight),
            When(present_conditions__code__in=cls.pvd.codes, then=cls.pvd.weight),
            When(present_conditions__code__in=cls.cvd.codes, then=cls.cvd.weight),
            When(
                present_conditions__code__in=cls.dementia.codes,
                then=cls.dementia.weight,
            ),
            When(
                present_conditions__code__in=cls.paralysis.codes,
                then=cls.paralysis.weight,
            ),
            When(
                present_conditions__code__in=cls.diabetes.codes
                + cls.diabates_complications.codes,
                then=Case(
                    When(
                        present_conditions__code__in=cls.diabetes.codes,
                        then=cls.diabetes.weight,
                    ),
                    When(
                        present_conditions__code__in=cls.diabates_complications.codes,
                        then=cls.diabates_complications.weight,
                    ),
                    default=0,
                ),
            ),
            When(
                present_conditions__code__in=cls.renal_disease.codes,
                then=cls.renal_disease.weight,
            ),
            When(
                present_conditions__code__in=cls.mild_liver_disease.codes
                + cls.liver_disease.codes,
                then=Case(
                    When(
                        present_conditions__code__in=cls.mild_liver_disease.codes,
                        then=cls.mild_liver_disease.weight,
                    ),
                    When(
                        present_conditions__code__in=cls.liver_disease.codes,
                        then=cls.liver_disease.weight,
                    ),
                    default=0,
                ),
            ),
            When(
                present_conditions__code__in=cls.ulcers.codes,
                then=cls.ulcers.weight,
            ),
            When(
                present_conditions__code__in=cls.rheumatic_disease.codes,
                then=cls.rheumatic_disease.weight,
            ),
            When(present_conditions__code__in=cls.aids.codes, then=cls.aids.weight),
            default=0,
            output_field=models.FloatField(),
        )
    )

ComorbiditiesAssessment

Bases: BaseModel

Represents an assessment of patient comorbidities within a specific clinical case.

Attributes:

Name Type Description
COMORBIDITY_PANELS_DETAILS dict

Maps comorbidity panel types to their detail classes.

objects QueryablePropertiesManager

Custom manager for querying properties.

case ForeignKey[PatientCase]

Reference to the patient case being assessed.

date DateField

Date when the comorbidities assessment was performed.

index_condition ForeignKey[NeoplasticEntity]

The primary neoplastic entity for comorbidity assessment.

panel CharField

Type of comorbidities panel used for assessment.

present_conditions CodedConceptField[ICD10Condition]

List of present comorbid conditions (ICD-10).

absent_conditions CodedConceptField[ICD10Condition]

List of absent comorbid conditions (ICD-10).

score AnnotationProperty

Calculated comorbidity score based on the selected panel.

COMORBIDITY_PANELS_DETAILS class-attribute instance-attribute

absent_conditions class-attribute instance-attribute

case class-attribute instance-attribute

date class-attribute instance-attribute

description property

index_condition class-attribute instance-attribute

objects class-attribute instance-attribute

panel class-attribute instance-attribute

present_conditions class-attribute instance-attribute

score class-attribute instance-attribute

ComorbiditiesAssessmentPanelChoices

Bases: TextChoices

An enumeration of comorbidity panel types used in oncology models.

Attributes:

Name Type Description
CHARLSON

Represents the Charlson comorbidity index panel.

ELIXHAUSER

Represents the Elixhauser comorbidity index panel.

NCI

Represents the National Cancer Institute (NCI) comorbidity index panel.

CHARLSON class-attribute instance-attribute

ELIXHAUSER class-attribute instance-attribute

NCI class-attribute instance-attribute

ComorbidityPanelCategory(label, default, codes, weight) dataclass

Represents a category within a comorbidity panel, including its label, default value, associated codes, and weight.

Attributes:

Name Type Description
label str

The display name of the comorbidity category.

default str

The default value or code for the category.

codes List[str]

A list of codes associated with this category.

weight int | float

The numerical weight assigned to this category.

Methods:

Name Description
get_weight

List[str]) -> int | float: Returns the weight of the category if any of the provided codes match the category's codes; otherwise, returns 0.

codes instance-attribute

default instance-attribute

label instance-attribute

weight instance-attribute

get_weight(codes)

Source code in onconova/oncology/models/comorbidities.py
def get_weight(self, codes: List[str]) -> int | float:
    return self.weight if any([code in codes for code in self.codes]) else 0

ElixhauserPanelDetails() dataclass

This class defines the Elixhauser comorbidity index panel, mapping ICD codes to comorbidity categories and their respective weights. Each comorbidity is represented as a class attribute, instantiated as a ComorbidityPanelCategory with a label, default ICD code, a list of ICD codes, and a weight.

References
  • van Walraven al., Medical Care 47(6):p 626-633, June 2009.
  • Quan H et al., Medical Care 2005; 43(11):1130-1139.

aids class-attribute instance-attribute

alcohol class-attribute instance-attribute

blane class-attribute instance-attribute

carit class-attribute instance-attribute

chf class-attribute instance-attribute

coag class-attribute instance-attribute

cpd class-attribute instance-attribute

dane class-attribute instance-attribute

depre class-attribute instance-attribute

diabc class-attribute instance-attribute

diabunc class-attribute instance-attribute

drug class-attribute instance-attribute

fed class-attribute instance-attribute

hypc class-attribute instance-attribute

hypothy class-attribute instance-attribute

hypunc class-attribute instance-attribute

ld class-attribute instance-attribute

obes class-attribute instance-attribute

ond class-attribute instance-attribute

para class-attribute instance-attribute

pcd class-attribute instance-attribute

psycho class-attribute instance-attribute

pud class-attribute instance-attribute

pvd class-attribute instance-attribute

rf class-attribute instance-attribute

rheumd class-attribute instance-attribute

valv class-attribute instance-attribute

wloss class-attribute instance-attribute

get_score_annotation() classmethod

Calculates the total comorbidity score annotation for a queryset by summing the weights of present conditions.

This method returns a Django ORM annotation that uses a conditional sum (Sum + Case + When) to assign specific weights to each condition code found in present_conditions__code. Each condition group (e.g., chf, carit, valv) has its own set of codes and associated weight. If a condition code matches one of the predefined groups, its corresponding weight is added to the total score. If no match is found, a default value of 0 is used.

Returns:

Type Description
Sum

An annotation that can be used in queryset aggregation to compute the total score.

Source code in onconova/oncology/models/comorbidities.py
@classmethod
def get_score_annotation(cls) -> Sum:
    """
    Calculates the total comorbidity score annotation for a queryset by summing the weights of present conditions.

    This method returns a Django ORM annotation that uses a conditional sum (Sum + Case + When) to assign
    specific weights to each condition code found in `present_conditions__code`. Each condition group (e.g., chf, carit, valv)
    has its own set of codes and associated weight. If a condition code matches one of the predefined groups,
    its corresponding weight is added to the total score. If no match is found, a default value of 0 is used.

    Returns:
        (django.db.models.Sum): An annotation that can be used in queryset aggregation to compute the total score.
    """
    return Sum(
        Case(
            When(present_conditions__code__in=cls.chf.codes, then=cls.chf.weight),
            When(
                present_conditions__code__in=cls.carit.codes,
                then=cls.carit.weight,
            ),
            When(present_conditions__code__in=cls.valv.codes, then=cls.valv.weight),
            When(present_conditions__code__in=cls.pcd.codes, then=cls.pcd.weight),
            When(present_conditions__code__in=cls.pvd.codes, then=cls.pvd.weight),
            When(
                present_conditions__code__in=cls.hypunc.codes,
                then=cls.hypunc.weight,
            ),
            When(present_conditions__code__in=cls.hypc.codes, then=cls.hypc.weight),
            When(present_conditions__code__in=cls.para.codes, then=cls.para.weight),
            When(present_conditions__code__in=cls.ond.codes, then=cls.ond.weight),
            When(present_conditions__code__in=cls.cpd.codes, then=cls.cpd.weight),
            When(
                present_conditions__code__in=cls.diabunc.codes,
                then=cls.diabunc.weight,
            ),
            When(
                present_conditions__code__in=cls.diabc.codes,
                then=cls.diabc.weight,
            ),
            When(
                present_conditions__code__in=cls.hypothy.codes,
                then=cls.hypothy.weight,
            ),
            When(present_conditions__code__in=cls.rf.codes, then=cls.rf.weight),
            When(present_conditions__code__in=cls.ld.codes, then=cls.ld.weight),
            When(present_conditions__code__in=cls.pud.codes, then=cls.pud.weight),
            When(present_conditions__code__in=cls.aids.codes, then=cls.aids.weight),
            When(
                present_conditions__code__in=cls.rheumd.codes,
                then=cls.rheumd.weight,
            ),
            When(present_conditions__code__in=cls.coag.codes, then=cls.coag.weight),
            When(present_conditions__code__in=cls.obes.codes, then=cls.obes.weight),
            When(
                present_conditions__code__in=cls.wloss.codes,
                then=cls.wloss.weight,
            ),
            When(present_conditions__code__in=cls.fed.codes, then=cls.fed.weight),
            When(
                present_conditions__code__in=cls.blane.codes,
                then=cls.blane.weight,
            ),
            When(present_conditions__code__in=cls.dane.codes, then=cls.dane.weight),
            When(
                present_conditions__code__in=cls.alcohol.codes,
                then=cls.alcohol.weight,
            ),
            When(present_conditions__code__in=cls.drug.codes, then=cls.drug.weight),
            When(
                present_conditions__code__in=cls.psycho.codes,
                then=cls.psycho.weight,
            ),
            When(
                present_conditions__code__in=cls.depre.codes,
                then=cls.depre.weight,
            ),
            default=0,
            output_field=models.FloatField(),
        )
    )

NciPanelDetails() dataclass

This class defines comorbidity categories and their associated ICD codes and weights for the NCI comorbidity panel. Each comorbidity is represented as a ComorbidityPanelCategory with a label, default ICD code, a list of ICD codes, and a weight.

References
  • C. N. Klabunde et al., Annals of Epidemiology, Volume 17, Issue 8, 2007, 584-590
  • Quan H et al., Medical Care 2005; 43(11):1130-1139.

acute_mi class-attribute instance-attribute

aids class-attribute instance-attribute

chf class-attribute instance-attribute

cpd class-attribute instance-attribute

cvd class-attribute instance-attribute

dementia class-attribute instance-attribute

diabates_complications class-attribute instance-attribute

diabetes class-attribute instance-attribute

history_mi class-attribute instance-attribute

liver_disease class-attribute instance-attribute

mild_liver_disease class-attribute instance-attribute

paralysis class-attribute instance-attribute

pvd class-attribute instance-attribute

renal_disease class-attribute instance-attribute

rheumatic_disease class-attribute instance-attribute

ulcers class-attribute instance-attribute

get_score_annotation() classmethod

Generates a Django ORM annotation that calculates the weighted comorbidity score for a queryset.

The score is computed by summing the weights of present comorbid conditions, based on their codes. Each condition is checked against its respective code list, and the corresponding weight is applied. Special handling is provided for diabetes and liver disease, where the weight depends on whether complications or severity are present.

Returns:

Name Type Description
Sum Sum

A Django ORM annotation representing the total comorbidity score as a float.

Source code in onconova/oncology/models/comorbidities.py
@classmethod
def get_score_annotation(cls) -> Sum:
    """
    Generates a Django ORM annotation that calculates the weighted comorbidity score for a queryset.

    The score is computed by summing the weights of present comorbid conditions, based on their codes.
    Each condition is checked against its respective code list, and the corresponding weight is applied.
    Special handling is provided for diabetes and liver disease, where the weight depends on whether
    complications or severity are present.

    Returns:
        Sum: A Django ORM annotation representing the total comorbidity score as a float.
    """
    return Sum(
        Case(
            When(
                present_conditions__code__in=cls.acute_mi.codes,
                then=cls.acute_mi.weight,
            ),
            When(
                present_conditions__code__in=cls.history_mi.codes,
                then=cls.history_mi.weight,
            ),
            When(present_conditions__code__in=cls.chf.codes, then=cls.chf.weight),
            When(present_conditions__code__in=cls.pvd.codes, then=cls.pvd.weight),
            When(present_conditions__code__in=cls.cvd.codes, then=cls.cvd.weight),
            When(
                present_conditions__code__in=cls.dementia.codes,
                then=cls.dementia.weight,
            ),
            When(
                present_conditions__code__in=cls.paralysis.codes,
                then=cls.paralysis.weight,
            ),
            When(
                present_conditions__code__in=cls.diabetes.codes
                + cls.diabates_complications.codes,
                then=Case(
                    When(
                        present_conditions__code__in=cls.diabetes.codes,
                        then=cls.diabetes.weight,
                    ),
                    When(
                        present_conditions__code__in=cls.diabates_complications.codes,
                        then=cls.diabates_complications.weight,
                    ),
                    default=0.0,
                ),
            ),
            When(
                present_conditions__code__in=cls.renal_disease.codes,
                then=cls.renal_disease.weight,
            ),
            When(
                present_conditions__code__in=cls.mild_liver_disease.codes
                + cls.liver_disease.codes,
                then=Case(
                    When(
                        present_conditions__code__in=cls.mild_liver_disease.codes,
                        then=cls.mild_liver_disease.weight,
                    ),
                    When(
                        present_conditions__code__in=cls.liver_disease.codes,
                        then=cls.liver_disease.weight,
                    ),
                    default=0.0,
                ),
            ),
            When(
                present_conditions__code__in=cls.ulcers.codes,
                then=cls.ulcers.weight,
            ),
            When(
                present_conditions__code__in=cls.rheumatic_disease.codes,
                then=cls.rheumatic_disease.weight,
            ),
            When(present_conditions__code__in=cls.aids.codes, then=cls.aids.weight),
            default=0.0,
            output_field=models.FloatField(),
        )
    )
runner