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

Duplicated .pdf in the discharge summary file names #1978

Merged
merged 3 commits into from
Mar 20, 2024
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
6 changes: 4 additions & 2 deletions care/facility/models/file_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ class FileCategory(enum.Enum):
FileTypeChoices = [(e.value, e.name) for e in FileType]
FileCategoryChoices = [(e.value, e.name) for e in FileCategory]

name = models.CharField(max_length=2000)
internal_name = models.CharField(max_length=2000)
name = models.CharField(max_length=2000) # name should not contain file extension
internal_name = models.CharField(
max_length=2000
) # internal_name should include file extension
associating_id = models.CharField(max_length=100, blank=False, null=False)
upload_completed = models.BooleanField(default=False)
is_archived = models.BooleanField(default=False)
Expand Down
28 changes: 28 additions & 0 deletions care/facility/tests/test_patient_consultation_api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import datetime
from unittest.mock import patch

from django.utils.timezone import make_aware
from rest_framework import status
from rest_framework.test import APITestCase

from care.facility.api.serializers.patient_consultation import MIN_ENCOUNTER_DATE
from care.facility.models.file_upload import FileUpload
from care.facility.models.icd11_diagnosis import (
ConditionVerificationStatus,
ICD11Diagnosis,
Expand Down Expand Up @@ -224,6 +226,32 @@ def test_discharge_as_recovered_with_expired_fields(self):
self.assertIsNone(consultation.death_datetime)
self.assertIsNot(consultation.death_confirmed_doctor, "Dr. Test")

def discharge_summary(self, consultation, **kwargs):
return self.client.post(
f"{self.get_url(consultation)}generate_discharge_summary/", kwargs, "json"
)

def test_discharge_summary(self):
consultation = self.create_admission_consultation(
suggestion=SuggestionChoices.A,
encounter_date=make_aware(datetime.datetime(2020, 4, 1, 15, 30, 00)),
)
with patch.object(FileUpload, "put_object"):
self.discharge_summary(
consultation,
new_discharge_reason=NewDischargeReasonEnum.RECOVERED,
discharge_date="2020-04-02T15:30:00Z",
discharge_notes="Discharge as recovered after admission before future",
)

file_res = FileUpload.objects.filter(
associating_id=consultation.external_id,
upload_completed=True,
is_archived=False,
)
uploaded_file = file_res[0]
self.assertFalse(uploaded_file.name.endswith(".pdf"))

def test_referred_to_external_null(self):
consultation = self.create_admission_consultation(
suggestion=SuggestionChoices.A,
Expand Down
2 changes: 1 addition & 1 deletion care/facility/utils/reports/discharge_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def generate_and_upload_discharge_summary(consultation: PatientConsultation):
try:
current_date = timezone.now()
summary_file = FileUpload(
name=f"discharge_summary-{consultation.patient.name}-{current_date}.pdf",
name=f"discharge_summary-{consultation.patient.name}-{current_date}",
internal_name=f"{uuid4()}.pdf",
file_type=FileUpload.FileType.DISCHARGE_SUMMARY.value,
associating_id=consultation.external_id,
Expand Down
Loading