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

Adds support for doctors and nurses discussions threads in Discussion Notes #2137

Merged
merged 7 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 10 additions & 0 deletions care/facility/api/serializers/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
PatientContactDetails,
PatientMetaInfo,
PatientNotes,
PatientNoteThreadChoices,
PatientRegistration,
)
from care.facility.models.bed import ConsultationBed
Expand Down Expand Up @@ -514,13 +515,18 @@ class PatientNotesSerializer(serializers.ModelSerializer):
allow_null=True,
read_only=True,
)
thread = serializers.ChoiceField(
choices=PatientNoteThreadChoices, required=False, allow_null=False
)

def validate_empty_values(self, data):
if not data.get("note", "").strip():
raise serializers.ValidationError({"note": ["Note cannot be empty"]})
return super().validate_empty_values(data)

def create(self, validated_data):
if "thread" not in validated_data:
raise serializers.ValidationError({"thread": "This field is required"})
user_type = User.REVERSE_TYPE_MAP[validated_data["created_by"].user_type]
# If the user is a doctor and the note is being created in the home facility
# then the user type is doctor else it is a remote specialist
Expand Down Expand Up @@ -548,6 +554,8 @@ def create(self, validated_data):
return instance

def update(self, instance, validated_data):
validated_data.pop("thread", None) # Disallow changing thread of the note.

user = self.context["request"].user
note = validated_data.get("note")

Expand All @@ -572,6 +580,7 @@ class Meta:
"note",
"facility",
"consultation",
"thread",
"created_by_object",
"user_type",
"created_date",
Expand All @@ -583,6 +592,7 @@ class Meta:
"id",
"created_date",
"modified_date",
"user_type",
"last_edited_by",
"last_edited_date",
)
2 changes: 2 additions & 0 deletions care/facility/api/viewsets/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
Facility,
FacilityPatientStatsHistory,
PatientNotes,
PatientNoteThreadChoices,
PatientRegistration,
ShiftingRequest,
)
Expand Down Expand Up @@ -813,6 +814,7 @@ def list(self, request, *args, **kwargs):


class PatientNotesFilterSet(filters.FilterSet):
thread = filters.ChoiceFilter(choices=PatientNoteThreadChoices.choices)
consultation = filters.CharFilter(field_name="consultation__external_id")


Expand Down
19 changes: 19 additions & 0 deletions care/facility/migrations/0429_patientnotes_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.8 on 2024-05-08 06:24

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("facility", "0428_alter_patientmetainfo_occupation"),
]

operations = [
migrations.AddField(
model_name="patientnotes",
name="thread",
field=models.SmallIntegerField(
choices=[(10, "DOCTORS"), (20, "NURSES")], db_index=True, default=10
),
),
]
10 changes: 10 additions & 0 deletions care/facility/models/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,11 @@ class PatientMobileOTP(BaseModel):
otp = models.CharField(max_length=10)


class PatientNoteThreadChoices(models.IntegerChoices):
DOCTORS = 10, "DOCTORS"
NURSES = 20, "NURSES"


class PatientNotes(FacilityBaseModel, ConsultationRelatedPermissionMixin):
patient = models.ForeignKey(
PatientRegistration, on_delete=models.PROTECT, null=False, blank=False
Expand All @@ -748,6 +753,11 @@ class PatientNotes(FacilityBaseModel, ConsultationRelatedPermissionMixin):
on_delete=models.SET_NULL,
null=True,
)
thread = models.SmallIntegerField(
choices=PatientNoteThreadChoices.choices,
db_index=True,
default=PatientNoteThreadChoices.DOCTORS,
)
note = models.TextField(default="", blank=True)

def get_related_consultation(self):
Expand Down
9 changes: 8 additions & 1 deletion care/facility/tests/test_patient_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from rest_framework import status
from rest_framework.test import APITestCase

from care.facility.models import PatientNoteThreadChoices
from care.facility.models.icd11_diagnosis import (
ConditionVerificationStatus,
ICD11Diagnosis,
Expand All @@ -22,6 +23,7 @@ class ExpectedPatientNoteKeys(Enum):
MODIFIED_DATE = "modified_date"
LAST_EDITED_BY = "last_edited_by"
LAST_EDITED_DATE = "last_edited_date"
THREAD = "thread"
USER_TYPE = "user_type"


Expand Down Expand Up @@ -131,6 +133,7 @@ def create_patient_note(
data = {
"facility": patient.facility or self.facility,
"note": note,
"thread": PatientNoteThreadChoices.DOCTORS,
}
data.update(kwargs)
self.client.force_authenticate(user=created_by)
Expand All @@ -140,7 +143,11 @@ def test_patient_notes(self):
self.client.force_authenticate(user=self.state_admin)
patientId = self.patient.external_id
response = self.client.get(
f"/api/v1/patient/{patientId}/notes/?consultation={self.consultation.external_id}"
f"/api/v1/patient/{patientId}/notes/",
{
"consultation": self.consultation.external_id,
"thread": PatientNoteThreadChoices.DOCTORS,
},
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertIsInstance(response.json()["results"], list)
Expand Down
Loading