Skip to content

Add report generation/emailing to ICD-10 feature branch - #3223

Open
Jongmassey wants to merge 9 commits into
icd-10-multi-edition-ui-changes-rebasedfrom
Jongmassey/icd-10-reports-emails-rebased
Open

Add report generation/emailing to ICD-10 feature branch#3223
Jongmassey wants to merge 9 commits into
icd-10-multi-edition-ui-changes-rebasedfrom
Jongmassey/icd-10-reports-emails-rebased

Conversation

@Jongmassey

Copy link
Copy Markdown
Contributor

No description provided.

@Jongmassey
Jongmassey force-pushed the Jongmassey/icd-10-reports-emails-rebased branch from 1ddb522 to b526bbf Compare September 2, 2026 10:11
rw251 and others added 5 commits September 2, 2026 15:32
- Queries a local db file for any codelists that flag either of the two warning banners
- Writes pdfs with summary of issues and links to the codelists
- Writes an example pdf with real OpenSAFELY codelists
- Groups codelists into user and organisation codelists
- For users outputs a csv with user email and pdf filename

# Conflicts:
#	coding_systems/icd10/known_diffs.py
- Previous edition didn't have 5 character modifier codes
- If someone has a code with children that exist in the new db but that don't in the old one, then we should notify them
- There are some edge cases e.g. M45 as a 3 character code which has no 4 character children, but has 5th character modified codes like M45X0
- The script now requires you to pass the new db and the old db so it can find all modified codes that couldn't be found in the old data
Full list of all affected codelists along with full list of all affected codes
Fields now, type, email, org, codelist url and pdf filename. Also includes org codelists
Uses simplified format to match codelists
@Jongmassey
Jongmassey force-pushed the Jongmassey/icd-10-reports-emails-rebased branch from b526bbf to 96a5c2e Compare September 2, 2026 14:32
Jongmassey and others added 3 commits September 2, 2026 15:43
Use the full ehrql_codelists.json dump to allow finding inline codes affected by ICD10 issues.

Write out condensed csv format for upload to GSheets.
Also strip out the code to map users to OCL orgs as that wasn't too useful
This uses mailgun with the same configuration as Anymail used elsewhere
in OpenCodelists.

It sends one email per user, for user-owned codelists only.
Organisations with affected codelists will be emailed separately.

User's `name`s are templated into the email body,
and so they are added to the reporting csv output which the emailer
consumes.
@Jongmassey
Jongmassey force-pushed the Jongmassey/icd-10-reports-emails-rebased branch from 96a5c2e to 8ce27d5 Compare September 2, 2026 14:43
@Jongmassey

Copy link
Copy Markdown
Contributor Author

@rw251 Do you want to do any further fettling/squishing etc. of commits here before merged into the feature branch?

# 429 codes are either rate exceeded (2 types), or too large
# https://documentation.mailgun.com/en/latest/api-sending.html#rate-limits
# with message "<why> limit exceeded, try again" where why=[bytes|request|recipient]
if response.status_code == "429":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response.status_code is an integer so I think this conditional is never true - but also I think the mailgun response has changed (https://documentation.mailgun.com/docs/mailgun/api-reference/api-overview#api-response-codes) and not sure it returns a "why" message. Might be easiest to just remove this

Comment thread scripts/icd10_reports/email.py Outdated
continue
try:
if only_seeds and email.lower() not in seed_emails:
continue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - but currently in dry run it prints "would send.." for everyone even if a seeds list is given. We could either move this if only_seeds higher up, or add a print like "Actually not in seeds so wouldn't send"

Comment thread scripts/generate_icd10_warning_pdfs.py Outdated
f"recipients.csv, summary.md, issues.json, and example.pdf."
)
if args.send_emails:
send_emails(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran this locally and it didn't print out the dry run messages - I think the generator isn't being consumed?

Multiple lines of defence against sending emails by mistake:
* default is to generate, not email
* dry run by default
* only to seed emails by default
@Jongmassey
Jongmassey force-pushed the Jongmassey/icd-10-reports-emails-rebased branch from 8ce27d5 to a8acb2b Compare September 2, 2026 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants