generalise a QuestionBase

This commit is contained in:
Ross
2023-06-05 09:10:54 +01:00
parent ac558b9ea2
commit e0723d4d3a
8 changed files with 177 additions and 141 deletions
+50 -16
View File
@@ -37,6 +37,7 @@ from generic.models import (
ExamBase,
Plane,
Contrast,
QuestionBase,
QuestionNote,
UserAnswerBase,
UserUserGroup,
@@ -79,7 +80,7 @@ def findMiddle(input_list):
@reversion.register
class Long(models.Model):
class Long(QuestionBase):
description = models.TextField(
blank=True,
help_text="Description of the case, for admin organisation, will not be visible when taking",
@@ -87,8 +88,6 @@ class Long(models.Model):
history = models.TextField(null=True, blank=True)
feedback = models.TextField(null=True, blank=True)
# TODO: merge with atlas condition / signs / finding
# condition = tagulous.models.TagField(
# to=Condition,
@@ -117,8 +116,6 @@ class Long(models.Model):
# help_text=
# "If we know the source of the image")
verified = models.BooleanField(default=False)
created_date = models.DateTimeField(default=timezone.now)
published_date = models.DateTimeField(blank=True, null=True)
author = models.ManyToManyField(
settings.AUTH_USER_MODEL,
blank=True,
@@ -130,10 +127,6 @@ class Long(models.Model):
default=False, help_text="Question has been scrapped and will not be shown"
)
open_access = models.BooleanField(
help_text="If a question should be freely available to browse", default=True
)
recreate_json = models.BooleanField(
help_text="If the json cache needs updating", default=False
)
@@ -146,8 +139,6 @@ class Long(models.Model):
series = SortedManyToManyField("LongSeries", related_name="long")
notes = GenericRelation(QuestionNote)
# question_file = models.FileField(upload_to=question_file_directory_path, blank=True, null=True)
def get_absolute_url(self):
@@ -354,6 +345,12 @@ class Long(models.Model):
return url
def get_unanswered_mark_and_text(self) -> tuple[int, str]:
"""
Override in models if needed
"""
return (4, ("Not answered",) * 5)
# def GetNonFeedbackQuestionImages(self):
# return self.get_images()
@@ -431,14 +428,12 @@ class LongSeries(models.Model):
)
def __str__(self):
#if self.long:
# if self.long:
# long_id = ", ".format([long.pk for long in self.long.all()])
# # long_id = self.long.pk
#else:
# else:
# long_id = "None"
return "{}/{} : {}".format(
self.pk, self.get_examination(), self.description
)
return "{}/{} : {}".format(self.pk, self.get_examination(), self.description)
def get_author_objects(self):
"""Returns a comma seperated text list of authors"""
@@ -655,6 +650,35 @@ class Exam(ExamBase):
exam_user_status = GenericRelation(ExamUserStatus)
def get_exam_question_json(self, question_id):
q = get_object_or_404(Long, pk=question_id)
# exam_order.append(q.id)
# Loop through longimage associations
images = []
image_titles = []
for series in q.series.all():
# image_array = []
# for i in series.images.all():
# image_array.append(image_as_base64(i.image))
# #image_array.append(i.image.url)
image_array = [image_as_base64(i.image) for i in series.images.all()]
images.append(image_array)
image_titles.append(series.get_examination())
exam_question = {
"title": q.history,
"images": images,
"image_titles": image_titles,
# "feedback_image": [],
# "annotations": [str(q.image_annotations)],
"type": "long",
"images_json": True,
}
return exam_question
def get_exam_json(self, based=True):
questions = self.exam_questions.all()
@@ -849,6 +873,15 @@ class UserAnswer(UserAnswerBase):
return True
return False
def get_answer(self):
(
self.answer_observations,
self.answer_interpretation,
self.answer_principle_diagnosis,
self.answer_differential_diagnosis,
self.answer_management,
)
def get_answer_string(self) -> str:
return f"""
Observations:
@@ -868,6 +901,7 @@ Management:
"""
@reversion.register
class AnswerMarks(models.Model):
score = models.CharField(max_length=3, choices=UserAnswer.ScoreOptions.choices)