Skip to content

Commit

Permalink
Add StatsD counters for copay notifications (#12909)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott James authored Jun 8, 2023
1 parent c9d3c63 commit a520766
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
9 changes: 8 additions & 1 deletion app/policies/medical_copays_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ def access?
end

def access_notifications?
Flipper.enabled?('medical_copay_notifications')
accessible = Flipper.enabled?('medical_copay_notifications')
if accessible
StatsD.increment('api.mcp.notification_policy.success')
else
StatsD.increment('api.mcp.notification_policy.failure')
end

accessible
end

def increment_statsd(accessible)
Expand Down
2 changes: 2 additions & 0 deletions app/workers/copay_notifications/mcp_notification_email_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ def perform(vet360_id, template_id, backup_email = nil, personalisation = nil)
email_address = person_resp.person&.emails&.first&.email_address || backup_email

if email_address
StatsD.increment('api.copay_notifications.new_statement.vet_360.success')
send_email(email_address, template_id, personalisation)
else
StatsD.increment('api.copay_notifications.new_statement.vet_360.failure')
log_exception_to_sentry(CopayNotifications::ProfileMissingEmail.new(vet360_id), {},
{ error: :mcp_notification_email_job })
end
Expand Down
47 changes: 32 additions & 15 deletions app/workers/copay_notifications/new_statement_notification_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,45 @@ class NewStatementNotificationJob
sidekiq_options retry: false

MCP_NOTIFICATION_TEMPLATE = Settings.vanotify.services.dmc.template_id.vha_new_copay_statement_email
STATSD_KEY_PREFIX = 'api.copay_notifications.new_statement'

def perform(statement)
mpi_response = if statement['identifierType'] == 'edipi'
MPI::Service.new.find_profile_by_edipi(edipi: statement['veteranIdentifier'])
else
MPI::Service.new.find_profile_by_facility(
facility_id: statement['facilityNum'],
vista_id: statement['veteranIdentifier']
)
end
StatsD.increment("#{STATSD_KEY_PREFIX}.total")
mpi_response = get_mpi_profile(identifier: statement['veteranIdentifier'],
identifier_type: statement['identifierType'],
facility_id: statement['facilityNum'])

if mpi_response.ok?
if mpi_response.profile.vet360_id
CopayNotifications::McpNotificationEmailJob.perform_async(mpi_response.profile.vet360_id,
MCP_NOTIFICATION_TEMPLATE)
else
log_exception_to_sentry(CopayNotifications::Vet360IdNotFound.new(mpi_response.profile.icn), {},
{ error: :new_statement_notification_job_error })
end
StatsD.increment("#{STATSD_KEY_PREFIX}.mpi.success")
create_notification_email_job(vet360_id: mpi_response.profile.vet360_id, icn: mpi_response.profile.icn)
else
StatsD.increment("#{STATSD_KEY_PREFIX}.mpi.failure")
raise mpi_response.error
end
end

def create_notification_email_job(vet360_id:, icn:)
if vet360_id
CopayNotifications::McpNotificationEmailJob.perform_async(vet360_id,
MCP_NOTIFICATION_TEMPLATE)
else
StatsD.increment("#{STATSD_KEY_PREFIX}.mpi.vet360_not_found")
log_exception_to_sentry(CopayNotifications::Vet360IdNotFound.new(icn), {},
{ error: :new_statement_notification_job_error })
end
end

def get_mpi_profile(identifier:, identifier_type:, facility_id:)
if identifier_type == 'edipi'
StatsD.increment("#{STATSD_KEY_PREFIX}.edipi")
MPI::Service.new.find_profile_by_edipi(edipi: identifier)
else
StatsD.increment("#{STATSD_KEY_PREFIX}.vista")
MPI::Service.new.find_profile_by_facility(
facility_id:,
vista_id: identifier
)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def self.throttle
LIMITER = throttle

def perform(statements_json_byte)
StatsD.increment('api.copay_notifications.json_file.total')
# Decode and parse large json file (~60-90k objects)
statements_json = Oj.load(Base64.decode64(statements_json_byte))
unique_statements = statements_json.uniq { |statement| statement['veteranIdentifier'] }
Expand Down

0 comments on commit a520766

Please sign in to comment.