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

fix: Add new fields for patient discharge feature #1155

Merged
merged 1 commit into from
Jan 13, 2023
Merged
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
24 changes: 24 additions & 0 deletions care/facility/api/viewsets/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,30 @@ def discharge_patient(self, request, *args, **kwargs):
if last_consultation.discharge_date is None:
last_consultation.discharge_date = current_time
last_consultation.current_bed = None
if reason == "EXP":
death_datetime = request.data.get("death_datetime")
death_confirmed_doctor = request.data.get("death_confirmed_doctor")
if death_datetime is None:
raise serializers.ValidationError(
{"death_datetime": "Please provide death date and time"}
)
if death_confirmed_doctor is None:
raise serializers.ValidationError(
{"death_confirmed_doctor": "Please provide doctor details"}
)
last_consultation.death_datetime = death_datetime
last_consultation.death_confirmed_doctor = death_confirmed_doctor
if reason == "REC":
prn_prescription = request.data.get("prn_prescription", [])
discharge_advice = request.data.get("discharge_advice", [])
discharge_date = request.data.get("discharge_date")
if discharge_date is None:
raise serializers.ValidationError(
{"discharge_date": "Please set the discharge date"}
)
last_consultation.prn_prescription = prn_prescription
last_consultation.discharge_advice = discharge_advice
last_consultation.discharge_date = discharge_date
last_consultation.save()
ConsultationBed.objects.filter(
consultation=last_consultation, end_date__isnull=True
Expand Down
26 changes: 26 additions & 0 deletions care/facility/migrations/0333_auto_20230112_2233.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 2.2.11 on 2023-01-12 17:03

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("facility", "0332_auto_20230110_2114"),
]

operations = [
migrations.AddField(
model_name="patientconsultation",
name="death_confirmed_doctor",
field=models.TextField(blank=True, default="", null=True),
),
migrations.AddField(
model_name="patientconsultation",
name="death_datetime",
field=models.DateTimeField(blank=True, null=True),
),
]
21 changes: 17 additions & 4 deletions care/facility/models/patient_consultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class PatientConsultation(PatientBaseModel, PatientRelatedPermissionMixin):
REVERSE_SUGGESTION_CHOICES = reverse_choices(SUGGESTION_CHOICES)

patient = models.ForeignKey(
"PatientRegistration", on_delete=models.CASCADE, related_name="consultations"
"PatientRegistration",
on_delete=models.CASCADE,
related_name="consultations",
)

ip_no = models.CharField(max_length=100, default="", null=True, blank=True)
Expand Down Expand Up @@ -94,6 +96,8 @@ class PatientConsultation(PatientBaseModel, PatientRelatedPermissionMixin):
null=True,
)
discharge_notes = models.TextField(default="", null=True, blank=True)
death_datetime = models.DateTimeField(null=True, blank=True)
death_confirmed_doctor = 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 All @@ -103,7 +107,10 @@ class PatientConsultation(PatientBaseModel, PatientRelatedPermissionMixin):
last_updated_by_telemedicine = models.BooleanField(default=False) # Deprecated

assigned_to = models.ForeignKey(
User, on_delete=models.SET_NULL, null=True, related_name="patient_assigned_to"
User,
on_delete=models.SET_NULL,
null=True,
related_name="patient_assigned_to",
)

verified_by = models.TextField(default="", null=True, blank=True)
Expand All @@ -113,11 +120,17 @@ class PatientConsultation(PatientBaseModel, PatientRelatedPermissionMixin):
)

last_edited_by = models.ForeignKey(
User, on_delete=models.SET_NULL, null=True, related_name="last_edited_user"
User,
on_delete=models.SET_NULL,
null=True,
related_name="last_edited_user",
)

last_daily_round = models.ForeignKey(
"facility.DailyRound", on_delete=models.SET_NULL, null=True, default=None
"facility.DailyRound",
on_delete=models.SET_NULL,
null=True,
default=None,
)

current_bed = models.ForeignKey(
Expand Down