Class: HCA::Service

Inherits:
Common::Client::Base show all
Includes:
Common::Client::Concerns::Monitoring, VA1010Forms::Utils
Defined in:
lib/hca/service.rb

Constant Summary collapse

STATSD_KEY_PREFIX =
'api.1010ez'

Instance Method Summary collapse

Methods included from VA1010Forms::Utils

#override_parsed_form, #soap

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

#with_monitoring

Methods inherited from Common::Client::Base

configuration, #raise_backend_exception

Methods included from SentryLogging

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

Constructor Details

#initialize(user_identifier = nil) ⇒ Service

Returns a new instance of Service.

Parameters:

  • user_identifier (Hash) (defaults to: nil)


18
19
20
# File 'lib/hca/service.rb', line 18

def initialize(user_identifier = nil)
  @user_identifier = user_identifier
end

Instance Method Details

#health_checkObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/hca/service.rb', line 47

def health_check
  submission = soap.build_request(:get_form_submission_status, message:
    { formSubmissionId: HCA::Configuration::HEALTH_CHECK_ID })
  response = with_monitoring do
    perform(:post, '', submission.body)
  end
  root = response.body.locate('S:Envelope/S:Body/retrieveFormSubmissionStatusResponse').first
  {
    formSubmissionId: root.locate('formSubmissionId').first.text.to_i,
    timestamp: root.locate('timeStamp').first&.text || Time.now.getlocal.to_s
  }
end

#submit_form(form) ⇒ Object

Parameters:

  • form (HashWithIndifferentAccess)

    JSON form data



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/hca/service.rb', line 23

def submit_form(form)
  formatted = HCA::EnrollmentSystem.veteran_to_save_submit_form(form, @user_identifier, '10-10EZ')
  content = Gyoku.xml(formatted)
  submission = soap.build_request(:save_submit_form, message: content)

  is_short_form = HealthCareApplication.new(form: form.to_json).short_form?

  response = with_monitoring do
    perform(:post, '', submission.body)
  rescue => e
    increment_failure('submit_form_short_form', e) if is_short_form
    raise e
  ensure
    increment_total('submit_form_short_form') if is_short_form
  end

  root = response.body.locate('S:Envelope/S:Body/submitFormResponse').first
  {
    success: true,
    formSubmissionId: root.locate('formSubmissionId').first.text.to_i,
    timestamp: root.locate('timeStamp').first&.text || Time.now.getlocal.to_s
  }
end