diff --git a/app/policies/medical_copays_policy.rb b/app/policies/medical_copays_policy.rb index ac90bcf2750..cf063678d16 100644 --- a/app/policies/medical_copays_policy.rb +++ b/app/policies/medical_copays_policy.rb @@ -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) diff --git a/app/workers/copay_notifications/mcp_notification_email_job.rb b/app/workers/copay_notifications/mcp_notification_email_job.rb index 532b0a9cb4b..56a2060eb05 100644 --- a/app/workers/copay_notifications/mcp_notification_email_job.rb +++ b/app/workers/copay_notifications/mcp_notification_email_job.rb @@ -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 diff --git a/app/workers/copay_notifications/new_statement_notification_job.rb b/app/workers/copay_notifications/new_statement_notification_job.rb index fefd874c28b..02c3dceee58 100644 --- a/app/workers/copay_notifications/new_statement_notification_job.rb +++ b/app/workers/copay_notifications/new_statement_notification_job.rb @@ -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 diff --git a/app/workers/copay_notifications/parse_new_statements_job.rb b/app/workers/copay_notifications/parse_new_statements_job.rb index b97e1f60c10..5d59dcfbc8e 100644 --- a/app/workers/copay_notifications/parse_new_statements_job.rb +++ b/app/workers/copay_notifications/parse_new_statements_job.rb @@ -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'] }