Skip to content

Commit

Permalink
Merge pull request #198 from prefeitura-rio/frontend/patient-using-bi…
Browse files Browse the repository at this point in the history
…g-query-data

fix: wrong timestamp interpretation + filter tag improvement
  • Loading branch information
TanookiVerde committed Aug 16, 2024
2 parents f414e62 + cb2aa7f commit 261365f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
38 changes: 26 additions & 12 deletions app/routers/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,21 @@ async def get_patient_summary(
],
}

@router.get("/patient/filter_tags")
async def get_filter_tags(
_: Annotated[User, Depends(get_current_active_user)]
) -> List[str]:
return [
"CF/CMS",
"HOSPITAL",
"CENTRO SAUDE ESCOLA",
"UPA",
"CCO",
"MATERNIDADE",
"CER",
"POLICLINICA",
]


@router.get("/patient/encounters/{cpf}")
async def get_patient_encounters(
Expand All @@ -179,26 +194,25 @@ async def get_patient_encounters(
"role": professional.get('especialidade')
}

# CIDs
cids = []
for cid in result['condicoes']:
nome, descricao = cid.get('id'), cid.get('descricao')
if nome is None or descricao is None:
continue
cids.append(f"{nome} - {descricao}")
# Filter Tags
unit_type = result['estabelecimento']['estabelecimento_tipo']
if unit_type in [
'CLINICA DA FAMILIA',
'CENTRO MUNICIPAL DE SAUDE'
]:
unit_type = 'CF/CMS'

encounter = {
"entry_datetime": read_timestamp(result['entrada_datahora'], format='datetime'),
"exit_datetime": read_timestamp(result['saida_datahora'], format='datetime'),
"location": result['estabelecimento']['nome'],
"type": result['tipo'],
"subtype": result['subtipo'],
"active_cids": cids,
"active_cids": [cid['descricao'] for cid in result['condicoes'] if cid['descricao']],
"responsible": professional,
"description": result['motivo_atendimento'],
"motivation": result['motivo_atendimento'],
"summary": result['desfecho_atendimento'],
"filter_tags": [result['estabelecimento']['estabelecimento_tipo']],
"clinical_motivation": result['motivo_atendimento'],
"clinical_outcome": result['desfecho_atendimento'],
"filter_tags": [unit_type],
}
encounters.append(encounter)

Expand Down
5 changes: 2 additions & 3 deletions app/types/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ class Encounter(BaseModel):
subtype: Optional[str]
active_cids: List[str]
responsible: Optional[Responsible]
description: Optional[str]
motivation: Optional[str]
summary: Optional[str]
clinical_motivation: Optional[str]
clinical_outcome: Optional[str]
filter_tags: List[str]


Expand Down
2 changes: 1 addition & 1 deletion app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async def get_instance(Model, table, slug=None, code=None):


def read_timestamp(timestamp: int, format=Literal['date','datetime']) -> str:
value = datetime(1970, 1, 1) + timedelta(milliseconds=timestamp)
value = datetime(1970, 1, 1) + timedelta(seconds=timestamp)
if format == 'datetime':
return value.strftime("%Y-%m-%d %H:%M:%S")
elif format == 'date':
Expand Down

0 comments on commit 261365f

Please sign in to comment.