From c436a9ee6ed5b2d02e5b0a50e58cec9b592adde2 Mon Sep 17 00:00:00 2001 From: sergei-krylov Date: Tue, 21 Oct 2014 13:28:47 +0300 Subject: [PATCH] Add first version of ICE client --- .gitignore | 18 +++++++++++++ Gemfile | 4 +++ README.md | 26 +++++++++++++++++++ Rakefile | 1 + lib/ruby_ICE_client.rb | 46 ++++++++++++++++++++++++++++++++++ lib/ruby_ICE_client/version.rb | 3 +++ ruby_ICE_client.gemspec | 25 ++++++++++++++++++ 7 files changed, 123 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 Rakefile create mode 100644 lib/ruby_ICE_client.rb create mode 100644 lib/ruby_ICE_client/version.rb create mode 100644 ruby_ICE_client.gemspec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..49f3cd2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +*.gem +*.rbc +.bundle +.config +.idea +.yardoc +Gemfile.lock +InstalledFiles +_yardoc +coverage +doc/ +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..e7b27b3 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in ruby_ICE_client.gemspec +gemspec diff --git a/README.md b/README.md index 6cd07de..b90425d 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,29 @@ ruby_ICE_client A ruby client for calling ICE - Immunization Calculation Engine http://www.hln.com/ice/ + +## Installation + +Add this line to your application's Gemfile: + + gem 'ruby_ICE_client' + +And then execute: + + $ bundle + +Or install it yourself as: + + $ gem install ruby_ICE_client + +## Usage + +TODO: Write usage instructions here + +## Contributing + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create new Pull Request diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..2995527 --- /dev/null +++ b/Rakefile @@ -0,0 +1 @@ +require "bundler/gem_tasks" diff --git a/lib/ruby_ICE_client.rb b/lib/ruby_ICE_client.rb new file mode 100644 index 0000000..b38b215 --- /dev/null +++ b/lib/ruby_ICE_client.rb @@ -0,0 +1,46 @@ +require 'ruby_ICE_client/version' +require 'nokogiri' +require 'base64' + +module RubyICEClient + class << self + def call(message, url) + xml = Nokogiri::XML::Builder.new + xml.Envelope { + xml.Body { + xml.evaluateAtSpecifiedTime('xmlns:ns2' => 'http://www.omg.org/spec/CDSS/201105/dss') { + xml.interactionId(scopingEntityId: 'gov.nyc.health', interactionId: '123456') + xml.specifiedTime "#{Date.today.strftime('%Y-%m-%d')}" + xml.evaluationRequest(clientLanguage: '', clientTimeZoneOffset: '') { + xml.kmEvaluationRequest { + xml.kmId(scopingEntityId: 'org.nyc.cir', businessId: 'ICE', version: '1.0.0') + } + xml.dataRequirementItemData { + xml.driId(itemId: 'cdsPayload') { + xml.containingEntityId(scopingEntityId: 'gov.nyc.health', businessId: 'ICEData', version: '1.0.0.0') + } + xml.data { + xml.informationModelSSId(scopingEntityId: 'org.opencds.vmr', businessId: 'VMR', version: '1.0') + xml.base64EncodedPayload Base64.encode64 message + } + } + } + } + } + } + ns = xml.doc.root.add_namespace_definition 'S', 'http://www.w3.org/2003/05/soap-envelope' + xml.doc.root.namespace = ns + xml.doc.root.child.namespace = ns + + uri = URI.parse url + http = Net::HTTP.new uri.host, uri.port + request = Net::HTTP::Post.new uri.path + request.body = xml.to_xml + response = http.request request + response_xml = Nokogiri::XML response.body + output_message_node = response_xml.xpath '//evaluationResponse//base64EncodedPayload' + + Base64.decode64 output_message_node.first.text + end + end +end diff --git a/lib/ruby_ICE_client/version.rb b/lib/ruby_ICE_client/version.rb new file mode 100644 index 0000000..cdf1951 --- /dev/null +++ b/lib/ruby_ICE_client/version.rb @@ -0,0 +1,3 @@ +module RubyICEClient + VERSION = "0.0.1" +end diff --git a/ruby_ICE_client.gemspec b/ruby_ICE_client.gemspec new file mode 100644 index 0000000..a84f87a --- /dev/null +++ b/ruby_ICE_client.gemspec @@ -0,0 +1,25 @@ +# coding: utf-8 +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'ruby_ICE_client/version' + +Gem::Specification.new do |spec| + spec.name = "ruby_ICE_client" + spec.version = RubyICEClient::VERSION + spec.authors = ["sergei-krylov"] + spec.email = ["sergei.krylov@itechart-group.com"] + spec.description = %q{A ruby client for calling ICE - Immunization Calculation Engine (http://www.hln.com/ice/)} + spec.summary = %q{} + spec.homepage = "" + spec.license = "MIT" + + spec.files = `git ls-files`.split($/) + spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } + spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) + spec.require_paths = ["lib"] + + spec.add_development_dependency "bundler", "~> 1.3" + spec.add_development_dependency "rake" + spec.add_development_dependency "nokogiri", "~> 1.6" + spec.add_development_dependency "base64" +end