From 981ac77a05bb1021494872ab72f5c21b26672475 Mon Sep 17 00:00:00 2001 From: Gregory Trullemans Date: Wed, 11 Oct 2023 16:32:09 +0200 Subject: [PATCH] Re-Add Injury model --- jarvis/followup/admin.py | 62 ++++----- jarvis/followup/forms.py | 116 ++++++++--------- jarvis/followup/migrations/0057_injury.py | 146 ++++++++++++++++++++++ jarvis/followup/models.py | 127 +++++++++---------- jarvis/followup/views.py | 4 +- jarvis/people/views.py | 6 +- 6 files changed, 300 insertions(+), 161 deletions(-) create mode 100644 jarvis/followup/migrations/0057_injury.py diff --git a/jarvis/followup/admin.py b/jarvis/followup/admin.py index a482849..b5ea04c 100644 --- a/jarvis/followup/admin.py +++ b/jarvis/followup/admin.py @@ -11,13 +11,12 @@ from .models import ( Note, Point, Chrono, - # Injury, + Injury, WellBeing, Intensity, HeightWeight, LearnedSkill, ChronoDetails, - # InjuryLocation, GymnastHasRoutine, SeasonInformation, NumberOfRoutineDone, @@ -91,38 +90,32 @@ class PointAdmin(admin.ModelAdmin): autocomplete_fields = ("gymnast", "event") -# class InjuryLocationAdmin(admin.ModelAdmin): -# model = InjuryLocation +class InjuryAdmin(admin.ModelAdmin): + model = Injury -# list_display = ("label",) -# fields = ("label",) -# search_fields = ("label",) - - -# class InjuryAdmin(admin.ModelAdmin): -# model = Injury - -# fields = ( -# "date", -# "gymnast", -# "skill", -# "location", -# "body_side", -# "mechanism", -# "nb_week_off", -# "informations", -# ) # educative -# readonly_fields = ("season", "week_number", "created_at", "updated_at") -# list_display = ("date", "gymnast", "skill") # educative -# list_filter = ( -# ("gymnast", RelatedDropdownFilter), -# ("location", RelatedDropdownFilter), -# ("body_side", DropdownFilter), -# ("mechanism", DropdownFilter), -# ) -# date_hierarchy = "date" -# search_fields = ("date", "gymnast") # educative -# autocomplete_fields = ("gymnast", "skill") + fields = ( + "date", + "gymnast", + "skill", + "injury_type", + "location", + "body_side", + "mechanism", + "nb_week_off", + "informations", + ) # educative + # readonly_fields = ("season", "week_number", "created_at", "updated_at") + list_display = ("date", "gymnast", "skill") # educative + list_filter = ( + ("gymnast", RelatedDropdownFilter), + ("injury_type", DropdownFilter), + ("location", DropdownFilter), + ("body_side", DropdownFilter), + ("mechanism", DropdownFilter), + ) + date_hierarchy = "date" + search_fields = ("date", "gymnast") # educative + autocomplete_fields = ("gymnast", "skill") class WellBeingAdmin(admin.ModelAdmin): @@ -298,13 +291,12 @@ admin.site.register(Plan, PlanAdmin) admin.site.register(Note, NoteAdmin) admin.site.register(Point, PointAdmin) admin.site.register(Chrono, ChronoAdmin) -# admin.site.register(Injury, InjuryAdmin) +admin.site.register(Injury, InjuryAdmin) admin.site.register(WellBeing, WellBeingAdmin) admin.site.register(Intensity, IntensityAdmin) admin.site.register(LearnedSkill, LearnedSkillAdmin) admin.site.register(HeightWeight, HeightWeightAdmin) admin.site.register(ChronoDetails, ChronoDetailsAdmin) -# admin.site.register(InjuryLocation, InjuryLocationAdmin) admin.site.register(SeasonInformation, SeasonInformationAdmin) admin.site.register(GymnastHasRoutine, GymnastHasRoutineAdmin) admin.site.register(NumberOfRoutineDone, NumberOfRoutineDoneAdmin) diff --git a/jarvis/followup/forms.py b/jarvis/followup/forms.py index 855364c..79cfdd3 100644 --- a/jarvis/followup/forms.py +++ b/jarvis/followup/forms.py @@ -7,7 +7,7 @@ from .models import ( Note, Point, Chrono, - # Injury, + Injury, WellBeing, Intensity, HeightWeight, @@ -181,65 +181,65 @@ class ScoreForm(forms.ModelForm): ) -# class InjuryForm(forms.ModelForm): -# class Meta: -# model = Injury -# fields = ( -# "gymnast", -# "date", -# "mechanism", -# "injury_type", -# "location", -# "body_side", -# "nb_week_off", -# "informations", -# ) -# widgets = { -# "date": forms.DateInput( -# attrs={ -# "class": "form-control datepicker", -# "placeholder": date.today().strftime("%Y-%m-%d"), -# "value": date.today().strftime("%Y-%m-%d"), -# } -# ), -# "gymnast": forms.HiddenInput(), -# "skill": forms.HiddenInput(), -# "injury_type": forms.Select(attrs={"class": "form-control selectpicker"}), -# "mechanism": forms.Select(attrs={"class": "form-control selectpicker"}), -# "location": forms.Select(attrs={"class": "form-control selectpicker"}), -# "body_side": forms.Select(attrs={"class": "form-control selectpicker"}), -# "nb_week_off": forms.NumberInput( -# attrs={"class": "form-control", "placeholder": "xx"} -# ), -# "informations": forms.Textarea( -# attrs={ -# "class": "form-control", -# "placeholder": "Informations about injury: context (why, where, …), consequencies, re-education exercices, …", # pylint: disable=line-too-long -# } -# ), -# } +class InjuryForm(forms.ModelForm): + class Meta: + model = Injury + fields = ( + "gymnast", + "date", + "mechanism", + "injury_type", + "location", + "body_side", + "nb_week_off", + "informations", + ) + widgets = { + "date": forms.DateInput( + attrs={ + "class": "form-control datepicker", + "placeholder": date.today().strftime("%Y-%m-%d"), + "value": date.today().strftime("%Y-%m-%d"), + } + ), + "gymnast": forms.HiddenInput(), + "skill": forms.HiddenInput(), + "injury_type": forms.Select(attrs={"class": "form-control selectpicker"}), + "mechanism": forms.Select(attrs={"class": "form-control selectpicker"}), + "location": forms.Select(attrs={"class": "form-control selectpicker"}), + "body_side": forms.Select(attrs={"class": "form-control selectpicker"}), + "nb_week_off": forms.NumberInput( + attrs={"class": "form-control", "placeholder": "xx"} + ), + "informations": forms.Textarea( + attrs={ + "class": "form-control", + "placeholder": "Informations about injury: context (why, where, …), consequencies, re-education exercices, …", # pylint: disable=line-too-long + } + ), + } -# gymnast_related = forms.CharField( -# required=False, -# widget=forms.TextInput( -# attrs={ -# "class": "form-control", -# "placeholder": "Searching gymnast…", -# "data-ref": "#id_gymnast", -# } -# ), -# ) + gymnast_related = forms.CharField( + required=False, + widget=forms.TextInput( + attrs={ + "class": "form-control", + "placeholder": "Searching gymnast…", + "data-ref": "#id_gymnast", + } + ), + ) -# skill_related = forms.CharField( -# required=False, -# widget=forms.TextInput( -# attrs={ -# "class": "form-control", -# "placeholder": "Searching skill…", -# "data-ref": "#id_skill", -# } -# ), -# ) + skill_related = forms.CharField( + required=False, + widget=forms.TextInput( + attrs={ + "class": "form-control", + "placeholder": "Searching skill…", + "data-ref": "#id_skill", + } + ), + ) class WellBeingForm(forms.ModelForm): diff --git a/jarvis/followup/migrations/0057_injury.py b/jarvis/followup/migrations/0057_injury.py new file mode 100644 index 0000000..1296b38 --- /dev/null +++ b/jarvis/followup/migrations/0057_injury.py @@ -0,0 +1,146 @@ +# Generated by Django 4.2 on 2023-10-11 14:24 + +from django.db import migrations, models +import django.db.models.deletion +import jarvis.tools.models + + +class Migration(migrations.Migration): + + dependencies = [ + ("people", "0008_alter_gymnast_orientation"), + ("objective", "0016_routine_is_routine"), + ("followup", "0056_delete_injury_delete_injurylocation"), + ] + + operations = [ + migrations.CreateModel( + name="Injury", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "date", + models.DateField( + default=jarvis.tools.models.get_default_date, + verbose_name="Date", + ), + ), + ("season", models.CharField(editable=False, max_length=9)), + ("week_number", models.PositiveSmallIntegerField(editable=False)), + ( + "informations", + models.TextField( + blank=True, + help_text="Only MarkDown is authorized", + null=True, + verbose_name="Comments", + ), + ), + ( + "location", + models.SmallIntegerField( + choices=[ + (0, "Abdomen"), + (1, "Ankle"), + (2, "Elbow"), + (3, "Foot / Toe"), + (4, "Hand / Finger / Thumb"), + (5, "Head / Face"), + (6, "Hip / Groin"), + (7, "Knee"), + (8, "Low back / Sacrum / Pelvis"), + (9, "Lower Leg / Achilles Tendon"), + (10, "Neck / Cervical Spine"), + (11, "Shoulder / Clavicula"), + (12, "Sternum / Ribs / Upper back"), + (13, "Thigh"), + (14, "Upper arm"), + (15, "Wrist"), + ], + verbose_name="Injury type", + ), + ), + ( + "injury_type", + models.SmallIntegerField( + choices=[ + (0, "Abrasion"), + (1, "Dental Injury"), + (2, "Dislocation / Subluxation"), + (3, "Fracture"), + (4, "Haematoma / Contusion / Bruise"), + (5, "Head Concussion"), + (6, "Laceration"), + (7, "Lesion of Meniscus or Cartilage"), + (8, "Muscle Rupture /Strain / Tear / Cramps"), + (9, "Nerve Injury"), + (10, "Other Bone Injury"), + (11, "Sprain / Ligament Injury"), + (12, "Tendon Injury / Rupture / Tendinosis / Bursitis"), + ], + verbose_name="Injury type", + ), + ), + ( + "body_side", + models.PositiveSmallIntegerField( + choices=[ + (0, "Not Applicable"), + (1, "Left"), + (2, "Right"), + (3, "Both"), + ], + verbose_name="Body side", + ), + ), + ( + "mechanism", + models.PositiveSmallIntegerField( + choices=[(0, "Overuse"), (1, "Trauma")], + verbose_name="Injury mechanism", + ), + ), + ( + "nb_week_off", + models.SmallIntegerField( + blank=True, null=True, verbose_name="# week off" + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ("updated_at", models.DateTimeField(auto_now=True)), + ( + "gymnast", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="injuries", + to="people.gymnast", + verbose_name="Gymnast", + ), + ), + ( + "skill", + models.ForeignKey( + blank=True, + default=None, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="injuries", + to="objective.skill", + verbose_name="Skill", + ), + ), + ], + options={ + "verbose_name": "Injury", + "verbose_name_plural": "Injuries", + }, + ), + ] diff --git a/jarvis/followup/models.py b/jarvis/followup/models.py index 1c2ec06..e0ccc5c 100644 --- a/jarvis/followup/models.py +++ b/jarvis/followup/models.py @@ -39,6 +39,25 @@ INJURY_TYPE_CHOICE = ( (12, "Tendon Injury / Rupture / Tendinosis / Bursitis"), ) +INJURY_LOCATION_CHOICE = ( + (0, "Abdomen"), + (1, "Ankle"), + (2, "Elbow"), + (3, "Foot / Toe"), + (4, "Hand / Finger / Thumb"), + (5, "Head / Face"), + (6, "Hip / Groin"), + (7, "Knee"), + (8, "Low back / Sacrum / Pelvis"), + (9, "Lower Leg / Achilles Tendon"), + (10, "Neck / Cervical Spine"), + (11, "Shoulder / Clavicula"), + (12, "Sternum / Ribs / Upper back"), + (13, "Thigh"), + (14, "Upper arm"), + (15, "Wrist"), +) + ROUTINE_TYPE_CHOICE = ( (0, "Other"), (1, "Q1R1"), @@ -162,73 +181,55 @@ class ChronoDetails(models.Model): value = models.DecimalField(max_digits=5, decimal_places=3) -# class InjuryLocation(models.Model): -# """ -# Classe représentant les localisations de blessures -# """ +class Injury(Markdownizable, Seasonisable): + """ + La classe `Injury` permet d'indiquer qu'un gymnaste a eu un blessure, en liaison avec un + skill ou non. + """ -# class Meta: -# verbose_name = "Injury Location" -# verbose_name_plural = "Injury Locations" + class Meta: + verbose_name = "Injury" + verbose_name_plural = "Injuries" + # unique_together = ("gymnast", "skill", "date") -# label = models.CharField(max_length=100, null=False, blank=False) + gymnast = models.ForeignKey( + Gymnast, + verbose_name="Gymnast", + related_name="injuries", + on_delete=models.CASCADE, + ) + skill = models.ForeignKey( + "objective.Skill", + verbose_name="Skill", + related_name="injuries", + on_delete=models.SET_NULL, + default=None, + blank=True, + null=True, + ) + location = models.SmallIntegerField( + choices=INJURY_LOCATION_CHOICE, verbose_name="Location" + ) + injury_type = models.SmallIntegerField( + choices=INJURY_TYPE_CHOICE, verbose_name="Type" + ) + body_side = models.PositiveSmallIntegerField( + choices=INJURY_BODY_SIDE_CHOICE, verbose_name="Body side" + ) + mechanism = models.PositiveSmallIntegerField( + choices=INJURY_MECHANISM_CHOICE, verbose_name="Mechanism" + ) + nb_week_off = models.SmallIntegerField( + blank=True, null=True, verbose_name="# week off" + ) + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) -# def __str__(self): -# return f"{self.label}" + def __str__(self): + return f"{self.gymnast} ({self.date})" - -# class Injury(Markdownizable, Seasonisable): -# """ -# La classe `Injury` permet d'indiquer qu'un gymnaste a eu un blessure, en liaison avec un -# skill ou non. -# """ - -# class Meta: -# verbose_name = "Injury" -# verbose_name_plural = "Injuries" -# # unique_together = ("gymnast", "skill", "date") - -# gymnast = models.ForeignKey( -# Gymnast, -# verbose_name="Gymnast", -# related_name="injuries", -# on_delete=models.CASCADE, -# ) -# skill = models.ForeignKey( -# "objective.Skill", -# verbose_name="Skill", -# related_name="injuries", -# on_delete=models.SET_NULL, -# default=None, -# blank=True, -# null=True, -# ) -# location = models.ForeignKey( -# InjuryLocation, -# verbose_name="Location", -# related_name="injuries", -# on_delete=models.CASCADE, -# ) -# injury_type = models.SmallIntegerField( -# choices=INJURY_TYPE_CHOICE, verbose_name="Injury type" -# ) -# body_side = models.PositiveSmallIntegerField( -# choices=INJURY_BODY_SIDE_CHOICE, verbose_name="Body side" -# ) -# mechanism = models.PositiveSmallIntegerField( -# choices=INJURY_MECHANISM_CHOICE, verbose_name="Injury mechanism" -# ) -# nb_week_off = models.SmallIntegerField( -# blank=True, null=True, verbose_name="# week off" -# ) -# created_at = models.DateTimeField(auto_now_add=True) -# updated_at = models.DateTimeField(auto_now=True) - -# def __str__(self): -# return f"{self.gymnast} ({self.date})" - -# def timeline_representation(self): -# return f"
  • {self.date:%d %b %Y} - Accident ({self.skill}): {self.nb_week_off} (weeks off)
  • " + def timeline_representation(self): + return f"
  • {self.date:%d %b %Y} - Accident ({self.skill}): {self.nb_week_off} (weeks off)
  • " class LearnedSkill(Seasonisable): diff --git a/jarvis/followup/views.py b/jarvis/followup/views.py index e485ff2..68ffbcb 100644 --- a/jarvis/followup/views.py +++ b/jarvis/followup/views.py @@ -19,7 +19,7 @@ from .models import ( Note, Point, Chrono, - # Injury, + Injury, WellBeing, Intensity, LearnedSkill, @@ -35,7 +35,7 @@ from .forms import ( NoteForm, ScoreForm, ChronoForm, - # InjuryForm, + InjuryForm, WellBeingForm, IntensityForm, HeightWeightForm, diff --git a/jarvis/people/views.py b/jarvis/people/views.py index 60dec2b..4eb7339 100644 --- a/jarvis/people/views.py +++ b/jarvis/people/views.py @@ -35,7 +35,7 @@ from jarvis.followup.models import ( Skill, Point, Chrono, - # Injury, + Injury, WellBeing, Intensity, LearnedSkill, @@ -287,7 +287,7 @@ def gymnast_display_injury(request, gymnast_id): Args: gymnast_id (int) identifiant du gymnast """ - injuries_list = None # Injury.objects.filter(gymnast=gymnast_id) + injuries_list = Injury.objects.filter(gymnast=gymnast_id) context = {"injuries_list": injuries_list, "gymnast_id": gymnast_id} return render(request, "gymnasts/list_injury.html", context) @@ -301,7 +301,7 @@ def gymnast_display_physiological(request, gymnast_id): Args: gymnast_id (int) identifiant du gymnast """ - injuries_list = None # Injury.objects.filter(gymnast=gymnast_id).order_by("date") + injuries_list = Injury.objects.filter(gymnast=gymnast_id).order_by("date") wellbeing_list = WellBeing.objects.filter(gymnast=gymnast_id).order_by("date") height_weight_list = HeightWeight.objects.filter(gymnast=gymnast_id).order_by( "date"