Skip to content

Commit

Permalink
fix: clinica da saude path + fix: timestamp convertion error
Browse files Browse the repository at this point in the history
  • Loading branch information
TanookiVerde committed Aug 20, 2024
1 parent f6b336f commit bd5c825
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
10 changes: 5 additions & 5 deletions app/routers/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ async def get_patient_header(
if len(patient_record["contato"]["telefone"]) > 0:
telefone_principal = patient_record["contato"]["telefone"][0]["valor"]

clinica_principal = {}
if len(patient_record["clinica_familia"]) > 0:
clinica_principal = patient_record["clinica_familia"][0]

equipe_principal = {}
clinica_principal, equipe_principal = {}, {}
medicos, enfermeiros = [], []
if len(patient_record["equipe_saude_familia"]) > 0:
equipe_principal = patient_record["equipe_saude_familia"][0]

# Pega Clínica da Família
if equipe_principal["clinica_familia"]:
clinica_principal = equipe_principal["clinica_familia"]

for equipe in patient_record["equipe_saude_familia"]:
medicos.extend(equipe["medicos"])
enfermeiros.extend(equipe["enfermeiros"])
Expand Down
18 changes: 11 additions & 7 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,22 @@ async def get_instance(Model, table, slug=None, code=None):


def read_timestamp(timestamp: int, output_format=Literal['date','datetime']) -> str:
if output_format == 'date':
denominator = 1000
str_format = "%Y-%m-%d"
elif output_format == 'datetime':
denominator = 1
str_format = "%Y-%m-%d %H:%M:%S"
else:
raise ValueError("Invalid format")

try:
value = datetime(1970, 1, 1) + timedelta(seconds=timestamp)
value = datetime(1970, 1, 1) + timedelta(seconds=timestamp/denominator)
except Exception as exc:
logger.error(f"Invalid timestamp: {timestamp} from {exc}")
return None

if output_format == 'datetime':
return value.strftime("%Y-%m-%d %H:%M:%S")
elif output_format == 'date':
return value.strftime("%Y-%m-%d")
else:
raise ValueError("Invalid format")
return value.strftime(str_format)

def normalize_case(text):
# TODO
Expand Down

0 comments on commit bd5c825

Please sign in to comment.