allscripts_unity_client 2.2.0 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/allscripts_unity_client.rb +9 -0
- data/lib/allscripts_unity_client/client.rb +76 -2
- data/lib/allscripts_unity_client/client_driver.rb +11 -0
- data/lib/allscripts_unity_client/client_options.rb +40 -0
- data/lib/allscripts_unity_client/json_client_driver.rb +9 -0
- data/lib/allscripts_unity_client/json_unity_request.rb +5 -0
- data/lib/allscripts_unity_client/json_unity_response.rb +4 -0
- data/lib/allscripts_unity_client/new_relic_support.rb +11 -0
- data/lib/allscripts_unity_client/soap_client_driver.rb +9 -0
- data/lib/allscripts_unity_client/unity_request.rb +26 -0
- data/lib/allscripts_unity_client/unity_response.rb +8 -0
- data/lib/allscripts_unity_client/utilities.rb +20 -0
- data/lib/allscripts_unity_client/version.rb +1 -1
- data/spec/client_spec.rb +1 -3
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 755d0135099c866fab0417634a30ee6af7a16418
|
4
|
+
data.tar.gz: e1113c97b700e1cfa5b242a4f6b39a6744eaa100
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53d015e539d900f44d011f4fa6ff7cfd8664e8ca942e43471d5e459a21db181ac71a4285d498e36aa9d17bcbf87b984eab7086a2438cf24dea0a6fb9f50ef3b0
|
7
|
+
data.tar.gz: 6e96196624e66005474455ddb45d68fe4eb86e64ae86d9ed8f6c20d852e6e205c8d19ff2d720c69c6c99d46052b5e98833427fb5b218834ad44a1d85e1aa61dc
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Allscripts Unity Client [![Build Status](https://travis-ci.org/healthfinch/allscripts-unity-client.png?branch=
|
1
|
+
# Allscripts Unity Client [![Build Status](https://travis-ci.org/healthfinch/allscripts-unity-client.png?branch=master)](https://travis-ci.org/healthfinch/allscripts-unity-client) [![Coverage Status](https://coveralls.io/repos/healthfinch/allscripts-unity-client/badge.png?branch=master)](https://coveralls.io/r/healthfinch/allscripts-unity-client?branch=master)
|
2
2
|
|
3
3
|
The `allscripts_unity_client` gem is a Ruby client for the Allscripts Unity API. See http://remotecentral.allscripts.com/UnityAPIReference for more documentation on the API.
|
4
4
|
|
@@ -11,10 +11,19 @@ require 'allscripts_unity_client/soap_client_driver'
|
|
11
11
|
require 'allscripts_unity_client/json_client_driver'
|
12
12
|
require 'allscripts_unity_client/new_relic_support'
|
13
13
|
|
14
|
+
# A library for consuming Allscripts Unity web services.
|
14
15
|
module AllscriptsUnityClient
|
16
|
+
|
17
|
+
# Any error returned from Unity is thrown as this error type
|
18
|
+
# with the error message.
|
15
19
|
class APIError < RuntimeError
|
16
20
|
end
|
17
21
|
|
22
|
+
# Create an instance of the Unity client.
|
23
|
+
#
|
24
|
+
# options:: See ClientOptions.
|
25
|
+
#
|
26
|
+
# Returns an instance of Client.
|
18
27
|
def self.create(options = {})
|
19
28
|
options[:mode] ||= :soap
|
20
29
|
options[:log] = true unless options[:log] === false
|
@@ -1,35 +1,89 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
|
3
3
|
module AllscriptsUnityClient
|
4
|
+
|
5
|
+
# Providers an interface to access Unity endpoints.
|
6
|
+
#
|
7
|
+
# Build using a dependcy injection pattern. A Client instances takes an instance of
|
8
|
+
# ClientDriver and delegates Unity endpoint methods to the ClientDriver.
|
4
9
|
class Client
|
5
10
|
attr_accessor :client_driver
|
6
11
|
|
12
|
+
# Constructor.
|
13
|
+
#
|
14
|
+
# client_driver:: An instance of a ClientDriver. Currently only SoapClientDriver and JsonClientDriver
|
15
|
+
# are supported.
|
7
16
|
def initialize(client_driver)
|
8
17
|
raise ArgumentError, 'client_driver can not be nil' if client_driver.nil?
|
9
18
|
|
10
19
|
@client_driver = client_driver
|
11
20
|
end
|
12
21
|
|
22
|
+
# Access client's options. See ClientOptions.
|
13
23
|
def options
|
14
24
|
@client_driver.options
|
15
25
|
end
|
16
26
|
|
27
|
+
# Implement Unity's Magic endpoint
|
28
|
+
#
|
29
|
+
# parameters:: A Hash of Unity parameters. Takes this form:
|
30
|
+
#
|
31
|
+
# {
|
32
|
+
# :action => ...,
|
33
|
+
# :userid => ...,
|
34
|
+
# :appname => ...,
|
35
|
+
# :patientid => ...,
|
36
|
+
# :token => ...,
|
37
|
+
# :parameter1 => ...,
|
38
|
+
# :parameter2 => ...,
|
39
|
+
# :parameter3 => ...,
|
40
|
+
# :parameter4 => ...,
|
41
|
+
# :parameter5 => ...,
|
42
|
+
# :parameter6 => ...,
|
43
|
+
# :data => ...
|
44
|
+
# }
|
45
|
+
#
|
46
|
+
# Returns the result of the Magic endpoint as a Hash.
|
17
47
|
def magic(parameters = {})
|
18
48
|
@client_driver.magic(parameters)
|
19
49
|
end
|
20
50
|
|
51
|
+
# Implement Unity's GetSecurityToken endpoint.
|
52
|
+
#
|
53
|
+
# Stores the results in @security_token.
|
54
|
+
#
|
55
|
+
# parameters:: A hash of Unity parameters for GetSecurityToken:
|
56
|
+
#
|
57
|
+
# {
|
58
|
+
# :username => ...,
|
59
|
+
# :password => ...,
|
60
|
+
# :appname => ...
|
61
|
+
# }
|
62
|
+
#
|
63
|
+
# Returns the security token.
|
21
64
|
def get_security_token!(parameters = {})
|
22
65
|
@client_driver.get_security_token!(parameters)
|
23
66
|
end
|
24
67
|
|
68
|
+
# Implement Unity's RetireSecurityToken endpoint using Savon.
|
69
|
+
#
|
70
|
+
# parameters:: A hash of Unity parameters for RetireSecurityToken. If not given then defaults to
|
71
|
+
# @security_token:
|
72
|
+
#
|
73
|
+
# {
|
74
|
+
# :token => ...,
|
75
|
+
# :appname => ...
|
76
|
+
# }
|
25
77
|
def retire_security_token!(parameters = {})
|
26
78
|
@client_driver.retire_security_token!(parameters)
|
27
79
|
end
|
28
80
|
|
81
|
+
# Return true if a Unity security token has been fetched and saved.
|
29
82
|
def security_token?
|
30
83
|
@client_driver.security_token?
|
31
84
|
end
|
32
85
|
|
86
|
+
# Return the client type, either :json or :soap.
|
33
87
|
def client_type
|
34
88
|
@client_driver.client_type
|
35
89
|
end
|
@@ -267,8 +321,28 @@ module AllscriptsUnityClient
|
|
267
321
|
raise NotImplementedError, 'GetPatientCDA magic action not implemented'
|
268
322
|
end
|
269
323
|
|
270
|
-
def get_patient_diagnosis
|
271
|
-
|
324
|
+
def get_patient_diagnosis(userid, patientid, encounter_date = nil, encounter_type = nil, encounter_date_range = nil, encounter_id = nil)
|
325
|
+
magic_params = {
|
326
|
+
action: 'GetPatientDiagnosis',
|
327
|
+
userid: userid,
|
328
|
+
patientid: patientid,
|
329
|
+
parameter1: encounter_date,
|
330
|
+
parameter2: encounter_type,
|
331
|
+
parameter3: encounter_date_range,
|
332
|
+
parameter4: encounter_id
|
333
|
+
}
|
334
|
+
|
335
|
+
results = magic(magic_params)
|
336
|
+
|
337
|
+
if !results.is_a? Array
|
338
|
+
if results.empty?
|
339
|
+
results = []
|
340
|
+
else
|
341
|
+
results = [results]
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
result
|
272
346
|
end
|
273
347
|
|
274
348
|
def get_patient_full
|
@@ -1,11 +1,17 @@
|
|
1
1
|
require 'logger'
|
2
2
|
|
3
3
|
module AllscriptsUnityClient
|
4
|
+
|
5
|
+
# An abstract class for ClientDrivers that fully implement
|
6
|
+
# making calls to a Unity server.
|
4
7
|
class ClientDriver
|
5
8
|
LOG_FILE = 'logs/unity_client.log'
|
6
9
|
|
7
10
|
attr_accessor :options, :security_token
|
8
11
|
|
12
|
+
# Constructor.
|
13
|
+
#
|
14
|
+
# options:: See ClientOptions.
|
9
15
|
def initialize(options)
|
10
16
|
@options = ClientOptions.new(options)
|
11
17
|
|
@@ -21,22 +27,27 @@ module AllscriptsUnityClient
|
|
21
27
|
end
|
22
28
|
end
|
23
29
|
|
30
|
+
# Returns true if security token is not nil.
|
24
31
|
def security_token?
|
25
32
|
!@security_token.nil?
|
26
33
|
end
|
27
34
|
|
35
|
+
# Returns the type of client, usually a symbol.
|
28
36
|
def client_type
|
29
37
|
:none
|
30
38
|
end
|
31
39
|
|
40
|
+
# See Client#magic.
|
32
41
|
def magic(parameters = {})
|
33
42
|
raise NotImplementedError, 'magic not implemented'
|
34
43
|
end
|
35
44
|
|
45
|
+
# See Client#get_security_token!.
|
36
46
|
def get_security_token!(parameters = {})
|
37
47
|
raise NotImplementedError, 'get_security_token! not implemented'
|
38
48
|
end
|
39
49
|
|
50
|
+
# See Client#retire_security_token!.
|
40
51
|
def retire_security_token!(parameters = {})
|
41
52
|
raise NotImplementedError, 'retire_security_token! not implemented'
|
42
53
|
end
|
@@ -1,8 +1,24 @@
|
|
1
1
|
module AllscriptsUnityClient
|
2
|
+
|
3
|
+
# Contains various options for Unity configuration.
|
2
4
|
class ClientOptions
|
3
5
|
attr_accessor :proxy, :logger, :ca_file, :ca_path, :timeout, :new_relic
|
4
6
|
attr_reader :base_unity_url, :username, :password, :appname, :timezone
|
5
7
|
|
8
|
+
# Constructor.
|
9
|
+
#
|
10
|
+
# options::
|
11
|
+
#
|
12
|
+
# - :username - Unity license username __(required)__.
|
13
|
+
# - :password - Unity license password __(required)__.
|
14
|
+
# - :appname - Unity license appname __(required)__.
|
15
|
+
# - :proxy - A string URL pointing to an HTTP proxy (optional, primarily for debugging)
|
16
|
+
# - :logger - A Ruby object that adheres to the same interface as Logger.
|
17
|
+
# - :ca_file - A string path for a CA File on the OS (JSON only).
|
18
|
+
# - :cs_path - A string path for a CA directory (JSON only).
|
19
|
+
# - :timeout - The number of seconds to set the HTTP response timeout and keepalive timeout (JSON only).
|
20
|
+
# - :new_relc - If set to true then New Relic mixins will be applied.
|
21
|
+
# - :base_unity_url - The URL where a Unity server is located (i.e. https://unity.server.com) __(required)__
|
6
22
|
def initialize(options = {})
|
7
23
|
@username = options[:username]
|
8
24
|
@password = options[:password]
|
@@ -20,6 +36,9 @@ module AllscriptsUnityClient
|
|
20
36
|
validate_options
|
21
37
|
end
|
22
38
|
|
39
|
+
# Validates options by ensuring that all required options are present.
|
40
|
+
#
|
41
|
+
# See #initialize.
|
23
42
|
def validate_options(options = {})
|
24
43
|
base_unity_url = options.has_key?(:base_unity_url) ? options[:base_unity_url] : @base_unity_url
|
25
44
|
username = options.has_key?(:username) ? options[:username] : @username
|
@@ -32,26 +51,41 @@ module AllscriptsUnityClient
|
|
32
51
|
raise ArgumentError, 'appname can not be nil' if appname.nil?
|
33
52
|
end
|
34
53
|
|
54
|
+
# Mutator for @base_unity_url.
|
55
|
+
#
|
56
|
+
# Strips trailing slash for URL.
|
35
57
|
def base_unity_url=(base_unity_url)
|
36
58
|
validate_options(base_unity_url: base_unity_url)
|
37
59
|
@base_unity_url = base_unity_url.gsub /\/$/, ''
|
38
60
|
end
|
39
61
|
|
62
|
+
# Mutator for username.
|
63
|
+
#
|
64
|
+
# Ensures username is not nil,
|
40
65
|
def username=(username)
|
41
66
|
validate_options(username: username)
|
42
67
|
@username = username
|
43
68
|
end
|
44
69
|
|
70
|
+
# Mutator for password.
|
71
|
+
#
|
72
|
+
# Ensures password is not nil,
|
45
73
|
def password=(password)
|
46
74
|
validate_options(password: password)
|
47
75
|
@password = password
|
48
76
|
end
|
49
77
|
|
78
|
+
# Mutator for appname.
|
79
|
+
#
|
80
|
+
# Ensures appname is not nil,
|
50
81
|
def appname=(appname)
|
51
82
|
validate_options(appname: appname)
|
52
83
|
@appname = appname
|
53
84
|
end
|
54
85
|
|
86
|
+
# Mutator for timezone.
|
87
|
+
#
|
88
|
+
# Ensures timezone is not nil,
|
55
89
|
def timezone=(timezone)
|
56
90
|
if !timezone.nil?
|
57
91
|
@timezone = ActiveSupport::TimeZone[timezone]
|
@@ -60,26 +94,32 @@ module AllscriptsUnityClient
|
|
60
94
|
end
|
61
95
|
end
|
62
96
|
|
97
|
+
# Return true if proxy is set and not empty.
|
63
98
|
def proxy?
|
64
99
|
!@proxy.to_s.strip.empty?
|
65
100
|
end
|
66
101
|
|
102
|
+
# Return true if logger is not nil.
|
67
103
|
def logger?
|
68
104
|
!@logger.nil?
|
69
105
|
end
|
70
106
|
|
107
|
+
# Return true if ca_file is not empty.
|
71
108
|
def ca_file?
|
72
109
|
!@ca_file.to_s.strip.empty?
|
73
110
|
end
|
74
111
|
|
112
|
+
# Return true if ca_path is not empty.
|
75
113
|
def ca_path?
|
76
114
|
!@ca_path.to_s.strip.empty?
|
77
115
|
end
|
78
116
|
|
117
|
+
# Return true if timeout is not empty.
|
79
118
|
def timeout?
|
80
119
|
!@timeout.to_s.strip.empty?
|
81
120
|
end
|
82
121
|
|
122
|
+
# Return true if new_relic is not nil.
|
83
123
|
def new_relic?
|
84
124
|
!@new_relic.nil?
|
85
125
|
end
|
@@ -3,11 +3,16 @@ require 'faraday'
|
|
3
3
|
require 'em-http-request'
|
4
4
|
|
5
5
|
module AllscriptsUnityClient
|
6
|
+
|
7
|
+
# A ClientDriver that supports Unity's JSON endpoints.
|
6
8
|
class JSONClientDriver < ClientDriver
|
7
9
|
attr_accessor :json_base_url, :connection
|
8
10
|
|
9
11
|
UNITY_JSON_ENDPOINT = '/Unity/UnityService.svc/json'
|
10
12
|
|
13
|
+
# Constructor.
|
14
|
+
#
|
15
|
+
# options:: See ClientOptions.
|
11
16
|
def initialize(options)
|
12
17
|
super
|
13
18
|
@connection = Faraday.new(build_faraday_options) do |conn|
|
@@ -15,10 +20,12 @@ module AllscriptsUnityClient
|
|
15
20
|
end
|
16
21
|
end
|
17
22
|
|
23
|
+
# Returns :json.
|
18
24
|
def client_type
|
19
25
|
:json
|
20
26
|
end
|
21
27
|
|
28
|
+
# See Client#magic.
|
22
29
|
def magic(parameters = {})
|
23
30
|
request_data = JSONUnityRequest.new(parameters, @options.timezone, @options.appname, @security_token)
|
24
31
|
|
@@ -44,6 +51,7 @@ module AllscriptsUnityClient
|
|
44
51
|
response.to_hash
|
45
52
|
end
|
46
53
|
|
54
|
+
# See Client#get_security_token!.
|
47
55
|
def get_security_token!(parameters = {})
|
48
56
|
username = parameters[:username] || @options.username
|
49
57
|
password = parameters[:password] || @options.password
|
@@ -74,6 +82,7 @@ module AllscriptsUnityClient
|
|
74
82
|
@security_token = response.body
|
75
83
|
end
|
76
84
|
|
85
|
+
# See Client#retire_security_token!.
|
77
86
|
def retire_security_token!(parameters = {})
|
78
87
|
token = parameters[:token] || @security_token
|
79
88
|
appname = parameters[:appname] || @options.appname
|
@@ -1,5 +1,10 @@
|
|
1
1
|
module AllscriptsUnityClient
|
2
|
+
|
3
|
+
# Transform a Unity request into a Hash suitable for sending using Faraday.
|
2
4
|
class JSONUnityRequest < UnityRequest
|
5
|
+
|
6
|
+
# Convert the parameters to a Hash for Faraday with all possible dates
|
7
|
+
# converted to the Organization's localtime.
|
3
8
|
def to_hash
|
4
9
|
action = @parameters[:action]
|
5
10
|
userid = @parameters[:userid]
|
@@ -1,5 +1,11 @@
|
|
1
1
|
module AllscriptsUnityClient
|
2
|
+
|
3
|
+
# A mixin to provide support for New Relic instrumentation.
|
2
4
|
module NewRelicSupport
|
5
|
+
|
6
|
+
# Mixin NewRelic::Agent::MethodTracer for a given object.
|
7
|
+
#
|
8
|
+
# instance:: The object to use as the target for the mixin.
|
3
9
|
def self.enable_method_tracer(instance)
|
4
10
|
class << instance
|
5
11
|
if !respond_to?(:trace_execution_scoped) && !respond_to?(:add_method_tracer)
|
@@ -8,6 +14,11 @@ module AllscriptsUnityClient
|
|
8
14
|
end
|
9
15
|
end
|
10
16
|
|
17
|
+
# If a given class supports New Relic trace_execution_scoped, then
|
18
|
+
# run the given block using that method.
|
19
|
+
#
|
20
|
+
# klass:: The target class.
|
21
|
+
# scope:: A New Relic scope string.
|
11
22
|
def self.trace_execution_scoped_if_available(klass, scope)
|
12
23
|
if klass.respond_to?(:trace_execution_scoped)
|
13
24
|
klass.trace_execution_scoped(scope, &Proc.new)
|
@@ -1,12 +1,17 @@
|
|
1
1
|
require 'savon'
|
2
2
|
|
3
3
|
module AllscriptsUnityClient
|
4
|
+
|
5
|
+
# A ClientDriver that supports Unity's SOAP endpoints.
|
4
6
|
class SOAPClientDriver < ClientDriver
|
5
7
|
attr_accessor :savon_client
|
6
8
|
|
7
9
|
UNITY_SOAP_ENDPOINT = '/Unity/UnityService.svc/unityservice'
|
8
10
|
UNITY_ENDPOINT_NAMESPACE = 'http://www.allscripts.com/Unity/IUnityService'
|
9
11
|
|
12
|
+
# Constructor.
|
13
|
+
#
|
14
|
+
# options:: See ClientOptions.
|
10
15
|
def initialize(options)
|
11
16
|
super
|
12
17
|
|
@@ -48,10 +53,12 @@ module AllscriptsUnityClient
|
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
56
|
+
# Returns :soap.
|
51
57
|
def client_type
|
52
58
|
:soap
|
53
59
|
end
|
54
60
|
|
61
|
+
# See Client#magic.
|
55
62
|
def magic(parameters = {})
|
56
63
|
request_data = UnityRequest.new(parameters, @options.timezone, @options.appname, @security_token)
|
57
64
|
call_data = {
|
@@ -76,6 +83,7 @@ module AllscriptsUnityClient
|
|
76
83
|
response.to_hash
|
77
84
|
end
|
78
85
|
|
86
|
+
# See Client#get_security_token!.
|
79
87
|
def get_security_token!(parameters = {})
|
80
88
|
username = parameters[:username] || @options.username
|
81
89
|
password = parameters[:password] || @options.password
|
@@ -106,6 +114,7 @@ module AllscriptsUnityClient
|
|
106
114
|
@security_token = response.body[:get_security_token_response][:get_security_token_result]
|
107
115
|
end
|
108
116
|
|
117
|
+
# See Client#retire_security_token!.
|
109
118
|
def retire_security_token!(parameters = {})
|
110
119
|
token = parameters[:token] || @security_token
|
111
120
|
appname = parameters[:appname] || @options.appname
|
@@ -1,7 +1,31 @@
|
|
1
1
|
module AllscriptsUnityClient
|
2
|
+
|
3
|
+
# Transform a Unity request into a Hash suitable for sending using Savon.
|
2
4
|
class UnityRequest
|
3
5
|
attr_accessor :parameters, :appname, :security_token, :timezone
|
4
6
|
|
7
|
+
# Constructor.
|
8
|
+
#
|
9
|
+
# parameters:: A Hash of Unity parameters. Takes this form:
|
10
|
+
#
|
11
|
+
# {
|
12
|
+
# 'Action' => ...,
|
13
|
+
# 'UserID' => ...,
|
14
|
+
# 'Appname' => ...,
|
15
|
+
# 'PatientID' => ...,
|
16
|
+
# 'Token' => ...,
|
17
|
+
# 'Parameter1' => ...,
|
18
|
+
# 'Parameter2' => ...,
|
19
|
+
# 'Parameter3' => ...,
|
20
|
+
# 'Parameter4' => ...,
|
21
|
+
# 'Parameter5' => ...,
|
22
|
+
# 'Parameter6' => ...,
|
23
|
+
# 'data' => ...
|
24
|
+
# }
|
25
|
+
#
|
26
|
+
# timezone:: An ActiveSupport::TimeZone instance.
|
27
|
+
# appname:: The Unity license appname.
|
28
|
+
# security_token:: A security token from the Unity GetSecurityToken call.
|
5
29
|
def initialize(parameters, timezone, appname, security_token)
|
6
30
|
raise ArgumentError, 'parameters can not be nil' if parameters.nil?
|
7
31
|
raise ArgumentError, 'timezone can not be nil' if timezone.nil?
|
@@ -14,6 +38,8 @@ module AllscriptsUnityClient
|
|
14
38
|
@timezone = timezone
|
15
39
|
end
|
16
40
|
|
41
|
+
# Convert the parameters to a Hash for Savon with all possible dates
|
42
|
+
# converted to the Organization's localtime.
|
17
43
|
def to_hash
|
18
44
|
action = @parameters[:action]
|
19
45
|
userid = @parameters[:userid]
|
@@ -1,9 +1,15 @@
|
|
1
1
|
require 'date'
|
2
2
|
|
3
3
|
module AllscriptsUnityClient
|
4
|
+
|
5
|
+
# Transform Unity responses from Savon into Hash objects.
|
4
6
|
class UnityResponse
|
5
7
|
attr_accessor :response, :timezone
|
6
8
|
|
9
|
+
# Constructor.
|
10
|
+
#
|
11
|
+
# response:: The response to transform.
|
12
|
+
# timezone:: An ActiveSupport:TimeZone instance.
|
7
13
|
def initialize(response, timezone)
|
8
14
|
raise ArgumentError, 'timezone can not be nil' if timezone.nil?
|
9
15
|
raise ArgumentError, 'response can not be nil' if response.nil?
|
@@ -12,6 +18,8 @@ module AllscriptsUnityClient
|
|
12
18
|
@timezone = timezone
|
13
19
|
end
|
14
20
|
|
21
|
+
# Convert the Unity response to a Hash with symbolized snake_case keys
|
22
|
+
# and convert all dates to UTC.
|
15
23
|
def to_hash
|
16
24
|
result = @response[:magic_response][:magic_result][:diffgram]
|
17
25
|
result = strip_attributes(result)
|
@@ -3,10 +3,20 @@ require 'date'
|
|
3
3
|
require 'american_date'
|
4
4
|
|
5
5
|
module AllscriptsUnityClient
|
6
|
+
|
7
|
+
# Utilities for massaging the data that comes back from Unity.
|
6
8
|
class Utilities
|
7
9
|
DATETIME_REGEX = /^((\d{1,2}[-\/]\d{1,2}[-\/]\d{4})|(\d{4}[-\/]\d{1,2}[-\/]\d{1,2})|(\d{1,2}-[A-Za-z]{3,4}-\d{4})|([A-Za-z]{3,4} +\d{1,2} \d{2,4}))(T| +)(\d{1,2}:\d{2}(:\d{2})?(\.\d+)? ?(PM|AM|pm|am)?((-|\+)\d{2}:?\d{2})?Z?)$/
|
8
10
|
DATE_REGEX = /^((\d{1,2}[-\/]\d{1,2}[-\/]\d{4})|(\d{4}[-\/]\d{1,2}[-\/]\d{1,2})|(\d{1,2}-[A-Za-z]{3,4}-\d{4})|([A-Za-z]{3,4} +\d{1,2} \d{2,4}))$/
|
9
11
|
|
12
|
+
# Try to encode a string into a Data or ActiveSupport::TimeWithZone object.
|
13
|
+
#
|
14
|
+
# Uses DATETIME_REGEX and DATE_REGEX to match possible date string.
|
15
|
+
#
|
16
|
+
# timezone:: An ActiveSupport::TimeZone instance.
|
17
|
+
# possible_data:: A string that could contain a date.
|
18
|
+
#
|
19
|
+
# Returns Date or ActiveSupport::TimeWithZone, or the string if it did not contain a date.
|
10
20
|
def self.try_to_encode_as_date(timezone, possible_date)
|
11
21
|
if possible_date.nil?
|
12
22
|
return nil
|
@@ -23,6 +33,11 @@ module AllscriptsUnityClient
|
|
23
33
|
possible_date
|
24
34
|
end
|
25
35
|
|
36
|
+
# Encode binary data into Base64 encoding.
|
37
|
+
#
|
38
|
+
# data:: Data to encode.
|
39
|
+
#
|
40
|
+
# The Base64 encoding of the data.
|
26
41
|
def self.encode_data(data)
|
27
42
|
if data.nil?
|
28
43
|
return nil
|
@@ -35,6 +50,11 @@ module AllscriptsUnityClient
|
|
35
50
|
end
|
36
51
|
end
|
37
52
|
|
53
|
+
# Transform string keys into symbols and convert CamelCase to snake_case.
|
54
|
+
#
|
55
|
+
# hash:: The hash to transform.
|
56
|
+
#
|
57
|
+
# Returns the transformed hash.
|
38
58
|
def self.recursively_symbolize_keys(hash)
|
39
59
|
# Base case: nil maps to nil
|
40
60
|
if hash.nil?
|
data/spec/client_spec.rb
CHANGED
@@ -150,9 +150,7 @@ describe AllscriptsUnityClient::Client do
|
|
150
150
|
it { expect { subject.get_patient_cda }.to raise_error(NotImplementedError) }
|
151
151
|
end
|
152
152
|
|
153
|
-
describe '#get_patient_diagnosis'
|
154
|
-
it { expect { subject.get_patient_diagnosis }.to raise_error(NotImplementedError) }
|
155
|
-
end
|
153
|
+
describe '#get_patient_diagnosis'
|
156
154
|
|
157
155
|
describe '#get_patient_full' do
|
158
156
|
it { expect { subject.get_patient_full }.to raise_error(NotImplementedError) }
|
data/spec/spec_helper.rb
CHANGED
@@ -56,7 +56,7 @@ RSpec.configure do |config|
|
|
56
56
|
# Print the 10 slowest examples and example groups at the
|
57
57
|
# end of the spec run, to help surface which specs are running
|
58
58
|
# particularly slow.
|
59
|
-
config.profile_examples = 10
|
59
|
+
# config.profile_examples = 10
|
60
60
|
|
61
61
|
# Run specs in random order to surface order dependencies. If you find an
|
62
62
|
# order dependency and want to debug it, you can fix the order by providing
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: allscripts_unity_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ash Gupta
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: savon
|