This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import base64
|
||||
import io
|
||||
from datetime import UTC, datetime
|
||||
from json import dumps
|
||||
from logging import getLogger
|
||||
@ -5,8 +7,10 @@ from secrets import token_urlsafe
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Body, Depends, UploadFile, status
|
||||
from fastapi.responses import StreamingResponse
|
||||
from orjson import loads
|
||||
|
||||
from apps.remd.dependencies import convert_aemd_to_pdf, get_parsable_ids
|
||||
from apps.tdn.auth import token
|
||||
from apps.users.auth import login
|
||||
from apps.users.models import User
|
||||
@ -28,13 +32,13 @@ router = APIRouter(
|
||||
)
|
||||
|
||||
|
||||
@cache_response(ttl=600, namespace='main')
|
||||
@router.get(
|
||||
'/getProfile',
|
||||
responses={
|
||||
status.HTTP_200_OK: {'model': vs.ProfileModel},
|
||||
},
|
||||
)
|
||||
@cache_response(ttl=600, namespace='main')
|
||||
async def get_profile(user: Annotated[User, Depends(login)]):
|
||||
"""
|
||||
Get profile of user.
|
||||
@ -42,13 +46,13 @@ async def get_profile(user: Annotated[User, Depends(login)]):
|
||||
return await c.vitacore_api.getProfile(user.vita_id)
|
||||
|
||||
|
||||
@cache_response(ttl=3600, namespace='main')
|
||||
@router.get(
|
||||
'/getDepartments',
|
||||
responses={
|
||||
status.HTTP_200_OK: {'model': vs.OrganizationsModel},
|
||||
},
|
||||
)
|
||||
@cache_response(ttl=3600, namespace='main')
|
||||
async def get_departments():
|
||||
"""
|
||||
Get list of departments.
|
||||
@ -56,10 +60,10 @@ async def get_departments():
|
||||
return await c.vitacore_api.getDepartments()
|
||||
|
||||
|
||||
@cache_response(ttl=3600, namespace='main')
|
||||
@router.get(
|
||||
'/getWorkers', responses={status.HTTP_200_OK: {'model': vs.WorkersModel}}
|
||||
)
|
||||
@cache_response(ttl=3600, namespace='main')
|
||||
async def get_workers(
|
||||
user: Annotated[User, Depends(login)], departmentId: str
|
||||
):
|
||||
@ -69,11 +73,11 @@ async def get_workers(
|
||||
return await c.vitacore_api.getWorkers(departmentId)
|
||||
|
||||
|
||||
@cache_response(ttl=3600, namespace='main')
|
||||
@router.get(
|
||||
'/getSpecs',
|
||||
responses={status.HTTP_200_OK: {'model': vs.SpecsV021Model}},
|
||||
)
|
||||
@cache_response(ttl=3600, namespace='main')
|
||||
async def get_specs(user: Annotated[User, Depends(login)]):
|
||||
"""
|
||||
Get list of specialties.
|
||||
@ -198,7 +202,10 @@ async def queue(_: Annotated[User, Depends(login)]):
|
||||
|
||||
|
||||
@router.get('/aemd')
|
||||
async def get_aemd(user: Annotated[User, Depends(login)]):
|
||||
async def get_aemd(
|
||||
user: Annotated[User, Depends(login)],
|
||||
parsable_ids: Annotated[list[str], Depends(get_parsable_ids)],
|
||||
):
|
||||
profile = await c.vitacore_api.getProfile(user.vita_id)
|
||||
snils = profile.SNILS.replace('-', '').replace(' ', '')
|
||||
docs = await c.aemd_api.searchRegistryItem(patient_snils=snils)
|
||||
@ -206,6 +213,9 @@ async def get_aemd(user: Annotated[User, Depends(login)]):
|
||||
return_items: list[s.AEMDReturnFile] = []
|
||||
|
||||
for item in items:
|
||||
if item['DocKind'] not in parsable_ids:
|
||||
continue
|
||||
|
||||
is_cached = await cache.get(f'aemd:{user.vita_id}:{item["emdrId"]}')
|
||||
|
||||
return_items.append(
|
||||
@ -232,13 +242,25 @@ async def post_aemd(user: Annotated[User, Depends(login)], emdrId: str):
|
||||
|
||||
|
||||
@router.get('/aemd/{emdrId}')
|
||||
async def get_aemd_file(user: Annotated[User, Depends(login)], emdrId: str):
|
||||
async def get_aemd_file(
|
||||
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')
|
||||
|
||||
return loads(data)
|
||||
b64 = loads(data)['data']
|
||||
decoded = base64.b64decode(b64)
|
||||
pdf = await convert_aemd_to_pdf(decoded, docKind)
|
||||
|
||||
return StreamingResponse(
|
||||
io.BytesIO(pdf),
|
||||
media_type='application/pdf',
|
||||
headers={
|
||||
'Content-Disposition': f'attachment; filename="{emdrId}.pdf"'
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@router.post('/measurement', status_code=status.HTTP_202_ACCEPTED)
|
||||
|
||||
Reference in New Issue
Block a user