Skip to content

Commit

Permalink
small code clean up for routes (#99)
Browse files Browse the repository at this point in the history
Problem
there are some easy improvements to the routes

Solution
- removed unused imports
- fixed some copy paste naming errors
- replaced return type Any with actual return type
- change return HTTPException with raise HTTPException

Ticket URL
Start of this ticket: https://mediform.atlassian.net/browse/MEDI-55
Documentation
NA

Tests Run
- make all && make testapi
  • Loading branch information
MadelaineJ authored Feb 11, 2024
1 parent dcd582b commit ed32aa3
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from typing import Any
from uuid import UUID

from fastapi import Depends, HTTPException, Response
Expand All @@ -11,24 +10,21 @@
from api.main.auth import load_current_user
from api.main.database import get_db
from api.models.user import UserMedical as User
from api.models.patient_encounter import PatientEncounter
from api.models.patient_encounter import (
get_patient_encounter_by_uuid,
soft_delete_patient_encounter,
)
from api.schemas.patient_encounter import PatientEncounterSchema

LOGGER = logging.getLogger(__name__)


@router.delete(
"/patient-encounter",
status_code=204,
name="get-patient-encounter",
name="delete-patient-encounter",
)
def delete_patient_encounter(
uuid: UUID,
loaded_user: User = Depends(load_current_user),
db: Session = Depends(get_db),
) -> Response:
"""
Expand All @@ -38,7 +34,7 @@ def delete_patient_encounter(
encounter = get_patient_encounter_by_uuid(db, str(uuid))
except Exception as err:
LOGGER.error(f"Server error while trying to find patient encounter: {err}")
return HTTPException(
raise HTTPException(
status_code=500,
detail="Unable to find that patient encounter at this time. Please try again later or contact support.",
)
Expand All @@ -52,7 +48,7 @@ def delete_patient_encounter(
soft_delete_patient_encounter(db, str(uuid))
except Exception as err:
LOGGER.error(f"Server error while trying to delete patient encounter: {err}")
return HTTPException(
raise HTTPException(
status_code=500,
detail="Unable to delete patient encounter at this time. Please try again later or contact support.",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from uuid import UUID
from typing import Any

from fastapi import Depends, HTTPException
Expand All @@ -25,9 +24,8 @@
)
def get_latest_patient_encounter_rfid(
patient_rfid: str,
loaded_user: User = Depends(load_current_user),
db: Session = Depends(get_db),
) -> Any:
) -> PatientEncounterResponseSchema:
"""
Retrieve a patient encounter from the database with the provided RFID.
"""
Expand All @@ -37,7 +35,7 @@ def get_latest_patient_encounter_rfid(
LOGGER.error(
f"Server error while trying to get patient encounter: {err}",
)
return HTTPException(
raise HTTPException(
status_code=500,
detail="Unable to get patient encounter at this time. Please try again later or contact support.",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
)
def get_patient_encounter(
uuid: UUID,
loaded_user: User = Depends(load_current_user),
db: Session = Depends(get_db),
) -> Any:
) -> PatientEncounterResponseSchema:
"""
Retrieve a patient encounter from the database with the provided UUID.
"""
Expand All @@ -37,7 +36,7 @@ def get_patient_encounter(
LOGGER.error(
f"Server error while trying to get patient encounters: {err}",
)
return HTTPException(
raise HTTPException(
status_code=500,
detail="Unable to get patient encounters at this time. Please try again later or contact support.",
)
Expand Down
3 changes: 1 addition & 2 deletions app/api/routes/patient_encounter/get_patient_encounters.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
name="get-patient-encounters",
)
def get_patient_encounters(
loaded_user: User = Depends(load_current_user),
db: Session = Depends(get_db),
arrival_date_min: Optional[str] = Query(
None, description="The start date of the patient encounter(s) to retrieve."
),
arrival_date_max: Optional[str] = Query(
None, description="The end date of the patient encounter(s) to retrieve."
),
) -> Any:
) -> List[PatientEncounterResponseSchema]:
"""
Retrieve all patient encounters from the database and return a list of patient encounters.
Expand Down
4 changes: 2 additions & 2 deletions app/api/routes/patient_encounter/submit_patient_encounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def post_patient_encounter(
data: PatientEncounterSchema,
loaded_user: User = Depends(load_current_user),
db: Session = Depends(get_db),
) -> Any:
) -> PatientEncounterResponseSchema:
"""
Create a new patient encounter.
"""
Expand All @@ -39,7 +39,7 @@ def post_patient_encounter(
encounter = create_patient_encounter(db, new_encounter)
except Exception as err:
LOGGER.error(f"Server error while trying to create patient encounter: {err}")
return HTTPException(
raise HTTPException(
status_code=500,
detail="Unable to create patient encounter at this time. Please try again later or contact support.",
)
Expand Down
8 changes: 3 additions & 5 deletions app/api/routes/patient_encounter/update_patient_encounter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
from typing import Any
from uuid import UUID

from fastapi import Depends, HTTPException

Expand Down Expand Up @@ -30,17 +29,16 @@
)
def update_encounter(
data: PatientEncounterResponseSchema,
loaded_user: User = Depends(load_current_user),
db: Session = Depends(get_db),
) -> Any:
) -> PatientEncounterResponseSchema:
"""
Update a given patient encounter. In the event that a patient
"""
try:
encounter = get_patient_encounter_by_uuid(db, data.patient_encounter_uuid)
except Exception as err:
LOGGER.error(f"Server error while trying to retrieve patient encounter: {err}")
return HTTPException(
raise HTTPException(
status_code=500,
detail="Unable to retrieve patient encounter to update at this time. Please try again later or contact support.",
)
Expand All @@ -57,7 +55,7 @@ def update_encounter(
updated_encounter = update_patient_encounter(db, encounter, data_dict)
except Exception as err:
LOGGER.error(f"Server error while trying to update patient encounter: {err}")
return HTTPException(
raise HTTPException(
status_code=500,
detail="Unable to update patient encounter at this time. Please try again later or contact support.",
)
Expand Down

0 comments on commit ed32aa3

Please sign in to comment.