Class: VirtualRegionalOffice::Client

Inherits:
Common::Client::Base show all
Includes:
Common::Client::Concerns::Monitoring
Defined in:
lib/virtual_regional_office/client.rb

Constant Summary collapse

STATSD_KEY_PREFIX =
'api.vro'

Instance Method Summary collapse

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

#increment, #increment_failure, #increment_total, #with_monitoring

Methods inherited from Common::Client::Base

#config, configuration, #connection, #delete, #get, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name

Methods included from SentryLogging

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

Instance Method Details

#classify_vagov_contentions(params) ⇒ Object



12
13
14
15
16
# File 'lib/virtual_regional_office/client.rb', line 12

def classify_vagov_contentions(params)
  with_monitoring do
    perform(:post, Settings.virtual_regional_office.vagov_classification_path, params.to_json.to_s, headers_hash)
  end
end

#classify_vagov_contentions_expanded(params) ⇒ Object



18
19
20
21
22
# File 'lib/virtual_regional_office/client.rb', line 18

def classify_vagov_contentions_expanded(params)
  with_monitoring do
    perform(:post, Settings.virtual_regional_office.expanded_classification_path, params.to_json.to_s, headers_hash)
  end
end

#download_summary(claim_submission_id:) ⇒ Object



49
50
51
52
# File 'lib/virtual_regional_office/client.rb', line 49

def download_summary(claim_submission_id:)
  path = "#{Settings.virtual_regional_office.evidence_pdf_path}/#{claim_submission_id}"
  perform(:get, path, {}, headers_hash.merge(Accept: 'application/pdf'))
end

#generate_summary(claim_submission_id:, diagnostic_code:, veteran_info:, evidence:) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/virtual_regional_office/client.rb', line 38

def generate_summary(claim_submission_id:, diagnostic_code:, veteran_info:, evidence:)
  params = {
    claimSubmissionId: claim_submission_id,
    diagnosticCode: diagnostic_code,
    veteranInfo: veteran_info,
    evidence:
  }

  perform(:post, Settings.virtual_regional_office.evidence_pdf_path, params.to_json.to_s, headers_hash)
end

#get_max_rating_for_diagnostic_codes(diagnostic_codes_array) ⇒ Object



24
25
26
27
28
29
# File 'lib/virtual_regional_office/client.rb', line 24

def get_max_rating_for_diagnostic_codes(diagnostic_codes_array)
  with_monitoring do
    params = { diagnostic_codes: diagnostic_codes_array }
    perform(:post, Settings.virtual_regional_office.max_cfi_path, params.to_json.to_s, headers_hash)
  end
end

#headers_hashObject (private)



65
66
67
68
69
# File 'lib/virtual_regional_office/client.rb', line 65

def headers_hash
  {
    'X-API-Key': Settings.virtual_regional_office.api_key
  }
end

#merge_end_products(pending_claim_id:, ep400_id:) ⇒ Object



31
32
33
34
35
36
# File 'lib/virtual_regional_office/client.rb', line 31

def merge_end_products(pending_claim_id:, ep400_id:)
  with_monitoring do
    params = { pending_claim_id: pending_claim_id.to_i, ep400_claim_id: ep400_id.to_i }
    perform(:post, Settings.virtual_regional_office.ep_merge_path, params.to_json.to_s, headers_hash)
  end
end

#perform(method, path, params, headers = nil, options = nil) ⇒ Object

Tiny middleware to replace the configuration option ‘faraday.response :json` with behavior that only decodes JSON for application/json responses. This allows us to handle non-JSON responses (e.g. application/pdf) without loss of convenience.



57
58
59
60
61
# File 'lib/virtual_regional_office/client.rb', line 57

def perform(method, path, params, headers = nil, options = nil)
  result = super
  result.body = JSON.parse(result.body) if result.response_headers['content-type'] == 'application/json'
  result
end