Class: Chip::Service
- Inherits:
-
Common::Client::Base
- Object
- Common::Client::Base
- Chip::Service
- Defined in:
- lib/chip/service.rb
Constant Summary collapse
- STATSD_KEY_PREFIX =
'api.chip'
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#redis_client ⇒ Object
readonly
Returns the value of attribute redis_client.
-
#tenant_id ⇒ Object
readonly
Returns the value of attribute tenant_id.
-
#tenant_name ⇒ Object
readonly
Returns the value of attribute tenant_name.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
-
.build(opts = {}) ⇒ Service
Builds a Service instance.
Instance Method Summary collapse
- #default_headers ⇒ Object private
-
#get_demographics(patient_dfn:, station_no:) ⇒ Faraday::Response
Get the auth demographics data from CHIP.
-
#get_token ⇒ Faraday::Response
Get the auth token from CHIP.
-
#initialize(opts = {}) ⇒ Service
constructor
A new instance of Service.
-
#post_patient_check_in(appointment_ien:, patient_dfn:, station_no:) ⇒ Faraday::Response
Post the check-in status to CHIP.
- #request_headers ⇒ Object private
- #token ⇒ Object private
- #token_headers ⇒ Object private
-
#update_demographics(patient_dfn:, station_no:, demographic_confirmations:) ⇒ Faraday::Response
Post the demographics confirmation data to CHIP.
- #validate_arguments! ⇒ Object private
- #with_monitoring_and_error_handling ⇒ Object private
Methods included from Common::Client::Concerns::Monitoring
#increment, #increment_failure, #increment_total, #with_monitoring
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Methods inherited from Common::Client::Base
#config, configuration, #connection, #delete, #get, #perform, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name
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
#password ⇒ Object (readonly)
Returns the value of attribute password.
17 18 19 |
# File 'lib/chip/service.rb', line 17 def password @password end |
#redis_client ⇒ Object (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_id ⇒ Object (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_name ⇒ Object (readonly)
Returns the value of attribute tenant_name.
17 18 19 |
# File 'lib/chip/service.rb', line 17 def tenant_name @tenant_name end |
#username ⇒ Object (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
30 31 32 |
# File 'lib/chip/service.rb', line 30 def self.build(opts = {}) new(opts) end |
Instance Method Details
#default_headers ⇒ Object (private)
105 106 107 108 109 110 |
# File 'lib/chip/service.rb', line 105 def default_headers { 'Content-Type' => 'application/json', 'x-apigw-api-id' => config.api_gtwy_id } end |
#get_demographics(patient_dfn:, station_no:) ⇒ Faraday::Response
Get the auth demographics data from CHIP
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_token ⇒ Faraday::Response
Get the auth token from CHIP
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
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 |
#request_headers ⇒ Object (private)
96 97 98 |
# File 'lib/chip/service.rb', line 96 def request_headers default_headers.merge('Authorization' => "Bearer #{token}") end |
#token ⇒ Object (private)
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/chip/service.rb', line 112 def token @token ||= begin token = redis_client.get if token.present? token else resp = get_token Oj.load(resp.body)&.fetch('token').tap do |jwt_token| redis_client.save(token: jwt_token) end end end end |
#token_headers ⇒ Object (private)
100 101 102 103 |
# File 'lib/chip/service.rb', line 100 def token_headers claims_token = Base64.encode64("#{username}:#{password}") default_headers.merge('Authorization' => "Basic #{claims_token}") end |
#update_demographics(patient_dfn:, station_no:, demographic_confirmations:) ⇒ Faraday::Response
Post the demographics confirmation data to CHIP
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 |
#validate_arguments! ⇒ Object (private)
140 141 142 143 144 145 |
# File 'lib/chip/service.rb', line 140 def validate_arguments! raise ArgumentError, 'Invalid username' if username.blank? raise ArgumentError, 'Invalid password' if password.blank? raise ArgumentError, 'Invalid tenant parameters' if tenant_name.blank? || tenant_id.blank? raise ArgumentError, 'Tenant parameters do not exist' unless config.valid_tenant?(tenant_name:, tenant_id:) end |
#with_monitoring_and_error_handling ⇒ Object (private)
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/chip/service.rb', line 127 def with_monitoring_and_error_handling(&) with_monitoring(2, &) rescue => e log_exception_to_sentry(e, { url: "#{config.url}/#{config.base_path}", original_body: e.original_body, original_status: e.original_status }, { external_service: self.class.to_s.underscore, team: 'check-in' }) raise e end |