Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call Digital Growth Charts API asynchronously #418

Merged
merged 8 commits into from
Dec 5, 2024
Merged

Conversation

mbarton
Copy link
Member

@mbarton mbarton commented Dec 5, 2024

Fixes #399
Fixes #415

Follow on from #388 and #405, moving the calls to the Digital Growth Charts API to be made asynchronously during CSV upload.

Uploading a CSV of 100 patients with 16 visits each (1600 rows):

  • Before: 66 seconds
  • After: 21.5 seconds

Also pass through warnings from the API as validation errors. This catches height and weight measurements that are so extreme they are wrong (see rcpch/rcpchgrowth-python#32 for the methodology)

@mbarton mbarton self-assigned this Dec 5, 2024
@@ -61,15 +58,7 @@ class Meta:
"hospital_discharge_date",
"hospital_admission_reason",
"dka_additional_therapies",
"hospital_admission_other",
# calculated fields
"height_centile",
Copy link
Member Author

Choose a reason for hiding this comment

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

As these are calculated fields it should not be possible to submit them through the form

pass
cleaned_data["weight"] = weight = round_to_one_decimal_place(weight)

if not getattr(self, "async_validation_results", None):
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the same trick we already use for the patient form, allows us to run things asynchronously for the CSV upload but synchronously for the questionnaire form submission

@@ -0,0 +1,46 @@
from asgiref.sync import async_to_sync
Copy link
Member Author

Choose a reason for hiding this comment

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

I wrote this for performance profiling as you can put cProfile in front of it easily (https://stackoverflow.com/questions/582336/how-do-i-profile-a-python-script).

@mbarton mbarton merged commit 610d7c7 into live Dec 5, 2024
1 check passed
@mbarton mbarton deleted the mbarton/async-dgc branch December 5, 2024 14:10
@mbarton
Copy link
Member Author

mbarton commented Dec 5, 2024

Seen on STAGING (merged by @mbarton 6 minutes and 32 seconds ago) Please check your changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CSV upload calls dGC in sequence Pass through warnings from dGC API
1 participant