add person id
This commit is contained in:
@@ -27,6 +27,11 @@ async def get_medical_card(
|
||||
) -> Optional[MedicalCardDetailOut]:
|
||||
return medical_cards_service.get(medical_card_id)
|
||||
|
||||
@router.get('/person/{person_id}', response_model=MedicalCardDetailOut)
|
||||
async def get_medical_card_by_person(
|
||||
person_id: UUID4, medical_cards_service: MedicalCardService = Depends(get_medical_cards_service)
|
||||
) -> Optional[MedicalCardDetailOut]:
|
||||
return medical_cards_service.get_by_person(person_id)
|
||||
@router.post('/', status_code=201, response_model=MedicalCardShortOut)
|
||||
async def create_medical_card(
|
||||
medical_card: MedicalCardCreateIn, medical_cards_service: MedicalCardService = Depends(get_medical_cards_service)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import Any, List, Optional
|
||||
from medical_info.db.schemas import (
|
||||
PersonOut,
|
||||
PersonOut,
|
||||
MedicalCardOut,
|
||||
MedicalCardDetailOut,
|
||||
MedicalCardCreateIn,
|
||||
@@ -46,13 +46,13 @@ class MedicalCardService(BaseService[models.MedicalCard, MedicalCardCreateIn, An
|
||||
raise HTTPException(status_code=exc.response.status_code, detail=f"Ошибка вызова {exc.request.url!r}.")
|
||||
|
||||
return parse_obj_as(PersonOut, response.json())
|
||||
|
||||
|
||||
def list(self, searchstring: str) -> List[MedicalCardOut]:
|
||||
if searchstring is None or searchstring == '':
|
||||
raise HTTPException(status_code=409, detail='searchstring is required')
|
||||
|
||||
persons = self.get_persons(searchstring)
|
||||
person_ids = [person.id for person in persons]
|
||||
person_ids = [person.id for person in persons]
|
||||
|
||||
if len(person_ids) < 1:
|
||||
return []
|
||||
@@ -64,7 +64,7 @@ class MedicalCardService(BaseService[models.MedicalCard, MedicalCardCreateIn, An
|
||||
for p in persons:
|
||||
if str(mc.person_id) == str(p.id):
|
||||
mc.person = p
|
||||
|
||||
|
||||
return medical_cards
|
||||
|
||||
def get(self, id: UUID4) -> Optional[MedicalCardDetailOut]:
|
||||
@@ -77,15 +77,24 @@ class MedicalCardService(BaseService[models.MedicalCard, MedicalCardCreateIn, An
|
||||
|
||||
return medical_card
|
||||
|
||||
def get_by_person(self, id: UUID4) -> Optional[MedicalCardDetailOut]:
|
||||
medical_card_obj: Optional[models.MedicalCard] = self.db_session.get(self.model, {"person_id": id})
|
||||
if medical_card_obj is None:
|
||||
raise HTTPException(status_code=404, detail=f'Медкарта {id} не найдена')
|
||||
|
||||
medical_card = MedicalCardDetailOut.from_orm(medical_card_obj)
|
||||
medical_card.person = self.get_person(medical_card_obj.person_id)
|
||||
|
||||
return medical_card
|
||||
|
||||
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')
|
||||
|
||||
|
||||
for column, value in mc_request.dict(exclude_unset=True).items():
|
||||
setattr(mc_obj, column, value)
|
||||
|
||||
self.db_session.commit()
|
||||
|
||||
|
||||
return mc_obj
|
||||
|
||||
Reference in New Issue
Block a user