From 0637c13cf6b34bef7b47a7349a10785209b56c2c Mon Sep 17 00:00:00 2001 From: Pedro Marques Date: Wed, 8 Jan 2025 17:41:00 -0300 Subject: [PATCH 1/4] feat: enhance patient search results by adding sorting --- app/routers/frontend.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/routers/frontend.py b/app/routers/frontend.py index ab90fe7..d43d336 100644 --- a/app/routers/frontend.py +++ b/app/routers/frontend.py @@ -128,6 +128,7 @@ async def search_patient( SELECT * FROM `{BIGQUERY_PROJECT}`.{BIGQUERY_PATIENT_SEARCH_TABLE_ID} WHERE {clause} + ORDER BY nome ASC """, from_file="/tmp/credentials.json", ) From adf6fb11cc86d9f8f366c95f3b469b545b5072ae Mon Sep 17 00:00:00 2001 From: Pedro Marques Date: Wed, 8 Jan 2025 17:41:14 -0300 Subject: [PATCH 2/4] fix: clean input name in search_patient function to improve query accuracy --- app/routers/frontend.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/routers/frontend.py b/app/routers/frontend.py index d43d336..ea1756f 100644 --- a/app/routers/frontend.py +++ b/app/routers/frontend.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import asyncio +import unicodedata import datetime from typing import Annotated, List from fastapi import APIRouter, Depends, Request @@ -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( @@ -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""" From 8c732e89d0c65f2d188438c7f0331852ee04d235 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 8 Jan 2025 20:55:11 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- app/routers/frontend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/routers/frontend.py b/app/routers/frontend.py index ea1756f..0fff6f6 100644 --- a/app/routers/frontend.py +++ b/app/routers/frontend.py @@ -104,7 +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( From 317d57c2dc0ecac5f7fee90b02550064552af473 Mon Sep 17 00:00:00 2001 From: Pedro Marques Date: Wed, 8 Jan 2025 18:04:53 -0300 Subject: [PATCH 4/4] fix: refine name cleaning process in search_patient function to exclude diacritics for improved query accuracy --- app/routers/frontend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/routers/frontend.py b/app/routers/frontend.py index ea1756f..c3e1e01 100644 --- a/app/routers/frontend.py +++ b/app/routers/frontend.py @@ -123,7 +123,7 @@ async def search_patient( elif cpf: clause = f"cpf = '{cpf}'" elif name: - name_cleaned = ''.join(c for c in unicodedata.normalize('NFD', name) if unicodedata.category(c) + 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(