Class: BB::Client

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

#session

Instance Method Summary collapse

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

#streaming_get

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.

Parameters:

  • doctype (String)

    one of: “txt” or “pdf”

  • header_callback (Proc)

    should be a callable that will accept an enumerator of response headers as key/value pairs

  • yielder (Enumerable::Yielder)

    a target to which a stream of response body chunks can be yielded (see for example Enumerator.new)



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_classesCommon::Collection

Build the checkboxes for the form used to make a generate report request

Returns:



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_statusCommon::Collection

Note:

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

Returns:



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_statusHash

Get current status of user’s VHIE sharing.

Returns:

  • (Hash)

    an object containing the body of the response



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

Note:

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

Parameters:

  • params (Hash)

    an object containing a date range and array of data classes

Returns:

  • (Hash)

    an object containing the body of the response

Raises:



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_inObject

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.message.include? 'already.opted.in'
end

#post_opt_outObject

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.message.include? 'Opt-out consent policy is already set'
end