Class: TermsOfUse::Provisioner

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/services/terms_of_use/provisioner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(icn:) ⇒ Provisioner

Returns a new instance of Provisioner.



13
14
15
16
17
18
19
20
# File 'app/services/terms_of_use/provisioner.rb', line 13

def initialize(icn:)
  @icn = icn

  validate!
rescue ActiveModel::ValidationError => e
  log_provisioner_error(e)
  raise Errors::ProvisionerError, e.message
end

Instance Attribute Details

#icnObject (readonly)

Returns the value of attribute icn.



9
10
11
# File 'app/services/terms_of_use/provisioner.rb', line 9

def icn
  @icn
end

Instance Method Details

#first_nameObject (private)



53
54
55
# File 'app/services/terms_of_use/provisioner.rb', line 53

def first_name
  mpi_profile.given_names.first
end

#last_nameObject (private)



57
58
59
# File 'app/services/terms_of_use/provisioner.rb', line 57

def last_name
  mpi_profile.family_name
end

#log_provisioner_error(error) ⇒ Object (private)



44
45
46
# File 'app/services/terms_of_use/provisioner.rb', line 44

def log_provisioner_error(error)
  Rails.logger.error("[TermsOfUse] [Provisioner] Error: #{error.message}", { icn: })
end

#mpi_gcidsObject (private)



61
62
63
# File 'app/services/terms_of_use/provisioner.rb', line 61

def mpi_gcids
  mpi_profile.full_mvi_ids.join('|')
end

#mpi_profileObject (private)



48
49
50
51
# File 'app/services/terms_of_use/provisioner.rb', line 48

def mpi_profile
  @mpi_profile ||= MPI::Service.new.find_profile_by_identifier(identifier: icn,
                                                               identifier_type: MPI::Constants::ICN)&.profile
end

#performObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/services/terms_of_use/provisioner.rb', line 22

def perform
  response = update_provisioning

  if response[:agreement_signed].blank?
    Rails.logger.error('[TermsOfUse] [Provisioner] update_provisioning error', { icn:, response: })
    raise(Errors::ProvisionerError, 'Agreement not accepted')
  end
  if response[:cerner_provisioned].blank?
    Rails.logger.error('[TermsOfUse] [Provisioner] update_provisioning error', { icn:, response: })
    raise(Errors::ProvisionerError, 'Account not Provisioned')
  end
rescue Common::Client::Errors::ClientError => e
  log_provisioner_error(e)
  raise Errors::ProvisionerError, e.message
end

#update_provisioningObject (private)



40
41
42
# File 'app/services/terms_of_use/provisioner.rb', line 40

def update_provisioning
  MAP::SignUp::Service.new.update_provisioning(icn:, first_name:, last_name:, mpi_gcids:)
end