Skip to content

Commit

Permalink
Merge pull request #268 from prefeitura-rio/search-adjustments
Browse files Browse the repository at this point in the history
Search adjustments
  • Loading branch information
TanookiVerde authored Jan 8, 2025
2 parents 311ec4a + 4ccc394 commit 85a57ef
Showing 1 changed file with 5 additions and 1 deletion.
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

0 comments on commit 85a57ef

Please sign in to comment.