Фикс
All checks were successful
Build And Push / publish (push) Successful in 2m35s

This commit is contained in:
2026-04-15 16:15:29 +03:00
parent 8f92e91994
commit f4a4bd7ddd
5 changed files with 107 additions and 27 deletions

View File

@ -7,11 +7,14 @@ from typing import Annotated
from fastapi import APIRouter, Body, Depends, UploadFile, status
from orjson import loads
from xsdata.formats.dataclass.parsers.config import ParserConfig
from xsdata_pydantic.bindings import XmlParser
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
from apps.xml.clinical_document import ClinicalDocument
from clients import clients as c
from clients.tmk import schema as ts
from clients.vitacore import schema as vs
@ -28,6 +31,12 @@ router = APIRouter(
],
)
config = ParserConfig(
fail_on_unknown_attributes=False, fail_on_unknown_properties=False
)
parser = XmlParser(config=config)
@router.get(
'/getProfile',
@ -118,9 +127,10 @@ async def get_vaccs_report_download(
filename = f'vaccs_report_{resultId or user.vita_id}.doc'
xml_data = base64.b64decode(file.content)
xml_data = xml_data.strip()
xml_model = s.ClinicalDocument.from_xml(xml_data)
inner_base64 = xml_model.component.non_xml_body.text.content.strip()
xml_data = xml_data.decode('utf-8').strip()
xml_model = parser.from_string(xml_data, ClinicalDocument)
pdf_string = xml_model.component.non_xmlbody.text.value.strip()
pdf_bytes = base64.b64decode(pdf_string)
temp_link_token = token_urlsafe(32)
await cache.set(
@ -129,7 +139,7 @@ async def get_vaccs_report_download(
{
'filename': filename,
'content_type': 'application/pdf',
'data': inner_base64,
'data': pdf_bytes,
}
),
ex=600,

View File

@ -1,7 +1,6 @@
from typing import TypedDict
from pydantic import BaseModel
from pydantic_xml import BaseXmlModel, attr, element
class AEMDFile(TypedDict):
@ -36,26 +35,5 @@ class Complaints(BaseModel):
complaints: str
NS = 'urn:hl7-org:v3'
class TextElement(BaseXmlModel, tag='text', ns=NS):
representation: str | None = attr(default=None)
media_type: str | None = attr(name='mediaType', default=None)
content: str
class NonXMLBody(BaseXmlModel, tag='nonXMLBody', ns=NS):
text: TextElement = element(tag='text')
class Component(BaseXmlModel, tag='component', ns=NS):
non_xml_body: NonXMLBody = element(tag='nonXMLBody')
class ClinicalDocument(BaseXmlModel, tag='ClinicalDocument', ns=NS):
component: Component = element(tag='component')
class DownloadFile(BaseModel):
link: str

0
src/apps/xml/__init__.py Normal file
View File

View File

@ -0,0 +1,90 @@
from __future__ import annotations
from pydantic import BaseModel, ConfigDict
from xsdata_pydantic.fields import field
__NAMESPACE__ = 'urn:hl7-org:v3'
class Text(BaseModel):
class Meta:
name = 'text'
namespace = 'urn:hl7-org:v3'
model_config = ConfigDict(defer_build=True)
representation: str = field( # type: ignore
metadata={
'type': 'Attribute',
}
)
media_type: str = field( # type: ignore
metadata={
'name': 'mediaType',
'type': 'Attribute',
}
)
value: str = field(default='') # type: ignore
class NonXmlbody(BaseModel):
class Meta:
name = 'nonXMLBody'
namespace = 'urn:hl7-org:v3'
model_config = ConfigDict(defer_build=True)
class_code: str = field( # type: ignore
metadata={
'name': 'classCode',
'type': 'Attribute',
}
)
mood_code: str = field( # type: ignore
metadata={
'name': 'moodCode',
'type': 'Attribute',
}
)
text: Text = field( # type: ignore
metadata={
'type': 'Element',
}
)
class Component(BaseModel):
class Meta:
name = 'component'
namespace = 'urn:hl7-org:v3'
model_config = ConfigDict(defer_build=True)
non_xmlbody: NonXmlbody = field( # type: ignore
metadata={
'name': 'nonXMLBody',
'type': 'Element',
}
)
class ClinicalDocument(BaseModel):
class Meta:
namespace = 'urn:hl7-org:v3'
model_config = ConfigDict(defer_build=True)
schema_location: str = field( # type: ignore
metadata={
'name': 'schemaLocation',
'type': 'Attribute',
'namespace': 'http://www.w3.org/2001/XMLSchema-instance',
}
)
mood_code: str = field( # type: ignore
metadata={
'name': 'moodCode',
'type': 'Attribute',
}
)
component: Component = field( # type: ignore
metadata={
'type': 'Element',
}
)