Skip to content

Commit 69d1172

Browse files
authored
Merge pull request #484 from NHSDigital/screen-or-assess-fix
Handle correct and incorrect Screen Or Assess headings
2 parents 00dca7f + 6f56fea commit 69d1172

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

manage_breast_screening/notifications/management/commands/create_appointments.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,26 @@ def update_or_create_appointment(
113113
nbss_id=row["Appointment ID"],
114114
nhs_number=row["NHS Num"],
115115
number=row["Screen Appt num"],
116-
batch_id=row.get("Batch ID", row.get("BatchID")),
116+
batch_id=self.handle_aliased_column("Batch ID", "BatchID", row),
117117
clinic=clinic,
118118
episode_started_at=datetime.strptime(
119119
row["Episode Start"], "%Y%m%d"
120120
).replace(tzinfo=TZ_INFO),
121-
episode_type=row.get("Episode Type", row.get("Epsiode Type")),
121+
episode_type=self.handle_aliased_column(
122+
"Episode Type", "Epsiode Type", row
123+
),
122124
starts_at=self.appointment_date_and_time(row),
123125
status=row["Status"],
124126
booked_by=row["Booked By"],
125127
booked_at=self.workflow_action_date_and_time(
126128
row["Action Timestamp"]
127129
),
128-
assessment=(row["Screen or Asses"] == "A"),
130+
assessment=(
131+
self.handle_aliased_column(
132+
"Screen or Assess", "Screen or Asses", row
133+
)
134+
== "A"
135+
),
129136
),
130137
True,
131138
)
@@ -163,6 +170,11 @@ def workflow_action_date_and_time(self, timestamp: str) -> datetime:
163170
dt = datetime.strptime(timestamp, "%Y%m%d-%H%M%S")
164171
return dt.replace(tzinfo=TZ_INFO)
165172

173+
def handle_aliased_column(
174+
self, expected_name: str, fallback_name: str, row: pandas.Series
175+
) -> object:
176+
return row.get(expected_name, row.get(fallback_name))
177+
166178
def appointment_date_and_time(self, row: pandas.Series) -> datetime:
167179
dt = datetime.strptime(
168180
f"{row['Appt Date']} {row['Appt Time']}",

0 commit comments

Comments
 (0)