Skip to content

Commit

Permalink
Convert enum choices to integer choices in Daily Rounds (#2462)
Browse files Browse the repository at this point in the history
Convert enum choices to integer choices in Daily Rounds (#2462)
  • Loading branch information
DraKen0009 authored Sep 19, 2024
1 parent 28e2ac0 commit d5a2278
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 124 deletions.
26 changes: 13 additions & 13 deletions care/facility/api/serializers/daily_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DailyRoundSerializer(serializers.ModelSerializer):

taken_at = serializers.DateTimeField(required=True)

rounds_type = ChoiceField(choices=DailyRound.RoundsTypeChoice, required=True)
rounds_type = ChoiceField(choices=DailyRound.RoundsType.choices, required=True)

# Community Nurse's Log

Expand All @@ -65,38 +65,38 @@ class DailyRoundSerializer(serializers.ModelSerializer):
# Critical Care Components

consciousness_level = ChoiceField(
choices=DailyRound.ConsciousnessChoice, required=False
choices=DailyRound.ConsciousnessTypeChoice.choices, required=False
)
left_pupil_light_reaction = ChoiceField(
choices=DailyRound.PupilReactionChoice, required=False
choices=DailyRound.PupilReactionType.choices, required=False
)
right_pupil_light_reaction = ChoiceField(
choices=DailyRound.PupilReactionChoice, required=False
choices=DailyRound.PupilReactionType.choices, required=False
)
limb_response_upper_extremity_right = ChoiceField(
choices=DailyRound.LimbResponseChoice, required=False
choices=DailyRound.LimbResponseType.choices, required=False
)
limb_response_upper_extremity_left = ChoiceField(
choices=DailyRound.LimbResponseChoice, required=False
choices=DailyRound.LimbResponseType.choices, required=False
)
limb_response_lower_extremity_left = ChoiceField(
choices=DailyRound.LimbResponseChoice, required=False
choices=DailyRound.LimbResponseType.choices, required=False
)
limb_response_lower_extremity_right = ChoiceField(
choices=DailyRound.LimbResponseChoice, required=False
choices=DailyRound.LimbResponseType.choices, required=False
)
rhythm = ChoiceField(choices=DailyRound.RythmnChoice, required=False)
rhythm = ChoiceField(choices=DailyRound.RythmnType.choices, required=False)
ventilator_interface = ChoiceField(
choices=DailyRound.VentilatorInterfaceChoice, required=False
choices=DailyRound.VentilatorInterfaceType.choices, required=False
)
ventilator_mode = ChoiceField(
choices=DailyRound.VentilatorModeChoice, required=False
choices=DailyRound.VentilatorModeType.choices, required=False
)
ventilator_oxygen_modality = ChoiceField(
choices=DailyRound.VentilatorOxygenModalityChoice, required=False
choices=DailyRound.VentilatorOxygenModalityType.choices, required=False
)
insulin_intake_frequency = ChoiceField(
choices=DailyRound.InsulinIntakeFrequencyChoice, required=False
choices=DailyRound.InsulinIntakeFrequencyType.choices, required=False
)

last_edited_by = UserBaseMinimumSerializer(read_only=True)
Expand Down
4 changes: 2 additions & 2 deletions care/facility/api/viewsets/daily_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class DailyRoundFilterSet(filters.FilterSet):

def filter_rounds_type(self, queryset, name, value):
rounds_type = set()
values = value.split(",")
values = value.upper().split(",")
for v in values:
try:
rounds_type.add(DailyRound.RoundsTypeDict[v])
rounds_type.add(DailyRound.RoundsType[v].value)
except KeyError:
pass
return queryset.filter(rounds_type__in=list(rounds_type))
Expand Down
5 changes: 3 additions & 2 deletions care/facility/api/viewsets/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
REVERSE_FACILITY_TYPES = covert_choice_dict(FACILITY_TYPES)
REVERSE_BED_TYPES = covert_choice_dict(BedTypeChoices)
DISCHARGE_REASONS = [choice[0] for choice in DISCHARGE_REASON_CHOICES]
VENTILATOR_CHOICES = covert_choice_dict(DailyRound.VentilatorInterfaceChoice)


class PatientFilterSet(filters.FilterSet):
Expand Down Expand Up @@ -220,7 +219,9 @@ def filter_by_bed_type(self, queryset, name, value):
)
ventilator_interface = CareChoiceFilter(
field_name="last_consultation__last_daily_round__ventilator_interface",
choice_dict=VENTILATOR_CHOICES,
choice_dict={
label: value for value, label in DailyRound.VentilatorInterfaceType.choices
},
)

# Vaccination Filters
Expand Down
188 changes: 81 additions & 107 deletions care/facility/models/daily_round.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import enum

from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.db.models import JSONField
Expand All @@ -10,7 +8,6 @@
COVID_CATEGORY_CHOICES,
PatientBaseModel,
)
from care.facility.models.base import covert_choice_dict
from care.facility.models.bed import AssetBed
from care.facility.models.json_schema.daily_round import (
BLOOD_PRESSURE,
Expand All @@ -29,28 +26,23 @@


class DailyRound(PatientBaseModel):
class RoundsType(enum.Enum):
NORMAL = 0
COMMUNITY_NURSES_LOG = 30
DOCTORS_LOG = 50
VENTILATOR = 100
ICU = 200
AUTOMATED = 300
TELEMEDICINE = 400

RoundsTypeChoice = [(e.value, e.name) for e in RoundsType]
RoundsTypeDict = covert_choice_dict(RoundsTypeChoice)

class ConsciousnessType(enum.Enum):
UNKNOWN = 0
ALERT = 5
RESPONDS_TO_VOICE = 10
RESPONDS_TO_PAIN = 15
UNRESPONSIVE = 20
AGITATED_OR_CONFUSED = 25
ONSET_OF_AGITATION_AND_CONFUSION = 30

ConsciousnessChoice = [(e.value, e.name) for e in ConsciousnessType]
class RoundsType(models.IntegerChoices):
NORMAL = 0, "NORMAL"
COMMUNITY_NURSES_LOG = 30, "COMMUNITY_NURSES_LOG"
DOCTORS_LOG = 50, "DOCTORS_LOG"
VENTILATOR = 100, "VENTILATOR"
ICU = 200, "ICU"
AUTOMATED = 300, "AUTOMATED"
TELEMEDICINE = 400, "TELEMEDICINE"

class ConsciousnessTypeChoice(models.IntegerChoices):
UNKNOWN = 0, "UNKNOWN"
ALERT = 5, "ALERT"
RESPONDS_TO_VOICE = 10, "RESPONDS_TO_VOICE"
RESPONDS_TO_PAIN = 15, "RESPONDS_TO_PAIN"
UNRESPONSIVE = 20, "UNRESPONSIVE"
AGITATED_OR_CONFUSED = 25, "AGITATED_OR_CONFUSED"
ONSET_OF_AGITATION_AND_CONFUSION = 30, "ONSET_OF_AGITATION_AND_CONFUSION"

class BowelDifficultyType(models.IntegerChoices):
NO_DIFFICULTY = 0, "NO_DIFFICULTY"
Expand Down Expand Up @@ -103,75 +95,57 @@ class AppetiteType(models.IntegerChoices):
NO_TASTE_FOR_FOOD = 4, "NO_TASTE_FOR_FOOD"
CANNOT_BE_ASSESSED = 5, "CANNOT_BE_ASSESSED"

class PupilReactionType(enum.Enum):
UNKNOWN = 0
BRISK = 5
SLUGGISH = 10
FIXED = 15
CANNOT_BE_ASSESSED = 20

PupilReactionChoice = [(e.value, e.name) for e in PupilReactionType]

class LimbResponseType(enum.Enum):
UNKNOWN = 0
STRONG = 5
MODERATE = 10
WEAK = 15
FLEXION = 20
EXTENSION = 25
NONE = 30

LimbResponseChoice = [(e.value, e.name) for e in LimbResponseType]

class RythmnType(enum.Enum):
UNKNOWN = 0
REGULAR = 5
IRREGULAR = 10

RythmnChoice = [(e.value, e.name) for e in RythmnType]

class VentilatorInterfaceType(enum.Enum):
UNKNOWN = 0
INVASIVE = 5
NON_INVASIVE = 10
OXYGEN_SUPPORT = 15

VentilatorInterfaceChoice = [(e.value, e.name) for e in VentilatorInterfaceType]

class VentilatorModeType(enum.Enum):
UNKNOWN = 0
VCV = 5
PCV = 10
PRVC = 15
APRV = 20
VC_SIMV = 25
PC_SIMV = 30
PRVC_SIMV = 40
ASV = 45
PSV = 50

VentilatorModeChoice = [(e.value, e.name) for e in VentilatorModeType]

class VentilatorOxygenModalityType(enum.Enum):
UNKNOWN = 0
NASAL_PRONGS = 5
SIMPLE_FACE_MASK = 10
NON_REBREATHING_MASK = 15
HIGH_FLOW_NASAL_CANNULA = 20

VentilatorOxygenModalityChoice = [
(e.value, e.name) for e in VentilatorOxygenModalityType
]

class InsulinIntakeFrequencyType(enum.Enum):
UNKNOWN = 0
OD = 5
BD = 10
TD = 15

InsulinIntakeFrequencyChoice = [
(e.value, e.name) for e in InsulinIntakeFrequencyType
]
class PupilReactionType(models.IntegerChoices):
UNKNOWN = 0, "UNKNOWN"
BRISK = 5, "BRISK"
SLUGGISH = 10, "SLUGGISH"
FIXED = 15, "FIXED"
CANNOT_BE_ASSESSED = 20, "CANNOT_BE_ASSESSED"

class LimbResponseType(models.IntegerChoices):
UNKNOWN = 0, "UNKNOWN"
STRONG = 5, "STRONG"
MODERATE = 10, "MODERATE"
WEAK = 15, "WEAK"
FLEXION = 20, "FLEXION"
EXTENSION = 25, "EXTENSION"
NONE = 30, "NONE"

class RythmnType(models.IntegerChoices):
UNKNOWN = 0, "UNKNOWN"
REGULAR = 5, "REGULAR"
IRREGULAR = 10, "IRREGULAR"

class VentilatorInterfaceType(models.IntegerChoices):
UNKNOWN = 0, "UNKNOWN"
INVASIVE = 5, "INVASIVE"
NON_INVASIVE = 10, "NON_INVASIVE"
OXYGEN_SUPPORT = 15, "OXYGEN_SUPPORT"

class VentilatorModeType(models.IntegerChoices):
UNKNOWN = 0, "UNKNOWN"
VCV = 5, "VCV"
PCV = 10, "PCV"
PRVC = 15, "PRVC"
APRV = 20, "APRV"
VC_SIMV = 25, "VC_SIMV"
PC_SIMV = 30, "PC_SIMV"
PRVC_SIMV = 40, "PRVC_SIMV"
ASV = 45, "ASV"
PSV = 50, "PSV"

class VentilatorOxygenModalityType(models.IntegerChoices):
UNKNOWN = 0, "UNKNOWN"
NASAL_PRONGS = 5, "NASAL_PRONGS"
SIMPLE_FACE_MASK = 10, "SIMPLE_FACE_MASK"
NON_REBREATHING_MASK = 15, "NON_REBREATHING_MASK"
HIGH_FLOW_NASAL_CANNULA = 20, "HIGH_FLOW_NASAL_CANNULA"

class InsulinIntakeFrequencyType(models.IntegerChoices):
UNKNOWN = 0, "UNKNOWN"
OD = 5, "OD"
BD = 10, "BD"
TD = 15, "TD"

consultation = models.ForeignKey(
PatientConsultation,
Expand Down Expand Up @@ -223,7 +197,7 @@ class InsulinIntakeFrequencyType(enum.Enum):
taken_at = models.DateTimeField(null=True, blank=True, db_index=True)

rounds_type = models.IntegerField(
choices=RoundsTypeChoice, default=RoundsType.NORMAL.value
choices=RoundsType.choices, default=RoundsType.NORMAL.value
)
is_parsed_by_ocr = models.BooleanField(default=False)

Expand Down Expand Up @@ -258,7 +232,7 @@ class InsulinIntakeFrequencyType(enum.Enum):
# Critical Care Attributes

consciousness_level = models.IntegerField(
choices=ConsciousnessChoice, default=None, null=True
choices=ConsciousnessTypeChoice.choices, default=None, null=True
)
consciousness_level_detail = models.TextField(default=None, null=True, blank=True)

Expand All @@ -272,7 +246,7 @@ class InsulinIntakeFrequencyType(enum.Enum):
)
left_pupil_size_detail = models.TextField(default=None, null=True, blank=True)
left_pupil_light_reaction = models.IntegerField(
choices=PupilReactionChoice, default=None, null=True
choices=PupilReactionType.choices, default=None, null=True
)
left_pupil_light_reaction_detail = models.TextField(
default=None, null=True, blank=True
Expand All @@ -285,7 +259,7 @@ class InsulinIntakeFrequencyType(enum.Enum):
)
right_pupil_size_detail = models.TextField(default=None, null=True, blank=True)
right_pupil_light_reaction = models.IntegerField(
choices=PupilReactionChoice, default=None, null=True
choices=PupilReactionType.choices, default=None, null=True
)
right_pupil_light_reaction_detail = models.TextField(
default=None, null=True, blank=True
Expand All @@ -311,16 +285,16 @@ class InsulinIntakeFrequencyType(enum.Enum):
validators=[MinValueValidator(3), MaxValueValidator(15)],
)
limb_response_upper_extremity_right = models.IntegerField(
choices=LimbResponseChoice, default=None, null=True
choices=LimbResponseType.choices, default=None, null=True
)
limb_response_upper_extremity_left = models.IntegerField(
choices=LimbResponseChoice, default=None, null=True
choices=LimbResponseType.choices, default=None, null=True
)
limb_response_lower_extremity_left = models.IntegerField(
choices=LimbResponseChoice, default=None, null=True
choices=LimbResponseType.choices, default=None, null=True
)
limb_response_lower_extremity_right = models.IntegerField(
choices=LimbResponseChoice, default=None, null=True
choices=LimbResponseType.choices, default=None, null=True
)
bp = JSONField(default=dict, validators=[JSONFieldSchemaValidator(BLOOD_PRESSURE)])
pulse = models.IntegerField(
Expand All @@ -333,15 +307,15 @@ class InsulinIntakeFrequencyType(enum.Enum):
null=True,
validators=[MinValueValidator(0), MaxValueValidator(150)],
)
rhythm = models.IntegerField(choices=RythmnChoice, default=None, null=True)
rhythm = models.IntegerField(choices=RythmnType.choices, default=None, null=True)
rhythm_detail = models.TextField(default=None, null=True, blank=True)
ventilator_interface = models.IntegerField(
choices=VentilatorInterfaceChoice,
choices=VentilatorInterfaceType.choices,
default=None,
null=True,
)
ventilator_mode = models.IntegerField(
choices=VentilatorModeChoice, default=None, null=True
choices=VentilatorModeType.choices, default=None, null=True
)
ventilator_peep = models.DecimalField(
decimal_places=2,
Expand Down Expand Up @@ -377,7 +351,7 @@ class InsulinIntakeFrequencyType(enum.Enum):
validators=[MinValueValidator(0), MaxValueValidator(1000)],
)
ventilator_oxygen_modality = models.IntegerField(
choices=VentilatorOxygenModalityChoice, default=None, null=True
choices=VentilatorOxygenModalityType.choices, default=None, null=True
)
ventilator_oxygen_modality_oxygen_rate = models.IntegerField(
default=None,
Expand Down Expand Up @@ -483,7 +457,7 @@ class InsulinIntakeFrequencyType(enum.Enum):
validators=[MinValueValidator(0), MaxValueValidator(100)],
)
insulin_intake_frequency = models.IntegerField(
choices=InsulinIntakeFrequencyChoice,
choices=InsulinIntakeFrequencyType.choices,
default=None,
null=True,
)
Expand Down

0 comments on commit d5a2278

Please sign in to comment.