This commit is contained in:
0
src/clients/tdn/__init__.py
Normal file
0
src/clients/tdn/__init__.py
Normal file
106
src/clients/tdn/api.py
Normal file
106
src/clients/tdn/api.py
Normal file
@ -0,0 +1,106 @@
|
||||
from json import dumps
|
||||
from logging import getLogger
|
||||
from urllib.parse import quote, urlencode
|
||||
|
||||
from fastapi import status as st
|
||||
from httpx import AsyncClient
|
||||
|
||||
from core.config import settings
|
||||
from shared import exceptions as e
|
||||
|
||||
from . import schema as s
|
||||
|
||||
|
||||
class TDN_API(AsyncClient):
|
||||
def __init__(self):
|
||||
self.logger = getLogger(__name__)
|
||||
super().__init__(
|
||||
base_url=settings.TDN_BASE_URL,
|
||||
headers={
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
)
|
||||
|
||||
async def signin(self):
|
||||
data = {
|
||||
'username': settings.TDN_LOGIN,
|
||||
'password': settings.TDN_PASSWORD,
|
||||
}
|
||||
|
||||
res = await self.post('/core/auth/signin', json=data)
|
||||
|
||||
match res.status_code:
|
||||
case st.HTTP_200_OK:
|
||||
return s.SignInModel.model_validate(res.json())
|
||||
case _:
|
||||
self.logger.error(res.json())
|
||||
raise e.UnknownException
|
||||
|
||||
async def patient_search(self, access_token: str, vitaId: str):
|
||||
data = quote(dumps({'vitaId': vitaId}))
|
||||
|
||||
_ = await self.get(
|
||||
'/ddn/patient/search',
|
||||
params={'query': data},
|
||||
headers={'Authorization': f'Bearer {access_token}'},
|
||||
)
|
||||
|
||||
async def observations_search(self, access_token: str, patientUid: str):
|
||||
data = quote(dumps({'where': {'patientUid': patientUid}}))
|
||||
|
||||
res = await self.get(
|
||||
'/ddn/observations/search',
|
||||
params={'query': data},
|
||||
headers={'Authorization': f'Bearer {access_token}'},
|
||||
)
|
||||
|
||||
match res.status_code:
|
||||
case st.HTTP_200_OK:
|
||||
return s.ObservationsModel.model_validate(res.json())
|
||||
case _:
|
||||
self.logger.error(res.json())
|
||||
raise e.UnknownException
|
||||
|
||||
async def observations_measurement_search(
|
||||
self, access_token: str, observationUid: str
|
||||
):
|
||||
# data = urlencode(
|
||||
# dumps(
|
||||
# {
|
||||
# 'where': {'observationUid': observationUid},
|
||||
# 'relations': [
|
||||
# 'measurement',
|
||||
# 'obsrvMtMetrics',
|
||||
# 'obsrvMtMetrics.metric',
|
||||
# ],
|
||||
# }
|
||||
# )
|
||||
# )
|
||||
encoded_query = urlencode(
|
||||
{
|
||||
'query': dumps(
|
||||
{
|
||||
'where': {'observationUid': observationUid},
|
||||
'relations': [
|
||||
'measurement',
|
||||
'obsrvMtMetrics',
|
||||
'obsrvMtMetrics.metric',
|
||||
],
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
res = await self.get(
|
||||
f'/ddn/observation/obsrv-measurements/search?{encoded_query}',
|
||||
headers={'Authorization': f'Bearer {access_token}'},
|
||||
)
|
||||
|
||||
match res.status_code:
|
||||
case st.HTTP_200_OK:
|
||||
return s.ObservationMeasurementsModel.model_validate(
|
||||
res.json()
|
||||
)
|
||||
case _:
|
||||
self.logger.error(res.json())
|
||||
raise e.UnknownException
|
||||
80
src/clients/tdn/schema.py
Normal file
80
src/clients/tdn/schema.py
Normal file
@ -0,0 +1,80 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class SignInModel(BaseModel):
|
||||
accessToken: str
|
||||
refreshToken: str
|
||||
|
||||
|
||||
class ObservationModel(BaseModel):
|
||||
uid: str
|
||||
createdAt: datetime
|
||||
updatedAt: datetime
|
||||
realmUid: str
|
||||
patientUid: str
|
||||
nosologyUid: str
|
||||
exclusionReasonUid: str | None
|
||||
exclusionComment: str | None
|
||||
exclusionDate: datetime | None
|
||||
employeeUid: str
|
||||
mobileId: str | None
|
||||
|
||||
|
||||
class ObservationsModel(BaseModel):
|
||||
items: list[ObservationModel]
|
||||
total: int
|
||||
|
||||
|
||||
class MeasurementModel(BaseModel):
|
||||
uid: str
|
||||
createdAt: datetime
|
||||
updatedAt: datetime
|
||||
code: str
|
||||
title: str
|
||||
order: int
|
||||
isSelfControl: bool
|
||||
|
||||
|
||||
class MetricModel(BaseModel):
|
||||
uid: str
|
||||
createdAt: datetime
|
||||
updatedAt: datetime
|
||||
code: str
|
||||
title: str
|
||||
order: int
|
||||
shortName: str
|
||||
measureUid: str | None
|
||||
format: str
|
||||
|
||||
|
||||
class ObservationMtMetricModel(BaseModel):
|
||||
uid: str
|
||||
createdAt: datetime
|
||||
updatedAt: datetime
|
||||
obsrvMeasurementUid: str
|
||||
metricUid: str
|
||||
mobileId: str | None
|
||||
metric: MetricModel
|
||||
|
||||
|
||||
class ObservationMeasurementModel(BaseModel):
|
||||
uid: str
|
||||
createdAt: datetime
|
||||
updatedAt: datetime
|
||||
observationUid: str
|
||||
measurementUid: str
|
||||
timeFrequency: int
|
||||
timePeriod: int
|
||||
timePeriodMeasureUid: str
|
||||
timeOfDay: list[str]
|
||||
comment: str | None
|
||||
mobileId: str | None
|
||||
measurement: MeasurementModel
|
||||
obsrvMtMetrics: list[ObservationMtMetricModel]
|
||||
|
||||
|
||||
class ObservationMeasurementsModel(BaseModel):
|
||||
items: list[ObservationMeasurementModel]
|
||||
total: int
|
||||
Reference in New Issue
Block a user