Skip to content

Commit

Permalink
Duplicated .pdf in the discharge summary file names (#1978)
Browse files Browse the repository at this point in the history
* Add test for discharge summary file name

* Remove .pdf from discharge summary file name

---------

Co-authored-by: Aakash Singh <[email protected]>
  • Loading branch information
krassowska and sainak authored Mar 20, 2024
1 parent 02804ec commit 0ff895a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
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

0 comments on commit 0ff895a

Please sign in to comment.