allscripts_unity_client 1.3.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +66 -66
- data/allscripts_unity_client.gemspec +32 -32
- data/lib/allscripts_unity_client/client.rb +215 -205
- data/lib/allscripts_unity_client/client_driver.rb +15 -42
- data/lib/allscripts_unity_client/client_options.rb +68 -0
- data/lib/allscripts_unity_client/json_client_driver.rb +46 -50
- data/lib/allscripts_unity_client/json_unity_request.rb +20 -20
- data/lib/allscripts_unity_client/json_unity_response.rb +1 -1
- data/lib/allscripts_unity_client/soap_client_driver.rb +29 -29
- data/lib/allscripts_unity_client/timezone.rb +15 -10
- data/lib/allscripts_unity_client/unity_request.rb +17 -17
- data/lib/allscripts_unity_client/unity_response.rb +3 -3
- data/lib/allscripts_unity_client/utilities.rb +5 -5
- data/lib/allscripts_unity_client/version.rb +1 -1
- data/lib/allscripts_unity_client.rb +21 -25
- data/spec/allscripts_unity_client_spec.rb +12 -16
- data/spec/client_driver_spec.rb +1 -49
- data/spec/client_options_spec.rb +134 -0
- data/spec/client_spec.rb +9 -9
- data/spec/factories/allscripts_unity_client_parameters_factory.rb +2 -2
- data/spec/factories/client_driver_factory.rb +4 -5
- data/spec/factories/client_factory.rb +2 -2
- data/spec/factories/client_options.rb +13 -0
- data/spec/factories/json_client_driver_factory.rb +1 -1
- data/spec/factories/json_unity_request_factory.rb +1 -1
- data/spec/factories/json_unity_response_factory.rb +1 -1
- data/spec/factories/magic_request_factory.rb +4 -4
- data/spec/factories/soap_client_driver_factory.rb +1 -1
- data/spec/factories/timezone_factory.rb +2 -2
- data/spec/factories/unity_request_factory.rb +3 -3
- data/spec/factories/unity_response_factory.rb +2 -2
- data/spec/json_client_driver_spec.rb +18 -86
- data/spec/json_unity_request_spec.rb +7 -7
- data/spec/json_unity_response_spec.rb +6 -6
- data/spec/soap_client_driver_spec.rb +20 -82
- data/spec/spec_helper.rb +5 -9
- data/spec/support/shared_examples_for_client_driver.rb +37 -58
- data/spec/support/shared_examples_for_unity_request.rb +13 -13
- data/spec/support/shared_examples_for_unity_response.rb +4 -4
- data/spec/timezone_spec.rb +31 -11
- data/spec/unity_request_spec.rb +7 -7
- data/spec/unity_response_spec.rb +4 -4
- data/spec/utilities_spec.rb +2 -2
- metadata +30 -57
@@ -2,84 +2,57 @@ require 'logger'
|
|
2
2
|
|
3
3
|
module AllscriptsUnityClient
|
4
4
|
class ClientDriver
|
5
|
-
LOG_FILE =
|
5
|
+
LOG_FILE = 'logs/unity_client.log'
|
6
6
|
|
7
|
-
attr_accessor :
|
7
|
+
attr_accessor :options, :security_token
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
raise ArgumentError, "username can not be nil" if username.nil?
|
12
|
-
raise ArgumentError, "password can not be nil" if password.nil?
|
13
|
-
raise ArgumentError, "appname can not be nil" if appname.nil?
|
14
|
-
|
15
|
-
@base_unity_url = base_unity_url.gsub /\/$/, ""
|
16
|
-
@username = username
|
17
|
-
@password = password
|
18
|
-
@appname = appname
|
19
|
-
@proxy = proxy
|
20
|
-
@log = log
|
21
|
-
|
22
|
-
if logger.nil?
|
23
|
-
@logger = Logger.new(STDOUT)
|
24
|
-
@logger.level = Logger::INFO
|
25
|
-
else
|
26
|
-
@logger = logger
|
27
|
-
end
|
28
|
-
|
29
|
-
unless timezone.nil?
|
30
|
-
@timezone = Timezone.new(timezone)
|
31
|
-
else
|
32
|
-
@timezone = Timezone.new("UTC")
|
33
|
-
end
|
9
|
+
def initialize(options)
|
10
|
+
@options = ClientOptions.new(options)
|
34
11
|
end
|
35
12
|
|
36
13
|
def security_token?
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
def log?
|
41
|
-
return @log
|
14
|
+
!@security_token.nil?
|
42
15
|
end
|
43
16
|
|
44
17
|
def client_type
|
45
|
-
|
18
|
+
:none
|
46
19
|
end
|
47
20
|
|
48
21
|
def magic(parameters = {})
|
49
|
-
raise NotImplementedError,
|
22
|
+
raise NotImplementedError, 'magic not implemented'
|
50
23
|
end
|
51
24
|
|
52
25
|
def get_security_token!(parameters = {})
|
53
|
-
raise NotImplementedError,
|
26
|
+
raise NotImplementedError, 'get_security_token! not implemented'
|
54
27
|
end
|
55
28
|
|
56
29
|
def retire_security_token!(parameters = {})
|
57
|
-
raise NotImplementedError,
|
30
|
+
raise NotImplementedError, 'retire_security_token! not implemented'
|
58
31
|
end
|
59
32
|
|
60
33
|
protected
|
61
34
|
|
62
35
|
def log_get_security_token
|
63
|
-
message = "Unity API GetSecurityToken request to #{@base_unity_url}"
|
36
|
+
message = "Unity API GetSecurityToken request to #{@options.base_unity_url}"
|
64
37
|
log_info(message)
|
65
38
|
end
|
66
39
|
|
67
40
|
def log_retire_security_token
|
68
|
-
message = "Unity API RetireSecurityToken request to #{@base_unity_url}"
|
41
|
+
message = "Unity API RetireSecurityToken request to #{@options.base_unity_url}"
|
69
42
|
log_info(message)
|
70
43
|
end
|
71
44
|
|
72
45
|
def log_magic(request)
|
73
|
-
raise ArgumentError,
|
74
|
-
message = "Unity API Magic request to #{@base_unity_url} [#{request.parameters[:action]}]"
|
46
|
+
raise ArgumentError, 'request can not be nil' if request.nil?
|
47
|
+
message = "Unity API Magic request to #{@options.base_unity_url} [#{request.parameters[:action]}]"
|
75
48
|
log_info(message)
|
76
49
|
end
|
77
50
|
|
78
51
|
def log_info(message)
|
79
|
-
if
|
52
|
+
if @options.logger? && !message.nil?
|
80
53
|
message += " #{@timer} seconds" unless @timer.nil?
|
81
54
|
@timer = nil
|
82
|
-
logger.info(message)
|
55
|
+
@options.logger.info(message)
|
83
56
|
end
|
84
57
|
end
|
85
58
|
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module AllscriptsUnityClient
|
2
|
+
class ClientOptions
|
3
|
+
attr_accessor :proxy, :logger
|
4
|
+
attr_reader :base_unity_url, :username, :password, :appname, :timezone
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
@base_unity_url = options[:base_unity_url] ? options[:base_unity_url].gsub(/\/$/, '') : nil
|
8
|
+
@username = options[:username]
|
9
|
+
@password = options[:password]
|
10
|
+
@appname = options[:appname]
|
11
|
+
@proxy = options[:proxy]
|
12
|
+
self.timezone = options[:timezone]
|
13
|
+
@logger = options[:logger]
|
14
|
+
|
15
|
+
validate_options
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate_options(options = {})
|
19
|
+
base_unity_url = options.has_key?(:base_unity_url) ? options[:base_unity_url] : @base_unity_url
|
20
|
+
username = options.has_key?(:username) ? options[:username] : @username
|
21
|
+
password = options.has_key?(:password) ? options[:password] : @password
|
22
|
+
appname = options.has_key?(:appname) ? options[:appname] : @appname
|
23
|
+
|
24
|
+
raise ArgumentError, 'base_unity_url can not be nil' if base_unity_url.nil?
|
25
|
+
raise ArgumentError, 'username can not be nil' if username.nil?
|
26
|
+
raise ArgumentError, 'password can not be nil' if password.nil?
|
27
|
+
raise ArgumentError, 'appname can not be nil' if appname.nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
def base_unity_url=(base_unity_url)
|
31
|
+
validate_options(base_unity_url: base_unity_url)
|
32
|
+
@base_unity_url = base_unity_url.gsub /\/$/, ''
|
33
|
+
end
|
34
|
+
|
35
|
+
def username=(username)
|
36
|
+
validate_options(username: username)
|
37
|
+
@username = username
|
38
|
+
end
|
39
|
+
|
40
|
+
def password=(password)
|
41
|
+
validate_options(password: password)
|
42
|
+
@password = password
|
43
|
+
end
|
44
|
+
|
45
|
+
def appname=(appname)
|
46
|
+
validate_options(appname: appname)
|
47
|
+
@appname = appname
|
48
|
+
end
|
49
|
+
|
50
|
+
def timezone=(timezone)
|
51
|
+
if !timezone.nil?
|
52
|
+
@timezone = Timezone.new(timezone)
|
53
|
+
else
|
54
|
+
@timezone = Timezone.new('UTC')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def proxy?
|
59
|
+
return false if @proxy.nil?
|
60
|
+
return false if @proxy.empty?
|
61
|
+
true
|
62
|
+
end
|
63
|
+
|
64
|
+
def logger?
|
65
|
+
!@logger.nil?
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,31 +1,37 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'json'
|
2
|
+
require 'faraday'
|
3
|
+
require 'em-http-request'
|
3
4
|
|
4
5
|
module AllscriptsUnityClient
|
5
6
|
class JSONClientDriver < ClientDriver
|
6
|
-
attr_accessor :json_base_url
|
7
|
+
attr_accessor :json_base_url, :connection
|
7
8
|
|
8
|
-
UNITY_JSON_ENDPOINT =
|
9
|
+
UNITY_JSON_ENDPOINT = '/Unity/UnityService.svc/json'
|
9
10
|
|
10
|
-
def initialize(
|
11
|
+
def initialize(options)
|
11
12
|
super
|
13
|
+
@connection = Faraday.new(url: @options.base_unity_url) do |conn|
|
14
|
+
if @options.proxy?
|
15
|
+
conn.proxy @options.proxy
|
16
|
+
end
|
12
17
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@json_base_url = "#{@base_unity_url}#{UNITY_JSON_ENDPOINT}"
|
18
|
+
conn.adapter :em_http
|
19
|
+
end
|
17
20
|
end
|
18
21
|
|
19
22
|
def client_type
|
20
|
-
|
23
|
+
:json
|
21
24
|
end
|
22
25
|
|
23
26
|
def magic(parameters = {})
|
24
|
-
request_data = JSONUnityRequest.new(parameters, @timezone, @appname, @security_token)
|
25
|
-
request = create_httpi_request("#{@json_base_url}/MagicJson", request_data.to_hash)
|
27
|
+
request_data = JSONUnityRequest.new(parameters, @options.timezone, @options.appname, @security_token)
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
+
response = @connection.post do |request|
|
30
|
+
request.url "#{UNITY_JSON_ENDPOINT}/MagicJson"
|
31
|
+
request.headers['Content-Type'] = 'application/json'
|
32
|
+
request.body = JSON.generate(request_data.to_hash)
|
33
|
+
start_timer
|
34
|
+
end
|
29
35
|
end_timer
|
30
36
|
|
31
37
|
response = JSON.parse(response.body)
|
@@ -33,24 +39,27 @@ module AllscriptsUnityClient
|
|
33
39
|
raise_if_response_error(response)
|
34
40
|
log_magic(request_data)
|
35
41
|
|
36
|
-
response = JSONUnityResponse.new(response, @timezone)
|
42
|
+
response = JSONUnityResponse.new(response, @options.timezone)
|
37
43
|
response.to_hash
|
38
44
|
end
|
39
45
|
|
40
46
|
def get_security_token!(parameters = {})
|
41
|
-
username = parameters[:username] || @username
|
42
|
-
password = parameters[:password] || @password
|
43
|
-
appname = parameters[:appname] || @appname
|
47
|
+
username = parameters[:username] || @options.username
|
48
|
+
password = parameters[:password] || @options.password
|
49
|
+
appname = parameters[:appname] || @options.appname
|
44
50
|
|
45
51
|
request_data = {
|
46
|
-
|
47
|
-
|
48
|
-
|
52
|
+
'Username' => username,
|
53
|
+
'Password' => password,
|
54
|
+
'Appname' => appname
|
49
55
|
}
|
50
|
-
request = create_httpi_request("#{@json_base_url}/GetToken", request_data)
|
51
56
|
|
52
|
-
|
53
|
-
|
57
|
+
response = @connection.post do |request|
|
58
|
+
request.url "#{UNITY_JSON_ENDPOINT}/GetToken"
|
59
|
+
request.headers['Content-Type'] = 'application/json'
|
60
|
+
request.body = JSON.generate(request_data)
|
61
|
+
start_timer
|
62
|
+
end
|
54
63
|
end_timer
|
55
64
|
|
56
65
|
raise_if_response_error(response.body)
|
@@ -61,16 +70,19 @@ module AllscriptsUnityClient
|
|
61
70
|
|
62
71
|
def retire_security_token!(parameters = {})
|
63
72
|
token = parameters[:token] || @security_token
|
64
|
-
appname = parameters[:appname] || @appname
|
73
|
+
appname = parameters[:appname] || @options.appname
|
65
74
|
|
66
75
|
request_data = {
|
67
|
-
|
68
|
-
|
76
|
+
'Token' => token,
|
77
|
+
'Appname' => appname
|
69
78
|
}
|
70
|
-
request = create_httpi_request("#{@json_base_url}/RetireSecurityToken", request_data)
|
71
79
|
|
72
|
-
|
73
|
-
|
80
|
+
response = @connection.post do |request|
|
81
|
+
request.url "#{UNITY_JSON_ENDPOINT}/RetireSecurityToken"
|
82
|
+
request.headers['Content-Type'] = 'application/json'
|
83
|
+
request.body = JSON.generate(request_data)
|
84
|
+
start_timer
|
85
|
+
end
|
74
86
|
end_timer
|
75
87
|
|
76
88
|
raise_if_response_error(response.body)
|
@@ -81,28 +93,12 @@ module AllscriptsUnityClient
|
|
81
93
|
|
82
94
|
private
|
83
95
|
|
84
|
-
def create_httpi_request(url, data)
|
85
|
-
request = HTTPI::Request.new
|
86
|
-
request.url = url
|
87
|
-
request.headers = {
|
88
|
-
"Accept-Encoding" => "gzip,deflate",
|
89
|
-
"Content-type" => "application/json;charset=utf-8"
|
90
|
-
}
|
91
|
-
request.body = JSON.generate(data)
|
92
|
-
|
93
|
-
unless @proxy.nil?
|
94
|
-
request.proxy = @proxy
|
95
|
-
end
|
96
|
-
|
97
|
-
request
|
98
|
-
end
|
99
|
-
|
100
96
|
def raise_if_response_error(response)
|
101
97
|
if response.nil?
|
102
|
-
raise APIError,
|
103
|
-
elsif response.is_a?(Array) && !response[0].nil? && !response[0][
|
104
|
-
raise APIError, response[0][
|
105
|
-
elsif response.is_a?(String) && response.include?(
|
98
|
+
raise APIError, 'Response was empty'
|
99
|
+
elsif response.is_a?(Array) && !response[0].nil? && !response[0]['Error'].nil?
|
100
|
+
raise APIError, response[0]['Error']
|
101
|
+
elsif response.is_a?(String) && response.include?('error:')
|
106
102
|
raise APIError, response
|
107
103
|
end
|
108
104
|
end
|
@@ -6,27 +6,27 @@ module AllscriptsUnityClient
|
|
6
6
|
appname = @parameters[:appname] || @appname
|
7
7
|
patientid = @parameters[:patientid]
|
8
8
|
token = @parameters[:token] || @security_token
|
9
|
-
parameter1 = process_date(@parameters[:parameter1]) ||
|
10
|
-
parameter2 = process_date(@parameters[:parameter2]) ||
|
11
|
-
parameter3 = process_date(@parameters[:parameter3]) ||
|
12
|
-
parameter4 = process_date(@parameters[:parameter4]) ||
|
13
|
-
parameter5 = process_date(@parameters[:parameter5]) ||
|
14
|
-
parameter6 = process_date(@parameters[:parameter6]) ||
|
15
|
-
data = Utilities::encode_data(@parameters[:data]) ||
|
9
|
+
parameter1 = process_date(@parameters[:parameter1]) || ''
|
10
|
+
parameter2 = process_date(@parameters[:parameter2]) || ''
|
11
|
+
parameter3 = process_date(@parameters[:parameter3]) || ''
|
12
|
+
parameter4 = process_date(@parameters[:parameter4]) || ''
|
13
|
+
parameter5 = process_date(@parameters[:parameter5]) || ''
|
14
|
+
parameter6 = process_date(@parameters[:parameter6]) || ''
|
15
|
+
data = Utilities::encode_data(@parameters[:data]) || ''
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
{
|
18
|
+
'Action' => action,
|
19
|
+
'AppUserID' => userid,
|
20
|
+
'Appname' => appname,
|
21
|
+
'PatientID' => patientid,
|
22
|
+
'Token' => token,
|
23
|
+
'Parameter1' => parameter1,
|
24
|
+
'Parameter2' => parameter2,
|
25
|
+
'Parameter3' => parameter3,
|
26
|
+
'Parameter4' => parameter4,
|
27
|
+
'Parameter5' => parameter5,
|
28
|
+
'Parameter6' => parameter6,
|
29
|
+
'Data' => data
|
30
30
|
}
|
31
31
|
end
|
32
32
|
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
require
|
1
|
+
require 'savon'
|
2
2
|
|
3
3
|
module AllscriptsUnityClient
|
4
4
|
class SOAPClientDriver < ClientDriver
|
5
5
|
attr_accessor :savon_client
|
6
6
|
|
7
|
-
UNITY_SOAP_ENDPOINT =
|
8
|
-
UNITY_ENDPOINT_NAMESPACE =
|
7
|
+
UNITY_SOAP_ENDPOINT = '/Unity/UnityService.svc/unityservice'
|
8
|
+
UNITY_ENDPOINT_NAMESPACE = 'http://www.allscripts.com/Unity/IUnityService'
|
9
9
|
|
10
|
-
def initialize(
|
10
|
+
def initialize(options)
|
11
11
|
super
|
12
12
|
|
13
|
-
client_proxy = @proxy
|
14
|
-
base_unity_url = "#{@base_unity_url}#{UNITY_SOAP_ENDPOINT}"
|
13
|
+
client_proxy = @options.proxy
|
14
|
+
base_unity_url = "#{@options.base_unity_url}#{UNITY_SOAP_ENDPOINT}"
|
15
15
|
|
16
16
|
@savon_client = Savon.client do
|
17
17
|
# Removes the wsdl: namespace from body elements in the SOAP
|
@@ -24,7 +24,7 @@ module AllscriptsUnityClient
|
|
24
24
|
|
25
25
|
# Manually register SOAP namespace. This URL isn't live, but the
|
26
26
|
# internal SOAP endpoints expect it.
|
27
|
-
namespace
|
27
|
+
namespace 'http://www.allscripts.com/Unity'
|
28
28
|
|
29
29
|
# Register proxy with Savon if one was given.
|
30
30
|
unless client_proxy.nil?
|
@@ -41,7 +41,7 @@ module AllscriptsUnityClient
|
|
41
41
|
# Enable gzip on HTTP responses. Unity does not currently support this
|
42
42
|
# as of Born On 10/7/2013, but it doesn't hurt to future-proof. If gzip
|
43
43
|
# is ever enabled, this library will get a speed bump for free.
|
44
|
-
headers({
|
44
|
+
headers({ 'Accept-Encoding' => 'gzip,deflate'})
|
45
45
|
|
46
46
|
# Disable Savon logs
|
47
47
|
log false
|
@@ -49,19 +49,19 @@ module AllscriptsUnityClient
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def client_type
|
52
|
-
|
52
|
+
:soap
|
53
53
|
end
|
54
54
|
|
55
55
|
def magic(parameters = {})
|
56
|
-
request_data = UnityRequest.new(parameters, @timezone,
|
56
|
+
request_data = UnityRequest.new(parameters, @options.timezone, @options.appname, @security_token)
|
57
57
|
call_data = {
|
58
|
-
:
|
59
|
-
:
|
58
|
+
message: request_data.to_hash,
|
59
|
+
soap_action: "#{UNITY_ENDPOINT_NAMESPACE}/Magic"
|
60
60
|
}
|
61
61
|
|
62
62
|
begin
|
63
63
|
start_timer
|
64
|
-
response = @savon_client.call(
|
64
|
+
response = @savon_client.call('Magic', call_data)
|
65
65
|
end_timer
|
66
66
|
rescue Savon::SOAPFault => e
|
67
67
|
raise APIError, e.message
|
@@ -69,27 +69,27 @@ module AllscriptsUnityClient
|
|
69
69
|
|
70
70
|
log_magic(request_data)
|
71
71
|
|
72
|
-
response = UnityResponse.new(response.body, @timezone)
|
72
|
+
response = UnityResponse.new(response.body, @options.timezone)
|
73
73
|
response.to_hash
|
74
74
|
end
|
75
75
|
|
76
76
|
def get_security_token!(parameters = {})
|
77
|
-
username = parameters[:username] || @username
|
78
|
-
password = parameters[:password] || @password
|
79
|
-
appname = parameters[:appname] || @appname
|
77
|
+
username = parameters[:username] || @options.username
|
78
|
+
password = parameters[:password] || @options.password
|
79
|
+
appname = parameters[:appname] || @options.appname
|
80
80
|
|
81
81
|
call_data = {
|
82
|
-
:
|
83
|
-
|
84
|
-
|
85
|
-
|
82
|
+
message: {
|
83
|
+
'Username' => username,
|
84
|
+
'Password' => password,
|
85
|
+
'Appname' => appname
|
86
86
|
},
|
87
|
-
:
|
87
|
+
soap_action: "#{UNITY_ENDPOINT_NAMESPACE}/GetSecurityToken"
|
88
88
|
}
|
89
89
|
|
90
90
|
begin
|
91
91
|
start_timer
|
92
|
-
response = @savon_client.call(
|
92
|
+
response = @savon_client.call('GetSecurityToken', call_data)
|
93
93
|
end_timer
|
94
94
|
rescue Savon::SOAPFault => e
|
95
95
|
raise APIError, e.message
|
@@ -102,19 +102,19 @@ module AllscriptsUnityClient
|
|
102
102
|
|
103
103
|
def retire_security_token!(parameters = {})
|
104
104
|
token = parameters[:token] || @security_token
|
105
|
-
appname = parameters[:appname] || @appname
|
105
|
+
appname = parameters[:appname] || @options.appname
|
106
106
|
|
107
107
|
call_data = {
|
108
|
-
:
|
109
|
-
|
110
|
-
|
108
|
+
message: {
|
109
|
+
'Token' => token,
|
110
|
+
'Appname' => appname
|
111
111
|
},
|
112
|
-
:
|
112
|
+
soap_action: "#{UNITY_ENDPOINT_NAMESPACE}/RetireSecurityToken"
|
113
113
|
}
|
114
114
|
|
115
115
|
begin
|
116
116
|
start_timer
|
117
|
-
@savon_client.call(
|
117
|
+
@savon_client.call('RetireSecurityToken', call_data)
|
118
118
|
end_timer
|
119
119
|
rescue Savon::SOAPFault => e
|
120
120
|
raise APIError, e.message
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'date'
|
2
|
+
require 'tzinfo'
|
3
3
|
|
4
4
|
module AllscriptsUnityClient
|
5
5
|
class Timezone
|
6
6
|
attr_accessor :tzinfo
|
7
7
|
|
8
8
|
def initialize(zone_identifier)
|
9
|
-
raise ArgumentError,
|
9
|
+
raise ArgumentError, 'zone_identifier can not be nil' if zone_identifier.nil?
|
10
10
|
|
11
11
|
@tzinfo = TZInfo::Timezone.get(zone_identifier)
|
12
12
|
end
|
@@ -21,6 +21,11 @@ module AllscriptsUnityClient
|
|
21
21
|
convert_with_timezone(:utc_to_local, datetime)
|
22
22
|
end
|
23
23
|
|
24
|
+
def ==(timezone)
|
25
|
+
return false if !timezone.is_a?(Timezone)
|
26
|
+
@tzinfo == timezone.tzinfo
|
27
|
+
end
|
28
|
+
|
24
29
|
private
|
25
30
|
|
26
31
|
# Direction can be :utc_to_local or :local_to_utc
|
@@ -52,7 +57,7 @@ module AllscriptsUnityClient
|
|
52
57
|
|
53
58
|
if is_datetime
|
54
59
|
# Convert to a DateTime with a UTC offset
|
55
|
-
datetime = DateTime.parse("#{datetime.strftime(
|
60
|
+
datetime = DateTime.parse("#{datetime.strftime('%FT%T')}Z")
|
56
61
|
end
|
57
62
|
end
|
58
63
|
|
@@ -65,7 +70,7 @@ module AllscriptsUnityClient
|
|
65
70
|
end
|
66
71
|
end
|
67
72
|
|
68
|
-
|
73
|
+
datetime
|
69
74
|
end
|
70
75
|
|
71
76
|
# TZInfo does not correctly update a DateTime's
|
@@ -78,7 +83,7 @@ module AllscriptsUnityClient
|
|
78
83
|
|
79
84
|
offset = @tzinfo.current_period.utc_offset
|
80
85
|
negative_offset = false
|
81
|
-
datetime_string = datetime.strftime(
|
86
|
+
datetime_string = datetime.strftime('%FT%T')
|
82
87
|
|
83
88
|
if offset < 0
|
84
89
|
offset *= -1
|
@@ -86,11 +91,11 @@ module AllscriptsUnityClient
|
|
86
91
|
end
|
87
92
|
|
88
93
|
if offset == 0
|
89
|
-
offset_string =
|
94
|
+
offset_string = 'Z'
|
90
95
|
else
|
91
|
-
offset_string = Time.at(offset).utc.strftime(
|
92
|
-
offset_string =
|
93
|
-
offset_string =
|
96
|
+
offset_string = Time.at(offset).utc.strftime('%H:%M')
|
97
|
+
offset_string = '-' + offset_string if negative_offset
|
98
|
+
offset_string = '+' + offset_string unless negative_offset
|
94
99
|
end
|
95
100
|
|
96
101
|
"#{datetime_string}#{offset_string}"
|
@@ -3,10 +3,10 @@ module AllscriptsUnityClient
|
|
3
3
|
attr_accessor :parameters, :appname, :security_token, :timezone
|
4
4
|
|
5
5
|
def initialize(parameters, timezone, appname, security_token)
|
6
|
-
raise ArgumentError,
|
7
|
-
raise ArgumentError,
|
8
|
-
raise ArgumentError,
|
9
|
-
raise ArgumentError,
|
6
|
+
raise ArgumentError, 'parameters can not be nil' if parameters.nil?
|
7
|
+
raise ArgumentError, 'timezone can not be nil' if timezone.nil?
|
8
|
+
raise ArgumentError, 'appname can not be nil' if appname.nil?
|
9
|
+
raise ArgumentError, 'security_token can not be nil' if security_token.nil?
|
10
10
|
|
11
11
|
@appname = appname
|
12
12
|
@security_token = security_token
|
@@ -28,19 +28,19 @@ module AllscriptsUnityClient
|
|
28
28
|
parameter6 = process_date(@parameters[:parameter6])
|
29
29
|
data = Utilities::encode_data(@parameters[:data])
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
31
|
+
{
|
32
|
+
'Action' => action,
|
33
|
+
'UserID' => userid,
|
34
|
+
'Appname' => appname,
|
35
|
+
'PatientID' => patientid,
|
36
|
+
'Token' => token,
|
37
|
+
'Parameter1' => parameter1,
|
38
|
+
'Parameter2' => parameter2,
|
39
|
+
'Parameter3' => parameter3,
|
40
|
+
'Parameter4' => parameter4,
|
41
|
+
'Parameter5' => parameter5,
|
42
|
+
'Parameter6' => parameter6,
|
43
|
+
'data' => data
|
44
44
|
}
|
45
45
|
end
|
46
46
|
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require 'date'
|
2
2
|
|
3
3
|
module AllscriptsUnityClient
|
4
4
|
class UnityResponse
|
5
5
|
attr_accessor :response, :timezone
|
6
6
|
|
7
7
|
def initialize(response, timezone)
|
8
|
-
raise ArgumentError,
|
9
|
-
raise ArgumentError,
|
8
|
+
raise ArgumentError, 'timezone can not be nil' if timezone.nil?
|
9
|
+
raise ArgumentError, 'response can not be nil' if response.nil?
|
10
10
|
|
11
11
|
@response = response
|
12
12
|
@timezone = timezone
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'nori'
|
2
|
+
require 'date'
|
3
|
+
require 'american_date'
|
4
4
|
|
5
5
|
module AllscriptsUnityClient
|
6
6
|
class Utilities
|
@@ -29,9 +29,9 @@ module AllscriptsUnityClient
|
|
29
29
|
end
|
30
30
|
|
31
31
|
if data.respond_to?(:pack)
|
32
|
-
return data.pack(
|
32
|
+
return data.pack('m')
|
33
33
|
else
|
34
|
-
return [data].pack(
|
34
|
+
return [data].pack('m')
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|