|
| 1 | +from datetime import date, datetime |
| 2 | +from datetime import timezone as tz |
1 | 3 | from unittest.mock import patch |
2 | 4 |
|
3 | 5 | import pytest |
4 | 6 | import statemachine |
| 7 | +import time_machine |
5 | 8 | from django.contrib import messages |
6 | 9 | from django.contrib.messages import get_messages |
7 | 10 | from django.urls import reverse |
|
37 | 40 | AppointmentStatusNames, |
38 | 41 | AppointmentWorkflowStepCompletion, |
39 | 42 | ) |
| 43 | +from manage_breast_screening.participants.models.reported_mammograms import ( |
| 44 | + ParticipantReportedMammogram, |
| 45 | +) |
40 | 46 | from manage_breast_screening.participants.tests.factories import ( |
41 | 47 | AppointmentFactory, |
42 | 48 | MedicalInformationReviewFactory, |
| 49 | + ParticipantReportedMammogramFactory, |
43 | 50 | ) |
44 | 51 | from manage_breast_screening.users.tests.factories import UserFactory |
45 | 52 |
|
@@ -290,6 +297,157 @@ def test_identity_confirmed_step_incomplete( |
290 | 297 | ), |
291 | 298 | ) |
292 | 299 |
|
| 300 | + @pytest.mark.parametrize( |
| 301 | + "mammogram_kwargs", |
| 302 | + [ |
| 303 | + { |
| 304 | + "date_type": ParticipantReportedMammogram.DateType.LESS_THAN_SIX_MONTHS, |
| 305 | + "reason_for_continuing": "reason for continuing", |
| 306 | + }, |
| 307 | + { |
| 308 | + "date_type": ParticipantReportedMammogram.DateType.EXACT, |
| 309 | + "exact_date": date(2025, 8, 21), |
| 310 | + "reason_for_continuing": "reason for continuing", |
| 311 | + }, |
| 312 | + { |
| 313 | + "date_type": ParticipantReportedMammogram.DateType.EXACT, |
| 314 | + "exact_date": date(2025, 7, 31), |
| 315 | + "reason_for_continuing": "reason for continuing", |
| 316 | + }, |
| 317 | + { |
| 318 | + "date_type": ParticipantReportedMammogram.DateType.EXACT, |
| 319 | + "exact_date": date(2025, 2, 24), |
| 320 | + "reason_for_continuing": "reason for continuing", |
| 321 | + }, |
| 322 | + { |
| 323 | + "date_type": ParticipantReportedMammogram.DateType.EXACT, |
| 324 | + "exact_date": date(2025, 2, 23), |
| 325 | + "reason_for_continuing": "reason for continuing", |
| 326 | + }, |
| 327 | + { |
| 328 | + "date_type": ParticipantReportedMammogram.DateType.EXACT, |
| 329 | + "exact_date": date(2025, 2, 22), |
| 330 | + }, |
| 331 | + { |
| 332 | + "date_type": ParticipantReportedMammogram.DateType.EXACT, |
| 333 | + "exact_date": date(2024, 8, 21), |
| 334 | + }, |
| 335 | + {"date_type": ParticipantReportedMammogram.DateType.MORE_THAN_SIX_MONTHS}, |
| 336 | + ], |
| 337 | + ) |
| 338 | + @time_machine.travel(datetime(2025, 8, 22, 10, tzinfo=tz.utc)) |
| 339 | + def test_recent_mammogram_appointment_can_proceed( |
| 340 | + self, clinical_user_client, confirmed_identity_appointment, mammogram_kwargs |
| 341 | + ): |
| 342 | + ParticipantReportedMammogramFactory.create( |
| 343 | + appointment=confirmed_identity_appointment, |
| 344 | + location_type=ParticipantReportedMammogram.LocationType.SAME_PROVIDER, |
| 345 | + **mammogram_kwargs, |
| 346 | + ) |
| 347 | + response = clinical_user_client.http.get( |
| 348 | + reverse( |
| 349 | + "mammograms:record_medical_information", |
| 350 | + kwargs={"pk": confirmed_identity_appointment.pk}, |
| 351 | + ) |
| 352 | + ) |
| 353 | + assert response.status_code == 200 |
| 354 | + |
| 355 | + @pytest.mark.parametrize( |
| 356 | + "mammogram_kwargs", |
| 357 | + [ |
| 358 | + {"date_type": ParticipantReportedMammogram.DateType.LESS_THAN_SIX_MONTHS}, |
| 359 | + { |
| 360 | + "date_type": ParticipantReportedMammogram.DateType.EXACT, |
| 361 | + "exact_date": date(2025, 8, 21), |
| 362 | + }, |
| 363 | + { |
| 364 | + "date_type": ParticipantReportedMammogram.DateType.EXACT, |
| 365 | + "exact_date": date(2025, 7, 31), |
| 366 | + }, |
| 367 | + { |
| 368 | + "date_type": ParticipantReportedMammogram.DateType.EXACT, |
| 369 | + "exact_date": date(2025, 2, 24), |
| 370 | + }, |
| 371 | + { |
| 372 | + "date_type": ParticipantReportedMammogram.DateType.EXACT, |
| 373 | + "exact_date": date(2025, 2, 23), |
| 374 | + }, |
| 375 | + ], |
| 376 | + ) |
| 377 | + @time_machine.travel(datetime(2025, 8, 22, 10, tzinfo=tz.utc)) |
| 378 | + def test_recent_mammogram_appointment_should_not_proceed( |
| 379 | + self, clinical_user_client, confirmed_identity_appointment, mammogram_kwargs |
| 380 | + ): |
| 381 | + recent_mammogram = ParticipantReportedMammogramFactory.create( |
| 382 | + appointment=confirmed_identity_appointment, |
| 383 | + location_type=ParticipantReportedMammogram.LocationType.SAME_PROVIDER, |
| 384 | + **mammogram_kwargs, |
| 385 | + ) |
| 386 | + |
| 387 | + response = clinical_user_client.http.get( |
| 388 | + reverse( |
| 389 | + "mammograms:record_medical_information", |
| 390 | + kwargs={"pk": confirmed_identity_appointment.pk}, |
| 391 | + ) |
| 392 | + ) |
| 393 | + assertRedirects( |
| 394 | + response, |
| 395 | + reverse( |
| 396 | + "mammograms:appointment_should_not_proceed", |
| 397 | + kwargs={ |
| 398 | + "appointment_pk": confirmed_identity_appointment.pk, |
| 399 | + "participant_reported_mammogram_pk": recent_mammogram.pk, |
| 400 | + }, |
| 401 | + ), |
| 402 | + ) |
| 403 | + |
| 404 | + @time_machine.travel(datetime(2025, 8, 22, 10, tzinfo=tz.utc)) |
| 405 | + def test_multiple_recent_mammogram_appointment_should_not_proceed( |
| 406 | + self, clinical_user_client, confirmed_identity_appointment |
| 407 | + ): |
| 408 | + """ |
| 409 | + Test that, when multiple recent mammograms are present, |
| 410 | + the user is redirected to the "appointment cannot proceed" page for the most recently |
| 411 | + added mammogram that is within 6 months and does not have a reason for continuing". |
| 412 | + """ |
| 413 | + |
| 414 | + ParticipantReportedMammogramFactory.create( |
| 415 | + appointment=confirmed_identity_appointment, |
| 416 | + location_type=ParticipantReportedMammogram.LocationType.SAME_PROVIDER, |
| 417 | + date_type=ParticipantReportedMammogram.DateType.EXACT, |
| 418 | + exact_date=date(2025, 2, 23), |
| 419 | + ) |
| 420 | + recent_mammogram = ParticipantReportedMammogramFactory.create( |
| 421 | + appointment=confirmed_identity_appointment, |
| 422 | + location_type=ParticipantReportedMammogram.LocationType.SAME_PROVIDER, |
| 423 | + date_type=ParticipantReportedMammogram.DateType.EXACT, |
| 424 | + exact_date=date(2025, 2, 24), |
| 425 | + ) |
| 426 | + ParticipantReportedMammogramFactory.create( |
| 427 | + appointment=confirmed_identity_appointment, |
| 428 | + location_type=ParticipantReportedMammogram.LocationType.SAME_PROVIDER, |
| 429 | + date_type=ParticipantReportedMammogram.DateType.EXACT, |
| 430 | + exact_date=date(2025, 2, 25), |
| 431 | + reason_for_continuing="reason for continuing", |
| 432 | + ) |
| 433 | + |
| 434 | + response = clinical_user_client.http.get( |
| 435 | + reverse( |
| 436 | + "mammograms:record_medical_information", |
| 437 | + kwargs={"pk": confirmed_identity_appointment.pk}, |
| 438 | + ) |
| 439 | + ) |
| 440 | + assertRedirects( |
| 441 | + response, |
| 442 | + reverse( |
| 443 | + "mammograms:appointment_should_not_proceed", |
| 444 | + kwargs={ |
| 445 | + "appointment_pk": confirmed_identity_appointment.pk, |
| 446 | + "participant_reported_mammogram_pk": recent_mammogram.pk, |
| 447 | + }, |
| 448 | + ), |
| 449 | + ) |
| 450 | + |
293 | 451 |
|
294 | 452 | @pytest.mark.django_db |
295 | 453 | class TestUpsertImagesView: |
|
0 commit comments