Skip to content

Commit

Permalink
feat: Handle HTTP exceptions for patient not found and invalid CPF
Browse files Browse the repository at this point in the history
  • Loading branch information
TanookiVerde committed Aug 12, 2024
1 parent 3c14ab7 commit b156305
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions app/routers/frontend.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from typing import Annotated, List

from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, HTTPException

from app.dependencies import get_current_active_user
from app.models import User
Expand Down Expand Up @@ -39,6 +39,12 @@ async def get_patient_header(
_: Annotated[User, Depends(get_current_active_user)],
cpf: str,
) -> PatientHeader:

if cpf == '19530236069':
raise HTTPException(status_code=404, detail="Patient not found")
elif cpf == '11111111111':
raise HTTPException(status_code=400, detail="Invalid CPF")

return {
"registration_name": "José da Silva Xavier",
"social_name": None,
Expand Down Expand Up @@ -74,6 +80,12 @@ async def get_patient_summary(
_: Annotated[User, Depends(get_current_active_user)],
cpf: str,
) -> PatientSummary:

if cpf == '19530236069':
raise HTTPException(status_code=404, detail="Patient not found")
elif cpf == '11111111111':
raise HTTPException(status_code=400, detail="Invalid CPF")

return {
"allergies": [
"Sulfonamidas",
Expand Down Expand Up @@ -103,6 +115,12 @@ async def get_patient_encounters(
_: Annotated[User, Depends(get_current_active_user)],
cpf: str,
) -> List[Encounter]:

if cpf == '19530236069':
raise HTTPException(status_code=404, detail="Patient not found")
elif cpf == '11111111111':
raise HTTPException(status_code=400, detail="Invalid CPF")

return [
{
"entry_datetime": "2023-09-05T10:00:00",
Expand Down Expand Up @@ -143,7 +161,7 @@ async def get_patient_encounters(
"Lorem ipsum dolor sit amet consectetur. Sed vel suscipit id pulvinar"
"sed nam libero eu. Leo arcu sit lacus nisl nullam eget et dignissim sed."
),
"filter_tags": ["Pediatria"],
"filter_tags": ["CF", "Agendada"],
},
{
"entry_datetime": "2021-05-11T12:00:00",
Expand All @@ -156,6 +174,6 @@ async def get_patient_encounters(
"description": (
"Lorem ipsum dolor sit amet consectetur. Sed vel suscipit id pulvinar."
),
"filter_tags": [],
"filter_tags": ["CMS"],
}
]

0 comments on commit b156305

Please sign in to comment.