From 2cb25e817cfc35b6d0fedb5e7628b87a77f2ea3c Mon Sep 17 00:00:00 2001 From: Miwory Date: Wed, 15 Apr 2026 15:14:24 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BA=D0=BE=D0=BD=D0=B2=D0=B5=D1=80=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20xml=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B0=D1=82=D0=B0=20=D0=B2=20pdf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- src/apps/users/v1/router.py | 7 ++++--- src/apps/users/v1/schema.py | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8f03353..b37ad30 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "HospitalAssistantBackend" -version = "1.5.1" +version = "1.5.2" description = "Backend for Hospital Assistant" readme = "README.md" requires-python = ">=3.13,<3.14" diff --git a/src/apps/users/v1/router.py b/src/apps/users/v1/router.py index 5ec5fa6..3ae12a2 100644 --- a/src/apps/users/v1/router.py +++ b/src/apps/users/v1/router.py @@ -116,8 +116,9 @@ async def get_vaccs_report_download( if file is None: raise e.BadRequestException - file_bytes = base64.b64decode(file.content) filename = f'vaccs_report_{resultId or user.vita_id}.doc' + xml_model = s.ClinicalDocument.from_xml(file.content.encode('utf-8')) + inner_base64 = xml_model.component.non_xml_body.text.content.strip() temp_link_token = token_urlsafe(32) await cache.set( @@ -125,8 +126,8 @@ async def get_vaccs_report_download( dumps( { 'filename': filename, - 'content_type': 'application/msword', - 'data': base64.b64encode(file_bytes).decode('utf-8'), + 'content_type': 'application/pdf', + 'data': inner_base64, } ), ex=600, diff --git a/src/apps/users/v1/schema.py b/src/apps/users/v1/schema.py index 8737b4e..be2b780 100644 --- a/src/apps/users/v1/schema.py +++ b/src/apps/users/v1/schema.py @@ -1,3 +1,4 @@ +from pydantic_xml import BaseXmlModel, attr, element from typing import TypedDict from pydantic import BaseModel @@ -35,5 +36,26 @@ class Complaints(BaseModel): complaints: str +NS = 'urn:hl7-org:v3' + + +class TextElement(BaseXmlModel, tag='text', ns=NS): + representation: str = attr() + media_type: str = attr(name='mediaType') + content: str + + +class NonXMLBody(BaseXmlModel, tag='nonXMLBody', ns=NS): + text: TextElement = element() + + +class Component(BaseXmlModel, tag='component', ns=NS): + non_xml_body: NonXMLBody = element(tag='nonXMLBody') + + +class ClinicalDocument(BaseXmlModel, tag='ClinicalDocument', ns=NS): + component: Component = element() + + class DownloadFile(BaseModel): link: str