From 4ed990c8466ae91b8fe7d0ca2ea6cb256120b815 Mon Sep 17 00:00:00 2001 From: Pedro Nascimento Date: Mon, 29 Jul 2024 16:53:40 -0300 Subject: [PATCH] feat: create new endpoint --- app/models.py | 4 +- app/routers/auth.py | 2 +- app/routers/frontend.py | 112 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 app/routers/frontend.py diff --git a/app/models.py b/app/models.py index b2a81b7..fe67875 100644 --- a/app/models.py +++ b/app/models.py @@ -267,11 +267,13 @@ class Meta: class User(Model): id = fields.IntField(pk=True) username = fields.CharField(max_length=255, unique=True) + name = fields.CharField(max_length=255, null=True) + cpf = fields.CharField(max_length=11, unique=True, null=True, validators=[CPFValidator()]) email = fields.CharField(max_length=255, unique=True) - data_source = fields.ForeignKeyField("app.DataSource", related_name="users", null=True) password = fields.CharField(max_length=255) is_active = fields.BooleanField(default=True) is_superuser = fields.BooleanField(default=False) + data_source = fields.ForeignKeyField("app.DataSource", related_name="users", null=True) created_at = fields.DatetimeField(auto_now_add=True) updated_at = fields.DatetimeField(auto_now=True) diff --git a/app/routers/auth.py b/app/routers/auth.py index d7ee585..48b10e9 100644 --- a/app/routers/auth.py +++ b/app/routers/auth.py @@ -40,4 +40,4 @@ async def login_for_access_token( return { "access_token": access_token, "token_type": "bearer" - } + } \ No newline at end of file diff --git a/app/routers/frontend.py b/app/routers/frontend.py new file mode 100644 index 0000000..49da23a --- /dev/null +++ b/app/routers/frontend.py @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- +from typing import Annotated, List + +from fastapi import APIRouter, Depends +from fastapi.responses import HTMLResponse + +from tortoise.contrib.pydantic import pydantic_model_creator +from tortoise.exceptions import ValidationError + +from app.dependencies import get_current_active_user +from app.pydantic_models import ( + MergedPatient as PydanticMergedPatient, +) +from app.models import User + + +router = APIRouter(prefix="/frontend", tags=["Endpoints para consumo da aplicação Frontend"]) + + +@router.get("/user") +async def get_patient_header( + user: Annotated[User, Depends(get_current_active_user)], +) -> dict: + cpf = user.cpf + + return { + "nome": user.name, + "email": user.email, + "CPF": f"{cpf[:3]}.{cpf[3:6]}.{cpf[6:9]}-{cpf[9:]}", + } + + +@router.get("/patient/header/{cpf}") +async def get_patient_header( + _: Annotated[User, Depends(get_current_active_user)], + cpf: int, +) -> dict: + return { + "nome_registro": "José da Silva Xavier", + "nome_social": None, + "cpf": f"{cpf[:3]}.{cpf[3:6]}.{cpf[6:9]}-{cpf[9:]}", + "cns": "123456789012345", + "data_nascimento": "1972-08-01", + "genero": "masculino", + "raca": "parda", + "telefone": "(21) 99999-9999", + "clinica_familia": {"cnes": "1234567", "nome": "Clinica da Familia XXX"}, + "equipe_saude_familia": {"id_ine": "1234567", "nome": "Equipe Roxo"}, + "responsavel_medico": "Roberta dos Santos", + "responsavel_enfermagem": "Pedro da Nobrega", + "cadastro_validado_indicador": True, + } + + +@router.get("/patient/summary/{cpf}") +async def get_patient_summary( + _: Annotated[User, Depends(get_current_active_user)], + cpf: int, +) -> list: + return { + "alergias": [ + "Sulfonamidas", + "Ácaros do pó", + "Penicilina", + "Medicamentos anticonvulsivantes", + "Gatos", + "Gramíneas", + "Picadas de abelhas", + "Picadas de vespas", + "Preservativos", + "Luvas de látex", + ], + "medicamentos_uso_continuo": [ + "Losartana potássica", + "Enalapril maleato", + "Besilato de anlodipino", + "Captopril", + "Clonazepam", + "Enalapril", + ], + } + + +@router.get("/patient/encounters/{cpf}") +async def get_patient_encouters( + _: Annotated[User, Depends(get_current_active_user)], + cpf: int, +) -> list: + return [ + { + "datahora_entrada": "2023-09-01T10:00:00", + "datahora_saida": "2023-09-01T12:00:00", + "local": "UPA 24h Magalhães Bastos", + "tipo": "Consulta", + "subtipo": "Emergência", + "cids_ativos": ["A10.2", "B02.5"], + "responsavel": {"nome": "Dr. João da Silva", "funcao": "Médico(a)"}, + "descricao": "Lorem ipsum dolor sit amet consectetur. ", + "tags_filtro": ["UPA"], + }, + { + "datahora_entrada": "2021-09-01T10:00:00", + "datahora_saida": "2021-09-01T12:00:00", + "local": "UPA 24h Magalhães Bastos", + "tipo": "Consulta", + "subtipo": "Emergência", + "cids_ativos": ["A10.2"], + "responsavel": {"nome": "Dr. João da Silva", "funcao": "Médico(a)"}, + "descricao": "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. Fames pretium cursus viverra posuere arcu tortor sit lectus congue. Velit tempor ultricies pulvinar magna pulvinar ridiculus consequat nibh...", + "tags_filtro": ["UPA", "Emergência"], + }, + ]