-
-
Notifications
You must be signed in to change notification settings - Fork 70
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(PNI): include PNI Database #181
Changes from 11 commits
d6a8598
02a12d6
5cbfd9e
148a1bd
c52482e
b6992c5
8091488
f381a88
bcdf5f7
fc3c4f3
97de9ac
c5d2cd8
a79c06b
e7d3615
14a0fe8
fe019ba
39e587e
f23c7c0
3864601
6cbd5f9
2fc9f66
a7ef912
db990fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ wget = "^3.2" | |
loguru = "^0.6.0" | ||
Unidecode = "^1.3.6" | ||
dateparser = "^1.1.8" | ||
pandas = ">=1.5.3" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pandas 1.5.3 uses applymap instead of map |
||
pandas = ">=2.1.0" | ||
urwid = "^2.1.2" | ||
elasticsearch = { version = "7.16.2", extras=["preprocessing"] } | ||
# FTP | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
from typing import List, Union, Optional | ||
|
||
from pysus.ftp import Database, Directory, File | ||
from pysus.ftp.utils import zfill_year, to_list, parse_UFs, UFs, MONTHS | ||
|
||
|
||
class CIHA(Database): | ||
name = "CIHA" | ||
paths = (Directory("/dissemin/publicos/CIHA/201101_/Dados")) | ||
metadata = { | ||
"long_name": "Comunicação de Internação Hospitalar e Ambulatorial", | ||
"source": "http://ciha.datasus.gov.br/CIHA/index.php", | ||
"description": ( | ||
"A CIHA foi criada para ampliar o processo de planejamento, programação, " | ||
"controle, avaliação e regulação da assistência à saúde permitindo um " | ||
"conhecimento mais abrangente e profundo dos perfis nosológico e " | ||
"epidemiológico da população brasileira, da capacidade instalada e do " | ||
"potencial de produção de serviços do conjunto de estabelecimentos de saúde " | ||
"do País. O sistema permite o acompanhamento das ações e serviços de saúde " | ||
"custeados por: planos privados de assistência à saúde; planos públicos; " | ||
"pagamento particular por pessoa física; pagamento particular por pessoa " | ||
"jurídica; programas e projetos federais (PRONON, PRONAS, PROADI); recursos " | ||
"próprios das secretarias municipais e estaduais de saúde; DPVAT; gratuidade " | ||
"e, a partir da publicação da Portaria GM/MS nº 2.905/2022, consórcios públicos. " | ||
"As informações registradas na CIHA servem como base para o processo de " | ||
"Certificação de Entidades Beneficentes de Assistência Social em Saúde (CEBAS) " | ||
"e para monitoramento dos programas PRONAS e PRONON." | ||
), | ||
} | ||
groups = { | ||
"CIHA": "Comunicação de Internação Hospitalar e Ambulatorial", | ||
} | ||
|
||
def describe(self, file: File): | ||
if not isinstance(file, File): | ||
return file | ||
|
||
if file.extension.upper() in [".DBC", ".DBF"]: | ||
group, _uf, year, month = self.format(file) | ||
|
||
try: | ||
uf = UFs[_uf] | ||
except KeyError: | ||
uf = _uf | ||
|
||
description = { | ||
"name": str(file.basename), | ||
"group": self.groups[group], | ||
"uf": uf, | ||
"month": MONTHS[int(month)], | ||
"year": zfill_year(year), | ||
"size": file.info["size"], | ||
"last_update": file.info["modify"], | ||
} | ||
|
||
return description | ||
return file | ||
|
||
def format(self, file: File) -> tuple: | ||
group, _uf = file.name[:4].upper(), file.name[4:6].upper() | ||
year, month = file.name[-4:-2], file.name[-2:] | ||
return group, _uf, zfill_year(year), month | ||
|
||
def get_files( | ||
self, | ||
uf: Optional[Union[List[str], str]] = None, | ||
year: Optional[Union[list, str, int]] = None, | ||
month: Optional[Union[list, str, int]] = None, | ||
group: Union[List[str], str] = "CIHA", | ||
) -> List[File]: | ||
files = list(filter( | ||
lambda f: f.extension.upper() in [".DBC", ".DBF"], self.files | ||
)) | ||
|
||
groups = [gr.upper() for gr in to_list(group)] | ||
|
||
if not all(gr in list(self.groups) for gr in groups): | ||
raise ValueError( | ||
"Unknown CIHA Group(s): " | ||
f"{set(groups).difference(list(self.groups))}" | ||
) | ||
|
||
files = list(filter(lambda f: self.format(f)[0] in groups, files)) | ||
|
||
if uf: | ||
ufs = parse_UFs(uf) | ||
files = list(filter(lambda f: self.format(f)[1] in ufs, files)) | ||
|
||
if year or str(year) in ["0", "00"]: | ||
years = [zfill_year(str(m)[-2:]) for m in to_list(year)] | ||
files = list(filter(lambda f: self.format(f)[2] in years, files)) | ||
|
||
if month: | ||
months = [str(y)[-2:].zfill(2) for y in to_list(month)] | ||
files = list(filter(lambda f: self.format(f)[3] in months, files)) | ||
|
||
return files |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
from typing import List, Union, Optional, Literal | ||
|
||
from pysus.ftp import Database, Directory, File | ||
from pysus.ftp.utils import zfill_year, to_list, parse_UFs, UFs | ||
|
||
|
||
class PNI(Database): | ||
name = "PNI" | ||
paths = ( | ||
Directory("/dissemin/publicos/PNI/DADOS"), | ||
) | ||
metadata = { | ||
"long_name": "Sistema de Informações do Programa Nacional de Imunizações", | ||
"source": ( | ||
"https://datasus.saude.gov.br/acesso-a-informacao/morbidade-hospitalar-do-sus-sih-sus/", | ||
"https://datasus.saude.gov.br/acesso-a-informacao/producao-hospitalar-sih-sus/", | ||
), | ||
"description": ( | ||
"O SI-PNI é um sistema desenvolvido para possibilitar aos gestores " | ||
"envolvidos no Programa Nacional de Imunização, a avaliação dinâmica " | ||
"do risco quanto à ocorrência de surtos ou epidemias, a partir do " | ||
"registro dos imunobiológicos aplicados e do quantitativo populacional " | ||
"vacinado, agregados por faixa etária, período de tempo e área geográfica. " | ||
"Possibilita também o controle do estoque de imunobiológicos necessário " | ||
"aos administradores que têm a incumbência de programar sua aquisição e " | ||
"distribuição. Controla as indicações de aplicação de vacinas de " | ||
"imunobiológicos especiais e seus eventos adversos, dentro dos Centros " | ||
"de Referências em imunobiológicos especiais." | ||
), | ||
} | ||
groups = { | ||
"CPNI": "Centro de Parto Normal Intra-Hospitalar", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's curious that PNI has a dataset for "Parto Normal Intra-Hospitalar", does not seem related... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By any chance, do you know the difference between CPNI and DPNI? both file prefixes are found in the ftp server |
||
"DPNI": "Departamento de Imunização e Doenças Imunopreveníveis", | ||
} | ||
|
||
def describe(self, file: File) -> dict: | ||
if file.extension.upper() in [".DBC", ".DBF"]: | ||
group, _uf, year = self.format(file) | ||
|
||
try: | ||
uf = UFs[_uf] | ||
except KeyError: | ||
uf = _uf | ||
|
||
description = { | ||
"name": file.basename, | ||
"group": self.groups[group], | ||
"uf": uf, | ||
"year": zfill_year(year), | ||
"size": file.info["size"], | ||
"last_update": file.info["modify"], | ||
} | ||
|
||
return description | ||
return {} | ||
|
||
def format(self, file: File) -> tuple: | ||
|
||
if len(file.name) != 8: | ||
raise ValueError(f"Can't format {file.name}") | ||
|
||
n = file.name | ||
group, _uf, year = n[:4], n[4:6], n[-2:] | ||
return group, _uf, zfill_year(year) | ||
|
||
def get_files( | ||
self, | ||
group: Union[list, Literal["CNPI", "DPNI"]], | ||
uf: Optional[Union[List[str], str]] = None, | ||
year: Optional[Union[list, str, int]] = None, | ||
) -> List[File]: | ||
files = list(filter( | ||
lambda f: f.extension.upper() in [".DBC", ".DBF"], self.files | ||
)) | ||
|
||
groups = [gr.upper() for gr in to_list(group)] | ||
|
||
if not all(gr in list(self.groups) for gr in groups): | ||
raise ValueError( | ||
"Unknown PNI Group(s): " | ||
f"{set(groups).difference(list(self.groups))}" | ||
) | ||
|
||
files = list(filter(lambda f: self.format(f)[0] in groups, files)) | ||
|
||
if uf: | ||
ufs = parse_UFs(uf) | ||
files = list(filter(lambda f: self.format(f)[1] in ufs, files)) | ||
|
||
if year or str(year) in ["0", "00"]: | ||
years = [zfill_year(str(m)[-2:]) for m in to_list(year)] | ||
files = list(filter(lambda f: self.format(f)[2] in years, files)) | ||
|
||
return files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for some reason, poetry.lock wasn't on repo yet 🤔