Skip to content

Commit

Permalink
fix: clean input name in search_patient function to improve query acc…
Browse files Browse the repository at this point in the history
…uracy
  • Loading branch information
TanookiVerde committed Jan 8, 2025
1 parent 0637c13 commit adf6fb1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 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,7 +123,8 @@ 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)
clause = f"search(nome,'{name_cleaned}')"

results = await read_bq(
f"""
Expand Down

0 comments on commit adf6fb1

Please sign in to comment.