Class: MedicalCopays::ZeroBalanceStatements

Inherits:
Object
  • Object
show all
Defined in:
app/services/medical_copays/zero_balance_statements.rb

Overview

Object for building a list of the user’s zero balance statements

Returns:

  • (Array<Hash>)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ ZeroBalanceStatements

Returns a new instance of ZeroBalanceStatements.



27
28
29
30
31
# File 'app/services/medical_copays/zero_balance_statements.rb', line 27

def initialize(opts)
  @facility_hash = opts[:facility_hash]
  @statements = opts[:statements]
  @facilities = get_facilities || []
end

Instance Attribute Details

#facilitiesObject

Returns the value of attribute facilities.



15
16
17
# File 'app/services/medical_copays/zero_balance_statements.rb', line 15

def facilities
  @facilities
end

#facility_hashArray<Hash>

Object for building a list of the user’s zero balance statements

Returns:

  • (Array<Hash>)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/services/medical_copays/zero_balance_statements.rb', line 13

class ZeroBalanceStatements
  attr_reader :facility_hash, :statements
  attr_accessor :facilities

  ##
  # Builds a ZeroBalanceStatements instance
  #
  # @param opts [Hash]
  # @return [ZeroBalanceStatements] an instance of this class
  #
  def self.build(opts = {})
    new(opts)
  end

  def initialize(opts)
    @facility_hash = opts[:facility_hash]
    @statements = opts[:statements]
    @facilities = get_facilities || []
  end

  ##
  # Format collection of facilities to match VBS response
  #
  # @return [Array<Hash>]
  #
  def list
    facilities.map do |facility|
      {
        'pH_AMT_DUE' => 0,
        'pS_STATEMENT_DATE' => Time.zone.today.strftime('%m%d%Y'),
        'station' => {
          'facilitY_NUM' => facility['id'].sub('vha_', ''),
          'city' => facility['address']['physical']['city'].upcase
        }
      }
    end
  end

  private

  ##
  # The list of vista keys associated with the user's profile
  #
  # @return [Array<String>]
  #
  def facilities_ids
    facility_hash&.keys
  end

  ##
  # The list of facility ids found from the VBS response
  #
  # @return [Array<String>]
  #
  def statements_facilities_ids
    statements.map { |i| i['pS_FACILITY_NUM'] }
  end

  ##
  # The unique list of facilities with zero balance
  #
  # @return [Array<String>]
  #
  def zero_balance_facilities_ids
    facilities_ids.uniq - statements_facilities_ids unless facilities_ids.nil?
  end

  ##
  # Formatted object to pass to the Lightouse API
  #
  # @return [Hash]
  #
  def request_data
    vha_formatted_ids = zero_balance_facilities_ids.map { |i| i.dup.prepend('vha_') }.join(',')
    { ids: vha_formatted_ids }
  end

  ##
  # Get facilities that have zero balance from Lighthouse
  #
  # @return [Array<Lighthouse::Facilities::Facility>]
  #
  def get_facilities
    facility_api.get_facilities(request_data) if zero_balance_facilities_ids.present?
  rescue Common::Exceptions::BackendServiceException
    []
  end

  def facility_api
    Lighthouse::Facilities::Client.new
  end
end

#statementsArray<Hash>

Object for building a list of the user’s zero balance statements

Returns:

  • (Array<Hash>)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/services/medical_copays/zero_balance_statements.rb', line 13

class ZeroBalanceStatements
  attr_reader :facility_hash, :statements
  attr_accessor :facilities

  ##
  # Builds a ZeroBalanceStatements instance
  #
  # @param opts [Hash]
  # @return [ZeroBalanceStatements] an instance of this class
  #
  def self.build(opts = {})
    new(opts)
  end

  def initialize(opts)
    @facility_hash = opts[:facility_hash]
    @statements = opts[:statements]
    @facilities = get_facilities || []
  end

  ##
  # Format collection of facilities to match VBS response
  #
  # @return [Array<Hash>]
  #
  def list
    facilities.map do |facility|
      {
        'pH_AMT_DUE' => 0,
        'pS_STATEMENT_DATE' => Time.zone.today.strftime('%m%d%Y'),
        'station' => {
          'facilitY_NUM' => facility['id'].sub('vha_', ''),
          'city' => facility['address']['physical']['city'].upcase
        }
      }
    end
  end

  private

  ##
  # The list of vista keys associated with the user's profile
  #
  # @return [Array<String>]
  #
  def facilities_ids
    facility_hash&.keys
  end

  ##
  # The list of facility ids found from the VBS response
  #
  # @return [Array<String>]
  #
  def statements_facilities_ids
    statements.map { |i| i['pS_FACILITY_NUM'] }
  end

  ##
  # The unique list of facilities with zero balance
  #
  # @return [Array<String>]
  #
  def zero_balance_facilities_ids
    facilities_ids.uniq - statements_facilities_ids unless facilities_ids.nil?
  end

  ##
  # Formatted object to pass to the Lightouse API
  #
  # @return [Hash]
  #
  def request_data
    vha_formatted_ids = zero_balance_facilities_ids.map { |i| i.dup.prepend('vha_') }.join(',')
    { ids: vha_formatted_ids }
  end

  ##
  # Get facilities that have zero balance from Lighthouse
  #
  # @return [Array<Lighthouse::Facilities::Facility>]
  #
  def get_facilities
    facility_api.get_facilities(request_data) if zero_balance_facilities_ids.present?
  rescue Common::Exceptions::BackendServiceException
    []
  end

  def facility_api
    Lighthouse::Facilities::Client.new
  end
end

Class Method Details

.build(opts = {}) ⇒ ZeroBalanceStatements

Builds a ZeroBalanceStatements instance

Parameters:

  • opts (Hash) (defaults to: {})

Returns:



23
24
25
# File 'app/services/medical_copays/zero_balance_statements.rb', line 23

def self.build(opts = {})
  new(opts)
end

Instance Method Details

#listArray<Hash>

Format collection of facilities to match VBS response

Returns:

  • (Array<Hash>)


38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/services/medical_copays/zero_balance_statements.rb', line 38

def list
  facilities.map do |facility|
    {
      'pH_AMT_DUE' => 0,
      'pS_STATEMENT_DATE' => Time.zone.today.strftime('%m%d%Y'),
      'station' => {
        'facilitY_NUM' => facility['id'].sub('vha_', ''),
        'city' => facility['address']['physical']['city'].upcase
      }
    }
  end
end