Class: AllscriptsApi::Client
- Inherits:
-
Object
- Object
- AllscriptsApi::Client
- 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
"/Unity/UnityService.svc/json".freeze
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
-
#sso_token ⇒ Object
writeonly
Sets the attribute sso_token.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#unity_url ⇒ Object
readonly
Returns the value of attribute unity_url.
Instance Method Summary collapse
-
#get_token ⇒ String
Gets security token necessary in all workflows.
-
#get_user_authentication(username, password) ⇒ Hash
Assign a security token from ‘get_token` to a specific Allscripts user.
-
#initialize(url, app_name, app_username, app_password) ⇒ Client
constructor
Instantiation of the Client.
-
#magic(action, magic_params: MagicParams.format) ⇒ Hash, MagicError
Main method for interacting with the Allscripts UnityAPI.
-
#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“.
Methods included from Documents::DocumentMethods
Methods included from OrderingMethods
Methods included from NamedMagicMethods
#get_ccda, #get_clinical_summary, #get_dictionary, #get_encounter_list, #get_list_of_dictionaries, #get_patient, #get_patient_full, #get_patient_problems, #get_schedule, #search_patients
Constructor Details
#initialize(url, app_name, app_username, app_password) ⇒ Client
Instantiation of the Client
23 24 25 26 27 28 29 |
# File 'lib/allscripts_api/client.rb', line 23 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
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
11 12 13 |
# File 'lib/allscripts_api/client.rb', line 11 def adapter @adapter end |
#app_name ⇒ Object (readonly)
Returns the value of attribute app_name.
11 12 13 |
# File 'lib/allscripts_api/client.rb', line 11 def app_name @app_name end |
#sso_token=(value) ⇒ Object (writeonly)
Sets the attribute sso_token
12 13 14 |
# File 'lib/allscripts_api/client.rb', line 12 def sso_token=(value) @sso_token = value end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
11 12 13 |
# File 'lib/allscripts_api/client.rb', line 11 def token @token end |
#unity_url ⇒ Object (readonly)
Returns the value of attribute unity_url.
11 12 13 |
# File 'lib/allscripts_api/client.rb', line 11 def unity_url @unity_url end |
Instance Method Details
#get_token ⇒ String
Gets security token necessary in all workflows
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/allscripts_api/client.rb', line 33 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.
51 52 53 54 55 56 |
# File 'lib/allscripts_api/client.rb', line 51 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)
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/allscripts_api/client.rb', line 83 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
65 66 67 68 69 70 |
# File 'lib/allscripts_api/client.rb', line 65 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 |