This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "HospitalAssistantBackend"
|
name = "HospitalAssistantBackend"
|
||||||
version = "1.5.5"
|
version = "1.5.6"
|
||||||
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"
|
||||||
@ -35,6 +35,8 @@ dependencies = [
|
|||||||
"lxml==6.0.2; sys_platform != 'win32'",
|
"lxml==6.0.2; sys_platform != 'win32'",
|
||||||
# CLI
|
# CLI
|
||||||
"typer-slim==0.16.1",
|
"typer-slim==0.16.1",
|
||||||
|
"xsdata[cli]>=26.2",
|
||||||
|
"xsdata-pydantic>=24.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependency-groups]
|
[dependency-groups]
|
||||||
|
|||||||
@ -7,11 +7,14 @@ from typing import Annotated
|
|||||||
|
|
||||||
from fastapi import APIRouter, Body, Depends, UploadFile, status
|
from fastapi import APIRouter, Body, Depends, UploadFile, status
|
||||||
from orjson import loads
|
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.remd.dependencies import convert_aemd_to_pdf, get_parsable_ids
|
||||||
from apps.tdn.auth import token
|
from apps.tdn.auth import token
|
||||||
from apps.users.auth import login
|
from apps.users.auth import login
|
||||||
from apps.users.models import User
|
from apps.users.models import User
|
||||||
|
from apps.xml.clinical_document import ClinicalDocument
|
||||||
from clients import clients as c
|
from clients import clients as c
|
||||||
from clients.tmk import schema as ts
|
from clients.tmk import schema as ts
|
||||||
from clients.vitacore import schema as vs
|
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(
|
@router.get(
|
||||||
'/getProfile',
|
'/getProfile',
|
||||||
@ -118,9 +127,10 @@ async def get_vaccs_report_download(
|
|||||||
|
|
||||||
filename = f'vaccs_report_{resultId or user.vita_id}.doc'
|
filename = f'vaccs_report_{resultId or user.vita_id}.doc'
|
||||||
xml_data = base64.b64decode(file.content)
|
xml_data = base64.b64decode(file.content)
|
||||||
xml_data = xml_data.strip()
|
xml_data = xml_data.decode('utf-8').strip()
|
||||||
xml_model = s.ClinicalDocument.from_xml(xml_data)
|
xml_model = parser.from_string(xml_data, ClinicalDocument)
|
||||||
inner_base64 = xml_model.component.non_xml_body.text.content.strip()
|
pdf_string = xml_model.component.non_xmlbody.text.value.strip()
|
||||||
|
pdf_bytes = base64.b64decode(pdf_string)
|
||||||
|
|
||||||
temp_link_token = token_urlsafe(32)
|
temp_link_token = token_urlsafe(32)
|
||||||
await cache.set(
|
await cache.set(
|
||||||
@ -129,7 +139,7 @@ async def get_vaccs_report_download(
|
|||||||
{
|
{
|
||||||
'filename': filename,
|
'filename': filename,
|
||||||
'content_type': 'application/pdf',
|
'content_type': 'application/pdf',
|
||||||
'data': inner_base64,
|
'data': pdf_bytes,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
ex=600,
|
ex=600,
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
from typing import TypedDict
|
from typing import TypedDict
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from pydantic_xml import BaseXmlModel, attr, element
|
|
||||||
|
|
||||||
|
|
||||||
class AEMDFile(TypedDict):
|
class AEMDFile(TypedDict):
|
||||||
@ -36,26 +35,5 @@ class Complaints(BaseModel):
|
|||||||
complaints: str
|
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):
|
class DownloadFile(BaseModel):
|
||||||
link: str
|
link: str
|
||||||
|
|||||||
0
src/apps/xml/__init__.py
Normal file
0
src/apps/xml/__init__.py
Normal file
90
src/apps/xml/clinical_document.py
Normal file
90
src/apps/xml/clinical_document.py
Normal 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',
|
||||||
|
}
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user