Module: Services::SltcRegistrationCompleter

Defined in:
app/roles/services/sltc_registration_completer.rb

Instance Method Summary collapse

Instance Method Details

#complete(params) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/roles/services/sltc_registration_completer.rb', line 5

def complete(params)
  configure_only = params[:configure_only].present? && params[:configure_only] == 'true'

  am = (params[:third_party_id], params[:account_id])

  ca = (params[:service_definition_id], params[:account_id], configure_only)

  # The requestor only wants the account configured for operations. Does NOT
  # want to process the registration any further at this time. The 'complete' method
  # is re-entrant in that it will continue even if the account stuff has already been
  # configured.
  return if configure_only

  si = ca.service_definition.service_implementation

  # Take care of configuring all the facilities for the new account
  si.identify_providers(ca)

  # Now, request baselines for all the configured facilities
  uploaded_before = Time.now
  uploaded_after = uploaded_before - (params[:baseline_days].present? ? params[:baseline_days].to_i : 90).days

  abaqis_facility_ids = ApplicationApi.api_impl.(params[:account_id]).pluck(:id)

  ca.service_definition.third_party.facility_mappings.where(facility_id: abaqis_facility_ids).each do | facility_mapping |
    si.request_baseline(ca, facility_mapping.facility_code, uploaded_after, uploaded_before)
  end

  update_attributes(status: Services::SltcRegistration::STATUS_REGISTERED)

end