Skip to content

Commit

Permalink
feat: Update dependencies and normalize case in clinical motivation a…
Browse files Browse the repository at this point in the history
…nd outcome
  • Loading branch information
TanookiVerde committed Aug 19, 2024
1 parent 6d80d82 commit 21cc50a
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 5 deletions.
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

0 comments on commit 21cc50a

Please sign in to comment.