Skip to content

Commit d4c9dc1

Browse files
committed
add aliased column function - PR comment
1 parent 0babec6 commit d4c9dc1

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

manage_breast_screening/notifications/management/commands/create_appointments.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,28 @@ 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=row.get(
117+
self.handle_aliased_column("Batch ID", "BatchID", row)
118+
),
117119
clinic=clinic,
118120
episode_started_at=datetime.strptime(
119121
row["Episode Start"], "%Y%m%d"
120122
).replace(tzinfo=TZ_INFO),
121-
episode_type=row.get("Episode Type", row.get("Epsiode Type")),
123+
episode_type=row.get(
124+
self.handle_aliased_column("Episode Type", "Epsiode Type", row)
125+
),
122126
starts_at=self.appointment_date_and_time(row),
123127
status=row["Status"],
124128
booked_by=row["Booked By"],
125129
booked_at=self.workflow_action_date_and_time(
126130
row["Action Timestamp"]
127131
),
128-
assessment=self.is_assessment(row),
132+
assessment=row.get(
133+
self.handle_aliased_column(
134+
"Screen or Assess", "Screen or Asses", row
135+
)
136+
)
137+
== "A",
129138
),
130139
True,
131140
)
@@ -163,15 +172,12 @@ def workflow_action_date_and_time(self, timestamp: str) -> datetime:
163172
dt = datetime.strptime(timestamp, "%Y%m%d-%H%M%S")
164173
return dt.replace(tzinfo=TZ_INFO)
165174

166-
def is_assessment(self, row: pandas.Series) -> bool:
167-
"""
168-
There was an error in the data where the column was initially misspelled as 'Screen or Asses'. To ensure backwards compatibility, we check for both spellings.
169-
"""
170-
if "Screen or Assess" in row:
171-
return row["Screen or Assess"] == "A"
172-
elif "Screen or Asses" in row:
173-
return row["Screen or Asses"] == "A"
174-
return False
175+
def handle_aliased_column(
176+
self, expected_name: str, fallback_name: str, row: pandas.Series
177+
) -> str:
178+
if expected_name in row:
179+
return row[expected_name]
180+
return row[fallback_name]
175181

176182
def appointment_date_and_time(self, row: pandas.Series) -> datetime:
177183
dt = datetime.strptime(

0 commit comments

Comments
 (0)