From b680ae749f52229e31057091202ccdbb218d6ca7 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 20 Oct 2025 12:04:10 +0100 Subject: [PATCH] Add sources JSONField to Question model and update import functions to handle source references --- sbas/migrations/0020_question_sources.py | 18 ++++++++++++++++++ sbas/views.py | 12 ++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 sbas/migrations/0020_question_sources.py diff --git a/sbas/migrations/0020_question_sources.py b/sbas/migrations/0020_question_sources.py new file mode 100644 index 00000000..0148202a --- /dev/null +++ b/sbas/migrations/0020_question_sources.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.4 on 2025-10-20 11:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sbas', '0019_question_title'), + ] + + operations = [ + migrations.AddField( + model_name='question', + name='sources', + field=models.JSONField(blank=True, help_text='List of source references for the question (e.g. article DOIs or StatDx IDs or Source file names).', null=True), + ), + ] diff --git a/sbas/views.py b/sbas/views.py index e7ac15da..1e4c9cf9 100644 --- a/sbas/views.py +++ b/sbas/views.py @@ -737,6 +737,12 @@ def import_llm_questions(request): q.best_answer = payload.get("best_answer") if cat_obj: q.category = cat_obj + # populate sources JSONField if provided (accept list or single string) + srcs = payload.get("sources") + if isinstance(srcs, list): + q.sources = srcs + elif srcs: + q.sources = [str(srcs)] q.save() # For each M2M, create missing items if allowed and attach resolved @@ -871,6 +877,12 @@ def import_llm_confirm(request): if isinstance(cat_val, str): cat_obj, _ = Category.objects.get_or_create(category=cat_val) q.category = cat_obj + # populate sources JSONField if provided (accept list or single string) + srcs = payload.get("sources") + if isinstance(srcs, list): + q.sources = srcs + elif srcs: + q.sources = [str(srcs)] q.save() for key, model_cls in (("finding", Finding), ("structure", Structure), ("condition", Condition), ("presentation", Presentation), ("subspecialty", Subspecialty)):