Skip to content

Commit b270bc5

Browse files
authored
Merge pull request #321 from NHSDigital/DTOSS-10670-save-file-data-to-appointment
[DTOSS-10670] save file data to appointment
2 parents 30f9f89 + 5396167 commit b270bc5

5 files changed

Lines changed: 35 additions & 8 deletions

File tree

manage_breast_screening/notifications/management/commands/create_appointments.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def handle(self, *args, **options):
5252
self.stdout.write(f"{clinic} created")
5353

5454
appt, appt_created = self.update_or_create_appointment(
55-
row, clinic
55+
row, clinic, blob.name
5656
)
5757
if appt_created:
5858
self.stdout.write(f"{appt} created")
@@ -93,10 +93,11 @@ def find_or_create_clinic(self, row: pandas.Series) -> tuple[Clinic, bool]:
9393
)
9494

9595
def update_or_create_appointment(
96-
self, row: pandas.Series, clinic: Clinic
96+
self, row: pandas.Series, clinic: Clinic, blob_name: str
9797
) -> tuple[Appointment, bool]:
9898
defaults = {
9999
"batch_id": row["BatchID"],
100+
"blob_name": blob_name,
100101
"number": row["Sequence"],
101102
"status": row["Status"],
102103
"episode_type": row["Episode Type"],
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 5.2.3 on 2025-08-21 14:36
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('notifications', '0012_alter_message_batch_notify_errors'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='appointment',
15+
name='blob_name',
16+
field=models.TextField(default='/'),
17+
preserve_default=False,
18+
),
19+
]

manage_breast_screening/notifications/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class Appointment(models.Model):
126126
starts_at = models.DateTimeField(null=False)
127127
created_at = models.DateTimeField(null=False, auto_now_add=True)
128128
updated_at = models.DateTimeField(null=True, auto_now=True)
129+
blob_name = models.TextField(null=False)
129130

130131
clinic = models.ForeignKey("notifications.Clinic", on_delete=models.PROTECT)
131132

manage_breast_screening/notifications/tests/integration/test_create_appointments_from_azure_storage.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ def helpers(self):
2727
@pytest.mark.django_db
2828
def test_appointments_created_from_file_stored_in_azure(self, helpers):
2929
today_dirname = datetime.today().strftime("%Y-%m-%d")
30+
test_file_path = "ABC_20241202091221_APPT_106.dat"
31+
blob_name = f"{today_dirname}/{test_file_path}"
3032

31-
with open(
32-
helpers.get_test_file_path("ABC_20241202091221_APPT_106.dat")
33-
) as test_file:
34-
BlobStorage().add(
35-
f"{today_dirname}/ABC_20241202091221_APPT_106.dat", test_file.read()
36-
)
33+
with open(helpers.get_test_file_path(test_file_path)) as test_file:
34+
BlobStorage().add(blob_name, test_file.read())
3735

3836
Command().handle(**{"date_str": today_dirname})
3937

@@ -80,3 +78,7 @@ def test_appointments_created_from_file_stored_in_azure(self, helpers):
8078
assert appointments[0].clinic == clinics[0]
8179
assert appointments[1].clinic == clinics[1]
8280
assert appointments[2].clinic == clinics[1]
81+
82+
assert appointments[0].blob_name == blob_name
83+
assert appointments[1].blob_name == blob_name
84+
assert appointments[2].blob_name == blob_name

manage_breast_screening/notifications/tests/management/commands/test_create_appointments.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def test_handle_creates_records(self):
9595
assert appointments[1].clinic == clinics[1]
9696
assert appointments[2].clinic == clinics[1]
9797

98+
assert appointments[0].blob_name == mock_blob.name.return_value
99+
assert appointments[1].blob_name == mock_blob.name.return_value
100+
assert appointments[2].blob_name == mock_blob.name.return_value
101+
98102
@pytest.mark.django_db
99103
def test_handles_holding_clinics(self):
100104
"""Test does not create appointments for valid NBSS data marked as a Holding Clinic"""

0 commit comments

Comments
 (0)