Class: AllscriptsApi::Client

Inherits:
Object
  • Object
show all
Includes:
Demographics::DemographicsMethods, Documents::DocumentMethods, NamedMagicMethods, Orders::OrderingMethods, Patients::PatientMethods
Defined in:
lib/allscripts_api/client.rb

Overview

Client serves as an entry point for making calls

Constant Summary collapse

ENDPOINT =

hardcoded to use the JSON endpoint

"/UnityService.svc/json".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Documents::DocumentMethods

#get_ccda, #save_document_image

Methods included from Demographics::DemographicsMethods

#get_patient, #get_patient_full, #search_patients

Methods included from Patients::PatientMethods

#get_changed_patients, #get_clinical_summary

Methods included from Orders::OrderingMethods

#get_order_workflow, #save_order

Methods included from NamedMagicMethods

#get_dictionary, #get_encounter_list, #get_list_of_dictionaries, #get_patient_problems, #get_provider, #get_providers, #get_results, #get_schedule, #get_server_info, #last_logs

Constructor Details

#initialize(url, app_name, app_username, app_password) ⇒ Client

Instantiation of the Client

Parameters:

  • url (String)

    Allscripts URL to be used to make Unity API calls

  • app_name (String)

    app name assigned by Allscripts

  • app_username (String)

    the app username supplied by Allscripts

  • app_password (String)

    the app password supplied by Allscripts



25
26
27
28
29
30
31
# File 'lib/allscripts_api/client.rb', line 25

def initialize(url, app_name, app_username, app_password)
  @unity_url = url
  @app_name = app_name
  @username = app_username
  @password = app_password
  @adapter = check_adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



13
14
15
# File 'lib/allscripts_api/client.rb', line 13

def adapter
  @adapter
end

#app_nameObject (readonly)

Returns the value of attribute app_name.



13
14
15
# File 'lib/allscripts_api/client.rb', line 13

def app_name
  @app_name
end

#sso_token=(value) ⇒ Object (writeonly)

Sets the attribute sso_token

Parameters:

  • value

    the value to set the attribute sso_token to.



14
15
16
# File 'lib/allscripts_api/client.rb', line 14

def sso_token=(value)
  @sso_token = value
end

#tokenObject (readonly)

Returns the value of attribute token.



13
14
15
# File 'lib/allscripts_api/client.rb', line 13

def token
  @token
end

#unity_urlObject (readonly)

Returns the value of attribute unity_url.



13
14
15
# File 'lib/allscripts_api/client.rb', line 13

def unity_url
  @unity_url
end

Instance Method Details

#get_tokenString

Gets security token necessary in all workflows

Returns:

  • (String)

    security token

Raises:



35
36
37
38
39
40
41
42
43
44
# File 'lib/allscripts_api/client.rb', line 35

def get_token
  full_path = build_request_path("/GetToken")
  response = conn.post do |req|
    req.url(full_path)
    req.body = { Username: @username, Password: @password }.to_json
  end

  raise(GetTokenError, response.body) unless response.status == 200
  @token = response.body
end

#get_user_authentication(username, password) ⇒ Hash

Assign a security token from ‘get_token` to a specific Allscripts user. This creates a link on the Allscripts server that allows that token to be used in subsequent `magic` calls passed that user’s username.

Parameters:

  • username (String)

    the Allscripts user’s username (from Allscripts)

  • password (String)

    the Allscripts user’s password (from Allscripts)

Returns:

  • (Hash)

    user permissions, etc.



53
54
55
56
57
58
# File 'lib/allscripts_api/client.rb', line 53

def get_user_authentication(username, password)
  @allscripts_username = username
  params = MagicParams.format(user_id: username, parameter1: password)
  response = magic("GetUserAuthentication", magic_params: params)
  response["getuserauthenticationinfo"][0]
end

#magic(action, magic_params: MagicParams.format) ⇒ Hash, MagicError

Main method for interacting with the Allscripts UnityAPI

used to build the Magic Action request body’s user_id, patient_id, and magic parameters. The patient_id is sometimes oprional and the numbered params are generally optional, but must be sent as blank strings if unused. a ‘MagicError` with the API error message(hopefully)

Parameters:

  • action (String)

    the API action to be performed

  • magic_params (MagicParams) (defaults to: MagicParams.format)

    a params object

Returns:

  • (Hash, MagicError)

    the parsed JSON response from Allscripts or



85
86
87
88
89
90
91
92
93
94
# File 'lib/allscripts_api/client.rb', line 85

def magic(action, magic_params: MagicParams.format)
  full_path = build_request_path("/MagicJson")
  body = build_magic_body(action, magic_params)
  response =
    conn.post do |req|
      req.url(full_path)
      req.body = body
    end
  read_magic_response(response)
end

#validate_sso_token(sso_token = nil) ⇒ Object

Validate a token generated and passed by Allscripts during SSO Falls back and looks for sso_token on the client if not passed one Note that sso_token is not the token from ‘get_token“

TODO: test and validate. Add error handling

Parameters:

  • sso_token (String) (defaults to: nil)

    the Allscripts SSO token (from Allscripts)



67
68
69
70
71
72
# File 'lib/allscripts_api/client.rb', line 67

def validate_sso_token(sso_token = nil)
  sso_token ||= @sso_token
  params = MagicParams.format(parameter1: sso_token)
  response = magic("GetTokenValidation", magic_params: params)
  response["Table"][0]
end