ref CRU Medical Cards
This commit is contained in:
@@ -1,22 +1,23 @@
|
||||
from typing import Any, List, Optional
|
||||
from medical_info.db.models import MedicalCard
|
||||
from medical_info.db.schemas import (
|
||||
PersonOut,
|
||||
MedicalCardOut,
|
||||
MedicalCardDetailOut,
|
||||
MedicalCardCreate, MedicalCardBase, MedicalCardResponse)
|
||||
MedicalCardCreateIn,
|
||||
MedicalCardUpdateIn
|
||||
)
|
||||
from medical_info.services.base import BaseService
|
||||
from sqlalchemy.orm import Session
|
||||
from pydantic import parse_obj_as
|
||||
from pydantic.types import UUID4
|
||||
from medical_info.db import schemas, models
|
||||
from medical_info.db import models
|
||||
from starlette.exceptions import HTTPException
|
||||
import os
|
||||
import httpx
|
||||
|
||||
class MedicalCardService(BaseService[MedicalCard, MedicalCardCreate, Any]):
|
||||
class MedicalCardService(BaseService[models.MedicalCard, MedicalCardCreateIn, Any]):
|
||||
def __init__(self, db_session: Session):
|
||||
super(MedicalCardService, self).__init__(MedicalCard, db_session)
|
||||
super(MedicalCardService, self).__init__(models.MedicalCard, db_session)
|
||||
LOCAL_PERSONAL_INFO_URL = 'http://localhost:8001/persons'
|
||||
self.PERSONAL_INFO_URL = os.environ.get('ASTRA-PESONAL-INFORMATION') or LOCAL_PERSONAL_INFO_URL
|
||||
|
||||
@@ -46,7 +47,7 @@ class MedicalCardService(BaseService[MedicalCard, MedicalCardCreate, Any]):
|
||||
|
||||
return parse_obj_as(PersonOut, response.json())
|
||||
|
||||
def list(self, searchstring: str) -> Any:
|
||||
def list(self, searchstring: str) -> List[MedicalCardOut]:
|
||||
if searchstring is None or searchstring == '':
|
||||
raise HTTPException(status_code=409, detail='searchstring is required')
|
||||
|
||||
@@ -76,7 +77,7 @@ class MedicalCardService(BaseService[MedicalCard, MedicalCardCreate, Any]):
|
||||
|
||||
return medical_card
|
||||
|
||||
def update(self, id: UUID4, mc_request: schemas.MedicalCardUpdateRq) -> Optional[MedicalCard]:
|
||||
def update(self, id: UUID4, mc_request: MedicalCardUpdateIn) -> Optional[MedicalCardOut]:
|
||||
mc_obj = self.db_session.get(self.model, id)
|
||||
if mc_obj is None:
|
||||
raise HTTPException(status_code=404, detail='NotFound')
|
||||
|
||||
Reference in New Issue
Block a user