Class: ClaimFastTracking::MaxRatingAnnotator

Inherits:
Object
  • Object
show all
Defined in:
app/services/claim_fast_tracking/max_rating_annotator.rb

Constant Summary collapse

EXCLUDED_DIGESTIVE_CODES =
[7318, 7319, 7327, 7336, 7346].freeze

Class Method Summary collapse

Class Method Details

.annotate_disabilities(rated_disabilities_response) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/claim_fast_tracking/max_rating_annotator.rb', line 9

def self.annotate_disabilities(rated_disabilities_response)
  return if rated_disabilities_response.rated_disabilities.blank?

  log_hyphenated_diagnostic_codes(rated_disabilities_response.rated_disabilities)

  diagnostic_codes = rated_disabilities_response.rated_disabilities
                                                .compact # filter out nil entries in rated_disabilities
                                                .select { |rd| eligible_for_request?(rd) } # select only eligible
                                                .map(&:diagnostic_code) # map to diagnostic_code field in rating
  return rated_disabilities_response if diagnostic_codes.empty?

  ratings = get_ratings(diagnostic_codes)
  return rated_disabilities_response unless ratings

  ratings_hash = ratings.to_h { |rating| [rating['diagnostic_code'], rating['max_rating']] }
  rated_disabilities_response.rated_disabilities.each do |rated_disability|
    max_rating = ratings_hash[rated_disability.diagnostic_code]
    rated_disability.maximum_rating_percentage = max_rating if max_rating
  end
  rated_disabilities_response
end

.diagnostic_code_type(rated_disability) ⇒ Object



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

def self.diagnostic_code_type(rated_disability)
  case rated_disability&.diagnostic_code
  when nil
    :missing_diagnostic_code
  when 7200..7399
    :digestive_system
  when 6300..6399
    :infectious_disease
  else
    if (rated_disability&.hyphenated_diagnostic_code || 0) % 100 == 99
      :analogous_code
    else
      :primary_max_rating
    end
  end
end

.eligible_for_request?(rated_disability) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
69
# File 'app/services/claim_fast_tracking/max_rating_annotator.rb', line 66

def self.eligible_for_request?(rated_disability)
  %i[infectious_disease missing_diagnostic_code].exclude?(diagnostic_code_type(rated_disability)) &&
    EXCLUDED_DIGESTIVE_CODES.exclude?(rated_disability.diagnostic_code)
end

.get_ratings(diagnostic_codes) ⇒ Object (private)



57
58
59
60
61
62
63
64
# File 'app/services/claim_fast_tracking/max_rating_annotator.rb', line 57

def self.get_ratings(diagnostic_codes)
  vro_client = VirtualRegionalOffice::Client.new
  response = vro_client.get_max_rating_for_diagnostic_codes(diagnostic_codes)
  response.body['ratings']
rescue Common::Client::Errors::ClientError => e
  Rails.logger.error "Get Max Ratings Failed  #{e.message}.", backtrace: e.backtrace
  nil
end

.log_hyphenated_diagnostic_codes(rated_disabilities) ⇒ Object



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

def self.log_hyphenated_diagnostic_codes(rated_disabilities)
  rated_disabilities.each do |dis|
    Rails.logger.info('Max CFI rated disability',
                      diagnostic_code: dis&.diagnostic_code,
                      diagnostic_code_type: diagnostic_code_type(dis),
                      hyphenated_diagnostic_code: dis&.hyphenated_diagnostic_code)
  end
end