redox 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f8779e7746c52bb1e149b95b8a28719fce07048b9b08538ea32841c66e6958a
4
- data.tar.gz: fe25242609d42be438e504f719bcdbde764aa7c7c0c47ae1f1cf404012bd2478
3
+ metadata.gz: b6ab25d3f19478659e8b289237cfc384ac214d2ac2fe880a4e5ea324b16488e0
4
+ data.tar.gz: 035f903ba8152429b06c1ab2e1a6a17bc7639974bd483440448a391bab7c7763
5
5
  SHA512:
6
- metadata.gz: 3c9fd7c435756453d2b388c8af01d7664281ffa5c69c7eaaa8a2c9d24ba98746046319fb62f74532e1e19c2e271248f6cd640d24b87c0263939a41d654f803e6
7
- data.tar.gz: 721b2e09e0c8e8768ad4f452ee3ae7e7dfc84ccbaeb22d43af80f8c0aefca244395bb5c11f1fc1d991d2175ed1fb181c7fbd6689dd0f1d3a6e5f7b757e4581d2
6
+ metadata.gz: de4c1669a46c1cc4257d84ae12a8a3243679bf6d264e58383519a57cc405ab71fa870d098903b92edd322a672f6901481e9e824d259c6f1d86e8223d642f25e7
7
+ data.tar.gz: e98d7dfdfd023b845dcffadfcf46e17f8e21d2f1357f88cc0e0454cb377d2f7e6dad179a9c206f75be9432630cc6ccfcb6ec6ab6d73da8e06f73f43657e88de4
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /redox*.gem
data/CHANGELOG.md CHANGED
@@ -5,7 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
- None
8
+ ### Added
9
+ - <TBD>
10
+
11
+ ## [0.1.5] - 2019-04-09
12
+ ### Added
13
+ - Patient, Demographics, Identities models
9
14
 
10
15
  ## [0.1.4] - 2019-04-02
11
16
  ### Added
@@ -28,7 +33,7 @@ None
28
33
  ### Removed
29
34
  - rubocop
30
35
 
31
- # [0.1.2] - 2018-03-08
36
+ ## [0.1.2] - 2018-03-08
32
37
  ### Added
33
38
  - CircleCI config
34
39
  - .editorconfig
@@ -38,7 +43,7 @@ None
38
43
  - Corrected author email
39
44
  - Tweaks to pass rubocop
40
45
 
41
- # [0.1.1] - 2017-10-12
46
+ ## [0.1.1] - 2017-10-12
42
47
  ### Removed
43
48
  - Redundant .gem file
44
49
  - Fix WeInfuse capitalization
@@ -47,8 +52,9 @@ None
47
52
  ### Added
48
53
  - Initial Release
49
54
 
50
- [Unreleased]: https://github.com/WeInfuse/redox/compare/0.1.4...HEAD
51
- [0.1.4]: https://github.com/WeInfuse/redox/compare/0.1.3...0.1.4
55
+ [Unreleased]: https://github.com/WeInfuse/redox/compare/v0.1.5...HEAD
56
+ [0.1.5]: https://github.com/WeInfuse/redox/compare/v0.1.4...v0.1.5
57
+ [0.1.4]: https://github.com/WeInfuse/redox/compare/0.1.3...v0.1.4
52
58
  [0.1.3]: https://github.com/WeInfuse/redox/compare/0.1.2...0.1.3
53
59
  [0.1.2]: https://github.com/WeInfuse/redox/compare/0.1.1...0.1.2
54
60
  [0.1.1]: https://github.com/WeInfuse/redox/compare/0.1.0...0.1.1
data/lib/redox.rb CHANGED
@@ -1,8 +1,13 @@
1
- require 'redox/version'
2
1
  require 'json'
3
2
  require 'net/http'
4
3
  require 'uri'
5
4
  require 'openssl'
5
+ require 'redox/version'
6
+ require 'redox/redox_exception'
7
+ require 'redox/models/model'
8
+ require 'redox/models/patient'
9
+ require 'redox/models/demographics'
10
+ require 'redox/models/identifiers'
6
11
 
7
12
  module Redox
8
13
  # Redox API client
@@ -82,7 +87,7 @@ module Redox
82
87
  # Send PatientSearch query
83
88
  #
84
89
  # @param [Hash] patient_params data to send in the Patient JSON object
85
- # @return [Hash] parsed response object
90
+ # @return [Hash] Redox Patient object
86
91
  # @example
87
92
  # Redox::Redox.new(*connection_params).search_patients(
88
93
  # Identifiers: [],
@@ -91,15 +96,14 @@ module Redox
91
96
  # }
92
97
  # )
93
98
  def search_patients(patient_params)
94
- patient_request = Net::HTTP::Post.new('/query', auth_header)
95
- request_body = request_meta(
96
- data_model: 'PatientSearch', event_type: 'Query'
97
- ).merge(Patient: patient_params)
99
+ patient_request = Net::HTTP::Post.new(Models::Patient::SEARCH[:endpoint], auth_header)
100
+ request_body = request_meta(Models::Patient::SEARCH[:meta])
101
+ .merge(Patient: patient_params)
98
102
  patient_request.body = request_body.to_json
99
103
 
100
104
  response = connection.request(patient_request)
101
105
 
102
- JSON.parse(response.body)
106
+ return Models::Patient.new(JSON.parse(response.body))
103
107
  end
104
108
 
105
109
  private
@@ -116,7 +120,7 @@ module Redox
116
120
  response = connection.request(login_request)
117
121
 
118
122
  if (false == response.is_a?(Net::HTTPOK))
119
- raise "Failed to authenticate '#{response.code}' '#{response.body}'."
123
+ raise RedoxException.from_response(response, msg: 'Authentication')
120
124
  end
121
125
 
122
126
  body = JSON.parse(response.body)
@@ -0,0 +1,7 @@
1
+ module Redox
2
+ module Models
3
+ class Demographics < Model
4
+ KEY = 'Demographics'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Redox
2
+ module Models
3
+ class Identifiers < Model
4
+ KEY = 'Identifiers'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,49 @@
1
+ module Redox
2
+ module Models
3
+ class Model
4
+ KEY = nil
5
+
6
+ def initialize(data)
7
+ @data = data.freeze
8
+ end
9
+
10
+ def valid?
11
+ return @data.is_a?(Hash) && @data.include?(self.class::KEY)
12
+ end
13
+
14
+ def raw(key: self.class::KEY)
15
+ if key.nil?
16
+ return @data
17
+ else
18
+ return @data[key]
19
+ end
20
+ end
21
+
22
+ def map(mapper: {}, data: self.raw)
23
+ result = {}
24
+
25
+ if (true == mapper.is_a?(Hash))
26
+ mapper.each do |key, value|
27
+ if (true == value.is_a?(Hash))
28
+ result = result.merge(self.map(data: data[key], mapper: value))
29
+ elsif (true == value.respond_to?(:call))
30
+ lambda_result = value.call(data[key])
31
+
32
+ if (true == lambda_result.is_a?(Hash))
33
+ result = result.merge(lambda_result)
34
+ else
35
+ raise "lambda must return hash"
36
+ end
37
+ else
38
+ result[value] = data[key]
39
+ end
40
+ end
41
+ else
42
+ raise "mapper must be a hash, got '#{mapper}'"
43
+ end
44
+
45
+ return result
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,26 @@
1
+ module Redox
2
+ module Models
3
+ class Patient < Model
4
+ attr_reader :demographics, :identifiers
5
+
6
+ KEY = 'Patient'
7
+
8
+ SEARCH = {
9
+ meta: {
10
+ data_model: 'PatientSearch',
11
+ event_type: 'Query'
12
+ },
13
+ endpoint: '/query'
14
+ }
15
+
16
+ def initialize(data)
17
+ super(data)
18
+
19
+ if (self.valid?)
20
+ @demographics = Demographics.new(self.raw)
21
+ @identifiers = Identifiers.new(self.raw)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ module Redox
2
+ class RedoxException < Exception
3
+ def self.from_response(response, msg: nil)
4
+ exception_msg = "Failed #{msg}:"
5
+ exception_msg << " HTTP code: #{response.code} MSG: "
6
+
7
+ begin
8
+ error_response = JSON.parse(response.body)
9
+
10
+ if (error_response.is_a?(Hash) && error_response.include?("Meta") && error_response["Meta"].include?("Errors"))
11
+ exception_msg << error_response["Meta"]["Errors"]
12
+ else
13
+ exception_msg << error_response
14
+ end
15
+ rescue JSON::ParserError
16
+ exception_msg << response.body
17
+ end
18
+
19
+ return RedoxException.new(exception_msg)
20
+ end
21
+ end
22
+ end
data/lib/redox/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Redox
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.1.5'.freeze
3
3
  end
data/redox.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ['lib']
28
28
 
29
- spec.add_development_dependency 'bundler', '~> 1.13'
29
+ spec.add_development_dependency 'bundler'
30
30
  spec.add_development_dependency 'minitest', '~> 5.0'
31
31
  spec.add_development_dependency 'rake', '~> 10.0'
32
32
  spec.add_development_dependency 'webmock', '~> 3.1'
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Clark
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-03 00:00:00.000000000 Z
11
+ date: 2019-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.13'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -98,6 +98,11 @@ files:
98
98
  - bin/console
99
99
  - bin/setup
100
100
  - lib/redox.rb
101
+ - lib/redox/models/demographics.rb
102
+ - lib/redox/models/identifiers.rb
103
+ - lib/redox/models/model.rb
104
+ - lib/redox/models/patient.rb
105
+ - lib/redox/redox_exception.rb
101
106
  - lib/redox/version.rb
102
107
  - redox.gemspec
103
108
  homepage: https://github.com/WeInfuse/redox
@@ -119,7 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
124
  - !ruby/object:Gem::Version
120
125
  version: '0'
121
126
  requirements: []
122
- rubygems_version: 3.0.3
127
+ rubyforge_project:
128
+ rubygems_version: 2.7.6
123
129
  signing_key:
124
130
  specification_version: 4
125
131
  summary: Ruby wrapper for the Redox Engine API