Skip to content

Commit 62c6869

Browse files
authored
fix: Refactors ehr zip download to use storage path (M2-9443) (#1893)
Simplifies the ehr zip download process by directly using the storage path. This eliminates redundant path construction and improves code readability.
1 parent 490401d commit 62c6869

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/apps/answers/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,9 @@ async def applet_ehr_answers_export(
969969
)
970970
ehr_zip_buffer = io.BytesIO()
971971
try:
972-
ehr_zip_filename = ehr_storage.download_ehr_zip(data, ehr_zip_buffer)
972+
ehr_zip_filename = ehr_storage.download_ehr_zip(
973+
storage_path=ehr_answer.ehr_storage_uri, data=data, file_buffer=ehr_zip_buffer
974+
)
973975

974976
zip_file.writestr(ehr_zip_filename, ehr_zip_buffer.getvalue())
975977
finally:

src/apps/answers/tests/test_answers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4432,7 +4432,7 @@ async def test_applet_ehr_data_endpoint(
44324432

44334433
file_names = []
44344434

4435-
def _mock_download_ehr_zip(data, file_buffer):
4435+
def _mock_download_ehr_zip(storage_path, data, file_buffer):
44364436
file_buffer.write(b"mocked EHR zip data")
44374437
file_buffer.seek(0)
44384438

@@ -4486,7 +4486,7 @@ async def test_applet_ehr_data_endpoint_filtering_by_flow(
44864486

44874487
file_names = []
44884488

4489-
def _mock_download_ehr_zip(data, file_buffer):
4489+
def _mock_download_ehr_zip(storage_path, data, file_buffer):
44904490
file_buffer.write(b"mocked EHR zip data")
44914491
file_buffer.seek(0)
44924492

src/apps/integrations/oneup_health/service/ehr_storage.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,9 @@ async def upload_ehr_zip(self, resources_files: list[str], data: EHRData) -> tup
110110
finally:
111111
zip_buffer.close()
112112

113-
def download_ehr_zip(self, data: EHRData, file_buffer: BinaryIO) -> str:
114-
base_path = self._get_base_path(data)
113+
def download_ehr_zip(self, storage_path: str, data: EHRData, file_buffer: BinaryIO) -> str:
115114
filename = EHRStorage.ehr_zip_filename(data)
116-
key = self._cdn_client.generate_key(FileScopeEnum.EHR, base_path, filename)
115+
key = f"{storage_path}/{filename}"
117116

118117
self._cdn_client.download(key, file_buffer)
119118

0 commit comments

Comments
 (0)