Class: MAP::SignUp::Service
Instance Method Summary
collapse
-
#agreements_accept(icn:, signature_name:, version:) ⇒ Object
-
#agreements_body(icn, signature_name, version) ⇒ Object
private
-
#agreements_decline(icn:) ⇒ Object
-
#authenticated_header(icn) ⇒ Object
private
-
#build_response(response_body) ⇒ Object
private
-
#logger ⇒ Object
private
-
#logging_prefix ⇒ Object
private
-
#parse_and_raise_error(e, icn, action) ⇒ Object
private
-
#status(icn:) ⇒ Object
-
#successful_update_provisioning_response(response, icn) ⇒ Object
private
-
#update_provisioning(icn:, first_name:, last_name:, mpi_gcids:) ⇒ Object
-
#update_provisioning_params(first_name, last_name, mpi_gcids) ⇒ Object
private
#config, configuration, #connection, #delete, #get, #perform, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Instance Method Details
#agreements_accept(icn:, signature_name:, version:) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/map/sign_up/service.rb', line 23
def agreements_accept(icn:, signature_name:, version:)
perform(:post,
config.patients_agreements_path(icn),
agreements_body(icn, signature_name, version),
(icn))
logger.info("#{logging_prefix} agreements accept success, icn: #{icn}")
rescue Common::Client::Errors::ParsingError => e
message = "#{logging_prefix} agreements accept response parsing error"
logger.error(message, { icn: })
raise e, "#{message}, response unknown, icn: #{icn}"
rescue Common::Client::Errors::ClientError => e
parse_and_raise_error(e, icn, 'agreements accept')
end
|
#agreements_body(icn, signature_name, version) ⇒ Object
73
74
75
76
77
78
79
80
81
|
# File 'lib/map/sign_up/service.rb', line 73
def agreements_body(icn, signature_name, version)
{
responseDate: Time.zone.now,
icn:,
signatureName: signature_name,
version: config.agreements_version_mapping[version],
legalDisplayVersion: config.legal_display_version
}.to_json
end
|
#agreements_decline(icn:) ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/map/sign_up/service.rb', line 37
def agreements_decline(icn:)
perform(:delete, config.patients_agreements_path(icn), nil, (icn))
logger.info("#{logging_prefix} agreements decline success, icn: #{icn}")
rescue Common::Client::Errors::ParsingError => e
message = "#{logging_prefix} agreements decline response parsing error"
logger.error(message, { icn: })
raise e, "#{message}, response unknown, icn: #{icn}"
rescue Common::Client::Errors::ClientError => e
parse_and_raise_error(e, icn, 'agreements decline')
end
|
68
69
70
71
|
# File 'lib/map/sign_up/service.rb', line 68
def (icn)
access_token = SecurityToken::Service.new.token(application: :sign_up_service, icn:)
config.(access_token[:access_token])
end
|
#build_response(response_body) ⇒ Object
115
116
117
118
119
120
121
122
|
# File 'lib/map/sign_up/service.rb', line 115
def build_response(response_body)
{
agreement_signed: response_body['agreementSigned'],
opt_out: response_body['optOut'],
cerner_provisioned: response_body['cernerProvisioned'],
bypass_eligible: response_body['bypassEligible']
}
end
|
#logger ⇒ Object
124
125
126
|
# File 'lib/map/sign_up/service.rb', line 124
def logger
Rails.logger
end
|
#logging_prefix ⇒ Object
128
129
130
|
# File 'lib/map/sign_up/service.rb', line 128
def logging_prefix
config.logging_prefix
end
|
#parse_and_raise_error(e, icn, action) ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/map/sign_up/service.rb', line 101
def parse_and_raise_error(e, icn, action)
status = e.status
parsed_body = e.body.presence || {}
context = {
id: parsed_body['id'],
code: parsed_body['code'],
error_code: parsed_body['errorCode'],
message: parsed_body['message'],
trace_id: parsed_body['traceId']
}.compact
raise e, "#{logging_prefix} #{action} failed, client error, status: #{status}," \
" icn: #{icn}, context: #{context}"
end
|
#status(icn:) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/map/sign_up/service.rb', line 11
def status(icn:)
response = perform(:get, config.status_unauthenticated_path(icn), nil)
logger.info("#{logging_prefix} status success, icn: #{icn}")
build_response(response.body)
rescue Common::Client::Errors::ParsingError => e
message = "#{logging_prefix} status response parsing error"
logger.error(message, { icn: })
raise e, "#{message}, response unknown, icn: #{icn}"
rescue Common::Client::Errors::ClientError => e
parse_and_raise_error(e, icn, 'status')
end
|
#successful_update_provisioning_response(response, icn) ⇒ Object
92
93
94
95
96
97
98
99
|
# File 'lib/map/sign_up/service.rb', line 92
def successful_update_provisioning_response(response, icn)
parsed_response = build_response(response.body)
logger.info("#{logging_prefix} update provisioning success," \
" icn: #{icn}, parsed_response: #{parsed_response}")
parsed_response
end
|
#update_provisioning(icn:, first_name:, last_name:, mpi_gcids:) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/map/sign_up/service.rb', line 48
def update_provisioning(icn:, first_name:, last_name:, mpi_gcids:)
response = perform(:put,
config.patients_provisioning_path(icn),
update_provisioning_params(first_name, last_name, mpi_gcids).to_json,
config.)
successful_update_provisioning_response(response, icn)
rescue Common::Client::Errors::ParsingError => e
message = "#{logging_prefix} update provisioning response parsing error"
logger.error(message, { icn: })
raise e, "#{message}, response unknown, icn: #{icn}"
rescue Common::Client::Errors::ClientError => e
if config.provisioning_acceptable_status.include?(e.status)
successful_update_provisioning_response(e, icn)
else
parse_and_raise_error(e, icn, 'update provisioning')
end
end
|
#update_provisioning_params(first_name, last_name, mpi_gcids) ⇒ Object
83
84
85
86
87
88
89
90
|
# File 'lib/map/sign_up/service.rb', line 83
def update_provisioning_params(first_name, last_name, mpi_gcids)
{
provisionUser: true,
gcids: mpi_gcids,
firstName: first_name,
lastName: last_name
}
end
|