This commit is contained in:
@ -1,6 +1,7 @@
|
||||
from .aemd.api import AEMD_API
|
||||
from .esia.api import ESIA_API
|
||||
from .tdn.api import TDN_API
|
||||
from .tmk.api import TMK_API
|
||||
from .vitacore.api import VITACORE_API
|
||||
|
||||
|
||||
@ -8,6 +9,7 @@ class ClientsObject:
|
||||
_esia_api = None
|
||||
_vitacore_api = None
|
||||
_tdn_api = None
|
||||
_tmk_api = None
|
||||
_aemd_api = None
|
||||
|
||||
@property
|
||||
@ -31,6 +33,13 @@ class ClientsObject:
|
||||
|
||||
return self._tdn_api
|
||||
|
||||
@property
|
||||
def tmk_api(self):
|
||||
if not self._tmk_api:
|
||||
self._tmk_api = TMK_API()
|
||||
|
||||
return self._tmk_api
|
||||
|
||||
@property
|
||||
def aemd_api(self):
|
||||
if not self._aemd_api:
|
||||
|
||||
0
src/clients/tmk/__init__.py
Normal file
0
src/clients/tmk/__init__.py
Normal file
97
src/clients/tmk/api.py
Normal file
97
src/clients/tmk/api.py
Normal file
@ -0,0 +1,97 @@
|
||||
from datetime import date
|
||||
from logging import getLogger
|
||||
from typing import Literal
|
||||
|
||||
from fastapi import status as st
|
||||
from httpx import AsyncClient
|
||||
|
||||
from core.config import settings
|
||||
from shared import exceptions as e
|
||||
from shared.functions import clean_params
|
||||
from shared.redis import client as cache
|
||||
|
||||
from . import schema as s
|
||||
|
||||
|
||||
class TMK_API(AsyncClient):
|
||||
def __init__(self):
|
||||
self.logger = getLogger(__name__)
|
||||
super().__init__(
|
||||
base_url=settings.TMK_BASE_URL,
|
||||
)
|
||||
|
||||
async def get_token(self):
|
||||
token = cache.get('tmk_token')
|
||||
|
||||
if token is None:
|
||||
token = await self.login()
|
||||
cache.set('tmk_token', token, 10800)
|
||||
|
||||
else:
|
||||
token = token.decode()
|
||||
|
||||
return token
|
||||
|
||||
async def login(self):
|
||||
req = await self.post(
|
||||
'/auth',
|
||||
json={
|
||||
'login': settings.TMK_LOGIN,
|
||||
'password': settings.TMK_PASSWORD,
|
||||
},
|
||||
)
|
||||
|
||||
match req.status_code:
|
||||
case st.HTTP_200_OK:
|
||||
return s.AccessTokenModel.model_validate(
|
||||
req.json()
|
||||
).access_token
|
||||
|
||||
case _:
|
||||
self.logger.error(req.json())
|
||||
raise e.UnknownException
|
||||
|
||||
async def getQueue(
|
||||
self,
|
||||
code_mo: str | None = None,
|
||||
doctor_spec: str | None = None,
|
||||
doctor_snils: str | None = None,
|
||||
doctor_snils_strict: Literal['y', 'n'] = 'n',
|
||||
date_begin: date | None = None,
|
||||
date_end: date | None = None,
|
||||
patient_snils: str | None = None,
|
||||
patient_fio: str | None = None,
|
||||
patient_policy: str | None = None,
|
||||
patient_phone: str | None = None,
|
||||
patient_birthdate: date | None = None,
|
||||
tk_status: str | None = None,
|
||||
):
|
||||
token = await self.get_token()
|
||||
req = await self.get(
|
||||
'/getQueue',
|
||||
headers={'Authorization': f'Bearer {token}'},
|
||||
params=clean_params(
|
||||
{
|
||||
'code_mo': code_mo,
|
||||
'doctor_spec': doctor_spec,
|
||||
'doctor_snils': doctor_snils,
|
||||
'doctor_snils_strict': doctor_snils_strict,
|
||||
'date_begin': date_begin,
|
||||
'date_end': date_end,
|
||||
'patient_snils': patient_snils,
|
||||
'patient_fio': patient_fio,
|
||||
'patient_policy': patient_policy,
|
||||
'patient_phone': patient_phone,
|
||||
'patient_birthdate': patient_birthdate,
|
||||
'tk_status': tk_status,
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
match req.status_code:
|
||||
case st.HTTP_200_OK:
|
||||
return [s.QueueModel.model_validate(i) for i in req.json()]
|
||||
|
||||
case _:
|
||||
self.logger.error(req.json())
|
||||
raise e.UnknownException
|
||||
31
src/clients/tmk/schema.py
Normal file
31
src/clients/tmk/schema.py
Normal file
@ -0,0 +1,31 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class AccessTokenModel(BaseModel):
|
||||
access_token: str
|
||||
|
||||
|
||||
class QueueModel(BaseModel):
|
||||
id: int
|
||||
guid: str
|
||||
created_at: datetime
|
||||
code_mo: int | None
|
||||
mo_name: str | None
|
||||
doctor_spec: str
|
||||
doctor_snils: str | None
|
||||
doctor_fio: str | None
|
||||
patient_name: str | None
|
||||
patient_birthday: datetime | None
|
||||
patient_snils: str
|
||||
patient_policy: str | None
|
||||
patient_phone: str | None
|
||||
patient_email: str | None
|
||||
tmk_status: int
|
||||
tmk_status_name: str
|
||||
tmk_cancel_reason: int | None
|
||||
tmk_cancel_reason_name: str | None
|
||||
vks_doctor_link: str | None
|
||||
vks_patient_link: str | None
|
||||
doctor_spec_name: str | None
|
||||
Reference in New Issue
Block a user