Class: RedoxEngine::Client

Inherits:
Object
  • Object
show all
Includes:
RequestHelpers
Defined in:
lib/redox-engine/client.rb

Overview

RedoxEngine API client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, destinations:, test_mode: true, token: nil, refresh_token: nil) ⇒ Client

Instantiates a new RedoxEngine Client object

Examples:

redox = RedoxEngine::Client.new(
  source: source,
  destinations: destinations,
  test_mode: true,
  OPTIONAL: (If tokens/refresh_tokens are being persisted elsewhere)
  token: (existing access token),
  refresh_token: (existing refresh token)
)

Parameters:

  • source (Hash)

    source information

  • destinations (Array<Hash>)

    list of destinations

  • test_mode (Boolean) (defaults to: true)

    whether to use test mode

  • access_token (String)

    Optional param to provide an existing Access Token

  • refresh_token (String) (defaults to: nil)

    Optional param to provide an existing Refresh Token



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/redox-engine/client.rb', line 28

def initialize(
  source:, destinations:, test_mode: true, token: nil, refresh_token: nil
)
  if [RedoxEngine.api_key, RedoxEngine.secret].any?(&:nil?)
    raise APIKeyError
  end
  @refresh_token = refresh_token
  @access_token = token || fetch_access_token

  @source = source
  @destinations = destinations
  @test = test_mode
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



6
7
8
# File 'lib/redox-engine/client.rb', line 6

def access_token
  @access_token
end

#destinationsObject (readonly)

Returns the value of attribute destinations.



6
7
8
# File 'lib/redox-engine/client.rb', line 6

def destinations
  @destinations
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token.



6
7
8
# File 'lib/redox-engine/client.rb', line 6

def refresh_token
  @refresh_token
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/redox-engine/client.rb', line 6

def response
  @response
end

#sourceObject (readonly)

Returns the value of attribute source.



6
7
8
# File 'lib/redox-engine/client.rb', line 6

def source
  @source
end

#testObject (readonly)

Returns the value of attribute test.



6
7
8
# File 'lib/redox-engine/client.rb', line 6

def test
  @test
end

Instance Method Details

#add_appointment(visit:, patient:) ⇒ Hash

Send Scheduling#New message

)

Examples:

RedoxEngine::Client.new(*connection_params).get_available_slots(
 visit: <Visit>
 patient: <Patient>

Parameters:

Returns:

  • (Hash)

    parsed response object



202
203
204
205
206
207
208
209
210
# File 'lib/redox-engine/client.rb', line 202

def add_appointment(visit:, patient:)
  request_body = scheduling_query(
    query_data: { visit: visit, patient: patient }, type: 'New'
  )
  handle_request(
    request_body,
    'Error posting New Appointment.'
  )
end

#add_patient(patient_params) ⇒ Hash

Send PatientAdmin#NewPatient message

Examples:

RedoxEngine::Client.new(*connection_params).add_patient(
  Identifiers: [{
    ID: string
    IDType: string
  }*],
  Demographics: {
    FirstName: string
    ...
  }
)

Parameters:

  • patient_params (Hash)

    data to send in the Patient JSON object

Returns:

  • (Hash)

    parsed response object



57
58
59
60
61
62
63
# File 'lib/redox-engine/client.rb', line 57

def add_patient(patient_params)
  request_body = request_meta(
    data_model: 'PatientAdmin',
    event_type: 'NewPatient'
  ).merge(Patient: patient_params.redoxify_keys)
  handle_request(request_body, 'Error in Patient New.')
end

#get_available_slots(visit:, patient: nil, start_time: nil, end_time: nil) ⇒ Hash

Send Scheduling#AvailableSlots message

NOTE: Endpoint not supported by all Health Systems, talk to your redox rep for more information )

Examples:

RedoxEngine::Client.new(*connection_params).get_available_slots(
  query_data: {
    visit: <Visit>
    patient: <Patient>
 }
 start_time?: Time | String (ISO-8601 Time String)
 end_time?: Time | String (ISO-8601 Time String)

Parameters:

  • query_data (Hash)

    to send in the <Visit>/<Patient> JSON objects

  • start_time (String|Time) (defaults to: nil)

    datetime to search from

Returns:

  • (Hash)

    parsed response object



179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/redox-engine/client.rb', line 179

def get_available_slots(
  visit:, patient: nil, start_time: nil, end_time: nil
)
  visit[:reasons] = ['-1']
  request_body = scheduling_query(
    query_data: { visit: visit, patient: patient },
    start_time: start_time,
    end_time: end_time,
    type: 'AvailableSlots'
  )
  handle_request(request_body, 'Error fetching Available Slots.')
end

#get_booked_slots(visit:, patient: nil, start_time: nil, end_time: nil) ⇒ Hash

Send Scheduling#BookedSlots message

NOTE: Endpoint not supported by all Health Systems, talk to your redox rep for more information )

Examples:

RedoxEngine::Client.new(*connection_params).get_booked_slots(
  query_data: {
    visit: <Visit>
    patient: <Patient>
 }
 start_time?: Time | String (ISO-8601 Time String)
 end_time?: Time | String (ISO-8601 Time String)

Parameters:

  • query_data (Hash)

    to send in the <Visit>/<Patient> JSON objects

  • start_time (String|Time) (defaults to: nil)

    datetime to search from

Returns:

  • (Hash)

    parsed response object



149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/redox-engine/client.rb', line 149

def get_booked_slots(visit:, patient: nil, start_time: nil, end_time: nil)
  request_body = scheduling_query(
    query_data: { visit: visit, patient: patient },
    start_time: start_time,
    end_time: end_time,
    type: 'Booked'
  )
  handle_request(
    request_body,
    'Error fetching Booked Slots.'
  )
end

#get_summary_for_patient(patient_params) ⇒ Hash

Send ClinicalSummary#PatientQuery message

Examples:

RedoxEngine::Client.new(*connection_params).search_patient(
  identifiers: [
    {
      id: string
      id_type: string
    }
  ]
)

Parameters:

  • <Patient> (Hash)

    data to send in the Patient JSON object

Returns:

  • (Hash)

    parsed response object



121
122
123
124
125
126
127
128
129
130
# File 'lib/redox-engine/client.rb', line 121

def get_summary_for_patient(patient_params)
  request_body = request_meta(
    data_model: 'Clinical Summary',
    event_type: 'PatientQuery'
  ).merge(Patient: patient_params.redoxify_keys)
  handle_request(
    request_body,
    'Error fetching Patient Clinical Summary'
  )
end

#search_patient(patient_params) ⇒ Hash

Send PatientSearch#Query message

Examples:

RedoxEngine::Client.new(*connection_params).search_patient(
  demographics: {
    FirstName: string
    ...
  }
)

Parameters:

  • <Patient> (Hash)

    data to send in the Patient JSON object

Returns:

  • (Hash)

    parsed response object



100
101
102
103
104
105
106
# File 'lib/redox-engine/client.rb', line 100

def search_patient(patient_params)
  request_body = request_meta(
    data_model: 'PatientSearch',
    event_type: 'Query'
  ).merge(Patient: patient_params.redoxify_keys)
  handle_request(request_body, 'Error in Patient Search.')
end

#update_patient(patient_params) ⇒ Hash

Send PatientAdmin#PatientUpdate message

Examples:

RedoxEngine::Client.new(*connection_params).update_patient(
  Identifiers: [{
    ID: string
    IDType: string
  }*],
  Demographics: {
    FirstName: string
    ...
  }
)

Parameters:

  • <Patient> (Hash)

    patient_params data to send in the Patient JSON object

Returns:

  • (Hash)

    parsed response object



81
82
83
84
85
86
87
# File 'lib/redox-engine/client.rb', line 81

def update_patient(patient_params)
  request_body = request_meta(
    data_model: 'PatientAdmin',
    event_type: 'PatientUpdate'
  ).merge(Patient: patient_params.redoxify_keys)
  handle_request(request_body, 'Error updating Patient.')
end