Class: BB::Client
- Inherits:
-
Common::Client::Base
- Object
- Common::Client::Base
- BB::Client
- Includes:
- Common::Client::Concerns::MHVSessionBasedClient, Common::Client::Concerns::StreamingClient, SentryLogging
- Defined in:
- lib/bb/client.rb
Overview
Core class responsible for BB API interface operations
Constant Summary collapse
- CACHE_TTL =
cache for 3 hours
3600 * 3
Constants included from Common::Client::Concerns::MhvLockedSessionClient
Common::Client::Concerns::MhvLockedSessionClient::LOCK_RETRY_DELAY, Common::Client::Concerns::MhvLockedSessionClient::RETRY_ATTEMPTS
Instance Attribute Summary
Attributes included from Common::Client::Concerns::MHVSessionBasedClient
Attributes included from Common::Client::Concerns::MhvLockedSessionClient
Instance Method Summary collapse
- #cache_key(action) ⇒ Object private
-
#get_download_report(doctype, header_callback, yielder) ⇒ Object
Get a health record report.
-
#get_eligible_data_classes ⇒ Common::Collection
Build the checkboxes for the form used to make a generate report request.
-
#get_extract_status ⇒ Common::Collection
PHR (Personal Health Record) refresh.
-
#get_status ⇒ Hash
Get current status of user’s VHIE sharing.
- #log_refresh_errors(attrs) ⇒ Object private
-
#post_generate(params) ⇒ Hash
Trigger a BB report generation.
-
#post_opt_in ⇒ Object
Opt user in to VHIE sharing.
-
#post_opt_out ⇒ Object
Opt user out of VHIE sharing.
- #refresh_final?(attrs) ⇒ Boolean private
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Methods included from Common::Client::Concerns::StreamingClient
Methods included from Common::Client::Concerns::MHVSessionBasedClient
#auth_headers, #get_session, #get_session_tagged, #invalid?, #session_config_key, #token_headers, #user_key
Methods included from Common::Client::Concerns::MhvLockedSessionClient
#authenticate, #initialize, #invalid?, #lock_and_get_session, #obtain_redis_lock, #refresh_session, #release_redis_lock
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
Instance Method Details
#cache_key(action) ⇒ Object (private)
113 114 115 116 117 118 |
# File 'lib/bb/client.rb', line 113 def cache_key(action) return nil unless config.caching_enabled? return nil if session.user_id.blank? "#{session.user_id}:#{action}" end |
#get_download_report(doctype, header_callback, yielder) ⇒ Object
Get a health record report. Because of potentially large payload size the content must be streamed.
74 75 76 77 78 79 80 |
# File 'lib/bb/client.rb', line 74 def get_download_report(doctype, header_callback, yielder) # TODO: For testing purposes, use one of the following static URIs: # uri = URI("#{Settings.mhv.rx.host}/vetsgov/1mb.file") # uri = URI("#{Settings.mhv.rx.host}/vetsgov/90mb.file") uri = URI.join(config.base_path, "bluebutton/bbreport/#{doctype}") streaming_get(uri, token_headers, header_callback, yielder) end |
#get_eligible_data_classes ⇒ Common::Collection
Build the checkboxes for the form used to make a generate report request
42 43 44 45 46 |
# File 'lib/bb/client.rb', line 42 def get_eligible_data_classes Common::Collection.fetch(::EligibleDataClass, cache_key: cache_key('geteligibledataclass'), ttl: CACHE_TTL) do perform(:get, 'bluebutton/geteligibledataclass', nil, token_headers).body end end |
#get_extract_status ⇒ Common::Collection
this should be called once per user, will take up to 15 minutes to process, but its the only way to refresh a user’s data
PHR (Personal Health Record) refresh
31 32 33 34 35 |
# File 'lib/bb/client.rb', line 31 def get_extract_status json = perform(:get, 'bluebutton/extractstatus', nil, token_headers).body log_refresh_errors(json[:data]) if refresh_final?(json[:data]) Common::Collection.new(ExtractStatus, **json) end |
#get_status ⇒ Hash
Get current status of user’s VHIE sharing.
107 108 109 |
# File 'lib/bb/client.rb', line 107 def get_status perform(:get, 'bluebutton/external/optinout/status', nil, token_headers).body end |
#log_refresh_errors(attrs) ⇒ Object (private)
124 125 126 127 128 129 130 |
# File 'lib/bb/client.rb', line 124 def log_refresh_errors(attrs) failed = attrs.select { |e| e[:status] == 'ERROR' }.pluck(:extract_type) if failed.present? ('Final health record refresh contained one or more error statuses', :warn, refresh_failures: failed.sort) end end |
#post_generate(params) ⇒ Hash
These PDFs take time to generate, hence why this separate call just to generate. It should be quick enough that download report can be called more or less right after
Trigger a BB report generation
57 58 59 60 61 62 |
# File 'lib/bb/client.rb', line 57 def post_generate(params) form = BB::GenerateReportRequestForm.new(self, params) raise Common::Exceptions::ValidationErrors, form unless form.valid? perform(:post, 'bluebutton/generate', form.params, token_headers).body end |
#post_opt_in ⇒ Object
Opt user in to VHIE sharing.
85 86 87 88 89 90 |
# File 'lib/bb/client.rb', line 85 def post_opt_in perform(:post, 'bluebutton/external/optinout/optin', nil, token_headers).body rescue ServiceException => e # Ignore the error that the user is already opted in to VHIE sharing. raise unless e..include? 'already.opted.in' end |
#post_opt_out ⇒ Object
Opt user out of VHIE sharing.
95 96 97 98 99 100 |
# File 'lib/bb/client.rb', line 95 def post_opt_out perform(:post, 'bluebutton/external/optinout/optout', nil, token_headers).body rescue ServiceException => e # Ignore the error that the user is already opted out of VHIE sharing. raise unless e..include? 'Opt-out consent policy is already set' end |
#refresh_final?(attrs) ⇒ Boolean (private)
120 121 122 |
# File 'lib/bb/client.rb', line 120 def refresh_final?(attrs) attrs.all? { |e| e[:status].present? } end |