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 retrieving file uploads in doctor notes #2291

Closed
Closed
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
4 changes: 4 additions & 0 deletions care/facility/api/serializers/file_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def check_permissions(file_type, associating_id, user, action="create"): # noqa
FileUpload.FileType.COMMUNICATION.value,
):
return associating_id
elif file_type == FileUpload.FileType.COMMUNICATION.value:
return associating_id
elif file_type == FileUpload.FileType.NOTES.value:
return associating_id
msg = "Undefined File Type"
raise Exception(msg)

Expand Down
12 changes: 12 additions & 0 deletions care/facility/api/serializers/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
from care.users.models import User
from care.utils.notification_handler import NotificationGenerator
from care.utils.queryset.facility import get_home_facility_queryset
from care.utils.serializer.external_id_field import ExternalIdSerializerField
from care.facility.models.file_upload import FileUpload
from care.utils.serializers.fields import ChoiceField, ExternalIdSerializerField


Expand Down Expand Up @@ -491,6 +493,15 @@ class PatientNotesSerializer(serializers.ModelSerializer):
allow_null=True,
)
reply_to_object = ReplyToPatientNoteSerializer(source="reply_to", read_only=True)
files = serializers.SerializerMethodField()

def get_files(self, obj):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This serves a lot of internal metadata about the row which is not needed.

return FileUpload.objects.filter(
associating_id=obj.id,
file_type=FileUpload.FileType.NOTES.value,
upload_completed=True,
is_archived=False,
).values()

def validate_empty_values(self, data):
if not data.get("note", "").strip():
Expand Down Expand Up @@ -575,6 +586,7 @@ class Meta:
"last_edited_date",
"reply_to",
"reply_to_object",
"files",
)
read_only_fields = (
"id",
Expand Down
1 change: 1 addition & 0 deletions care/facility/models/file_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class FileType(models.IntegerChoices):
COMMUNICATION = 6, "COMMUNICATION"
CONSENT_RECORD = 7, "CONSENT_RECORD"
ABDM_HEALTH_INFORMATION = 8, "ABDM_HEALTH_INFORMATION"
NOTES = 9, "NOTES"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we retrieve the files? there is no authz implemented for the same.


file_type = models.IntegerField(choices=FileType, default=FileType.PATIENT)
is_archived = models.BooleanField(default=False)
Expand Down