Class: AllscriptsUnityClient::UnityRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/allscripts_unity_client/unity_request.rb

Overview

Transform a Unity request into a Hash suitable for sending using Savon.

Direct Known Subclasses

JSONUnityRequest

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameters, timezone, appname, security_token, raw_dates = false) ⇒ UnityRequest

Constructor.

parameters

A Hash of Unity parameters. Takes this form:

{
  'Action' => ...,
  'UserID' => ...,
  'Appname' => ...,
  'PatientID' => ...,
  'Token' => ...,
  'Parameter1' => ...,
  'Parameter2' => ...,
  'Parameter3' => ...,
  'Parameter4' => ...,
  'Parameter5' => ...,
  'Parameter6' => ...,
  'data' => ...
}
timezone

An ActiveSupport::TimeZone instance.

appname

The Unity license appname.

security_token

A security token from the Unity GetSecurityToken call.

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/allscripts_unity_client/unity_request.rb', line 29

def initialize(parameters, timezone, appname, security_token, raw_dates=false)
  raise ArgumentError, 'parameters can not be nil' if parameters.nil?
  raise ArgumentError, 'timezone can not be nil' if timezone.nil?
  raise ArgumentError, 'appname can not be nil' if appname.nil?
  raise ArgumentError, 'security_token can not be nil' if security_token.nil?

  @appname = appname
  @security_token = security_token
  @parameters = parameters
  @timezone = timezone
  @raw_dates = raw_dates
end

Instance Attribute Details

#appnameObject

Returns the value of attribute appname.



5
6
7
# File 'lib/allscripts_unity_client/unity_request.rb', line 5

def appname
  @appname
end

#parametersObject

Returns the value of attribute parameters.



5
6
7
# File 'lib/allscripts_unity_client/unity_request.rb', line 5

def parameters
  @parameters
end

#raw_datesObject

Returns the value of attribute raw_dates.



5
6
7
# File 'lib/allscripts_unity_client/unity_request.rb', line 5

def raw_dates
  @raw_dates
end

#security_tokenObject

Returns the value of attribute security_token.



5
6
7
# File 'lib/allscripts_unity_client/unity_request.rb', line 5

def security_token
  @security_token
end

#timezoneObject

Returns the value of attribute timezone.



5
6
7
# File 'lib/allscripts_unity_client/unity_request.rb', line 5

def timezone
  @timezone
end

Instance Method Details

#to_hashObject

Convert the parameters to a Hash for Savon with all possible dates converted to the Organization’s localtime.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/allscripts_unity_client/unity_request.rb', line 44

def to_hash
  action = @parameters[:action]
  userid = @parameters[:userid]
  appname = @parameters[:appname] || @appname
  patientid = @parameters[:patientid]
  token = @parameters[:token] || @security_token
  parameter1 = process_date(@parameters[:parameter1])
  parameter2 = process_date(@parameters[:parameter2])
  parameter3 = process_date(@parameters[:parameter3])
  parameter4 = process_date(@parameters[:parameter4])
  parameter5 = process_date(@parameters[:parameter5])
  parameter6 = process_date(@parameters[:parameter6])
  data = Utilities::encode_data(@parameters[:data])

  {
    'Action' => action,
    'UserID' => userid,
    'Appname' => appname,
    'PatientID' => patientid,
    'Token' => token,
    'Parameter1' => parameter1,
    'Parameter2' => parameter2,
    'Parameter3' => parameter3,
    'Parameter4' => parameter4,
    'Parameter5' => parameter5,
    'Parameter6' => parameter6,
    'data' => data
  }
end