diff --git a/atlas/templates/atlas/_categories_search_results.html b/atlas/templates/atlas/_categories_search_results.html new file mode 100644 index 00000000..29cb585f --- /dev/null +++ b/atlas/templates/atlas/_categories_search_results.html @@ -0,0 +1,34 @@ +
+
+
Search results for "{{ query }}"
+ + {% for group_name, items in results.items %} + {% if items.exists %} +
{{ group_name|capfirst }}
+ + {% endif %} + {% endfor %} + + {% if not results.conditions.exists and not results.findings.exists and not results.structures.exists and not results.subspecialties.exists and not results.presentations.exists %} +

No matches found.

+ {% endif %} +
+
diff --git a/atlas/templates/atlas/categories_list.html b/atlas/templates/atlas/categories_list.html index c3338a27..f3e4cabb 100644 --- a/atlas/templates/atlas/categories_list.html +++ b/atlas/templates/atlas/categories_list.html @@ -12,6 +12,24 @@
  • Pathological Process
  • +
    +
    + + +
    +
    + +
    + {% if results is not None %} + {% include 'atlas/_categories_search_results.html' %} + {% endif %} +
    + {% if request.user.is_staff %}

    Manage Examinations

    diff --git a/atlas/urls.py b/atlas/urls.py index 66b59ce5..5606d170 100755 --- a/atlas/urls.py +++ b/atlas/urls.py @@ -347,6 +347,7 @@ urlpatterns = [ path("question_schema/schemas", views.question_schema_schemas, name="question_schema_schemas"), path("condition/", views.ConditionView.as_view(), name="condition_view"), path("categories/", views.categories_list, name="categories_list"), + path("categories/search_partial/", views.categories_search_partial, name="categories_search_partial"), path("condition/", views.condition_detail, name="condition_detail"), path( "condition//delete", diff --git a/atlas/views.py b/atlas/views.py index 55e26257..bd32d00c 100755 --- a/atlas/views.py +++ b/atlas/views.py @@ -1999,16 +1999,51 @@ class SubspecialtyAutocomplete(autocomplete.Select2QuerySetView): @login_required # @user_is_atlas_editor def categories_list(request): - # condition = get_object_or_404(Condition, pk=pk) + # Allow an optional global search across category models via GET `q`. + query = request.GET.get("q", "").strip() - # logging.debug(atlas.subspecialty.first().name.all()) - return render( - request, - "atlas/categories_list.html", - # { - # "condition": condition, - # }, - ) + results = None + if query: + from .models import Condition, Finding, Structure, Subspecialty, Presentation + + # Simple case-insensitive contains search on `name` field for each model + conditions = Condition.objects.filter(name__icontains=query).order_by("name") + findings = Finding.objects.filter(name__icontains=query).order_by("name") + structures = Structure.objects.filter(name__icontains=query).order_by("name") + subspecialties = Subspecialty.objects.filter(name__icontains=query).order_by("name") + presentations = Presentation.objects.filter(name__icontains=query).order_by("name") + + results = { + "conditions": conditions, + "findings": findings, + "structures": structures, + "subspecialties": subspecialties, + "presentations": presentations, + } + + return render(request, "atlas/categories_list.html", {"query": query, "results": results}) + + +@login_required +def categories_search_partial(request): + """Return only the search results partial for HTMX requests. + + Expects GET param `q`. + """ + query = request.GET.get("q", "").strip() + results = {"conditions": (), "findings": (), "structures": (), "subspecialties": (), "presentations": ()} + if query: + from .models import Condition, Finding, Structure, Subspecialty, Presentation + + results = { + "conditions": Condition.objects.filter(name__icontains=query).order_by("name"), + "findings": Finding.objects.filter(name__icontains=query).order_by("name"), + "structures": Structure.objects.filter(name__icontains=query).order_by("name"), + "subspecialties": Subspecialty.objects.filter(name__icontains=query).order_by("name"), + "presentations": Presentation.objects.filter(name__icontains=query).order_by("name"), + } + + return render(request, "atlas/_categories_search_results.html", {"query": query, "results": results}) # def collection_view(request): diff --git a/templates/base.html b/templates/base.html index 2d9475c7..89243788 100644 --- a/templates/base.html +++ b/templates/base.html @@ -237,7 +237,10 @@ console.error('Error hiding review modal', err); } }); + + + \ No newline at end of file