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

Migrate consultation's assigned_to to assigned_clinicians #1903

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
Refactor generate_extra_users method to optimize database queries
Ashesh3 committed Mar 31, 2024
commit 0951a557cdf096fceea1936789b5c01897ddea67
27 changes: 22 additions & 5 deletions care/utils/notification_handler.py
Original file line number Diff line number Diff line change
@@ -143,23 +143,40 @@ def deserialize_extra_data(self, extra_data):
return extra_data

def generate_extra_users(self):
assigned_clinicians_fields = ("id", "local_body", "district", "state")
if isinstance(self.caused_object, PatientConsultation):
for clinician in self.caused_object.assigned_clinicians.all():
for clinician in self.caused_object.assigned_clinicians.all().only(
*assigned_clinicians_fields
):
self.extra_users.append(clinician.id)
if isinstance(self.caused_object, PatientRegistration):
if self.caused_object.last_consultation:
for (
clinician
) in self.caused_object.last_consultation.assigned_clinicians.all():
) in self.caused_object.last_consultation.assigned_clinicians.all().only(
*assigned_clinicians_fields
):
self.extra_users.append(clinician.id)
if isinstance(self.caused_object, InvestigationSession):
for clinician in self.extra_data["consultation"].assigned_clinicians.all():
for clinician in (
self.extra_data["consultation"]
.assigned_clinicians.all()
.only(*assigned_clinicians_fields)
):
self.extra_users.append(clinician.id)
if isinstance(self.caused_object, InvestigationValue):
for clinician in self.caused_object.consultation.assigned_clinicians.all():
for (
clinician
) in self.caused_object.consultation.assigned_clinicians.all().only(
*assigned_clinicians_fields
):
self.extra_users.append(clinician.id)
if isinstance(self.caused_object, DailyRound):
for clinician in self.caused_object.consultation.assigned_clinicians.all():
for (
clinician
) in self.caused_object.consultation.assigned_clinicians.all().only(
*assigned_clinicians_fields
):
self.extra_users.append(clinician.id)

def generate_system_message(self):