tiss-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +111 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/tiss/constants.rb +73 -0
- data/lib/tiss/creator.rb +52 -0
- data/lib/tiss/generator/generator.rb +20 -0
- data/lib/tiss/generator/generators/base_generator.rb +54 -0
- data/lib/tiss/generator/generators/model_generator.rb +36 -0
- data/lib/tiss/generator/generators/templates/model_template.erb +22 -0
- data/lib/tiss/generator/generators/templates/validator_template.erb +60 -0
- data/lib/tiss/generator/generators/validator_generator.rb +44 -0
- data/lib/tiss/model.rb +66 -0
- data/lib/tiss/models/anexo_clinico.rb +18 -0
- data/lib/tiss/models/anexo_clinico_prorrogacao.rb +18 -0
- data/lib/tiss/models/anexos_clinicos.rb +22 -0
- data/lib/tiss/models/anexos_guias_tiss.rb +22 -0
- data/lib/tiss/models/beneficiario.rb +18 -0
- data/lib/tiss/models/cabecalho_demonstrativo_odonto.rb +26 -0
- data/lib/tiss/models/cabecalho_guia.rb +11 -0
- data/lib/tiss/models/cabecalho_transacao.rb +36 -0
- data/lib/tiss/models/cod_profissional.rb +14 -0
- data/lib/tiss/models/codigo_contratado.rb +14 -0
- data/lib/tiss/models/contratado_executante.rb +11 -0
- data/lib/tiss/models/cpf_cnpj_contratado.rb +14 -0
- data/lib/tiss/models/ct_anexo_cabecalho.rb +34 -0
- data/lib/tiss/models/ct_anexo_lote.rb +14 -0
- data/lib/tiss/models/ct_anexo_recebimento.rb +38 -0
- data/lib/tiss/models/ct_autorizacao_dados.rb +36 -0
- data/lib/tiss/models/ct_autorizacao_internacao.rb +32 -0
- data/lib/tiss/models/ct_autorizacao_sadt.rb +32 -0
- data/lib/tiss/models/ct_autorizacao_solicita_status.rb +18 -0
- data/lib/tiss/models/ct_beneficiario_dados.rb +36 -0
- data/lib/tiss/models/ct_conta_medica_resumo.rb +52 -0
- data/lib/tiss/models/ct_contratado_dados.rb +22 -0
- data/lib/tiss/models/ct_contratado_profissional_dados.rb +26 -0
- data/lib/tiss/models/ct_credito_odonto.rb +14 -0
- data/lib/tiss/models/ct_dados_complementares_beneficiario.rb +26 -0
- data/lib/tiss/models/ct_dados_complementares_beneficiario_radio.rb +14 -0
- data/lib/tiss/models/ct_dados_resumo_demonstrativo.rb +34 -0
- data/lib/tiss/models/ct_demonstrativo_cabecalho.rb +26 -0
- data/lib/tiss/models/ct_demonstrativo_retorno.rb +26 -0
- data/lib/tiss/models/ct_demonstrativo_solicitacao.rb +14 -0
- data/lib/tiss/models/ct_descontos.rb +22 -0
- data/lib/tiss/models/ct_diagnostico.rb +18 -0
- data/lib/tiss/models/ct_diagnostico_oncologico.rb +34 -0
- data/lib/tiss/models/ct_drogas_solicitadas.rb +31 -0
- data/lib/tiss/models/ct_elegibilidade_recibo.rb +58 -0
- data/lib/tiss/models/ct_elegibilidade_verifica.rb +50 -0
- data/lib/tiss/models/ct_fonte_pagadora.rb +14 -0
- data/lib/tiss/models/ct_glosa_recibo.rb +54 -0
- data/lib/tiss/models/ct_glosa_recibo_odonto.rb +54 -0
- data/lib/tiss/models/ct_guia_cabecalho.rb +14 -0
- data/lib/tiss/models/ct_guia_cancelamento.rb +22 -0
- data/lib/tiss/models/ct_guia_cancelamento_recibo.rb +18 -0
- data/lib/tiss/models/ct_guia_dados.rb +44 -0
- data/lib/tiss/models/ct_guia_dados_anexo.rb +34 -0
- data/lib/tiss/models/ct_guia_dados_odonto.rb +66 -0
- data/lib/tiss/models/ct_guia_recurso.rb +26 -0
- data/lib/tiss/models/ct_guia_recurso_lote.rb +14 -0
- data/lib/tiss/models/ct_guia_valor_total.rb +38 -0
- data/lib/tiss/models/ct_guia_valor_total_sadt.rb +34 -0
- data/lib/tiss/models/ct_hipotese_diagnostica.rb +14 -0
- data/lib/tiss/models/ct_ident_equipe.rb +34 -0
- data/lib/tiss/models/ct_ident_equipe_sadt.rb +34 -0
- data/lib/tiss/models/ct_intervalo_ciclos.rb +14 -0
- data/lib/tiss/models/ct_login_senha.rb +14 -0
- data/lib/tiss/models/ct_lote_anexo_status.rb +26 -0
- data/lib/tiss/models/ct_lote_status.rb +30 -0
- data/lib/tiss/models/ct_motivo_glosa.rb +14 -0
- data/lib/tiss/models/ct_opm_utilizada.rb +14 -0
- data/lib/tiss/models/ct_opme_dados.rb +14 -0
- data/lib/tiss/models/ct_outras_despesas.rb +10 -0
- data/lib/tiss/models/ct_pagamento_dados.rb +26 -0
- data/lib/tiss/models/ct_pagamento_resumo.rb +22 -0
- data/lib/tiss/models/ct_prestador_identificacao.rb +18 -0
- data/lib/tiss/models/ct_procedimento_autorizado.rb +51 -0
- data/lib/tiss/models/ct_procedimento_dados.rb +18 -0
- data/lib/tiss/models/ct_procedimento_executado.rb +59 -0
- data/lib/tiss/models/ct_procedimento_executado_honor_indiv.rb +55 -0
- data/lib/tiss/models/ct_procedimento_executado_int.rb +55 -0
- data/lib/tiss/models/ct_procedimento_executado_odonto.rb +47 -0
- data/lib/tiss/models/ct_procedimento_executado_outras.rb +62 -0
- data/lib/tiss/models/ct_procedimento_executado_sadt.rb +55 -0
- data/lib/tiss/models/ct_procedimento_solicitado.rb +18 -0
- data/lib/tiss/models/ct_procedimentos_complementares.rb +18 -0
- data/lib/tiss/models/ct_protocolo_anexo_status.rb +18 -0
- data/lib/tiss/models/ct_protocolo_detalhe.rb +22 -0
- data/lib/tiss/models/ct_protocolo_detalhe_anexo.rb +26 -0
- data/lib/tiss/models/ct_protocolo_recebimento.rb +26 -0
- data/lib/tiss/models/ct_protocolo_recebimento_anexo.rb +30 -0
- data/lib/tiss/models/ct_protocolo_recebimento_recurso.rb +30 -0
- data/lib/tiss/models/ct_protocolo_recurso.rb +18 -0
- data/lib/tiss/models/ct_protocolo_solicitacao_status.rb +14 -0
- data/lib/tiss/models/ct_protocolo_status.rb +18 -0
- data/lib/tiss/models/ct_recebimento_lote.rb +14 -0
- data/lib/tiss/models/ct_recebimento_recurso.rb +14 -0
- data/lib/tiss/models/ct_recibo_cancela_guia.rb +14 -0
- data/lib/tiss/models/ct_recibo_comunicacao.rb +14 -0
- data/lib/tiss/models/ct_recurso_glosa_recebimento.rb +54 -0
- data/lib/tiss/models/ct_resposta_elegibilidade.rb +14 -0
- data/lib/tiss/models/ct_resposta_glosa.rb +22 -0
- data/lib/tiss/models/ct_resposta_glosa_guia_medica.rb +35 -0
- data/lib/tiss/models/ct_resposta_glosa_item_medico.rb +55 -0
- data/lib/tiss/models/ct_resposta_recurso_guia_odonto.rb +34 -0
- data/lib/tiss/models/ct_resposta_recurso_item_odonto.rb +26 -0
- data/lib/tiss/models/ct_situacao_autorizacao.rb +26 -0
- data/lib/tiss/models/ct_situacao_clinica.rb +10 -0
- data/lib/tiss/models/ct_situacao_inicial.rb +22 -0
- data/lib/tiss/models/ct_situacao_protocolo.rb +18 -0
- data/lib/tiss/models/ct_valor_credito_desconto.rb +18 -0
- data/lib/tiss/models/ct_valor_total.rb +18 -0
- data/lib/tiss/models/ctm_anexo_solicitacao_opme.rb +34 -0
- data/lib/tiss/models/ctm_anexo_solicitacao_quimio.rb +55 -0
- data/lib/tiss/models/ctm_anexo_solicitacao_radio.rb +59 -0
- data/lib/tiss/models/ctm_anexo_solicitante.rb +18 -0
- data/lib/tiss/models/ctm_autorizacao_internacao.rb +22 -0
- data/lib/tiss/models/ctm_autorizacao_opme.rb +30 -0
- data/lib/tiss/models/ctm_autorizacao_prorrogacao.rb +22 -0
- data/lib/tiss/models/ctm_autorizacao_quimio.rb +67 -0
- data/lib/tiss/models/ctm_autorizacao_radio.rb +71 -0
- data/lib/tiss/models/ctm_autorizacao_servico.rb +47 -0
- data/lib/tiss/models/ctm_beneficiario_comunicacao.rb +22 -0
- data/lib/tiss/models/ctm_beneficiario_comunicacao_recibo.rb +18 -0
- data/lib/tiss/models/ctm_consulta_atendimento.rb +18 -0
- data/lib/tiss/models/ctm_consulta_guia.rb +52 -0
- data/lib/tiss/models/ctm_demonstrativo_analise_conta.rb +34 -0
- data/lib/tiss/models/ctm_demonstrativo_pagamento.rb +26 -0
- data/lib/tiss/models/ctm_guia_lote.rb +14 -0
- data/lib/tiss/models/ctm_honorario_individual_guia.rb +58 -0
- data/lib/tiss/models/ctm_internacao_dados.rb +42 -0
- data/lib/tiss/models/ctm_internacao_dados_saida.rb +18 -0
- data/lib/tiss/models/ctm_internacao_resumo_guia.rb +54 -0
- data/lib/tiss/models/ctm_internacao_solicitacao_guia.rb +65 -0
- data/lib/tiss/models/ctm_prorrogacao_solicitacao_guia.rb +50 -0
- data/lib/tiss/models/ctm_recurso_glosa.rb +50 -0
- data/lib/tiss/models/ctm_solicitacao_lote.rb +22 -0
- data/lib/tiss/models/ctm_sp_sadt_atendimento.rb +22 -0
- data/lib/tiss/models/ctm_sp_sadt_guia.rb +54 -0
- data/lib/tiss/models/ctm_sp_sadt_solicitacao_guia.rb +65 -0
- data/lib/tiss/models/cto_anexo_situacao_inicial.rb +34 -0
- data/lib/tiss/models/cto_anexo_situacao_inicialna_gto.rb +22 -0
- data/lib/tiss/models/cto_autorizacao_servico.rb +52 -0
- data/lib/tiss/models/cto_demonstrativo_odontologia.rb +42 -0
- data/lib/tiss/models/cto_guia_odontologia.rb +108 -0
- data/lib/tiss/models/cto_odonto_solicitacao_guia.rb +110 -0
- data/lib/tiss/models/cto_recurso_glosa_odonto.rb +50 -0
- data/lib/tiss/models/dados_beneficiario.rb +28 -0
- data/lib/tiss/models/dados_conta.rb +10 -0
- data/lib/tiss/models/dados_contratado.rb +22 -0
- data/lib/tiss/models/dados_contratado_executante.rb +18 -0
- data/lib/tiss/models/dados_executante.rb +22 -0
- data/lib/tiss/models/dados_guia.rb +18 -0
- data/lib/tiss/models/dados_guias_protocolo.rb +14 -0
- data/lib/tiss/models/dados_hospital_solicitado.rb +18 -0
- data/lib/tiss/models/dados_internacao.rb +54 -0
- data/lib/tiss/models/dados_pagamento.rb +71 -0
- data/lib/tiss/models/dados_pagamento_guia.rb +58 -0
- data/lib/tiss/models/dados_pagamento_por_data.rb +26 -0
- data/lib/tiss/models/dados_prestador.rb +26 -0
- data/lib/tiss/models/dados_profissionais_responsaveis.rb +58 -0
- data/lib/tiss/models/dados_resumo.rb +10 -0
- data/lib/tiss/models/dados_solicitacao.rb +18 -0
- data/lib/tiss/models/dados_solicitante.rb +14 -0
- data/lib/tiss/models/deb_cred_demonstrativo.rb +10 -0
- data/lib/tiss/models/deb_cred_por_data_pagamento.rb +10 -0
- data/lib/tiss/models/debitos_creditos_por_data.rb +10 -0
- data/lib/tiss/models/declaracoes.rb +22 -0
- data/lib/tiss/models/demonstrativo_analise.rb +18 -0
- data/lib/tiss/models/demonstrativo_pagamento.rb +22 -0
- data/lib/tiss/models/dente_regiao.rb +14 -0
- data/lib/tiss/models/dentes.rb +14 -0
- data/lib/tiss/models/despesa.rb +24 -0
- data/lib/tiss/models/destino.rb +14 -0
- data/lib/tiss/models/detalhes_guia.rb +43 -0
- data/lib/tiss/models/diagnostico_oncologico_quimioterapia.rb +33 -0
- data/lib/tiss/models/diagnostico_oncologico_radio.rb +14 -0
- data/lib/tiss/models/drogas_solicitadas.rb +10 -0
- data/lib/tiss/models/epilogo.rb +10 -0
- data/lib/tiss/models/glosa_anexo.rb +14 -0
- data/lib/tiss/models/glosa_guia.rb +10 -0
- data/lib/tiss/models/glosa_protocolo.rb +14 -0
- data/lib/tiss/models/glosas_procedimento.rb +14 -0
- data/lib/tiss/models/guias_canceladas.rb +10 -0
- data/lib/tiss/models/guias_cancelamento.rb +14 -0
- data/lib/tiss/models/guias_medicas.rb +10 -0
- data/lib/tiss/models/guias_odonto.rb +10 -0
- data/lib/tiss/models/guias_recurso.rb +22 -0
- data/lib/tiss/models/guias_tiss.rb +34 -0
- data/lib/tiss/models/hipoteses_diagnosticas.rb +14 -0
- data/lib/tiss/models/ident_equipe.rb +10 -0
- data/lib/tiss/models/identificacao_opm.rb +26 -0
- data/lib/tiss/models/identificacao_solicitante.rb +14 -0
- data/lib/tiss/models/identificacao_transacao.rb +22 -0
- data/lib/tiss/models/itens_guia.rb +47 -0
- data/lib/tiss/models/local_contratado.rb +18 -0
- data/lib/tiss/models/lote.rb +14 -0
- data/lib/tiss/models/lote_anexo.rb +14 -0
- data/lib/tiss/models/mensagem_tiss.rb +27 -0
- data/lib/tiss/models/motivos_glosa.rb +10 -0
- data/lib/tiss/models/motivos_negativa.rb +10 -0
- data/lib/tiss/models/opcao_recurso.rb +14 -0
- data/lib/tiss/models/opcao_recurso_guia.rb +18 -0
- data/lib/tiss/models/operadora_prestador.rb +50 -0
- data/lib/tiss/models/opm.rb +10 -0
- data/lib/tiss/models/opme_solicitada.rb +34 -0
- data/lib/tiss/models/opme_solicitadas.rb +10 -0
- data/lib/tiss/models/origem.rb +14 -0
- data/lib/tiss/models/pagamentos.rb +10 -0
- data/lib/tiss/models/pagamentos_por_data.rb +26 -0
- data/lib/tiss/models/periodo.rb +14 -0
- data/lib/tiss/models/periodo_proc.rb +14 -0
- data/lib/tiss/models/prestador_autorizado.rb +14 -0
- data/lib/tiss/models/prestador_operadora.rb +50 -0
- data/lib/tiss/models/procedimento.rb +18 -0
- data/lib/tiss/models/procedimento_realizado.rb +11 -0
- data/lib/tiss/models/procedimento_solicitado.rb +34 -0
- data/lib/tiss/models/procedimentos_adicionais.rb +14 -0
- data/lib/tiss/models/procedimentos_autorizados.rb +48 -0
- data/lib/tiss/models/procedimentos_complementares.rb +11 -0
- data/lib/tiss/models/procedimentos_executados.rb +51 -0
- data/lib/tiss/models/procedimentos_realizados.rb +10 -0
- data/lib/tiss/models/procedimentos_solicitados.rb +54 -0
- data/lib/tiss/models/profissionais.rb +34 -0
- data/lib/tiss/models/protocolos.rb +22 -0
- data/lib/tiss/models/recebimento_anexo.rb +14 -0
- data/lib/tiss/models/recibo_glosa_status.rb +42 -0
- data/lib/tiss/models/recurso_guia.rb +58 -0
- data/lib/tiss/models/recurso_guia_completa.rb +14 -0
- data/lib/tiss/models/recurso_procedimento.rb +55 -0
- data/lib/tiss/models/recurso_protocolo.rb +23 -0
- data/lib/tiss/models/relacao_glosa.rb +14 -0
- data/lib/tiss/models/relacao_guias.rb +70 -0
- data/lib/tiss/models/resposta_elegibilidade.rb +14 -0
- data/lib/tiss/models/servicos_autorizados.rb +10 -0
- data/lib/tiss/models/situacao_demonstrativo_retorno.rb +34 -0
- data/lib/tiss/models/totais_bruto_demonstrativo.rb +26 -0
- data/lib/tiss/models/totais_brutos_demonstrativo.rb +22 -0
- data/lib/tiss/models/totais_brutos_por_data.rb +22 -0
- data/lib/tiss/models/totais_demonstrativo.rb +18 -0
- data/lib/tiss/models/totais_liquidos_demonstrativo.rb +18 -0
- data/lib/tiss/models/totais_liquidos_por_data.rb +18 -0
- data/lib/tiss/models/totais_por_data.rb +26 -0
- data/lib/tiss/models/totais_por_protocolo.rb +26 -0
- data/lib/tiss/models/total_liquido_por_data.rb +18 -0
- data/lib/tiss/models/tratamentos_anteriores.rb +30 -0
- data/lib/tiss/tiss.rb +39 -0
- data/lib/tiss/version.rb +5 -0
- data/lib/tiss/xsd/class_maker.rb +242 -0
- data/lib/tiss/xsd/convert.rb +26 -0
- data/lib/tiss-ruby.rb +3 -0
- data/lib/xsd/class_maker.rb +219 -0
- data/lib/xsd/convert.rb +26 -0
- data/resources/TabelasDominio.doc +0 -0
- data/resources/tissAssinaturaDigital_v1.01.xsd +16 -0
- data/resources/tissComplexTypesV3_02_00.xsd +1370 -0
- data/resources/tissComplexTypesV3_02_01.xsd +1370 -0
- data/resources/tissComplexTypesV3_02_02.xsd +1370 -0
- data/resources/tissComplexTypesV3_03_01.xsd +1372 -0
- data/resources/tissComplexTypesV3_03_02.xsd +1372 -0
- data/resources/tissComplexTypesV3_03_03.xsd +1372 -0
- data/resources/tissComplexTypesV3_04_00.xsd +1406 -0
- data/resources/tissGuiasV3_02_00.xsd +1387 -0
- data/resources/tissGuiasV3_02_01.xsd +1388 -0
- data/resources/tissGuiasV3_02_02.xsd +1389 -0
- data/resources/tissGuiasV3_03_01.xsd +1402 -0
- data/resources/tissGuiasV3_03_02.xsd +1401 -0
- data/resources/tissGuiasV3_03_03.xsd +1401 -0
- data/resources/tissGuiasV3_04_00.xsd +1387 -0
- data/resources/tissSimpleTypesV3_02_00.xsd +3158 -0
- data/resources/tissSimpleTypesV3_02_01.xsd +3597 -0
- data/resources/tissSimpleTypesV3_02_02.xsd +3830 -0
- data/resources/tissSimpleTypesV3_03_01.xsd +4120 -0
- data/resources/tissSimpleTypesV3_03_02.xsd +4144 -0
- data/resources/tissSimpleTypesV3_03_03.xsd +4163 -0
- data/resources/tissSimpleTypesV3_04_00.xsd +4233 -0
- data/resources/tissV3_02_00.xsd +118 -0
- data/resources/tissV3_02_01.xsd +118 -0
- data/resources/tissV3_02_02.xsd +121 -0
- data/resources/tissV3_03_01.xsd +118 -0
- data/resources/tissV3_03_02.xsd +118 -0
- data/resources/tissV3_03_03.xsd +118 -0
- data/resources/tissV3_04_00.xsd +118 -0
- data/resources/xmldsig-core-schema.xsd +309 -0
- data/tiss-ruby.gemspec +55 -0
- metadata +569 -0
data/lib/tiss/tiss.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
require 'dry-configurable'
|
5
|
+
require 'nokogiri'
|
6
|
+
|
7
|
+
require_relative 'constants'
|
8
|
+
require_relative 'xsd/convert'
|
9
|
+
require_relative 'generator/generator'
|
10
|
+
require_relative 'model'
|
11
|
+
require_relative 'creator'
|
12
|
+
|
13
|
+
|
14
|
+
Dir[File.join(__dir__, 'models', '*.rb')].sort.each { |file| require file }
|
15
|
+
|
16
|
+
module Tiss
|
17
|
+
extend Dry::Configurable
|
18
|
+
|
19
|
+
setting :default_version, '3_02_00'
|
20
|
+
setting :available_versions, %w[3_02_00 3_02_01 3_02_02 3_03_01 3_03_02 3_03_03 3_04_00]
|
21
|
+
|
22
|
+
# TODO: Refactor this
|
23
|
+
class ConvertFromXsd
|
24
|
+
def initialize
|
25
|
+
Tiss.config.available_versions.each do |version|
|
26
|
+
%w[tissComplexTypes tissGuias tiss].each do |xml_name|
|
27
|
+
puts "./resources/V#{[xml_name, version].join}.xsd"
|
28
|
+
Tiss::Convert.models_from(version, File.open("./resources/#{[xml_name, 'V', version].join}.xsd"))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def require_all(_dir)
|
36
|
+
Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), _dir)) + '/**/*.rb'].sort.each do |file|
|
37
|
+
require file
|
38
|
+
end
|
39
|
+
end
|
data/lib/tiss/version.rb
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_model'
|
4
|
+
require 'active_support'
|
5
|
+
|
6
|
+
module ClassMaker
|
7
|
+
include ActiveSupport::Inflector
|
8
|
+
|
9
|
+
XMLSchemaNS = 'http://www.w3.org/2001/XMLSchema'
|
10
|
+
|
11
|
+
def make_definition(node, target = Object)
|
12
|
+
return if is_text node
|
13
|
+
return if node.comment?
|
14
|
+
return if node.name === 'include'
|
15
|
+
|
16
|
+
attrs = node.attributes.to_hash
|
17
|
+
return unless attrs['name'].present?
|
18
|
+
|
19
|
+
name = attrs['name'].value
|
20
|
+
|
21
|
+
if is_element(node) || is_choice(node)
|
22
|
+
type = attrs['type'].value if attrs.key? 'type'
|
23
|
+
if type.nil?
|
24
|
+
complex_node = select_children(node, 'complexType').first
|
25
|
+
defined_class_name = define_class name, complex_node, target
|
26
|
+
{ name: name, type: defined_class_name }
|
27
|
+
else
|
28
|
+
{ name: name, type: sanitize_class_name(type.split(':').last) }
|
29
|
+
end
|
30
|
+
elsif is_simple node
|
31
|
+
unless name.nil?
|
32
|
+
restrictions = select_children(node, 'restriction').first
|
33
|
+
Tiss::Generator::ValidatorGenerator.call(@version, name, restrictions, target)
|
34
|
+
end
|
35
|
+
elsif is_complex_root node
|
36
|
+
define_class name, node, target
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def namespace_of(node)
|
43
|
+
node.namespace&.href
|
44
|
+
end
|
45
|
+
|
46
|
+
def is_text(node)
|
47
|
+
node.name == 'text'
|
48
|
+
end
|
49
|
+
|
50
|
+
def is_xml_schema_node(node)
|
51
|
+
namespace_of(node) == XMLSchemaNS
|
52
|
+
end
|
53
|
+
|
54
|
+
def is_element(node)
|
55
|
+
is_xml_schema_node(node) && (node.name == 'element')
|
56
|
+
end
|
57
|
+
|
58
|
+
def is_choice(node)
|
59
|
+
is_xml_schema_node(node) && (node.name == 'choice')
|
60
|
+
end
|
61
|
+
|
62
|
+
def is_simple(node)
|
63
|
+
is_xml_schema_node(node) && (node.name == 'simpleType')
|
64
|
+
end
|
65
|
+
|
66
|
+
def is_complex_root(node)
|
67
|
+
is_xml_schema_node(node) && (node.name == 'complexType')
|
68
|
+
end
|
69
|
+
|
70
|
+
def is_father(node)
|
71
|
+
is_xml_schema_node(node) && (node.name == 'complexType')
|
72
|
+
end
|
73
|
+
|
74
|
+
def sanitize_class_name(name)
|
75
|
+
name = underscore(name)
|
76
|
+
camelize(name.to_s.sub(/.*\./, ''))
|
77
|
+
end
|
78
|
+
|
79
|
+
def define_class(name, node, _target)
|
80
|
+
name = sanitize_class_name(name)
|
81
|
+
|
82
|
+
extension_class = ''
|
83
|
+
complex_content = select_children(node, 'complexContent')
|
84
|
+
extension = select_children(complex_content.first, 'extension').first
|
85
|
+
extension_type = extension.attributes['base'].value if extension
|
86
|
+
if extension
|
87
|
+
extension_class = sanitize_class_name(extension_type.split(':').last)
|
88
|
+
end
|
89
|
+
|
90
|
+
elems = []
|
91
|
+
unless node.nil?
|
92
|
+
|
93
|
+
# Take 4
|
94
|
+
elems = elements_by_node(node)
|
95
|
+
|
96
|
+
# Take 3
|
97
|
+
# parent_node = node
|
98
|
+
# until parent_node.children.empty?
|
99
|
+
# elems << select_children(parent_node.children, 'element')
|
100
|
+
# parent_node = parent_node.children.select(&:present?).first
|
101
|
+
# end
|
102
|
+
|
103
|
+
|
104
|
+
# Take 2
|
105
|
+
# parent_node = select_children(node, 'sequence')
|
106
|
+
# parent_node = select_children(node, 'choice') if !parent_node || parent_node.empty?
|
107
|
+
#
|
108
|
+
# choices = []
|
109
|
+
# choices = select_children parent_node.first, 'choice' unless parent_node.empty?
|
110
|
+
#
|
111
|
+
# elems = select_children parent_node.first, 'element' unless parent_node.empty?
|
112
|
+
# unless parent_node.empty? || choices.empty?
|
113
|
+
# elems += select_children choices.first, 'element'
|
114
|
+
# end
|
115
|
+
|
116
|
+
# Take 1
|
117
|
+
# sequence = select_children node, 'sequence'
|
118
|
+
# choices = select_children sequence.first, 'choice' unless sequence.empty?
|
119
|
+
# elems = select_children sequence.first, 'element' unless sequence.empty?
|
120
|
+
# unless sequence.empty? || choices.empty?
|
121
|
+
# elems += select_children choices.first, 'element'
|
122
|
+
# end
|
123
|
+
end
|
124
|
+
|
125
|
+
attributes = elems.flatten.map do |e|
|
126
|
+
make_definition(e, self)
|
127
|
+
end
|
128
|
+
|
129
|
+
return if attributes.blank?
|
130
|
+
|
131
|
+
Tiss::Generator::ModelGenerator.append(@version, name, attributes, extension_class)
|
132
|
+
name
|
133
|
+
end
|
134
|
+
|
135
|
+
def elements_by_node(node)
|
136
|
+
elems = []
|
137
|
+
node.children.each do |element|
|
138
|
+
next if element.nil?
|
139
|
+
|
140
|
+
if is_element(element)
|
141
|
+
elems << element
|
142
|
+
next
|
143
|
+
end
|
144
|
+
elems << elements_by_node(element)
|
145
|
+
end
|
146
|
+
elems.flatten.compact
|
147
|
+
end
|
148
|
+
|
149
|
+
def define_validator(name, restrictions, target)
|
150
|
+
name = "#{underscore(name)}_validator"
|
151
|
+
name = camelize(name.to_s.sub(/.*\./, ''))
|
152
|
+
|
153
|
+
base = restrictions
|
154
|
+
.attributes['base'].value.split(':').last
|
155
|
+
|
156
|
+
base = case base
|
157
|
+
when 'decimal'
|
158
|
+
'float'
|
159
|
+
when 'boolean'
|
160
|
+
'true_class'
|
161
|
+
else
|
162
|
+
base
|
163
|
+
end
|
164
|
+
|
165
|
+
type = constantize classify base
|
166
|
+
|
167
|
+
ws_action = select_children(restrictions, 'whiteSpace').first
|
168
|
+
ws_action = ws_action.attributes['value'].value unless ws_action.nil?
|
169
|
+
|
170
|
+
enum_values = select_children(restrictions, 'enumeration').collect do |enum|
|
171
|
+
enum.attributes['value'].value
|
172
|
+
end
|
173
|
+
|
174
|
+
pattern = select_children(restrictions, 'pattern').first
|
175
|
+
pattern = pattern.attributes['value'].value unless pattern.nil?
|
176
|
+
|
177
|
+
cls = Class.new ActiveModel::EachValidator do
|
178
|
+
const_set 'TYPE', type
|
179
|
+
const_set('WS_ACTION', ws_action) unless ws_action.nil?
|
180
|
+
const_set 'ENUM_VALUES', enum_values
|
181
|
+
unless pattern.nil?
|
182
|
+
const_set 'PATTERN', pattern
|
183
|
+
const_set 'REGEXP', Regexp.new("^#{pattern}$")
|
184
|
+
end
|
185
|
+
|
186
|
+
def validate_each(record, attribute, value)
|
187
|
+
validate_type record, attribute, value
|
188
|
+
handle_whitespaces record, attribute, value
|
189
|
+
unless self.class::ENUM_VALUES.empty?
|
190
|
+
validate_enumeration record, attribute, value
|
191
|
+
end
|
192
|
+
if self.class.const_defined? 'REGEXP'
|
193
|
+
validate_regexp record, attribute, value
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
private
|
198
|
+
|
199
|
+
def validate_type(record, attribute, value)
|
200
|
+
unless value.is_a? self.class::TYPE
|
201
|
+
add_error record, attribute, "#{value}: not a #{self.class::TYPE}"
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def handle_whitespaces(record, attribute, value)
|
206
|
+
if self.class.const_defined? 'WS_ACTION'
|
207
|
+
case self.class::WS_ACTION
|
208
|
+
when 'replace' then value.gsub! /[\n\t\r ]/, ' '
|
209
|
+
when 'collapse' then
|
210
|
+
value.gsub! /[\n\t\r]/, ' '
|
211
|
+
value = value.split.join ' '
|
212
|
+
end
|
213
|
+
record.send "#{attribute}=", value
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
def validate_enumeration(record, attribute, value)
|
218
|
+
unless self.class::ENUM_VALUES.include? value.to_s
|
219
|
+
add_error record, attribute, "#{value}: not in #{self.class::ENUM_VALUES}"
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
def validate_regexp(record, attribute, value)
|
224
|
+
unless value =~ self.class::REGEXP
|
225
|
+
add_error record, attribute, "#{value}: not matching #{self.class::PATTERN}"
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def add_error(record, attribute, message = '')
|
230
|
+
record.errors[attribute] << (options[:message] || message)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
ap name
|
234
|
+
target.const_set name, cls
|
235
|
+
end
|
236
|
+
|
237
|
+
def select_children(node, name)
|
238
|
+
return [] unless node
|
239
|
+
|
240
|
+
node.children.select { |n| n.name == name }
|
241
|
+
end
|
242
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
require_relative 'class_maker'
|
5
|
+
|
6
|
+
module Tiss
|
7
|
+
class Convert
|
8
|
+
class << self
|
9
|
+
include ClassMaker
|
10
|
+
|
11
|
+
def models_from(version, xsd_definitions)
|
12
|
+
doc = Nokogiri::XML xsd_definitions
|
13
|
+
@version = version
|
14
|
+
|
15
|
+
children = doc.children.reject { |node| node.name == 'comment' }
|
16
|
+
schema = children.first
|
17
|
+
|
18
|
+
raise 'Invalid XMLSchema root' if schema.name != 'schema'
|
19
|
+
raise 'Missing XMLSchema namespace' if schema.namespace.nil?
|
20
|
+
raise 'Wrong XMLSchema namespace' unless is_xml_schema_node schema
|
21
|
+
|
22
|
+
schema.children.each { |node| make_definition node }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/tiss-ruby.rb
ADDED
@@ -0,0 +1,219 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_model'
|
4
|
+
require 'active_support'
|
5
|
+
|
6
|
+
module ClassMaker
|
7
|
+
include ActiveSupport::Inflector
|
8
|
+
|
9
|
+
XMLSchemaNS = 'http://www.w3.org/2001/XMLSchema'
|
10
|
+
|
11
|
+
def make_definition(node, target = Object)
|
12
|
+
return if is_text node
|
13
|
+
return if node.comment?
|
14
|
+
return if node.name === 'include'
|
15
|
+
|
16
|
+
attrs = node.attributes.to_hash
|
17
|
+
return unless attrs['name'].present?
|
18
|
+
|
19
|
+
name = attrs['name'].value
|
20
|
+
|
21
|
+
if is_element(node) || is_choice(node)
|
22
|
+
type = attrs['type'].value if attrs.key? 'type'
|
23
|
+
if type.nil?
|
24
|
+
complex_node = select_children(node, 'complexType').first
|
25
|
+
defined_class_name = define_class name, complex_node, target
|
26
|
+
{ name: name, type: defined_class_name }
|
27
|
+
else
|
28
|
+
{ name: name, type: sanitize_class_name(type.split(':').last) }
|
29
|
+
end
|
30
|
+
elsif is_simple node
|
31
|
+
unless name.nil?
|
32
|
+
restrictions = select_children(node, 'restriction').first
|
33
|
+
Tiss::Generator::ValidatorGenerator.call(@version, name, restrictions, target)
|
34
|
+
end
|
35
|
+
elsif is_complex_root node
|
36
|
+
define_class name, node, target
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def namespace_of(node)
|
43
|
+
node.namespace.href
|
44
|
+
end
|
45
|
+
|
46
|
+
def is_text(node)
|
47
|
+
node.name == 'text'
|
48
|
+
end
|
49
|
+
|
50
|
+
def is_xml_schema_node(node)
|
51
|
+
namespace_of(node) == XMLSchemaNS
|
52
|
+
end
|
53
|
+
|
54
|
+
def is_element(node)
|
55
|
+
is_xml_schema_node(node) && (node.name == 'element')
|
56
|
+
end
|
57
|
+
|
58
|
+
def is_choice(node)
|
59
|
+
is_xml_schema_node(node) && (node.name == 'choice')
|
60
|
+
end
|
61
|
+
|
62
|
+
def is_simple(node)
|
63
|
+
is_xml_schema_node(node) && (node.name == 'simpleType')
|
64
|
+
end
|
65
|
+
|
66
|
+
def is_complex_root(node)
|
67
|
+
is_xml_schema_node(node) && (node.name == 'complexType')
|
68
|
+
end
|
69
|
+
|
70
|
+
def sanitize_class_name(name)
|
71
|
+
name = underscore(name)
|
72
|
+
camelize(name.to_s.sub(/.*\./, ''))
|
73
|
+
end
|
74
|
+
|
75
|
+
def define_class(name, node, _target)
|
76
|
+
name = sanitize_class_name(name)
|
77
|
+
|
78
|
+
extension_class = ''
|
79
|
+
complex_content = select_children(node, 'complexContent')
|
80
|
+
extension = select_children(complex_content.first, 'extension').first
|
81
|
+
extension_type = extension.attributes['base'].value if extension
|
82
|
+
if extension
|
83
|
+
extension_class = sanitize_class_name(extension_type.split(':').last)
|
84
|
+
end
|
85
|
+
|
86
|
+
elems = []
|
87
|
+
unless node.nil?
|
88
|
+
|
89
|
+
parent_node = node
|
90
|
+
until parent_node.children.empty?
|
91
|
+
elems << select_children(parent_node.children, 'element')
|
92
|
+
parent_node = parent_node.children.select(&:present?).first
|
93
|
+
end
|
94
|
+
|
95
|
+
# Take 2
|
96
|
+
# parent_node = select_children(node, 'sequence')
|
97
|
+
# parent_node = select_children(node, 'choice') if !parent_node || parent_node.empty?
|
98
|
+
#
|
99
|
+
# choices = []
|
100
|
+
# choices = select_children parent_node.first, 'choice' unless parent_node.empty?
|
101
|
+
#
|
102
|
+
# elems = select_children parent_node.first, 'element' unless parent_node.empty?
|
103
|
+
# unless parent_node.empty? || choices.empty?
|
104
|
+
# elems += select_children choices.first, 'element'
|
105
|
+
# end
|
106
|
+
|
107
|
+
# Take 1
|
108
|
+
# sequence = select_children node, 'sequence'
|
109
|
+
# choices = select_children sequence.first, 'choice' unless sequence.empty?
|
110
|
+
# elems = select_children sequence.first, 'element' unless sequence.empty?
|
111
|
+
# unless sequence.empty? || choices.empty?
|
112
|
+
# elems += select_children choices.first, 'element'
|
113
|
+
# end
|
114
|
+
end
|
115
|
+
|
116
|
+
attributes = elems.flatten.map do |e|
|
117
|
+
make_definition(e, self)
|
118
|
+
end
|
119
|
+
|
120
|
+
return if attributes.blank?
|
121
|
+
|
122
|
+
Tiss::Generator::ModelGenerator.append(@version, name, attributes, extension_class)
|
123
|
+
name
|
124
|
+
end
|
125
|
+
|
126
|
+
def define_validator(name, restrictions, target)
|
127
|
+
name = "#{underscore(name)}_validator"
|
128
|
+
name = camelize(name.to_s.sub(/.*\./, ''))
|
129
|
+
|
130
|
+
base = restrictions
|
131
|
+
.attributes['base'].value.split(':').last
|
132
|
+
|
133
|
+
base = case base
|
134
|
+
when 'decimal'
|
135
|
+
'float'
|
136
|
+
when 'boolean'
|
137
|
+
'true_class'
|
138
|
+
else
|
139
|
+
base
|
140
|
+
end
|
141
|
+
|
142
|
+
type = constantize classify base
|
143
|
+
|
144
|
+
ws_action = select_children(restrictions, 'whiteSpace').first
|
145
|
+
ws_action = ws_action.attributes['value'].value unless ws_action.nil?
|
146
|
+
|
147
|
+
enum_values = select_children(restrictions, 'enumeration').collect do |enum|
|
148
|
+
enum.attributes['value'].value
|
149
|
+
end
|
150
|
+
|
151
|
+
pattern = select_children(restrictions, 'pattern').first
|
152
|
+
pattern = pattern.attributes['value'].value unless pattern.nil?
|
153
|
+
|
154
|
+
cls = Class.new ActiveModel::EachValidator do
|
155
|
+
const_set 'TYPE', type
|
156
|
+
const_set('WS_ACTION', ws_action) unless ws_action.nil?
|
157
|
+
const_set 'ENUM_VALUES', enum_values
|
158
|
+
unless pattern.nil?
|
159
|
+
const_set 'PATTERN', pattern
|
160
|
+
const_set 'REGEXP', Regexp.new("^#{pattern}$")
|
161
|
+
end
|
162
|
+
|
163
|
+
def validate_each(record, attribute, value)
|
164
|
+
validate_type record, attribute, value
|
165
|
+
handle_whitespaces record, attribute, value
|
166
|
+
unless self.class::ENUM_VALUES.empty?
|
167
|
+
validate_enumeration record, attribute, value
|
168
|
+
end
|
169
|
+
if self.class.const_defined? 'REGEXP'
|
170
|
+
validate_regexp record, attribute, value
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
private
|
175
|
+
|
176
|
+
def validate_type(record, attribute, value)
|
177
|
+
unless value.is_a? self.class::TYPE
|
178
|
+
add_error record, attribute, "#{value}: not a #{self.class::TYPE}"
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def handle_whitespaces(record, attribute, value)
|
183
|
+
if self.class.const_defined? 'WS_ACTION'
|
184
|
+
case self.class::WS_ACTION
|
185
|
+
when 'replace' then value.gsub! /[\n\t\r ]/, ' '
|
186
|
+
when 'collapse' then
|
187
|
+
value.gsub! /[\n\t\r]/, ' '
|
188
|
+
value = value.split.join ' '
|
189
|
+
end
|
190
|
+
record.send "#{attribute}=", value
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def validate_enumeration(record, attribute, value)
|
195
|
+
unless self.class::ENUM_VALUES.include? value.to_s
|
196
|
+
add_error record, attribute, "#{value}: not in #{self.class::ENUM_VALUES}"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def validate_regexp(record, attribute, value)
|
201
|
+
unless value =~ self.class::REGEXP
|
202
|
+
add_error record, attribute, "#{value}: not matching #{self.class::PATTERN}"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def add_error(record, attribute, message = '')
|
207
|
+
record.errors[attribute] << (options[:message] || message)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
ap name
|
211
|
+
target.const_set name, cls
|
212
|
+
end
|
213
|
+
|
214
|
+
def select_children(node, name)
|
215
|
+
return [] unless node
|
216
|
+
|
217
|
+
node.children.select { |n| n.name == name }
|
218
|
+
end
|
219
|
+
end
|
data/lib/xsd/convert.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
require_relative 'class_maker'
|
5
|
+
|
6
|
+
module Tiss
|
7
|
+
class Convert
|
8
|
+
class << self
|
9
|
+
include ClassMaker
|
10
|
+
|
11
|
+
def models_from(version, xsd_definitions)
|
12
|
+
doc = Nokogiri::XML xsd_definitions
|
13
|
+
@version = version
|
14
|
+
|
15
|
+
children = doc.children.reject { |node| node.name == 'comment' }
|
16
|
+
schema = children.first
|
17
|
+
|
18
|
+
raise 'Invalid XMLSchema root' if schema.name != 'schema'
|
19
|
+
raise 'Missing XMLSchema namespace' if schema.namespace.nil?
|
20
|
+
raise 'Wrong XMLSchema namespace' unless is_xml_schema_node schema
|
21
|
+
|
22
|
+
schema.children.each { |node| make_definition node }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
Binary file
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!-- ***************************************************-->
|
3
|
+
<!-- *** Schema para assinaturas XML ***-->
|
4
|
+
<!-- *** a partir de certificados do padrão (X509) ***-->
|
5
|
+
<!-- *** ICP-Brasil - Projeto TISS***-->
|
6
|
+
<!-- ***************************************************-->
|
7
|
+
<!-- Schema for XML Signatures-->
|
8
|
+
<!--<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.w3.org/2000/09/xmldsig#" elementFormDefault="qualified" attributeFormDefault="unqualified" version="0.1">-->
|
9
|
+
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:ns1="http://www.ans.gov.br/padroes/tiss/schemas" targetNamespace="http://www.ans.gov.br/padroes/tiss/schemas" elementFormDefault="qualified" version="0.1">
|
10
|
+
<import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>
|
11
|
+
<complexType name="assinaturaDigital">
|
12
|
+
<complexContent>
|
13
|
+
<extension base="ds:SignatureType" />
|
14
|
+
</complexContent>
|
15
|
+
</complexType>
|
16
|
+
</schema>
|