Skip to content

Commit

Permalink
refactor: Update entities_mrg.py and entities_std.py routers to use p…
Browse files Browse the repository at this point in the history
…ipeline permissions for user validation
  • Loading branch information
TanookiVerde committed Sep 19, 2024
1 parent cda3f8a commit 4174891
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
17 changes: 9 additions & 8 deletions app/routers/entities_mrg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from tortoise.exceptions import ValidationError

from app.dependencies import (
assert_user_is_active
assert_user_has_pipeline_read_permition,
assert_user_has_pipeline_write_permition
)
from app.types.pydantic_models import (
CompletePatientModel,
Expand Down Expand Up @@ -49,7 +50,7 @@

@router.put("/patient")
async def create_or_update_patient(
_: Annotated[User, Depends(assert_user_is_active)],
_: Annotated[User, Depends(assert_user_has_pipeline_write_permition)],
patients: List[PydanticMergedPatient],
) -> int:

Expand Down Expand Up @@ -83,7 +84,7 @@ async def create_or_update_patient(

@router.put("/patientaddress")
async def create_or_update_patientaddress(
_: Annotated[User, Depends(assert_user_is_active)],
_: Annotated[User, Depends(assert_user_has_pipeline_write_permition)],
patientaddress_list: List[PydanticMergedPatientAddress],
) -> int:
# Get list of patient codes
Expand Down Expand Up @@ -113,7 +114,7 @@ async def create_or_update_patientaddress(

@router.put("/patienttelecom")
async def create_or_update_patienttelecom(
_: Annotated[User, Depends(assert_user_is_active)],
_: Annotated[User, Depends(assert_user_has_pipeline_write_permition)],
patienttelecom_list: List[PydanticMergedPatientTelecom],
) -> int:
# Get list of patient codes
Expand Down Expand Up @@ -142,7 +143,7 @@ async def create_or_update_patienttelecom(

@router.put("/patientcns")
async def create_or_update_patientcns(
_: Annotated[User, Depends(assert_user_is_active)],
_: Annotated[User, Depends(assert_user_has_pipeline_write_permition)],
patientcns_list: List[PydanticMergedPatientCns],
) -> int:
# Get list of patient codes
Expand Down Expand Up @@ -171,7 +172,7 @@ async def create_or_update_patientcns(

@router.get("/patient/{patient_cpf}")
async def get_patient(
_: Annotated[User, Depends(assert_user_is_active)],
_: Annotated[User, Depends(assert_user_has_pipeline_read_permition)],
patient_cpf: int,
)-> list[CompletePatientModel]:

Expand Down Expand Up @@ -227,7 +228,7 @@ async def get_patient(

@router.put("/professionals")
async def create_or_update_professionals(
_: Annotated[User, Depends(assert_user_is_active)],
_: Annotated[User, Depends(assert_user_has_pipeline_write_permition)],
professionals: List[ProfessionalModel],
) -> int:

Expand Down Expand Up @@ -330,7 +331,7 @@ async def create_or_update_professionals(

@router.put("/teams")
async def create_or_update_teams(
_: Annotated[User, Depends(assert_user_is_active)],
_: Annotated[User, Depends(assert_user_has_pipeline_write_permition)],
teams: List[TeamModel],
) -> int:

Expand Down
14 changes: 8 additions & 6 deletions app/routers/entities_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
from fastapi import APIRouter, Depends
from fastapi.responses import HTMLResponse


from tortoise import Tortoise
from tortoise.contrib.pydantic import pydantic_model_creator
from tortoise.exceptions import ValidationError, DoesNotExist

from app.dependencies import assert_user_is_active
from app.dependencies import (
assert_user_has_pipeline_read_permition,
assert_user_has_pipeline_write_permition
)
from app.types.pydantic_models import (
PatientMergeableRecord, StandardizedPatientRecordModel, StandardizedPatientConditionModel,
BulkInsertOutputModel, MergeableRecord, Page
Expand All @@ -37,7 +39,7 @@

@router.get("/patientrecords/updated")
async def get_patientrecords_of_updated_patients(
_: Annotated[User, Depends(assert_user_is_active)],
_: Annotated[User, Depends(assert_user_has_pipeline_read_permition)],
start_datetime: datetime.datetime = datetime.datetime.now() -
datetime.timedelta(hours=1),
end_datetime: datetime.datetime = datetime.datetime.now(),
Expand Down Expand Up @@ -100,7 +102,7 @@ async def get_patientrecords_of_updated_patients(

@router.post("/patientrecords", status_code=201)
async def create_standardized_patientrecords(
_: Annotated[User, Depends(assert_user_is_active)],
_: Annotated[User, Depends(assert_user_has_pipeline_write_permition)],
records: list[StandardizedPatientRecordModel],
) -> BulkInsertOutputModel:

Expand Down Expand Up @@ -164,7 +166,7 @@ async def create_standardized_patientrecords(

@router.get("/patientconditions")
async def get_standardized_patientconditions(
_: Annotated[User, Depends(assert_user_is_active)],
_: Annotated[User, Depends(assert_user_has_pipeline_read_permition)],
patient_cpf: str,
) -> list[MergeableRecord[StandardizedPatientConditionModel]]:

Expand All @@ -188,7 +190,7 @@ async def get_standardized_patientconditions(

@router.post("/patientconditions", status_code=201)
async def create_standardized_patientconditions(
_: Annotated[User, Depends(assert_user_is_active)],
_: Annotated[User, Depends(assert_user_has_pipeline_write_permition)],
conditions: list[StandardizedPatientConditionModel],
) -> BulkInsertOutputModel:

Expand Down

0 comments on commit 4174891

Please sign in to comment.