From 0ff895a257b7e083e017be265674cfc33578ab1e Mon Sep 17 00:00:00 2001 From: Karolina Krassowska <39529572+krassowska@users.noreply.github.com> Date: Wed, 20 Mar 2024 06:28:31 +0000 Subject: [PATCH] Duplicated .pdf in the discharge summary file names (#1978) * Add test for discharge summary file name * Remove .pdf from discharge summary file name --------- Co-authored-by: Aakash Singh --- care/facility/models/file_upload.py | 6 ++-- .../tests/test_patient_consultation_api.py | 28 +++++++++++++++++++ .../utils/reports/discharge_summary.py | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/care/facility/models/file_upload.py b/care/facility/models/file_upload.py index 584cda5e05..4aec7366ca 100644 --- a/care/facility/models/file_upload.py +++ b/care/facility/models/file_upload.py @@ -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) diff --git a/care/facility/tests/test_patient_consultation_api.py b/care/facility/tests/test_patient_consultation_api.py index 758163f404..5a4104b1ec 100644 --- a/care/facility/tests/test_patient_consultation_api.py +++ b/care/facility/tests/test_patient_consultation_api.py @@ -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, @@ -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, diff --git a/care/facility/utils/reports/discharge_summary.py b/care/facility/utils/reports/discharge_summary.py index 9c7db4db17..ac3afd1665 100644 --- a/care/facility/utils/reports/discharge_summary.py +++ b/care/facility/utils/reports/discharge_summary.py @@ -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,