Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from django.db.models import TextChoices
from django.forms import Form

from manage_breast_screening.nhsuk_forms.fields.choice_fields import ChoiceField


class RecordImagesTakenForm(Form):
class StandardImagesChoices(TextChoices):
YES_TWO_CC_AND_TWO_MLO = "YES_TWO_CC_AND_TWO_MLO", "Yes, 2 CC and 2 MLO"
NO_ADD_ADDITIONAL = (
"NO_ADD_ADDITIONAL",
"No, add other information",
)
NO_IMAGES_TAKEN = "NO_IMAGES_TAKEN", "No images taken"

standard_images = ChoiceField(
choices=StandardImagesChoices,
required=True,
choice_hints={
StandardImagesChoices.NO_ADD_ADDITIONAL: "Such as too few or additional images",
StandardImagesChoices.NO_IMAGES_TAKEN: "The appointment cannot proceed",
},
label="Have you taken a standard set of images?",
error_messages={
"required": "Select whether you have taken a standard set of images or not"
},
)

def save(self, study_service):
if (
self.cleaned_data["standard_images"]
== self.StandardImagesChoices.YES_TWO_CC_AND_TWO_MLO
):
study_service.create_with_default_series()
else:
study_service.remove_existing_study_and_series()

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "workflow_step.jinja" %}

{% set active_workflow_step = 'TAKE_IMAGES' %}

{% block form %}
{% do form.standard_images.add_divider_after("NO_ADD_ADDITIONAL", "or") %}
{{ form.standard_images.as_field_group() }}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def workflow_steps(self, active_workflow_step):
case AppointmentWorkflowStepCompletion.StepNames.REVIEW_MEDICAL_INFORMATION:
view_name = "record_medical_information"
case AppointmentWorkflowStepCompletion.StepNames.TAKE_IMAGES:
view_name = "awaiting_images"
view_name = "take_images"
case AppointmentWorkflowStepCompletion.StepNames.CHECK_INFORMATION:
view_name = "check_information"

Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from unittest.mock import MagicMock
from urllib.parse import urlencode

import pytest
from django.http import QueryDict

from manage_breast_screening.mammograms.forms.images.record_images_taken_form import (
RecordImagesTakenForm,
)
from manage_breast_screening.manual_images.services import StudyService


@pytest.fixture
def mock_study_service():
return MagicMock(spec=StudyService)


def test_invalid_form():
form = RecordImagesTakenForm(QueryDict())
assert not form.is_valid()
assert form.errors == {
"standard_images": [
"Select whether you have taken a standard set of images or not"
]
}


def test_valid_form():
form = RecordImagesTakenForm(
QueryDict(
urlencode(
{
"standard_images": RecordImagesTakenForm.StandardImagesChoices.YES_TWO_CC_AND_TWO_MLO
}
)
)
)
assert form.is_valid()


def test_save_with_yes_answer(mock_study_service):
form = RecordImagesTakenForm(
QueryDict(
urlencode(
{
"standard_images": RecordImagesTakenForm.StandardImagesChoices.YES_TWO_CC_AND_TWO_MLO
}
)
)
)
form.is_valid()
form.save(mock_study_service)

mock_study_service.create_with_default_series.assert_called_once()


def test_save_with_no_answer(mock_study_service):
form = RecordImagesTakenForm(
QueryDict(
urlencode(
{
"standard_images": RecordImagesTakenForm.StandardImagesChoices.NO_ADD_ADDITIONAL
}
)
)
)
form.is_valid()
form.save(mock_study_service)

mock_study_service.remove_existing_study_and_series.assert_called_once()
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def test_workflow_steps_confirm_identity(self, mock_appointment):
"current": False,
"disabled": True,
"classes": "app-workflow-side-nav__item app-workflow-side-nav__item--disabled",
"url": "/mammograms/53ce8d3b-9e65-471a-b906-73809c0475d0/awaiting-images/",
"url": "/mammograms/53ce8d3b-9e65-471a-b906-73809c0475d0/take-images/",
},
{
"label": "Check information",
Expand Down Expand Up @@ -412,7 +412,7 @@ def test_workflow_steps_review_medical_information(self, mock_appointment):
"current": False,
"disabled": True,
"classes": "app-workflow-side-nav__item app-workflow-side-nav__item--disabled",
"url": "/mammograms/53ce8d3b-9e65-471a-b906-73809c0475d0/awaiting-images/",
"url": "/mammograms/53ce8d3b-9e65-471a-b906-73809c0475d0/take-images/",
},
{
"label": "Check information",
Expand Down Expand Up @@ -455,7 +455,7 @@ def test_workflow_steps_take_images(self, mock_appointment):
"current": True,
"disabled": False,
"classes": "app-workflow-side-nav__item app-workflow-side-nav__item--current",
"url": "/mammograms/53ce8d3b-9e65-471a-b906-73809c0475d0/awaiting-images/",
"url": "/mammograms/53ce8d3b-9e65-471a-b906-73809c0475d0/take-images/",
},
{
"label": "Check information",
Expand Down Expand Up @@ -501,7 +501,7 @@ def test_workflow_steps_check_information(self, mock_appointment):
"current": False,
"disabled": False,
"classes": "app-workflow-side-nav__item app-workflow-side-nav__item--completed",
"url": "/mammograms/53ce8d3b-9e65-471a-b906-73809c0475d0/awaiting-images/",
"url": "/mammograms/53ce8d3b-9e65-471a-b906-73809c0475d0/take-images/",
},
{
"label": "Check information",
Expand Down Expand Up @@ -549,7 +549,7 @@ def test_workflow_steps_on_review_medical_information_when_already_reviewed(
"current": False,
"disabled": False,
"classes": "app-workflow-side-nav__item",
"url": "/mammograms/53ce8d3b-9e65-471a-b906-73809c0475d0/awaiting-images/",
"url": "/mammograms/53ce8d3b-9e65-471a-b906-73809c0475d0/take-images/",
},
{
"label": "Check information",
Expand Down Expand Up @@ -597,7 +597,7 @@ def test_workflow_steps_on_confirm_identity_when_already_taken_images(
"current": False,
"disabled": False,
"classes": "app-workflow-side-nav__item app-workflow-side-nav__item--completed",
"url": "/mammograms/53ce8d3b-9e65-471a-b906-73809c0475d0/awaiting-images/",
"url": "/mammograms/53ce8d3b-9e65-471a-b906-73809c0475d0/take-images/",
},
{
"label": "Check information",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

from manage_breast_screening.config.settings import LOGIN_URL
from manage_breast_screening.core.models import AuditLog
from manage_breast_screening.mammograms.forms.images.record_images_taken_form import (
RecordImagesTakenForm,
)
from manage_breast_screening.participants.models import MedicalInformationReview
from manage_breast_screening.participants.models.appointment import (
AppointmentWorkflowStepCompletion,
Expand Down Expand Up @@ -117,6 +120,100 @@ def test_records_completion(self, clinical_user_client):
)


@pytest.mark.django_db
class TestTakeImages:
def test_renders_response(self, clinical_user_client, appointment):
response = clinical_user_client.http.get(
reverse(
"mammograms:take_images",
kwargs={"pk": appointment.pk},
)
)
assert response.status_code == 200

def test_no_images_redirects_to_cannot_continue(
self, clinical_user_client, appointment
):
response = clinical_user_client.http.post(
reverse(
"mammograms:take_images",
kwargs={"pk": appointment.pk},
),
{
"standard_images": RecordImagesTakenForm.StandardImagesChoices.NO_IMAGES_TAKEN
},
)
assertRedirects(
response,
reverse(
"mammograms:appointment_cannot_go_ahead", kwargs={"pk": appointment.pk}
),
)

@pytest.mark.xfail(reason="The additional details view is not implemented yet")
def test_additional_info_redirects_to_additional_details(
self, clinical_user_client, appointment
):
response = clinical_user_client.http.post(
reverse(
"mammograms:take_images",
kwargs={"pk": appointment.pk},
),
{
"standard_images": RecordImagesTakenForm.StandardImagesChoices.NO_ADD_ADDITIONAL
},
)
assertRedirects(
response,
reverse(
"mammograms:additional_image_details", kwargs={"pk": appointment.pk}
),
)

def test_yes_marks_the_step_complete_and_redirects_to_check_info(
self, clinical_user_client, appointment
):
response = clinical_user_client.http.post(
reverse(
"mammograms:take_images",
kwargs={"pk": appointment.pk},
),
{
"standard_images": RecordImagesTakenForm.StandardImagesChoices.YES_TWO_CC_AND_TWO_MLO
},
)
assertRedirects(
response,
reverse("mammograms:check_information", kwargs={"pk": appointment.pk}),
)
assertQuerySetEqual(
appointment.completed_workflow_steps.filter(
created_by=clinical_user_client.user
)
.values_list("step_name", flat=True)
.distinct(),
[AppointmentWorkflowStepCompletion.StepNames.TAKE_IMAGES],
)

def test_yes_creates_the_study(self, clinical_user_client, appointment):
clinical_user_client.http.post(
reverse(
"mammograms:take_images",
kwargs={"pk": appointment.pk},
),
{
"standard_images": RecordImagesTakenForm.StandardImagesChoices.YES_TWO_CC_AND_TWO_MLO
},
)
assertQuerySetEqual(
appointment.study.series_set.values_list(
"view_position", "laterality", "count"
),
{("CC", "L", 1), ("CC", "R", 1), ("MLO", "L", 1), ("MLO", "R", 1)},
ordered=False,
)


@pytest.mark.django_db
class TestCheckIn:
def test_known_redirect(self, clinical_user_client):
Expand Down
18 changes: 15 additions & 3 deletions manage_breast_screening/mammograms/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.urls import path
from django.views.decorators.http import require_http_methods

from manage_breast_screening.mammograms.views import mammogram_views

Expand All @@ -21,6 +22,12 @@

app_name = "mammograms"


@require_http_methods(["GET"])
def not_implemented_view(request, pk):
raise NotImplementedError()


urlpatterns = [
path(
"<uuid:pk>/check-in/",
Expand Down Expand Up @@ -68,9 +75,9 @@
name="mark_section_reviewed",
),
path(
"<uuid:pk>/awaiting-images/",
appointment_views.AwaitingImages.as_view(),
name="awaiting_images",
"<uuid:pk>/take-images/",
appointment_views.TakeImages.as_view(),
name="take_images",
),
path(
"<uuid:pk>/cannot-go-ahead/",
Expand Down Expand Up @@ -282,6 +289,11 @@
mammogram_views.check_information,
name="check_information",
),
path(
"<uuid:pk>/image-details/new",
not_implemented_view,
name="new_image_details",
),
path(
"<uuid:pk>/complete-screening/",
mammogram_views.complete_screening,
Expand Down
Loading