Class: AllscriptsApi::Client
- Inherits:
-
Object
- Object
- AllscriptsApi::Client
- 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
-
#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
#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
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
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
13 14 15 |
# File 'lib/allscripts_api/client.rb', line 13 def adapter @adapter end |
#app_name ⇒ Object (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
14 15 16 |
# File 'lib/allscripts_api/client.rb', line 14 def sso_token=(value) @sso_token = value end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
13 14 15 |
# File 'lib/allscripts_api/client.rb', line 13 def token @token end |
#unity_url ⇒ Object (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_token ⇒ String
Gets security token necessary in all workflows
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.
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)
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
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 |