Class: Chip::Service

Inherits:
Common::Client::Base show all
Includes:
Common::Client::Concerns::Monitoring, SentryLogging
Defined in:
lib/chip/service.rb

Constant Summary collapse

STATSD_KEY_PREFIX =
'api.chip'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common::Client::Concerns::Monitoring

#with_monitoring

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger

Methods inherited from Common::Client::Base

configuration, #raise_backend_exception

Constructor Details

#initialize(opts = {}) ⇒ Service

Returns a new instance of Service.



34
35
36
37
38
39
40
41
42
43
# File 'lib/chip/service.rb', line 34

def initialize(opts = {})
  @tenant_name = opts[:tenant_name]
  @tenant_id = opts[:tenant_id]
  @username = opts[:username]
  @password = opts[:password]
  validate_arguments!

  @redis_client = RedisClient.build(tenant_id)
  super()
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



17
18
19
# File 'lib/chip/service.rb', line 17

def password
  @password
end

#redis_clientObject (readonly)

Returns the value of attribute redis_client.



17
18
19
# File 'lib/chip/service.rb', line 17

def redis_client
  @redis_client
end

#tenant_idObject (readonly)

Returns the value of attribute tenant_id.



17
18
19
# File 'lib/chip/service.rb', line 17

def tenant_id
  @tenant_id
end

#tenant_nameObject (readonly)

Returns the value of attribute tenant_name.



17
18
19
# File 'lib/chip/service.rb', line 17

def tenant_name
  @tenant_name
end

#usernameObject (readonly)

Returns the value of attribute username.



17
18
19
# File 'lib/chip/service.rb', line 17

def username
  @username
end

Class Method Details

.build(opts = {}) ⇒ Service

Builds a Service instance

Parameters:

  • opts (Hash) (defaults to: {})

    options to create the object

Options Hash (opts):

  • :tenant_name (String)
  • :tenant_id (String)
  • :username (String)
  • :password (String)

Returns:

  • (Service)

    an instance of this class



30
31
32
# File 'lib/chip/service.rb', line 30

def self.build(opts = {})
  new(opts)
end

Instance Method Details

#get_demographics(patient_dfn:, station_no:) ⇒ Faraday::Response

Get the auth demographics data from CHIP

Returns:

  • (Faraday::Response)

    response from CHIP authenticated-demographics endpoint



50
51
52
53
54
55
# File 'lib/chip/service.rb', line 50

def get_demographics(patient_dfn:, station_no:)
  with_monitoring_and_error_handling do
    perform(:get, "/#{config.base_path}/actions/authenticated-demographics",
            { patientDfn: patient_dfn, stationNo: station_no }, request_headers)
  end
end

#get_tokenFaraday::Response

Get the auth token from CHIP

Returns:

  • (Faraday::Response)

    response from CHIP token endpoint



75
76
77
78
79
# File 'lib/chip/service.rb', line 75

def get_token
  with_monitoring do
    perform(:post, "/#{config.base_path}/token", {}, token_headers)
  end
end

#post_patient_check_in(appointment_ien:, patient_dfn:, station_no:) ⇒ Faraday::Response

Post the check-in status to CHIP

Returns:

  • (Faraday::Response)

    response from CHIP authenticated-check-in endpoint



86
87
88
89
90
91
92
# File 'lib/chip/service.rb', line 86

def post_patient_check_in(appointment_ien:, patient_dfn:, station_no:)
  with_monitoring_and_error_handling do
    perform(:post, "/#{config.base_path}/actions/authenticated-checkin",
            { appointmentIen: appointment_ien, patientDfn: patient_dfn, stationNo: station_no },
            request_headers)
  end
end

#update_demographics(patient_dfn:, station_no:, demographic_confirmations:) ⇒ Faraday::Response

Post the demographics confirmation data to CHIP

Returns:

  • (Faraday::Response)

    response from CHIP authenticated-demographics endpoint



62
63
64
65
66
67
68
# File 'lib/chip/service.rb', line 62

def update_demographics(patient_dfn:, station_no:, demographic_confirmations:)
  with_monitoring_and_error_handling do
    perform(:post, "/#{config.base_path}/actions/authenticated-demographics",
            { patientDfn: patient_dfn, stationNo: station_no, demographicConfirmations: demographic_confirmations },
            request_headers)
  end
end