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

feat: Update dependencies and normalize case in clinical motivation a… #203

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 3 additions & 3 deletions app/routers/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
UserInfo,
)
from app.config import BIGQUERY_PROJECT
from app.utils import read_timestamp
from app.utils import read_timestamp, normalize_case

router = APIRouter(prefix="/frontend", tags=["Frontend Application"])

Expand Down Expand Up @@ -217,8 +217,8 @@ async def get_patient_encounters(
"subtype": result['subtipo'],
"active_cids": [cid['descricao'] for cid in result['condicoes'] if cid['descricao']],
"responsible": professional,
"clinical_motivation": result['motivo_atendimento'],
"clinical_outcome": result['desfecho_atendimento'],
"clinical_motivation": normalize_case(result['motivo_atendimento']),
"clinical_outcome": normalize_case(result['desfecho_atendimento']),
"filter_tags": [unit_type],
}
encounters.append(encounter)
Expand Down
28 changes: 27 additions & 1 deletion app/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
from datetime import datetime, timedelta
import re
import jwt
import hashlib
import json
from datetime import datetime, timedelta
import nltk
from typing import Literal
from loguru import logger
from passlib.context import CryptContext
Expand All @@ -11,6 +13,7 @@
from app.models import User


nltk.download('punkt_tab')
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")


Expand Down Expand Up @@ -137,3 +140,26 @@ def read_timestamp(timestamp: int, output_format=Literal['date','datetime']) ->
return value.strftime("%Y-%m-%d")
else:
raise ValueError("Invalid format")

def normalize_case(text):
if not text:
return None

processed_lines = []
for line in text.splitlines():
pre_symbol = ''
if line.startswith('#'):
pre_symbol = '#'
line = line[1:]
if line.startswith('-'):
pre_symbol = '-'
line = line[1:]
line = line.strip()

sentences = nltk.tokenize.sent_tokenize(line)
normalized_sentences = [sentence.capitalize() for sentence in sentences]
normalized_text = pre_symbol + ' ' + ' '.join(normalized_sentences)

processed_lines.append(normalized_text)

return '\n'.join(processed_lines)
126 changes: 125 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pyjwt = "^2.8.0"
urllib3 = "2.0.7"
idna = "3.7"
basedosdados = "^2.0.0b16"
nltk = "^3.9.1"


[tool.poetry.group.dev.dependencies]
Expand Down
Loading