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
Instance Attribute Summary
Attributes included from Common::Client::Concerns::MHVSessionBasedClient
Instance Method Summary collapse
-
#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.
-
#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.
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger
Methods included from Common::Client::Concerns::StreamingClient
Methods included from Common::Client::Concerns::MHVSessionBasedClient
#authenticate, #get_session, #initialize
Methods inherited from Common::Client::Base
configuration, #raise_backend_exception
Instance Method Details
#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 |
#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 |