Class: ClaimFastTracking::MaxCfiMetrics

Inherits:
Object
  • Object
show all
Includes:
SentryLogging
Defined in:
app/services/claim_fast_tracking/max_cfi_metrics.rb

Constant Summary collapse

MAX_CFI_STATSD_KEY_PREFIX =
'api.max_cfi'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

Constructor Details

#initialize(form, params) ⇒ MaxCfiMetrics

Returns a new instance of MaxCfiMetrics.



18
19
20
21
22
23
24
# File 'app/services/claim_fast_tracking/max_cfi_metrics.rb', line 18

def initialize(form, params)
  params[:metadata] ||= {}
  @form = form
  @form_data = params[:form_data] || params[:formData]
  @form_data = JSON.parse(form_data) if form_data.is_a?(String)
  @metadata = params[:metadata]
end

Instance Attribute Details

#formObject (readonly)

Returns the value of attribute form.



7
8
9
# File 'app/services/claim_fast_tracking/max_cfi_metrics.rb', line 7

def form
  @form
end

#form_dataObject (readonly)

Returns the value of attribute form_data.



7
8
9
# File 'app/services/claim_fast_tracking/max_cfi_metrics.rb', line 7

def form_data
  @form_data
end

#metadataObject (readonly)

Returns the value of attribute metadata.



7
8
9
# File 'app/services/claim_fast_tracking/max_cfi_metrics.rb', line 7

def 
  @metadata
end

Class Method Details

.log_form_update(form, params) ⇒ Object

Triggers any relevant StatsD metrics calls whenever a 526EZ InProgressForm is updated with a new params hash. The params hash will be mutated to include any metadata needed by this CFI metrics logic.



14
15
16
# File 'app/services/claim_fast_tracking/max_cfi_metrics.rb', line 14

def self.log_form_update(form, params)
  new(form, params).log_form_update if form.form_id == '21-526EZ'
end

Instance Method Details

#claiming_increase?Boolean

Returns:

  • (Boolean)


57
58
59
60
# File 'app/services/claim_fast_tracking/max_cfi_metrics.rb', line 57

def claiming_increase?
  form_data&.dig('view:claim_type', 'view:claiming_increase') ||
    form_data&.dig('view:claimType', 'view:claimingIncrease')
end

#create_or_load_metadataObject

Max CFI metrics progress is stored in InProgressForm#metadata, to prevent double-counting events over the IPF’s lifecycle. This method will create-or-load the progress metadata from the IPF, and updates an older scheme where the progress was just a boolean.



29
30
31
32
33
34
35
36
37
38
# File 'app/services/claim_fast_tracking/max_cfi_metrics.rb', line 29

def 
   = form.['cfiMetric']
  if .blank?
    { 'initLogged' => false, 'cfiLogged' => false }
  elsif  == true
    { 'initLogged' => true, 'cfiLogged' => true }
  else
    
  end
end

#log_cfi_metricObject (private)



88
89
90
91
92
93
94
# File 'app/services/claim_fast_tracking/max_cfi_metrics.rb', line 88

def log_cfi_metric
  StatsD.increment("#{MAX_CFI_STATSD_KEY_PREFIX}.on_rated_disabilities",
                   tags: ["has_max_rated:#{max_rated_disabilities.any?}"])
  max_rated_disabilities_diagnostic_codes.each do |dc|
    StatsD.increment("#{MAX_CFI_STATSD_KEY_PREFIX}.rated_disabilities", tags: ["diagnostic_code:#{dc}"])
  end
end

#log_form_updateObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/services/claim_fast_tracking/max_cfi_metrics.rb', line 40

def log_form_update
   = 
  unless ['initLogged']
    log_init_metric
    ['initLogged'] = true
  end
  if claiming_increase? && !['cfiLogged']
    log_cfi_metric
    ['cfiLogged'] = true
  end
  ['cfiMetric'] = 
rescue => e
  # Log the exception but but do not fail, otherwise in-progress form will not update
  Rails.logger.error("In-progress form failed to log Max CFI metrics: #{e.message}")
  log_exception_to_sentry(e)
end

#log_init_metricObject (private)



80
81
82
83
84
85
86
# File 'app/services/claim_fast_tracking/max_cfi_metrics.rb', line 80

def log_init_metric
  StatsD.increment("#{MAX_CFI_STATSD_KEY_PREFIX}.on_526_started",
                   tags: ["has_max_rated:#{max_rated_disabilities.any?}"])
  max_rated_disabilities_diagnostic_codes.each do |dc|
    StatsD.increment("#{MAX_CFI_STATSD_KEY_PREFIX}.526_started", tags: ["diagnostic_code:#{dc}"])
  end
end

#max_rated_disabilitiesObject



66
67
68
69
70
71
72
# File 'app/services/claim_fast_tracking/max_cfi_metrics.rb', line 66

def max_rated_disabilities
  rated_disabilities.filter do |dis|
    maximum_rating_percentage = dis['maximum_rating_percentage'] || dis['maximumRatingPercentage']
    rating_percentage = dis['rating_percentage'] || dis['ratingPercentage']
    maximum_rating_percentage.present? && maximum_rating_percentage == rating_percentage
  end
end

#max_rated_disabilities_diagnostic_codesObject



74
75
76
# File 'app/services/claim_fast_tracking/max_cfi_metrics.rb', line 74

def max_rated_disabilities_diagnostic_codes
  max_rated_disabilities.map { |dis| dis['diagnosticCode'] || dis['diagnostic_code'] }
end

#rated_disabilitiesObject



62
63
64
# File 'app/services/claim_fast_tracking/max_cfi_metrics.rb', line 62

def rated_disabilities
  form_data&.dig('rated_disabilities') || form_data&.dig('ratedDisabilities') || []
end