diff --git a/atlas/forms.py b/atlas/forms.py index d0d13c5d..01e50c99 100755 --- a/atlas/forms.py +++ b/atlas/forms.py @@ -8,7 +8,7 @@ from django.forms import ( ) from django.forms import inlineformset_factory -from atlas.models import Case, Series, SeriesImage, SeriesFinding +from atlas.models import Case, Differential, Series, SeriesImage, SeriesFinding from anatomy.models import Modality @@ -21,6 +21,7 @@ from django.forms.widgets import RadioSelect, TextInput, Textarea from tinymce.widgets import TinyMCE +from dal import autocomplete class ExaminationForm(ModelForm): class Meta: @@ -173,6 +174,7 @@ class CaseForm(ModelForm): # "mark_scheme": TinyMCE(attrs={"cols": 80, "rows": 30}), "description": Textarea(attrs={"cols": 80, "rows": 5}), "history": Textarea(attrs={"cols": 80, "rows": 5}), + "condition" : autocomplete.ModelSelect2(url='atlas:condition-autocomplete') } def save(self, commit=True): @@ -198,6 +200,14 @@ class CaseForm(ModelForm): return instance +CaseDifferentialFormSet = inlineformset_factory( + Case, + Differential, + exclude=[], + can_delete=True, + extra=0, + max_num=10, +) SeriesFormSet = inlineformset_factory( Case, diff --git a/atlas/models.py b/atlas/models.py index 98d33e43..2678c3e0 100644 --- a/atlas/models.py +++ b/atlas/models.py @@ -90,14 +90,14 @@ class SynMixin(object): class Finding(SynMixin, models.Model): - name = models.CharField(max_length=255) + name = models.CharField(max_length=255, unique=True) synonym = models.ManyToManyField("self", blank=True) primary_name = models.BooleanField(default="True") class Condition(SynMixin, models.Model): - name = models.CharField(max_length=255) + name = models.CharField(max_length=255, unique=True) synonym = models.ManyToManyField("self", blank=True) @@ -114,15 +114,22 @@ class Subspecialty(models.Model): class Differential(models.Model): - condition = models.ForeignKey( - Condition, on_delete=models.CASCADE - ) + condition = models.ForeignKey(Condition, on_delete=models.CASCADE) case = models.ForeignKey( "Case", on_delete=models.CASCADE, related_name="differentialcase" ) text = models.TextField(null=True, blank=True) +class Structure(SynMixin, models.Model): + structure = models.CharField(max_length=255, unique=True) + + synonym = models.ManyToManyField("self", blank=True) + + primary_name = models.BooleanField(default="True") + + + @reversion.register class Case(models.Model): # class SubspecialtyChoices(models.TextChoices): @@ -156,7 +163,9 @@ class Case(models.Model): condition = models.ManyToManyField(Condition, blank=True) - differential = models.ManyToManyField(Condition, through=Differential, related_name="casedifferential") + differential = models.ManyToManyField( + Condition, through=Differential, related_name="casedifferential" + ) sign = tagulous.models.TagField( to=Sign, blank=True, help_text="Radiological signs in the question" @@ -232,6 +241,7 @@ class SeriesFinding(models.Model): null=True, blank=True, help_text="Findings on the series / stack" ) findings = models.ManyToManyField(Finding, blank=True) + structures = models.ManyToManyField(Structure, blank=True) annotation_json = models.TextField(null=True, blank=True) viewport_json = models.TextField(null=True, blank=True) diff --git a/atlas/templates/atlas/case_form.html b/atlas/templates/atlas/case_form.html index 9e382aff..a6804023 100755 --- a/atlas/templates/atlas/case_form.html +++ b/atlas/templates/atlas/case_form.html @@ -42,7 +42,7 @@ {% endblock %} {% block content %} -