Skip to content

Commit

Permalink
Merge pull request #168 from prefeitura-rio/development
Browse files Browse the repository at this point in the history
Refactor SMSRio tables in Datalake
  • Loading branch information
TanookiVerde committed Jul 26, 2024
2 parents 0fdf92e + b0c1938 commit fb90a46
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 47 deletions.
22 changes: 1 addition & 21 deletions api/app/datalake/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
from typing import List
from app.datalake.utils import flatten, register_formatter
from app.datalake.models import (
SMSRioCnsProvisorio,
SMSRioPaciente,
SMSRioTelefone,
VitacarePaciente,
VitacarePacienteHistorico,
VitacareAtendimento,
Expand All @@ -28,26 +26,8 @@ def format_smsrio_patient(raw_record: dict) -> List:
raw_record['source_updated_at'] = str(raw_record['source_updated_at'])

flattened_patient = flatten(raw_record)
rows = [SMSRioPaciente(**flattened_patient)]

for field_name, FieldModel in [
('telefones', SMSRioTelefone),
('cns_provisorio', SMSRioCnsProvisorio)
]:
# If field not in record, skip
if field_name not in raw_record['data']:
continue

for value in raw_record['data'].pop(field_name) or []:
rows.append(
FieldModel(
value=value,
patient_cpf=raw_record.get("patient_cpf"),
source_updated_at=raw_record.get("source_updated_at")
)
)

return rows
return [SMSRioPaciente(**flattened_patient)]


@register_formatter(system="vitacare", entity="patientrecords")
Expand Down
26 changes: 0 additions & 26 deletions api/app/datalake/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,6 @@ class Config:
dataset_is_public = False


class SMSRioTelefone(BaseModel):
patient_cpf: str
value: str
source_updated_at: str

class Config:
dataset_id = "brutos_plataforma_smsrio"
table_id = "paciente_telefone_eventos"
partition_by_date = False
biglake_table = True
dataset_is_public = False


class SMSRioCnsProvisorio(BaseModel):
patient_cpf: str
value: str
source_updated_at: str

class Config:
dataset_id = "brutos_plataforma_smsrio"
table_id = "paciente_cns_eventos"
partition_by_date = False
biglake_table = True
dataset_is_public = False


# ===============
# Vitacare
# ===============
Expand Down

0 comments on commit fb90a46

Please sign in to comment.