voa-tiss 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. voa_tiss-0.2.0/.gitignore +65 -0
  2. voa_tiss-0.2.0/CONTRIBUTING.md +43 -0
  3. voa_tiss-0.2.0/DATA_SOURCES.md +76 -0
  4. voa_tiss-0.2.0/LICENSE +201 -0
  5. voa_tiss-0.2.0/PKG-INFO +213 -0
  6. voa_tiss-0.2.0/README.md +178 -0
  7. voa_tiss-0.2.0/docs/codigos.md +51 -0
  8. voa_tiss-0.2.0/infra/README.md +27 -0
  9. voa_tiss-0.2.0/pyproject.toml +148 -0
  10. voa_tiss-0.2.0/rules/README.md +8 -0
  11. voa_tiss-0.2.0/schemas/audit_context.schema.json +50 -0
  12. voa_tiss-0.2.0/schemas/finding.schema.json +134 -0
  13. voa_tiss-0.2.0/schemas/lote.schema.json +395 -0
  14. voa_tiss-0.2.0/schemas/openapi.json +1374 -0
  15. voa_tiss-0.2.0/schemas/report.schema.json +159 -0
  16. voa_tiss-0.2.0/schemas/rules.schema.json +208 -0
  17. voa_tiss-0.2.0/scripts/_manutencao_ans.py +397 -0
  18. voa_tiss-0.2.0/scripts/_manutencao_common.py +57 -0
  19. voa_tiss-0.2.0/scripts/_manutencao_glosa.py +123 -0
  20. voa_tiss-0.2.0/scripts/_manutencao_quality.py +418 -0
  21. voa_tiss-0.2.0/scripts/_manutencao_rede.py +245 -0
  22. voa_tiss-0.2.0/scripts/_manutencao_tuss.py +170 -0
  23. voa_tiss-0.2.0/scripts/manutencao.py +282 -0
  24. voa_tiss-0.2.0/src/voa_tiss/__init__.py +71 -0
  25. voa_tiss-0.2.0/src/voa_tiss/_audit.py +345 -0
  26. voa_tiss-0.2.0/src/voa_tiss/_audit_rules.py +85 -0
  27. voa_tiss-0.2.0/src/voa_tiss/_audit_schema.py +29 -0
  28. voa_tiss-0.2.0/src/voa_tiss/_check.py +254 -0
  29. voa_tiss-0.2.0/src/voa_tiss/_completeness.py +84 -0
  30. voa_tiss-0.2.0/src/voa_tiss/_data/examples/lote-exemplo.json +12 -0
  31. voa_tiss-0.2.0/src/voa_tiss/_data/glosas.json +6612 -0
  32. voa_tiss-0.2.0/src/voa_tiss/_data/sadt/fields.json +958 -0
  33. voa_tiss-0.2.0/src/voa_tiss/_data/sadt/template.css +171 -0
  34. voa_tiss-0.2.0/src/voa_tiss/_data/sadt/template.html +251 -0
  35. voa_tiss-0.2.0/src/voa_tiss/_data/schemas/4.02.00/provenance.json +16 -0
  36. voa_tiss-0.2.0/src/voa_tiss/_data/schemas/4.02.00/tissAssinaturaDigital_v1.01.xsd +16 -0
  37. voa_tiss-0.2.0/src/voa_tiss/_data/schemas/4.02.00/tissComplexTypesV4_02_00.xsd +1512 -0
  38. voa_tiss-0.2.0/src/voa_tiss/_data/schemas/4.02.00/tissGuiasV4_02_00.xsd +1469 -0
  39. voa_tiss-0.2.0/src/voa_tiss/_data/schemas/4.02.00/tissSimpleTypesV4_02_00.xsd +4505 -0
  40. voa_tiss-0.2.0/src/voa_tiss/_data/schemas/4.02.00/tissV4_02_00.xsd +130 -0
  41. voa_tiss-0.2.0/src/voa_tiss/_data/schemas/4.02.00/tissWebServicesV4_02_00.xsd +361 -0
  42. voa_tiss-0.2.0/src/voa_tiss/_data/schemas/4.02.00/xmldsig-core-schema.xsd +309 -0
  43. voa_tiss-0.2.0/src/voa_tiss/_data/schemas/4.03.00/provenance.json +17 -0
  44. voa_tiss-0.2.0/src/voa_tiss/_data/schemas/4.03.00/tissAssinaturaDigital_v1.01.xsd +16 -0
  45. voa_tiss-0.2.0/src/voa_tiss/_data/schemas/4.03.00/tissComplexTypesV4_03_00.xsd +1524 -0
  46. voa_tiss-0.2.0/src/voa_tiss/_data/schemas/4.03.00/tissGuiasV4_03_00.xsd +1472 -0
  47. voa_tiss-0.2.0/src/voa_tiss/_data/schemas/4.03.00/tissSimpleTypesV4_03_00.xsd +4832 -0
  48. voa_tiss-0.2.0/src/voa_tiss/_data/schemas/4.03.00/tissV4_03_00.xsd +130 -0
  49. voa_tiss-0.2.0/src/voa_tiss/_data/schemas/4.03.00/tissWebServicesV4_03_00.xsd +361 -0
  50. voa_tiss-0.2.0/src/voa_tiss/_data/schemas/4.03.00/xmldsig-core-schema.xsd +309 -0
  51. voa_tiss-0.2.0/src/voa_tiss/_glosa.py +36 -0
  52. voa_tiss-0.2.0/src/voa_tiss/_line_total.py +77 -0
  53. voa_tiss-0.2.0/src/voa_tiss/_lote.py +165 -0
  54. voa_tiss-0.2.0/src/voa_tiss/_lote_codec.py +336 -0
  55. voa_tiss-0.2.0/src/voa_tiss/_lote_xml.py +187 -0
  56. voa_tiss-0.2.0/src/voa_tiss/_patch.py +122 -0
  57. voa_tiss-0.2.0/src/voa_tiss/_report.py +135 -0
  58. voa_tiss-0.2.0/src/voa_tiss/_retorno.py +307 -0
  59. voa_tiss-0.2.0/src/voa_tiss/_rules.py +179 -0
  60. voa_tiss-0.2.0/src/voa_tiss/_rules_schema.py +89 -0
  61. voa_tiss-0.2.0/src/voa_tiss/_sadt.py +335 -0
  62. voa_tiss-0.2.0/src/voa_tiss/_sadt_builders.py +49 -0
  63. voa_tiss-0.2.0/src/voa_tiss/_sadt_bundle.py +70 -0
  64. voa_tiss-0.2.0/src/voa_tiss/_sadt_types.py +23 -0
  65. voa_tiss-0.2.0/src/voa_tiss/_sadt_values.py +103 -0
  66. voa_tiss-0.2.0/src/voa_tiss/_schema.py +85 -0
  67. voa_tiss-0.2.0/src/voa_tiss/_text.py +31 -0
  68. voa_tiss-0.2.0/src/voa_tiss/_validate.py +333 -0
  69. voa_tiss-0.2.0/src/voa_tiss/_validate_xsd.py +211 -0
  70. voa_tiss-0.2.0/src/voa_tiss/_xml.py +10 -0
  71. voa_tiss-0.2.0/src/voa_tiss/codes.py +77 -0
  72. voa_tiss-0.2.0/src/voa_tiss/dominio/__init__.py +146 -0
  73. voa_tiss-0.2.0/src/voa_tiss/dominio/_data/domain.json +6488 -0
  74. voa_tiss-0.2.0/src/voa_tiss/examples/__init__.py +20 -0
  75. voa_tiss-0.2.0/src/voa_tiss/examples/demonstrativo.xml +20 -0
  76. voa_tiss-0.2.0/src/voa_tiss/examples/lote-com-erros.xml +63 -0
  77. voa_tiss-0.2.0/src/voa_tiss/examples/lote-valido.xml +64 -0
  78. voa_tiss-0.2.0/src/voa_tiss/operadoras/__init__.py +95 -0
  79. voa_tiss-0.2.0/src/voa_tiss/operadoras/_data/indicadores.json +895 -0
  80. voa_tiss-0.2.0/src/voa_tiss/operadoras/_data/operators.json +11067 -0
  81. voa_tiss-0.2.0/src/voa_tiss/py.typed +0 -0
  82. voa_tiss-0.2.0/src/voa_tiss/rede/__init__.py +352 -0
  83. voa_tiss-0.2.0/src/voa_tiss/rede/__main__.py +5 -0
  84. voa_tiss-0.2.0/src/voa_tiss/rede/_data/manifesto.json +15 -0
  85. voa_tiss-0.2.0/src/voa_tiss/sandbox.py +351 -0
  86. voa_tiss-0.2.0/src/voa_tiss/server/__init__.py +7 -0
  87. voa_tiss-0.2.0/src/voa_tiss/server/__main__.py +22 -0
  88. voa_tiss-0.2.0/src/voa_tiss/server/_auth.py +252 -0
  89. voa_tiss-0.2.0/src/voa_tiss/server/_context.py +20 -0
  90. voa_tiss-0.2.0/src/voa_tiss/server/_http.py +266 -0
  91. voa_tiss-0.2.0/src/voa_tiss/server/_keys.py +106 -0
  92. voa_tiss-0.2.0/src/voa_tiss/server/_mcp.py +188 -0
  93. voa_tiss-0.2.0/src/voa_tiss/server/_ops.py +540 -0
  94. voa_tiss-0.2.0/src/voa_tiss/server/_ops_schemas.py +87 -0
  95. voa_tiss-0.2.0/src/voa_tiss/server/_quota.py +83 -0
  96. voa_tiss-0.2.0/src/voa_tiss/server/_telemetry.py +140 -0
  97. voa_tiss-0.2.0/src/voa_tiss/tuss/__init__.py +72 -0
  98. voa_tiss-0.2.0/src/voa_tiss/tuss/_data/tuss.json +544189 -0
  99. voa_tiss-0.2.0/src/voa_tiss/tuss/_index.py +357 -0
@@ -0,0 +1,65 @@
1
+ # Python
2
+ .venv/
3
+ venv/
4
+ __pycache__/
5
+ *.py[cod]
6
+ .pytest_cache/
7
+ .mypy_cache/
8
+ .dmypy.json
9
+ .ruff_cache/
10
+ .hypothesis/
11
+ .tox/
12
+ .nox/
13
+ .ipynb_checkpoints/
14
+
15
+ # Build e cobertura
16
+ dist/
17
+ build/
18
+ *.egg-info/
19
+ .eggs/
20
+ .coverage
21
+ .coverage.*
22
+ coverage.xml
23
+ htmlcov/
24
+
25
+ # Web
26
+ node_modules/
27
+ .next/
28
+ out/
29
+ .turbo/
30
+ .pnpm-store/
31
+ *.tsbuildinfo
32
+ web/next-env.d.ts
33
+ test-results/
34
+ playwright-report/
35
+ npm-debug.log*
36
+ pnpm-debug.log*
37
+
38
+ # Vercel
39
+ .vercel
40
+
41
+ # Dados baixados sob demanda
42
+ src/voa_tiss/rede/_data/*.sqlite*
43
+
44
+ # Segredos e certificados (inclusive ICP-Brasil A1)
45
+ .env*
46
+ !.env.example
47
+ *.pem
48
+ *.key
49
+ *.p12
50
+ *.pfx
51
+ *.jks
52
+ .aws/
53
+ gitleaks-report*.json
54
+
55
+ # Dados reais nunca entram no repositório
56
+ privado/
57
+
58
+ # Sistema e editores
59
+ .DS_Store
60
+ Thumbs.db
61
+ .idea/
62
+ .vscode/
63
+ *.swp
64
+ *~
65
+ *.log
@@ -0,0 +1,43 @@
1
+ # Contribuindo
2
+
3
+ ## Ambiente
4
+
5
+ Instale [uv](https://docs.astral.sh/uv/) e prepare o projeto:
6
+
7
+ ```sh
8
+ uv sync --all-extras --group dev
9
+ uvx pre-commit install
10
+ ```
11
+
12
+ ## Padrões
13
+
14
+ - Escreva textos curtos.
15
+ - Comente apenas para explicar uma intenção não óbvia.
16
+ - Descreva o que o código é, sem histórico, origem, decisões, processo ou nomes internos.
17
+ - Siga DRY: um conceito, uma declaração.
18
+ - Prefira poucos testes parametrizados pela API pública.
19
+ - Use apenas dados sintéticos nos testes.
20
+ - Escreva tutoriais em notebooks.
21
+ - Consulte `LIMITES` em `scripts/manutencao.py` para as guardas automáticas.
22
+ - Rode `uv run python scripts/manutencao.py verificar` antes de enviar.
23
+ - O Gitleaks bloqueia segredos na CI e no pre-commit.
24
+
25
+ ## Como contribuir
26
+
27
+ Antes de enviar, execute:
28
+
29
+ ```sh
30
+ uv run ruff check .
31
+ uv run ruff format --check .
32
+ uv run mypy src
33
+ uv run pytest
34
+ uv run python scripts/manutencao.py artefatos --check
35
+ uv run python scripts/manutencao.py verificar
36
+ uv run pytest --nbmake docs/tutoriais
37
+ ```
38
+
39
+ Para o site em `web/`, execute:
40
+
41
+ ```sh
42
+ cd web && pnpm install && pnpm lint && pnpm typecheck && pnpm build
43
+ ```
@@ -0,0 +1,76 @@
1
+ # Fontes de dados
2
+
3
+ ## XSD TISS 4.03.00
4
+
5
+ - Fonte ANS: https://www.gov.br/ans/pt-br/assuntos/prestadores/padrao-para-troca-de-informacao-de-saude-suplementar-2013-tiss/padrao-tiss-julho-2026
6
+ - Pacote de origem: https://www.gov.br/ans/pt-br/assuntos/prestadores/padrao-para-troca-de-informacao-de-saude-suplementar-2013-tiss/PadroTISSComunicao_202511.zip
7
+ - Data do pacote: 2025-11, conforme o nome do arquivo da ANS.
8
+ - Versão: 4.03.00; conjunto de 7 arquivos XSD e um manifesto de proveniência.
9
+ - SHA-256 do arquivo ZIP: `db8640e1c3b87085892f54f838bfcea9934439ff365798c8428559f88c13d62d`.
10
+ - Licença/atribuição: não informado na proveniência do pacote.
11
+ - Os hashes individuais dos XSDs estão registrados em `src/voa_tiss/_data/schemas/4.03.00/provenance.json`.
12
+
13
+ ## Produtos e Prestadores Hospitalares
14
+
15
+ - Fonte ANS: https://dadosabertos.ans.gov.br/FTP/PDA/produtos_e_prestadores_hospitalares/produtos_e_prestadores_hospitalares.zip
16
+ - Página: https://dados.gov.br/dados/conjuntos-dados/produtos-e-prestadores-hospitalares
17
+ - Data de atualização: 2026-09-24.
18
+ - SHA-256 do ZIP: `e16da0d641d1213d32cb6b35a9aa07c192edcecdee162a49df52d1e92b5df3dc`.
19
+ - Contagens: 680 operadoras, 33.092 estabelecimentos, 932.625 vínculos; 31.893 estabelecimentos com CNPJ.
20
+ - Licença/atribuição: `CC BY, atribuição à ANS`.
21
+
22
+ ## TUSS — tabelas 18, 19, 20 e 22
23
+
24
+ - Fonte: ANS, Terminologia Unificada da Saúde Suplementar (TUSS), dados abertos:
25
+ https://dadosabertos.ans.gov.br/FTP/PDA/terminologia_unificada_saude_suplementar_TUSS-049/
26
+ (arquivo `pda-049-tuss.zip`).
27
+ - Data da extração: 2026-10-09 (data do commit do conjunto de dados usado como origem).
28
+ - Registros: 68.022 no conjunto distribuído; tabela 18: 3.597; tabela 19: 45.889;
29
+ tabela 20: 12.572; tabela 22: 5.964.
30
+ - SHA-256 do arquivo distribuído: `edc1a978227f46eb33eb228877e51f3042d1863bf0f7e31f3f0889384ee3ab3d`.
31
+ - Licença: dados abertos da ANS, CC BY-ND; redistribuição verbatim com atribuição. As tabelas são distribuídas sem alteração.
32
+ - Atribuição: ANS — Terminologia Unificada da Saúde Suplementar (TUSS).
33
+ - A geração local usa `uv run python scripts/manutencao.py tuss --table ID=CAMINHO.csv`.
34
+
35
+ Quando a fonte não publica uma licença ou metadado específico, o valor é indicado como
36
+ “não informado”; não se presume autorização além dos termos publicados pela fonte.
37
+
38
+ ## Tabela 38 e domínios TISS
39
+
40
+ - Tabela 38: ANS, *Componente de Representação de Conceitos em Saúde*, versão 202609,
41
+ arquivo `TUSS - Demais terminologias - VERSÃO 202609.xlsx` no ZIP:
42
+ https://www.ans.gov.br/arquivos/extras/tiss/Padrao_TISS_Representacao_de_Conceitos_em_Saude_202609.zip
43
+ - SHA-256 do ZIP utilizado: `7f3d7a9794a8929fddd6f13af26dd9496087bf8b8670f275bd7ecd9a2f64172d`.
44
+ - Tabela 38: 470 termos; licença como publicada: não informado.
45
+ - A planilha não publica um campo de grupo. As orientações locais agrupam códigos
46
+ pelo prefixo de dois dígitos; essa classificação não é atribuída à ANS.
47
+ - Orientações de recurso por grupo foram escritas pela Voa, em caráter procedural e sem
48
+ afirmações clínicas.
49
+ - Domínios TISS: tabelas PDA do arquivo `pda-049-tuss.zip`; excluídas TUSS 18/19/20/22
50
+ e tabela 64. CADOP: `Relatorio_cadop.csv` de dados abertos ANS
51
+ (https://dados.gov.br/dados/conjuntos-dados/operadoras-de-planos-de-saude-ativas);
52
+ licença: CC BY, atribuição à ANS.
53
+ - Tamanhos distribuídos: `glosas.json` 285,670 bytes; domínio após incluir Tabela 38
54
+ varia com a versão do PDA; `operators.json` 371,829 bytes.
55
+
56
+ ## Painel de Indicadores de Glosa
57
+
58
+ - Fonte: ANS, Painel de Indicadores de Glosa:
59
+ https://dados.gov.br/dados/conjuntos-dados/painel-de-indicadores-de-glosa
60
+ - Arquivos: os cinco CSVs `pda-057-painel_de_glosas-*.csv` de
61
+ https://dadosabertos.ans.gov.br/FTP/PDA/painel_de_glosas-057/dados/; URL e SHA-256 de cada
62
+ um ficam em `src/voa_tiss/operadoras/_data/indicadores.json`.
63
+ - Data de carga (`DT_CARGA`): 2026-07-20; semestres de 2019-01 a 2025-02.
64
+ - Registros: 853 operadoras ativas no CADOP; as que não estão no CADOP ficam de fora.
65
+ - Licença: CC BY, atribuição à ANS.
66
+ - Valor ausente ou "-" vira `null`. O semestre fica inconsistente quando o valor é `null` ou
67
+ passa de três vezes a mediana dos semestres anteriores da mesma operadora e indicador, com
68
+ salto de ao menos 10 pontos percentuais (30 dias no tempo médio de pagamento) sobre essa
69
+ mediana; o valor é mantido. Essa marcação é da Voa, não da ANS.
70
+ - Tamanho distribuído: `indicadores.json` 490,139 bytes.
71
+ - A geração local usa `uv run python scripts/manutencao.py ans-glosa`.
72
+
73
+ ## Hash do epílogo
74
+
75
+ O hash do epílogo é o MD5 do conteúdo da mensagem, sem o epílogo, codificado em
76
+ ISO-8859-1, conforme o padrão TISS da ANS.
voa_tiss-0.2.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,213 @@
1
+ Metadata-Version: 2.5
2
+ Name: voa-tiss
3
+ Version: 0.2.0
4
+ Summary: Biblioteca Python offline para validar e operar documentos TISS.
5
+ Project-URL: Homepage, https://github.com/Voa-Health/tiss
6
+ Project-URL: Repository, https://github.com/Voa-Health/tiss
7
+ Project-URL: Issues, https://github.com/Voa-Health/tiss/issues
8
+ Project-URL: Documentation, https://github.com/Voa-Health/tiss#readme
9
+ Author: Voa Health
10
+ License: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: ANS,SP/SADT,TISS,TUSS,XML TISS,glosa,saúde suplementar
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: lxml<7,>=5
25
+ Provides-Extra: pdf
26
+ Requires-Dist: jinja2>=3.1; extra == 'pdf'
27
+ Requires-Dist: markupsafe>=2.1; extra == 'pdf'
28
+ Requires-Dist: weasyprint>=60; extra == 'pdf'
29
+ Provides-Extra: server
30
+ Requires-Dist: fastapi<1,>=0.115; extra == 'server'
31
+ Requires-Dist: jsonschema>=4.23; extra == 'server'
32
+ Requires-Dist: mcp<2,>=1.30; extra == 'server'
33
+ Requires-Dist: uvicorn<1,>=0.34; extra == 'server'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # voa-tiss
37
+
38
+ [![CI](https://github.com/Voa-Health/tiss/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/Voa-Health/tiss/actions/workflows/ci.yml)
39
+
40
+ **English:** Offline Python tools for ANS TISS documents.
41
+
42
+ Biblioteca Python para validar lotes TISS, ler demonstrativos e consultar TUSS sem rede.
43
+
44
+ Requer Python 3.10+.
45
+
46
+ Site técnico: [tiss-api.voa.health](https://tiss-api.voa.health).
47
+
48
+ ## Instalação
49
+
50
+ ```sh
51
+ pip install voa-tiss
52
+ pip install "voa-tiss[pdf]" # renderização SP/SADT
53
+ ```
54
+
55
+ ## Início rápido
56
+
57
+ ```python
58
+ from voa_tiss import examples, validate
59
+
60
+ report = validate(examples.load("lote-com-erros"))
61
+ [(finding.code, finding.severity) for finding in report.findings]
62
+ ```
63
+
64
+ ## API
65
+
66
+ | Símbolo | Uso |
67
+ | --- | --- |
68
+ | `validate` | Valida um lote TISS e retorna um relatório. |
69
+ | `check` | Verifica um lote JSON e propõe correções. |
70
+ | `apply_fixes` | Aplica correções determinísticas ao lote JSON. |
71
+ | `build_lote` | Gera o XML TISS a partir de um lote validado. |
72
+ | `parse_lote` | Converte XML TISS em um lote JSON. |
73
+ | `audit` | Audita o lote com o contexto da operadora. |
74
+ | `hash_epilogo` | Calcula o hash do epílogo. |
75
+ | `glosa` | Consulta um código da Tabela 38. |
76
+ | `dominio.lookup` / `dominio.search` | Consulta tabelas de domínio TISS. |
77
+ | `operadoras.lookup` / `operadoras.search` | Consulta operadoras ativas na ANS. |
78
+ | `operadoras.perfil` | Junta o cadastro e os indicadores de glosa da ANS. |
79
+ | `parse_demonstrativo` | Lê um demonstrativo e retorna decisões por guia. |
80
+ | `plan_reconciliation` | Propõe conciliação entre decisões e guias. |
81
+ | `sadt_missing` | Lista campos obrigatórios ausentes da guia SP/SADT. |
82
+ | `sadt_catalog` | Retorna uma cópia do catálogo SP/SADT. |
83
+ | `render_sadt` (extra `pdf`) | Gera um PDF da guia SP/SADT. |
84
+ | `tuss.lookup` | Consulta um código TUSS. |
85
+ | `tuss.search` | Busca registros TUSS por texto. |
86
+ | `rede.*` | Consulta vínculos da rede hospitalar da ANS. |
87
+ | `json_schema` | Retorna o esquema JSON de um tipo público. |
88
+ | `examples` | Disponibiliza exemplos sintéticos do pacote. |
89
+
90
+ `voa_tiss.rede` baixa e verifica os dados na primeira consulta. Defina
91
+ `VOA_TISS_REDE` com o caminho de um SQLite local para usar uma cópia própria.
92
+
93
+ ## Fluxo
94
+
95
+ ```mermaid
96
+ flowchart LR
97
+ A["Lote JSON"] --> B["check"]
98
+ B --> C{"Há correções?"}
99
+ C -->|sim| D["apply_fixes"]
100
+ D --> B
101
+ C -->|não| E["build_lote"]
102
+ E --> F["XML TISS"]
103
+ ```
104
+
105
+ ## Achados
106
+
107
+ | Campo | Significado |
108
+ | --- | --- |
109
+ | `code` | Código estável em [docs/codigos.md](docs/codigos.md) |
110
+ | `severity` | `error` ou `warning` |
111
+ | `guia` | Identificador da guia, quando houver |
112
+ | `xpath` | Localização no XML, quando houver |
113
+ | `message` | Descrição concisa do achado |
114
+ | `pointer` | JSON Pointer no lote JSON, quando houver |
115
+ | `fix` | Correção em JSON Patch, quando determinística |
116
+ | `needs` | Campos necessários para completar a guia |
117
+ | `glosa` | Código provável da Tabela 38, quando houver |
118
+ | `rule` | Regra de operadora que gerou o achado, quando houver |
119
+
120
+ ## Garantias
121
+
122
+ - Offline e determinístico.
123
+ - XSD fixado por hash.
124
+ - Texto livre da guia é dado, nunca instrução.
125
+
126
+ ## API e MCP
127
+
128
+ Instale o extra do servidor e inicie a API local:
129
+
130
+ ```sh
131
+ pip install "voa-tiss[server]"
132
+ python -m voa_tiss.server --host 127.0.0.1 --port 8000
133
+ ```
134
+
135
+ Valide XML como JSON ou como corpo XML:
136
+
137
+ ```sh
138
+ python -c 'import json, pathlib; print(json.dumps({"xml": pathlib.Path("lote.xml").read_text()}))' \
139
+ | curl https://tiss-api.voa.health/v1/validate \
140
+ -H 'Content-Type: application/json' \
141
+ --data-binary @-
142
+ curl https://tiss-api.voa.health/v1/validate \
143
+ -H 'Content-Type: application/xml' \
144
+ --data-binary @lote.xml
145
+ ```
146
+
147
+ Conecte clientes MCP:
148
+
149
+ ```sh
150
+ claude mcp add --transport http voa-tiss https://tiss-api.voa.health/mcp
151
+ ```
152
+
153
+ No Codex, adicione a `~/.codex/config.toml`:
154
+
155
+ ```toml
156
+ [mcp_servers.voa-tiss]
157
+ url = "https://tiss-api.voa.health/mcp"
158
+ ```
159
+
160
+ No Cursor, adicione ao `mcp.json`:
161
+
162
+ ```json
163
+ {
164
+ "mcpServers": {
165
+ "voa-tiss": {
166
+ "url": "https://tiss-api.voa.health/mcp"
167
+ }
168
+ }
169
+ }
170
+ ```
171
+
172
+ Consulte o [OpenAPI](https://tiss-api.voa.health/openapi.json) e o
173
+ [catálogo de operações](docs/api.md).
174
+
175
+ Sem chave, só as operações do sandbox respondem. Para as demais, entre com a
176
+ conta Voa em [tiss-api.voa.health/chaves](https://tiss-api.voa.health/chaves) e
177
+ envie a chave recebida. Não há limite diário.
178
+
179
+ ```sh
180
+ curl https://tiss-api.voa.health/v1/validate \
181
+ -H "Authorization: Bearer $VOA_TISS_API_KEY" \
182
+ -H 'Content-Type: application/xml' \
183
+ --data-binary @lote.xml
184
+ ```
185
+
186
+ A chave vale 24 horas. Renove com o `refresh_token` recebido no login; chave
187
+ inválida ou expirada retorna `401`:
188
+
189
+ ```sh
190
+ curl https://tiss-api.voa.health/v1/keys/refresh \
191
+ -H 'Content-Type: application/json' \
192
+ -d '{"refresh_token": "..."}'
193
+ ```
194
+
195
+ O serviço não armazena nem registra payloads e não os usa para treinar modelos.
196
+ Quando ativada por `POSTHOG_KEY`, a telemetria agregada contém apenas operação,
197
+ códigos de achados, registro ANS, versão TISS e data. Envie
198
+ `X-Voa-Telemetry: off` para desativá-la. A biblioteca local permanece offline e
199
+ nunca envia telemetria. `VOA_TISS_API_KEY` é a variável que clientes HTTP locais
200
+ podem ler para enviar uma chave de acesso.
201
+
202
+ ## Guias e contratos
203
+
204
+ - [Validar um lote](docs/tutoriais/01-validar-um-lote.ipynb)
205
+ - [Demonstrativo e conciliação](docs/tutoriais/02-demonstrativo-e-conciliacao.ipynb)
206
+ - [TUSS e SP/SADT](docs/tutoriais/03-tuss-e-sp-sadt.ipynb)
207
+ - [Gerar e corrigir um lote](docs/tutoriais/04-gerar-e-corrigir-um-lote.ipynb)
208
+ - [Regras por operadora](docs/tutoriais/05-regras-por-operadora.ipynb)
209
+ - [Operadora simulada](docs/tutoriais/06-operadora-simulada.ipynb)
210
+ - [Esquemas JSON](schemas/)
211
+ - [Fontes de dados](DATA_SOURCES.md)
212
+ - [Contribuição](CONTRIBUTING.md)
213
+ - [Licença](LICENSE)