Skip to content

Commit

Permalink
Added discharge_reason and discharge_notes in Patient Consultation (#902
Browse files Browse the repository at this point in the history
)

* feat (discharge_patient): added discharge_reason and discharge_notes

* fix (serializers/patient_consultation): made discharge_notes and discharge_reason read only

* fix (viewset/patient): added validation to ensure that the reason is within the choices specified

* db: merged conflicting migrations

* fix (viewset/patient): moved discharge reasons array outside of api function

* db: merged migrations

* clean migrations

Co-authored-by: Vignesh Hari <vichuhari100@gmail.com>
  • Loading branch information
khavinshankar and vigneshhari committed Jul 9, 2022
1 parent 5a796bd commit c5738df
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
8 changes: 7 additions & 1 deletion care/facility/api/serializers/patient_consultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from care.facility.models import CATEGORY_CHOICES, Facility, PatientRegistration
from care.facility.models.bed import Bed, ConsultationBed
from care.facility.models.notification import Notification
from care.facility.models.patient_base import SYMPTOM_CHOICES, SuggestionChoices
from care.facility.models.patient_base import SYMPTOM_CHOICES, DISCHARGE_REASON_CHOICES, SuggestionChoices
from care.facility.models.patient_consultation import PatientConsultation
from care.users.api.serializers.user import (
UserAssignedSerializer,
Expand Down Expand Up @@ -51,9 +51,15 @@ class PatientConsultationSerializer(serializers.ModelSerializer):
queryset=User.objects.all(), required=False, allow_null=True
)

discharge_reason = serializers.ChoiceField(
choices=DISCHARGE_REASON_CHOICES, read_only=True, required=False
)
discharge_notes = serializers.CharField(read_only=True)

action = ChoiceField(
choices=PatientRegistration.ActionChoices, write_only=True, required=False
)

review_time = serializers.IntegerField(default=-1, write_only=True, required=False)

last_edited_by = UserBaseMinimumSerializer(read_only=True)
Expand Down
12 changes: 11 additions & 1 deletion care/facility/api/viewsets/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from care.facility.models import (
CATEGORY_CHOICES,
FACILITY_TYPES,
DISCHARGE_REASON_CHOICES,
Facility,
FacilityPatientStatsHistory,
PatientConsultation,
Expand All @@ -54,6 +55,7 @@
from config.authentication import CustomBasicAuthentication, CustomJWTAuthentication, MiddlewareAuthentication

REVERSE_FACILITY_TYPES = covert_choice_dict(FACILITY_TYPES)
DISCHARGE_REASONS = [choice[0] for choice in DISCHARGE_REASON_CHOICES]


class PatientFilterSet(filters.FilterSet):
Expand Down Expand Up @@ -343,9 +345,17 @@ def discharge_patient(self, request, *args, **kwargs):
last_consultation = PatientConsultation.objects.filter(patient=patient).order_by("-id").first()
current_time = localtime(now())
if last_consultation:
reason = request.data.get("discharge_reason")
notes = request.data.get("discharge_notes", "")
if reason not in DISCHARGE_REASONS:
raise serializers.ValidationError(
{"discharge_reason": "discharge reason is not valid"}
)
last_consultation.discharge_reason = reason
last_consultation.discharge_notes = notes
if last_consultation.discharge_date is None:
last_consultation.discharge_date = current_time
last_consultation.save()
last_consultation.save()
ConsultationBed.objects.filter(consultation=last_consultation, end_date__isnull=True).update(
end_date=current_time
)
Expand Down
23 changes: 23 additions & 0 deletions care/facility/migrations/0301_auto_20220709_2051.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.2.11 on 2022-07-09 15:21

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('facility', '0300_merge_20220707_2339'),
]

operations = [
migrations.AddField(
model_name='patientconsultation',
name='discharge_notes',
field=models.TextField(blank=True, default='', null=True),
),
migrations.AddField(
model_name='patientconsultation',
name='discharge_reason',
field=models.CharField(blank=True, choices=[('REC', 'Recovered'), ('REF', 'Referred'), ('EXP', 'Expired')], default=None, max_length=4, null=True),
),
]
6 changes: 5 additions & 1 deletion care/facility/models/patient_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ def reverse_choices(choices):
(None, "UNCLASSIFIED"),
]


DISCHARGE_REASON_CHOICES = [
("REC", "Recovered"),
("REF", "Referred"),
("EXP", "Expired"),
]
class DiseaseStatusEnum(enum.IntEnum):
SUSPECTED = 1
POSITIVE = 2
Expand Down
5 changes: 5 additions & 0 deletions care/facility/models/patient_consultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
ADMIT_CHOICES,
REVERSE_SYMPTOM_CATEGORY_CHOICES,
SYMPTOM_CHOICES,
DISCHARGE_REASON_CHOICES,
SuggestionChoices,
reverse_choices,
)
Expand Down Expand Up @@ -49,6 +50,10 @@ class PatientConsultation(PatientBaseModel, PatientRelatedPermissionMixin):
admitted = models.BooleanField(default=False) # Deprecated
admission_date = models.DateTimeField(null=True, blank=True) # Deprecated
discharge_date = models.DateTimeField(null=True, blank=True)
discharge_reason = models.CharField(
choices=DISCHARGE_REASON_CHOICES, max_length=4, default=None, blank=True, null=True
)
discharge_notes = models.TextField(default="", null=True, blank=True)
bed_number = models.CharField(max_length=100, null=True, blank=True) # Deprecated

is_kasp = models.BooleanField(default=False)
Expand Down

0 comments on commit c5738df

Please sign in to comment.