From 74b397b04772c559fe09d14227e8c36faa7e16f8 Mon Sep 17 00:00:00 2001 From: Jacobjohnjeevan Date: Sat, 7 Dec 2024 20:05:19 +0530 Subject: [PATCH 1/2] Daily round notifications fix --- ...68_notifications_dailyround_external_id.py | 29 +++++++++++++++++++ care/utils/notification_handler.py | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 care/facility/migrations/0468_notifications_dailyround_external_id.py diff --git a/care/facility/migrations/0468_notifications_dailyround_external_id.py b/care/facility/migrations/0468_notifications_dailyround_external_id.py new file mode 100644 index 0000000000..c64f60d028 --- /dev/null +++ b/care/facility/migrations/0468_notifications_dailyround_external_id.py @@ -0,0 +1,29 @@ +# Generated by Django 5.1.3 on 2024-12-07 14:15 + +from django.db import migrations + + +def update_daily_rounds(apps, schema_editor): + Notification = apps.get_model("facility", "Notification") + DailyRound = apps.get_model("facility", "DailyRound") + + for notification in Notification.objects.all(): + + if daily_round_id := notification.caused_objects.get("daily_round"): + try: + daily_round = DailyRound.objects.get(id=daily_round_id) + notification.caused_objects["daily_round"] = str(daily_round.external_id) + notification.save() + except DailyRound.DoesNotExist: + # Handle the case where the DailyRound does not exist + pass + +class Migration(migrations.Migration): + + dependencies = [ + ('facility', '0467_alter_hospitaldoctors_area'), + ] + + operations = [ + migrations.RunPython(update_daily_rounds), + ] diff --git a/care/utils/notification_handler.py b/care/utils/notification_handler.py index 0ec1718ee0..eca26aa602 100644 --- a/care/utils/notification_handler.py +++ b/care/utils/notification_handler.py @@ -287,7 +287,7 @@ def generate_cause_objects(self): self.caused_objects["patient"] = str( self.caused_object.consultation.patient.external_id ) - self.caused_objects["daily_round"] = str(self.caused_object.id) + self.caused_objects["daily_round"] = str(self.caused_object.external_id) if self.caused_object.consultation.patient.facility: self.caused_objects["facility"] = str( self.caused_object.consultation.facility.external_id From 078a876bbe726844b9bb216365fabfa321ec5c63 Mon Sep 17 00:00:00 2001 From: Jacob John Jeevan <40040905+Jacobjeevan@users.noreply.github.com> Date: Fri, 13 Dec 2024 18:49:51 +0530 Subject: [PATCH 2/2] Delete care/facility/migrations/0468_notifications_dailyround_external_id.py --- ...68_notifications_dailyround_external_id.py | 29 ------------------- 1 file changed, 29 deletions(-) delete mode 100644 care/facility/migrations/0468_notifications_dailyround_external_id.py diff --git a/care/facility/migrations/0468_notifications_dailyround_external_id.py b/care/facility/migrations/0468_notifications_dailyround_external_id.py deleted file mode 100644 index c64f60d028..0000000000 --- a/care/facility/migrations/0468_notifications_dailyround_external_id.py +++ /dev/null @@ -1,29 +0,0 @@ -# Generated by Django 5.1.3 on 2024-12-07 14:15 - -from django.db import migrations - - -def update_daily_rounds(apps, schema_editor): - Notification = apps.get_model("facility", "Notification") - DailyRound = apps.get_model("facility", "DailyRound") - - for notification in Notification.objects.all(): - - if daily_round_id := notification.caused_objects.get("daily_round"): - try: - daily_round = DailyRound.objects.get(id=daily_round_id) - notification.caused_objects["daily_round"] = str(daily_round.external_id) - notification.save() - except DailyRound.DoesNotExist: - # Handle the case where the DailyRound does not exist - pass - -class Migration(migrations.Migration): - - dependencies = [ - ('facility', '0467_alter_hospitaldoctors_area'), - ] - - operations = [ - migrations.RunPython(update_daily_rounds), - ]