Добавлен эндпоинт на скачивание файла
All checks were successful
Build And Push / publish (push) Successful in 3m35s

This commit is contained in:
2026-04-13 16:19:22 +03:00
parent cad2397a69
commit 1808617548
2 changed files with 23 additions and 2 deletions

View File

@ -1,6 +1,6 @@
[project] [project]
name = "HospitalAssistantBackend" name = "HospitalAssistantBackend"
version = "1.2.1" version = "1.3.0"
description = "Backend for Hospital Assistant" description = "Backend for Hospital Assistant"
readme = "README.md" readme = "README.md"
requires-python = ">=3.13,<3.14" requires-python = ">=3.13,<3.14"

View File

@ -5,7 +5,7 @@ from logging import getLogger
from secrets import token_urlsafe from secrets import token_urlsafe
from typing import Annotated from typing import Annotated
from fastapi import APIRouter, Body, Depends, UploadFile, status from fastapi import APIRouter, Body, Depends, Response, UploadFile, status
from orjson import loads from orjson import loads
from apps.remd.dependencies import convert_aemd_to_pdf, get_parsable_ids from apps.remd.dependencies import convert_aemd_to_pdf, get_parsable_ids
@ -257,6 +257,27 @@ async def get_aemd_file(
} }
@router.get('/aemd/{emdrId}/download')
async def get_aemd_file_download(
user: Annotated[User, Depends(login)], emdrId: str, docKind: str
):
data = await cache.get(f'aemd:{user.vita_id}:{emdrId}')
if not data:
raise e.NotFoundException(status_code=404, detail='File not found')
b64 = loads(data)['data']
decoded = base64.b64decode(b64)
pdf_bytes = await convert_aemd_to_pdf(decoded, docKind)
filename = f'{emdrId}.pdf'
return Response(
content=pdf_bytes,
media_type='application/pdf',
headers={'Content-Disposition': f'attachment; filename="{filename}"'},
)
@router.post('/measurement', status_code=status.HTTP_202_ACCEPTED) @router.post('/measurement', status_code=status.HTTP_202_ACCEPTED)
async def measurement( async def measurement(
tdn_access_token: Annotated[str, Depends(token)], tdn_access_token: Annotated[str, Depends(token)],