Class: MedicalCopays::VistaAccountNumbers
- Inherits:
-
Object
- Object
- MedicalCopays::VistaAccountNumbers
- Defined in:
- app/services/medical_copays/vista_account_numbers.rb
Overview
Object for building a list of the user’s vista account numbers
Instance Attribute Summary collapse
- #data ⇒ Hash
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
-
.build(opts = {}) ⇒ VistaAccountNumbers
Builds a VistaAccountNumbers instance.
Instance Method Summary collapse
-
#default ⇒ Array
Default array and value if the user’s ‘vha_facility_hash` is blank.
-
#initialize(opts) ⇒ VistaAccountNumbers
constructor
A new instance of VistaAccountNumbers.
-
#list ⇒ Array
The calculated list of Vista Account Numbers for the VBS service.
- #treatment_facility_data(complete_facility_hash) ⇒ Object
-
#vista_account_id(key, id) ⇒ String
Create the Vista Account Number using the facility id, the associated vista id and the calculated number of ‘0’s required between the facility id and the vista id.
Constructor Details
#initialize(opts) ⇒ VistaAccountNumbers
Returns a new instance of VistaAccountNumbers.
22 23 24 25 |
# File 'app/services/medical_copays/vista_account_numbers.rb', line 22 def initialize(opts) @user = opts[:user] @data = treatment_facility_data(opts[:data]) end |
Instance Attribute Details
#data ⇒ Hash
9 10 11 12 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 |
# File 'app/services/medical_copays/vista_account_numbers.rb', line 9 class VistaAccountNumbers attr_reader :data, :user ## # Builds a VistaAccountNumbers instance # # @param opts [Hash] # @return [VistaAccountNumbers] an instance of this class # def self.build(opts = {}) new(opts) end def initialize(opts) @user = opts[:user] @data = treatment_facility_data(opts[:data]) end ## # The calculated list of Vista Account Numbers for the VBS service # # @return [Array] # def list return default if data.blank? data.each_with_object([]) do |(key, values), accumulator| next if values.blank? values.each do |id| accumulator << vista_account_id(key, id) end end end ## # Create the Vista Account Number using the facility id, # the associated vista id and the calculated number of '0's # required between the facility id and the vista id. # # @return [String] # def vista_account_id(key, id) Rails.logger.info( 'Building Vista Account ID', user_uuid: user.uuid, facility_id: key, vista_id_length: id.to_s.length ) offset = 16 - (key + id).length padding = '0' * offset if offset >= 0 "#{key}#{padding}#{id}".to_i end ## # Default array and value if the user's `vha_facility_hash` is blank # # @return [Array] # def default [1_234_567_891_011_121] end def treatment_facility_data(complete_facility_hash) complete_facility_hash.select do |facility_id| user.va_treatment_facility_ids.include?(facility_id) end end end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
10 11 12 |
# File 'app/services/medical_copays/vista_account_numbers.rb', line 10 def user @user end |
Class Method Details
.build(opts = {}) ⇒ VistaAccountNumbers
Builds a VistaAccountNumbers instance
18 19 20 |
# File 'app/services/medical_copays/vista_account_numbers.rb', line 18 def self.build(opts = {}) new(opts) end |
Instance Method Details
#default ⇒ Array
Default array and value if the user’s ‘vha_facility_hash` is blank
70 71 72 |
# File 'app/services/medical_copays/vista_account_numbers.rb', line 70 def default [1_234_567_891_011_121] end |
#list ⇒ Array
The calculated list of Vista Account Numbers for the VBS service
32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/services/medical_copays/vista_account_numbers.rb', line 32 def list return default if data.blank? data.each_with_object([]) do |(key, values), accumulator| next if values.blank? values.each do |id| accumulator << vista_account_id(key, id) end end end |
#treatment_facility_data(complete_facility_hash) ⇒ Object
74 75 76 77 78 |
# File 'app/services/medical_copays/vista_account_numbers.rb', line 74 def treatment_facility_data(complete_facility_hash) complete_facility_hash.select do |facility_id| user.va_treatment_facility_ids.include?(facility_id) end end |
#vista_account_id(key, id) ⇒ String
Create the Vista Account Number using the facility id, the associated vista id and the calculated number of ‘0’s required between the facility id and the vista id.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/services/medical_copays/vista_account_numbers.rb', line 51 def vista_account_id(key, id) Rails.logger.info( 'Building Vista Account ID', user_uuid: user.uuid, facility_id: key, vista_id_length: id.to_s.length ) offset = 16 - (key + id).length padding = '0' * offset if offset >= 0 "#{key}#{padding}#{id}".to_i end |