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

Remove event handlers #2593

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 1 addition & 19 deletions care/facility/api/serializers/daily_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from rest_framework import serializers
from rest_framework.exceptions import ValidationError

from care.facility.events.handler import create_consultation_events
from care.facility.models import (
CATEGORY_CHOICES,
COVID_CATEGORY_CHOICES,
Expand Down Expand Up @@ -167,17 +166,7 @@ def update(self, instance, validated_data):
facility=instance.consultation.patient.facility,
).generate()

instance = super().update(instance, validated_data)

create_consultation_events(
instance.consultation_id,
instance,
instance.created_by_id,
instance.created_date,
fields_to_store=set(validated_data.keys()),
)

return instance
return super().update(instance, validated_data)

def update_last_daily_round(self, daily_round_obj):
consultation = daily_round_obj.consultation
Expand Down Expand Up @@ -279,13 +268,6 @@ def create(self, validated_data):
if daily_round_obj.rounds_type != DailyRound.RoundsType.AUTOMATED.value:
self.update_last_daily_round(daily_round_obj)

create_consultation_events(
daily_round_obj.consultation_id,
daily_round_obj,
daily_round_obj.created_by_id,
daily_round_obj.created_date,
taken_at=daily_round_obj.taken_at,
)
return daily_round_obj

def validate(self, attrs):
Expand Down
30 changes: 2 additions & 28 deletions care/facility/api/serializers/encounter_symptom.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from copy import copy

from django.db import transaction
from django.utils.timezone import now
from rest_framework import serializers

from care.facility.events.handler import create_consultation_events
from care.facility.models.encounter_symptom import (
ClinicalImpressionStatus,
EncounterSymptom,
Expand Down Expand Up @@ -90,34 +86,12 @@ def create(self, validated_data):
validated_data["consultation"] = self.context["consultation"]
validated_data["created_by"] = self.context["request"].user

with transaction.atomic():
instance: EncounterSymptom = super().create(validated_data)

create_consultation_events(
instance.consultation_id,
instance,
instance.created_by_id,
instance.created_date,
)

return instance
return super().create(validated_data)

def update(self, instance, validated_data):
validated_data["updated_by"] = self.context["request"].user

with transaction.atomic():
old_instance = copy(instance)
instance = super().update(instance, validated_data)

create_consultation_events(
instance.consultation_id,
instance,
instance.updated_by_id,
instance.modified_date,
old=old_instance,
)

return instance
return super().update(instance, validated_data)


class EncounterCreateSymptomSerializer(serializers.ModelSerializer):
Expand Down
30 changes: 2 additions & 28 deletions care/facility/api/serializers/patient_consultation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from copy import copy
from datetime import timedelta

from django.conf import settings
Expand All @@ -24,7 +23,6 @@
EncounterSymptomSerializer,
)
from care.facility.api.serializers.facility import FacilityBasicInfoSerializer
from care.facility.events.handler import create_consultation_events
from care.facility.models import (
CATEGORY_CHOICES,
COVID_CATEGORY_CHOICES,
Expand Down Expand Up @@ -219,7 +217,6 @@ def validate_bed_number(self, bed_number):
return bed_number

def update(self, instance, validated_data):
old_instance = copy(instance)
instance.last_edited_by = self.context["request"].user

if instance.discharge_date:
Expand Down Expand Up @@ -269,14 +266,6 @@ def update(self, instance, validated_data):

consultation = super().update(instance, validated_data)

create_consultation_events(
consultation.id,
consultation,
self.context["request"].user.id,
consultation.modified_date,
old=old_instance,
)

if (
"assigned_to" in validated_data
and validated_data["assigned_to"] != _temp
Expand Down Expand Up @@ -415,7 +404,7 @@ def create(self, validated_data): # noqa: PLR0915 PLR0912
):
consultation.is_readmission = True

diagnosis = ConsultationDiagnosis.objects.bulk_create(
ConsultationDiagnosis.objects.bulk_create(
[
ConsultationDiagnosis(
consultation=consultation,
Expand All @@ -428,7 +417,7 @@ def create(self, validated_data): # noqa: PLR0915 PLR0912
]
)

symptoms = EncounterSymptom.objects.bulk_create(
EncounterSymptom.objects.bulk_create(
EncounterSymptom(
consultation=consultation,
symptom=obj.get("symptom"),
Expand Down Expand Up @@ -469,13 +458,6 @@ def create(self, validated_data): # noqa: PLR0915 PLR0912
consultation.save()
patient.save()

create_consultation_events(
consultation.id,
(consultation, *diagnosis, *symptoms),
consultation.created_by.id,
consultation.created_date,
)

NotificationGenerator(
event=Notification.Event.PATIENT_CONSULTATION_CREATED,
caused_by=user,
Expand Down Expand Up @@ -793,7 +775,6 @@ def validate(self, attrs):
return attrs

def update(self, instance: PatientConsultation, validated_data):
old_instance = copy(instance)
with transaction.atomic():
instance = super().update(instance, validated_data)
patient: PatientRegistration = instance.patient
Expand All @@ -804,13 +785,6 @@ def update(self, instance: PatientConsultation, validated_data):
ConsultationBed.objects.filter(
consultation=self.instance, end_date__isnull=True
).update(end_date=now())
create_consultation_events(
instance.id,
instance,
self.context["request"].user.id,
instance.modified_date,
old=old_instance,
)

return instance

Expand Down
35 changes: 1 addition & 34 deletions care/facility/api/viewsets/consultation_diagnosis.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
from copy import copy

from django.shortcuts import get_object_or_404
from django_filters import rest_framework as filters
from dry_rest_permissions.generics import DRYPermissions
from rest_framework import mixins
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

from care.facility.api.serializers.consultation_diagnosis import (
ConsultationDiagnosisSerializer,
)
from care.facility.events.handler import create_consultation_events
from care.facility.models import (
ConditionVerificationStatus,
ConsultationDiagnosis,
Expand Down Expand Up @@ -56,33 +52,4 @@ def get_queryset(self):

def perform_create(self, serializer):
consultation = self.get_consultation_obj()
diagnosis = serializer.save(
consultation=consultation, created_by=self.request.user
)
create_consultation_events(
consultation.id,
diagnosis,
caused_by=self.request.user.id,
created_date=diagnosis.created_date,
)

def perform_update(self, serializer):
return serializer.save()

def update(self, request, *args, **kwargs):
partial = kwargs.pop("partial", False)
instance = self.get_object()
old_instance = copy(instance)
serializer = self.get_serializer(instance, data=request.data, partial=partial)
serializer.is_valid(raise_exception=True)
instance = self.perform_update(serializer)

create_consultation_events(
instance.consultation_id,
instance,
caused_by=self.request.user.id,
created_date=instance.created_date,
old=old_instance,
)

return Response(serializer.data)
serializer.save(consultation=consultation, created_by=self.request.user)
8 changes: 0 additions & 8 deletions care/facility/api/viewsets/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
)
from care.facility.api.serializers.patient_icmr import PatientICMRSerializer
from care.facility.api.viewsets.mixins.history import HistoryMixin
from care.facility.events.handler import create_consultation_events
from care.facility.models import (
CATEGORY_CHOICES,
COVID_CATEGORY_CHOICES,
Expand Down Expand Up @@ -1045,13 +1044,6 @@ def perform_create(self, serializer):
created_by=self.request.user,
)

create_consultation_events(
instance.consultation_id,
instance,
self.request.user.id,
instance.created_date,
)

message = {
"facility_id": str(patient.facility.external_id),
"patient_id": str(patient.external_id),
Expand Down
Empty file removed care/facility/events/__init__.py
Empty file.
116 changes: 0 additions & 116 deletions care/facility/events/handler.py

This file was deleted.

Loading
Loading