Skip to content
Merged
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,10 @@ def mns_event_will_be_triggered_for_batch_record(context, action, valid_rows):
null_nhs_rows = [row for row in valid_rows if _is_null_nhs_row(row)]
positive_rows = [row for row in valid_rows if not _is_null_nhs_row(row)]

row_lookup = {str(row.NHS_NUMBER): row for row in positive_rows}
row_lookup = {}
for row in positive_rows:
nhs = str(row.NHS_NUMBER)
row_lookup.setdefault(nhs, []).append(row)
Comment thread
FimranNHS marked this conversation as resolved.
Outdated

messages = read_messages_for_batch(
context,
Expand All @@ -568,10 +571,15 @@ def mns_event_will_be_triggered_for_batch_record(context, action, valid_rows):

for msg in messages:
nhs = msg.subject
imms_id = msg.dataref.split("/")[-1]

assert nhs in row_lookup, f"Received message for NHS {nhs} but it does not exist in valid_rows"

row = row_lookup[nhs]
matching_rows = [r for r in row_lookup[nhs] if r.IMMS_ID_CLEAN == imms_id]

assert matching_rows, f"Message NHS {nhs} with IMMS_ID {imms_id} does not match any row"

row = matching_rows[0]
Comment thread
FimranNHS marked this conversation as resolved.
Outdated

context.nhs_number = row.NHS_NUMBER
context.gp_code = get_gp_code_by_nhs_number(row.NHS_NUMBER)
Expand Down
Loading