Files
HospitalAssistantBackend/src/clients/vitacore/api.py
Miwory a34deaedb3
All checks were successful
Build And Push / publish (push) Successful in 2m25s
Фиксы
2025-10-02 08:55:24 +03:00

192 lines
6.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from logging import getLogger
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 VITACORE_API(AsyncClient):
def __init__(self):
self.logger = getLogger(__name__)
super().__init__(base_url=settings.VITACORE_BASE_URL)
async def findBySnils(self, snils: str):
return
async def getProfile(self, patId: str):
req = await self.get('/getProfile', params={'patId': patId})
match req.status_code:
case st.HTTP_200_OK:
return s.ProfileModel.model_validate(req.json())
case _:
self.logger.error(req.json())
raise e.UnknownException
async def getDepartments(self):
req = await self.get('/getDepartments')
match req.status_code:
case st.HTTP_200_OK:
return s.OrganizationsModel.model_validate(req.json())
case _:
self.logger.error(req.json())
raise e.UnknownException
async def getWorkers(self, departmentId: str):
req = await self.get(
'/getWorkers', params={'departmentId': departmentId}
)
match req.status_code:
case st.HTTP_200_OK:
return s.WorkersModel.model_validate(req.json()['workers'])
case _:
self.logger.error(req.json())
raise e.UnknownException
async def getSpecsV021(self):
req = await self.get('/getSpecsV021')
match req.status_code:
case st.HTTP_200_OK:
return s.SpecsV021Model.model_validate(req.json())
case _:
self.logger.error(req.json())
raise e.UnknownException
async def getEntries(self, patId: str):
req = await self.get('/getEntries', params={'patId': patId})
match req.status_code:
case st.HTTP_200_OK:
return s.EntriesModel.model_validate(req.json())
case st.HTTP_206_PARTIAL_CONTENT:
error = s.ErrorModel.model_validate(req.json())
if error.error == 'Не найдены записи по указанному patId':
return s.EntriesModel(Entries=[])
case _:
self.logger.error(req.json())
raise e.UnknownException
async def getVaccsReport(self, patId: str):
req = await self.get('/getVaccsReport', params={'patId': patId})
match req.status_code:
case st.HTTP_200_OK:
return s.VaccsReportModel.model_validate(req.json())
case _:
self.logger.error(req.json())
raise e.UnknownException
async def getMedExamDict(self):
req = await self.get('/getMedExamDict')
match req.status_code:
case st.HTTP_200_OK:
return s.MedExamDictModel.model_validate(req.json())
case _:
self.logger.error(req.json())
raise e.UnknownException
async def getRoutesList(self, patId: str):
req = await self.get('/getRoutesList', params={'patId': patId})
match req.status_code:
case st.HTTP_200_OK:
return s.RoutesListModel.model_validate(req.json())
case _:
self.logger.error(req.json())
raise e.UnknownException
async def getHospExaminations(self, patId: str, examId: str):
req = await self.get(
'/getHospExaminations',
params={'patId': patId, 'examId': examId},
)
match req.status_code:
case st.HTTP_200_OK:
return s.HospExaminationsModel.model_validate(req.json())
case _:
self.logger.error(req.json())
raise e.UnknownException
async def getCurrHosp(self, patId: str):
req = await self.get('/getCurrHosp', params={'patId': patId})
match req.status_code:
case st.HTTP_200_OK:
return s.HospitalizationsModel.model_validate(req.json())
case _:
self.logger.error(req.json())
raise e.UnknownException
async def getHosps(self, patId: str):
req = await self.get('/getHosps', params={'patId': patId})
match req.status_code:
case st.HTTP_200_OK:
return s.HospitalizationsModel.model_validate(req.json())
case _:
self.logger.error(req.json())
raise e.UnknownException
async def getHospRecommendations(self, patId: str):
req = await self.get(
'/getHospRecommendations', params={'patId': patId}
)
match req.status_code:
case st.HTTP_200_OK:
return s.HospRecommendationsModel.model_validate(req.json())
case _:
self.logger.error(req.json())
raise e.UnknownException
async def getHospRoutes(self, patId: str):
req = await self.get('/getHospRoutes', params={'patId': patId})
match req.status_code:
case st.HTTP_200_OK:
return s.HospRoutesModel.model_validate(req.json())
case _:
self.logger.error(req.json())
raise e.UnknownException
async def getDiagnosticResults(self, patId: str):
req = await self.get('/getDiagnosticResults', params={'patId': patId})
match req.status_code:
case st.HTTP_200_OK:
return s.DiagnosticResultsModel.model_validate(req.json())
case _:
self.logger.error(req.json())
raise e.UnknownException
async def getELNs(self, patId: str):
req = await self.get('/getELNs', params={'patId': patId})
match req.status_code:
case st.HTTP_200_OK:
return s.ELNsModel.model_validate(req.json())
case _:
self.logger.error(req.json())
raise e.UnknownException
async def getPatFLG(self, patId: str):
req = await self.get('/getPatFLG', params={'patId': patId})
match req.status_code:
case st.HTTP_200_OK:
return s.PatientFLGModel.model_validate(req.json())
case _:
self.logger.error(req.json())
raise e.UnknownException