Skip to content

Commit

Permalink
feat: implemented filtering by cpf in GET std endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
TanookiVerde committed Jan 12, 2024
1 parent eacfcab commit 1d08e4f
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions api/app/routers/entities_std.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import datetime
from typing import Annotated
from typing import Annotated, Optional

from fastapi import APIRouter, Depends
from tortoise.contrib.pydantic import pydantic_model_creator
Expand All @@ -27,21 +27,21 @@
@router.get("/patientrecords", response_model=list[StandardizedPatientRecordOutput])
async def get_standardized_patientrecords(
current_user: Annotated[User, Depends(get_current_active_user)],
start_date: datetime.date = datetime.date.today(),
end_date: datetime.date = datetime.date.today() + datetime.timedelta(days=1),
patient_cpf: Optional[str] = None,
) -> list[StandardizedPatientRecordOutput]:
if current_user.is_superuser:
return await StandardizedPatientRecordOutput.from_queryset(StandardizedPatientRecord.filter(
created_at__gte=start_date,
created_at__lt=end_date
))

user_data_source = await current_user.data_source
return await StandardizedPatientRecordOutput.from_queryset(StandardizedPatientRecord.filter(
raw_source__data_source=user_data_source,
created_at__gte=start_date,
created_at__lt=end_date
))
if patient_cpf is not None:
queryset = StandardizedPatientRecord.filter(
patient_cpf=patient_cpf
)
else:
queryset = StandardizedPatientRecord.all()

if not current_user.is_superuser:
user_data_source = await current_user.data_source
queryset.filter(raw_source__data_source=user_data_source)

return await StandardizedPatientRecordOutput.from_queryset(queryset)


@router.post("/patientrecord", response_model=StandardizedPatientRecordOutput,
Expand All @@ -63,24 +63,21 @@ async def create_standardized_patientrecord(
@router.get("/patientconditions", response_model=list[StandardizedPatientConditionOutput])
async def get_standardized_patientconditions(
current_user: Annotated[User, Depends(get_current_active_user)],
start_date: datetime.date = datetime.date.today(),
end_date: datetime.date = datetime.date.today() + datetime.timedelta(days=1),
patient_cpf: Optional[str] = None,
) -> list[StandardizedPatientConditionOutput]:
if current_user.is_superuser:
return await StandardizedPatientConditionOutput.from_queryset(
StandardizedPatientCondition.filter(
created_at__gte=start_date,
created_at__lt=end_date
)

if patient_cpf is not None:
queryset = StandardizedPatientCondition.filter(
patient_cpf=patient_cpf
)
else:
queryset = StandardizedPatientCondition.all()

if not current_user.is_superuser:
user_data_source = await current_user.data_source
queryset.filter(raw_source__data_source=user_data_source)

user_data_source = await current_user.data_source
return await StandardizedPatientConditionOutput.from_queryset(
StandardizedPatientCondition.filter(
raw_source__data_source=user_data_source,
created_at__gte=start_date,
created_at__lt=end_date
))
return await StandardizedPatientConditionOutput.from_queryset(queryset)

@router.post("/patientcondition", response_model=StandardizedPatientConditionOutput,
status_code=201)
Expand Down

0 comments on commit 1d08e4f

Please sign in to comment.