diff --git a/atlas/forms.py b/atlas/forms.py index aa2795d5..abe7734e 100755 --- a/atlas/forms.py +++ b/atlas/forms.py @@ -16,6 +16,8 @@ from django.forms import ( ) from django.forms import inlineformset_factory from django.shortcuts import get_object_or_404 +from django_jsonforms.forms import JSONSchemaField + from atlas.models import ( Case, @@ -516,8 +518,13 @@ SeriesImageFormSet = inlineformset_factory( ) class BaseReportAnswerForm(ModelForm): + json_answer = JSONSchemaField( + schema = "schema/report.json", + #options = 'schema/options.json' + options = {} + ) class Meta: - fields = ["answer"] + fields = ["answer", "json_answer"] widgets = { # "normal": RadioSelect( @@ -532,9 +539,13 @@ class BaseReportAnswerForm(ModelForm): # "answer": "Write your answer in here." # } - def __init__(self, *args, **kwargs): + def __init__(self, *args, case_detail, **kwargs): super(BaseReportAnswerForm, self).__init__(*args, **kwargs) self.fields["answer"].required = False + #self.fields["json_answer"].schema = case_detail.question_schema + if case_detail.question_schema is not None: + self.fields["json_answer"] = JSONSchemaField(schema=case_detail.question_schema, options={}) + class CidReportAnswerForm(BaseReportAnswerForm): class Meta(BaseReportAnswerForm.Meta): @@ -698,4 +709,18 @@ class CaseAuthorForm(ExamAuthorFormMixin): model = Case class SeriesAuthorForm(ExamAuthorFormMixin): class Meta(ExamAuthorFormMixin.Meta): - model = Series \ No newline at end of file + model = Series + + +class AnswerJSONForm(Form): + + json = JSONSchemaField( + schema = 'schema/schema.json', + #options = 'schema/options.json' + options = {} + ) + +class CaseDetailForm(ModelForm): + class Meta: + model = CaseDetail + fields = ["sort_order", "question_schema"]#, "user"] \ No newline at end of file diff --git a/atlas/migrations/0049_casedetail_questions_cidreportanswer_json_answer_and_more.py b/atlas/migrations/0049_casedetail_questions_cidreportanswer_json_answer_and_more.py new file mode 100644 index 00000000..db083458 --- /dev/null +++ b/atlas/migrations/0049_casedetail_questions_cidreportanswer_json_answer_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 5.0.2 on 2024-04-29 10:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('atlas', '0048_cidreportanswer_completed_userreportanswer_completed_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='casedetail', + name='questions', + field=models.JSONField(blank=True, null=True), + ), + migrations.AddField( + model_name='cidreportanswer', + name='json_answer', + field=models.JSONField(blank=True, null=True), + ), + migrations.AddField( + model_name='userreportanswer', + name='json_answer', + field=models.JSONField(blank=True, null=True), + ), + ] diff --git a/atlas/migrations/0050_rename_questions_casedetail_question_schema.py b/atlas/migrations/0050_rename_questions_casedetail_question_schema.py new file mode 100644 index 00000000..78388d0a --- /dev/null +++ b/atlas/migrations/0050_rename_questions_casedetail_question_schema.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.2 on 2024-04-29 11:06 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('atlas', '0049_casedetail_questions_cidreportanswer_json_answer_and_more'), + ] + + operations = [ + migrations.RenameField( + model_name='casedetail', + old_name='questions', + new_name='question_schema', + ), + ] diff --git a/atlas/models.py b/atlas/models.py index 2d861d52..05b13d21 100644 --- a/atlas/models.py +++ b/atlas/models.py @@ -957,6 +957,8 @@ class CaseDetail(models.Model): case = models.ForeignKey(Case, on_delete=models.CASCADE) collection = models.ForeignKey(CaseCollection, on_delete=models.CASCADE) + question_schema = models.JSONField(null=True, blank=True) + sort_order = models.IntegerField(default=1000) class Meta: @@ -968,6 +970,8 @@ class BaseReportAnswer(models.Model): answer = models.TextField(blank=True) + json_answer = models.JSONField(null=True, blank=True) + feedback = models.TextField(blank=True) created = models.DateTimeField(auto_now_add=True) diff --git a/atlas/static/schema/report.json b/atlas/static/schema/report.json new file mode 100644 index 00000000..28fd8006 --- /dev/null +++ b/atlas/static/schema/report.json @@ -0,0 +1,14 @@ +{ + "title": "Report", + "description": "Report text", + "type": "object", + "required": [ + "report" + ], + "properties": { + "report": { + "type": "string", + "title": "Report" + } + } +} \ No newline at end of file diff --git a/atlas/templates/atlas/collection_case_detail.html b/atlas/templates/atlas/collection_case_detail.html new file mode 100644 index 00000000..13bca990 --- /dev/null +++ b/atlas/templates/atlas/collection_case_detail.html @@ -0,0 +1,12 @@ +{% extends 'atlas/exams.html' %} + +{% block content %} +

{{case_detail.collection.name}} / {{case_detail.case.pk}}

+ +
+ {% csrf_token %} + {{ form.as_p }} + +
+ +{% endblock %} diff --git a/atlas/templates/atlas/collection_case_view_take.html b/atlas/templates/atlas/collection_case_view_take.html index e715cc0a..d0bde8b0 100644 --- a/atlas/templates/atlas/collection_case_view_take.html +++ b/atlas/templates/atlas/collection_case_view_take.html @@ -53,7 +53,7 @@ {% if collection.show_ohif_viewer_link %}
- View case in OHIF + View case in OHIF
{% endif %} @@ -128,6 +128,7 @@ {% endif %}
{% csrf_token %} {% if collection.collection_type == "REP" %} + {{form.json.errors}}
{{form}} @@ -200,6 +201,7 @@ {% endblock %} {% block js %} + {{ form.media }}