update conditions

This commit is contained in:
Ross
2023-12-04 11:02:23 +00:00
parent 4d3014b489
commit f346a69bb5
6 changed files with 110 additions and 40 deletions
@@ -0,0 +1,67 @@
# Generated by Django 4.1.4 on 2023-12-04 11:01
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("atlas", "0029_alter_conditionrelationship_child_and_more"),
]
operations = [
migrations.AlterField(
model_name="condition",
name="parent",
field=models.ManyToManyField(
blank=True,
help_text="Use if the condition could be considered a subset of another, e.g. 'Alzheimer disease' and 'Dementia'.",
related_name="child",
through="atlas.ConditionRelationship",
to="atlas.condition",
),
),
migrations.AlterField(
model_name="condition",
name="primary",
field=models.BooleanField(
default="True",
help_text="Sets if this should be the canonical item, all other synonyms will then redirect to this by default.",
),
),
migrations.AlterField(
model_name="condition",
name="rcr_curriculum",
field=models.BooleanField(
default=False,
help_text="The condition is from the (non exhaustive) RCR curriculum",
),
),
migrations.AlterField(
model_name="condition",
name="rcr_curriculum_map",
field=models.ManyToManyField(
blank=True,
help_text="Specifies the related RCR curriculum condition (if it exists).",
limit_choices_to={"rcr_curriculum": True},
to="atlas.condition",
),
),
migrations.AlterField(
model_name="condition",
name="subspecialty",
field=models.ManyToManyField(
blank=True,
help_text="Sets the subspecialty(/ies) that this condition falls under.",
to="atlas.subspecialty",
),
),
migrations.AlterField(
model_name="condition",
name="synonym",
field=models.ManyToManyField(
blank=True,
help_text="Use if a direct synonym for the condition exists, e.g. 'Wegener granulomatosis' and 'Granulomatosis with Polyangitis'.",
to="atlas.condition",
),
),
]
+6 -6
View File
@@ -143,16 +143,16 @@ class Finding(SynMixin, models.Model):
class Condition(SynMixin, models.Model):
name = models.CharField(max_length=255, unique=True)
synonym = models.ManyToManyField("self", blank=True)
parent = models.ManyToManyField("self", blank=True, related_name="child", symmetrical=False, through="ConditionRelationship")
synonym = models.ManyToManyField("self", blank=True, help_text="Use if a direct synonym for the condition exists, e.g. 'Wegener granulomatosis' and 'Granulomatosis with Polyangitis'.")
parent = models.ManyToManyField("self", blank=True, related_name="child", symmetrical=False, through="ConditionRelationship", help_text="Use if the condition could be considered a subset of another, e.g. 'Alzheimer disease' and 'Dementia'.")
primary = models.BooleanField(default="True")
primary = models.BooleanField(default="True", help_text="Sets if this should be the canonical item, all other synonyms will then redirect to this by default.")
subspecialty = models.ManyToManyField("subspecialty", blank=True)
subspecialty = models.ManyToManyField("subspecialty", blank=True, help_text="Sets the subspecialty(/ies) that this condition falls under.")
rcr_curriculum_map = models.ManyToManyField("self", blank=True, limit_choices_to={"rcr_curriculum": True})
rcr_curriculum_map = models.ManyToManyField("self", blank=True, limit_choices_to={"rcr_curriculum": True}, help_text="Specifies the related RCR curriculum condition (if it exists).")
rcr_curriculum = models.BooleanField(default=False)
rcr_curriculum = models.BooleanField(default=False, help_text="The condition is from the (non exhaustive) RCR curriculum")
def get_absolute_url(self):
return reverse("atlas:condition_detail", kwargs={"pk": self.pk})
@@ -1,6 +1,8 @@
{% extends 'atlas/base.html' %}
{% block content %}
<h1>Categories</h1>
<p>The platform has numberous different ways to tag and categorise content. These help with organsing cases and series, given the ability to find cases by a particuarly property (such as a finding) or find similar cases.</p><p>These can be browsed below.</p>
<ul>
<li><a href="{% url 'atlas:condition_view' %}">Conditions</a></li>
<li><a href="{% url 'atlas:finding_view' %}">Findings</a></li>
+1 -2
View File
@@ -63,8 +63,7 @@
{% endif %}
{% if not condition.rcr_curriculum %}
{% if not condition.rcr_curriculum and can_merge %}
<details><summary>Merge</summary>
Merge this condition into another. This will transfer all associated cases (and differential) but will not transfer synonymns / parents or children.
+2 -1
View File
@@ -14,7 +14,8 @@
{% endblock %}
{% block content %}
<h2>Add/Edit Condition</h2>
Use this form to create or edit a condition.
<p>Use this form to create or edit a condition.</p>
<p>Please check if it already exists before doing so!</p>
<form action="" method="post" enctype="multipart/form-data" id="condition-form">
{% csrf_token %}
+32 -31
View File
@@ -187,29 +187,33 @@ def series_detail(request, pk, finding_pk=None):
@login_required
@user_is_atlas_editor
#@user_is_atlas_editor
def condition_detail(request, pk):
condition = get_object_or_404(Condition, pk=pk)
form = ConditionAutocompleteForm()
can_merge = False
if request.user.is_superuser or request.user.groups.filter(name="atlas_editor").exists():
can_merge = True
# logging.debug(atlas.subspecialty.first().name.all())
return render(
request,
"atlas/condition_detail.html",
{
"condition": condition,
"form": form
},
{"condition": condition, "form": form, "can_merge": can_merge},
)
#class GetConditionAutocomplete(HTMXAutoComplete):
# class GetConditionAutocomplete(HTMXAutoComplete):
# name = "conditions"
# multiselect = False
#
# class Meta:
# model = Condition
@login_required
@user_is_atlas_editor
def condition_merge(request, pk_to_merge):
@@ -217,7 +221,7 @@ def condition_merge(request, pk_to_merge):
raise Http404
condition_to_merge = get_object_or_404(Condition, pk=pk_to_merge)
#condition_to_merge_into = get_object_or_404(Condition, pk=pk_to_merge_into)
# condition_to_merge_into = get_object_or_404(Condition, pk=pk_to_merge_into)
print(condition_to_merge.case_set)
if condition_to_merge.rcr_curriculum:
@@ -233,26 +237,24 @@ def condition_merge(request, pk_to_merge):
if condition_to_merge == condition_to_merge_into:
return HttpResponse("You cannot merge into the same condition.")
# move all relevant relationships
cases = condition_to_merge.case_set.all().values_list("id", flat=True)
condition_to_merge_into.case_set.add(cases)
#cases = Case.objects.filter(condition=condition_to_merge)
#cases.update(condition=condition_to_merge_into)
# cases = Case.objects.filter(condition=condition_to_merge)
# cases.update(condition=condition_to_merge_into)
differentials = Differential.objects.filter(condition=condition_to_merge)
differentials.update(condition=condition_to_merge_into)
return HttpResponse("Merged")
#conditions = Condition.objects.all()
#return render(request, "atlas/condition_options.html", {"conditions": conditions})
# conditions = Condition.objects.all()
# return render(request, "atlas/condition_options.html", {"conditions": conditions})
@login_required
@user_is_atlas_editor
#@user_is_atlas_editor
def subspecialty_detail(request, pk):
subspecialty = get_object_or_404(Subspecialty, pk=pk)
@@ -267,7 +269,7 @@ def subspecialty_detail(request, pk):
@login_required
@user_is_atlas_editor
#@user_is_atlas_editor
def presentation_detail(request, pk):
presentation = get_object_or_404(Presentation, pk=pk)
@@ -282,7 +284,7 @@ def presentation_detail(request, pk):
@login_required
@user_is_atlas_editor
#@user_is_atlas_editor
def pathological_process_detail(request, pk):
pathological_process = get_object_or_404(PathologicalProcess, pk=pk)
@@ -297,7 +299,7 @@ def pathological_process_detail(request, pk):
@login_required
@user_is_atlas_editor
#@user_is_atlas_editor
def structure_detail(request, pk):
structure = get_object_or_404(Structure, pk=pk)
@@ -312,7 +314,7 @@ def structure_detail(request, pk):
@login_required
@user_is_atlas_editor
#@user_is_atlas_editor
def finding_detail(request, pk):
finding = get_object_or_404(Finding, pk=pk)
@@ -356,9 +358,9 @@ def user_collections(request):
return render(request, "atlas/user_collections.html", {"collections": collections})
@login_required
def user_uploads_series(request, series_instance_uid: str):
# We don't restrict to teh uploading user here. Should we?
dicoms = UncategorisedDicom.objects.filter(series_instance_uid=series_instance_uid)
@@ -366,9 +368,10 @@ def user_uploads_series(request, series_instance_uid: str):
raise Http404("Series not found")
return render(
request, "atlas/user_upload_viewer.html", {"dicoms": dicoms, "series_id": series_instance_uid}
request,
"atlas/user_upload_viewer.html",
{"dicoms": dicoms, "series_id": series_instance_uid},
)
@login_required
@@ -655,9 +658,7 @@ class SeriesUpdate(
return super().form_invalid(form)
class ConditionUpdate(
RevisionMixin, LoginRequiredMixin, AuthorOrCheckerRequiredMixin, UpdateView
):
class ConditionUpdate(RevisionMixin, LoginRequiredMixin, UpdateView):
model = Condition
form_class = ConditionForm
@@ -667,9 +668,7 @@ class ConditionCreate(RevisionMixin, LoginRequiredMixin, CreateView):
form_class = ConditionForm
class FindingUpdate(
RevisionMixin, LoginRequiredMixin, AuthorOrCheckerRequiredMixin, UpdateView
):
class FindingUpdate(RevisionMixin, LoginRequiredMixin, UpdateView):
model = Finding
form_class = FindingForm
@@ -679,9 +678,7 @@ class FindingCreate(RevisionMixin, LoginRequiredMixin, CreateView):
form_class = FindingForm
class StructureUpdate(
RevisionMixin, LoginRequiredMixin, AuthorOrCheckerRequiredMixin, UpdateView
):
class StructureUpdate(RevisionMixin, LoginRequiredMixin, UpdateView):
model = Structure
form_class = StructureForm
@@ -995,12 +992,14 @@ def series_order_dicom(request, pk):
return redirect("atlas:series_detail", pk=pk)
@login_required
def series_image_dicom(request, pk):
image = get_object_or_404(SeriesImage, pk=pk)
return render(request, "atlas/series_image_dicom.html", {"image": image})
@login_required
@user_is_author_or_atlas_series_checker
def series_anonymise_dicom(request, pk):
@@ -1114,6 +1113,7 @@ class ConditionAutocomplete(autocomplete.Select2QuerySetView):
return qs
class ConditionAutocompleteRCRCurriculum(autocomplete.Select2QuerySetView):
def get_queryset(self):
# Don't forget to filter out results depending on the visitor !
@@ -1131,6 +1131,7 @@ class ConditionAutocompleteRCRCurriculum(autocomplete.Select2QuerySetView):
return qs
class PresentationAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
# Don't forget to filter out results depending on the visitor !
@@ -1186,7 +1187,7 @@ class StructureAutocomplete(autocomplete.Select2QuerySetView):
@login_required
@user_is_atlas_editor
# @user_is_atlas_editor
def categories_list(request):
# condition = get_object_or_404(Condition, pk=pk)