Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search adjustments #268

Merged
merged 5 commits into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/routers/frontend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import asyncio
import unicodedata
import datetime
from typing import Annotated, List
from fastapi import APIRouter, Depends, Request
Expand Down Expand Up @@ -103,6 +104,7 @@ async def search_patient(
cns: str = None,
name: str = None,
) -> List[dict]:

filled_param_count = sum([bool(cpf), bool(cns), bool(name)])
if filled_param_count == 0:
return JSONResponse(
Expand All @@ -121,13 +123,15 @@ async def search_patient(
elif cpf:
clause = f"cpf = '{cpf}'"
elif name:
clause = f"search(nome,'{name}')"
name_cleaned = ''.join(c for c in unicodedata.normalize('NFD', name) if unicodedata.category(c) != 'Mn')
clause = f"search(nome,'{name_cleaned}')"

results = await read_bq(
f"""
SELECT *
FROM `{BIGQUERY_PROJECT}`.{BIGQUERY_PATIENT_SEARCH_TABLE_ID}
WHERE {clause}
ORDER BY nome ASC
""",
from_file="/tmp/credentials.json",
)
Expand Down
Loading