Class: MedicalCopays::VBS::RequestData

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

Overview

Object for handling VBS request parameters

Constant Summary collapse

MOCK_VISTA_ACCOUNT_NUMBERS =
[5_160_000_000_012_345].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ RequestData

Returns a new instance of RequestData.



70
71
72
73
74
75
76
# File 'app/services/medical_copays/vbs/request_data.rb', line 70

def initialize(opts)
  @user = opts[:user]
  @edipi = user.edipi
  @vha_facility_hash = user.vha_facility_hash
  @vista_account_numbers = MedicalCopays::VistaAccountNumbers.build(data: vha_facility_hash, user: @user)
  @errors = []
end

Instance Attribute Details

#edipiString

Returns:

  • (String)


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/vbs/request_data.rb', line 16

class RequestData
  MOCK_VISTA_ACCOUNT_NUMBERS = [5_160_000_000_012_345].freeze

  attr_reader :user, :edipi, :vha_facility_hash, :vista_account_numbers
  attr_accessor :errors

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

  ##
  # The schema for validating attribute data
  #
  # @return [Hash]
  #
  def self.statements_schema
    {
      'type' => 'object',
      'additionalProperties' => false,
      'required' => %w[edipi vistaAccountNumbers],
      'properties' => {
        'edipi' => {
          'type' => 'string'
        },
        'vistaAccountNumbers' => {
          'type' => 'array',
          'items' => {
            'type' => 'integer',
            'minLength' => 16,
            'maxLength' => 16
          }
        }
      }
    }
  end

  ##
  # The options to be passed to {JSON::Validator#fully_validate}
  #
  # @return [Hash]
  #
  def self.schema_validation_options
    {
      errors_as_objects: true,
      version: :draft6
    }
  end

  def initialize(opts)
    @user = opts[:user]
    @edipi = user.edipi
    @vha_facility_hash = user.vha_facility_hash
    @vista_account_numbers = MedicalCopays::VistaAccountNumbers.build(data: vha_facility_hash, user: @user)
    @errors = []
  end

  ##
  # The data to be posted to VBS
  #
  # @return [Hash]
  #
  def to_hash
    {
      'edipi' => edipi,
      'vistaAccountNumbers' => Settings.mcp.vbs.mock_vista ? MOCK_VISTA_ACCOUNT_NUMBERS : .list
    }
  end

  ##
  # Determine if the instance is valid based upon attribute data
  #
  # @return [Boolean]
  #
  def valid?
    errors = JSON::Validator.fully_validate(
      self.class.statements_schema,
      to_hash,
      self.class.schema_validation_options
    )

    errors.blank?
  end
end

#errorsArray

Returns:

  • (Array)


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/vbs/request_data.rb', line 16

class RequestData
  MOCK_VISTA_ACCOUNT_NUMBERS = [5_160_000_000_012_345].freeze

  attr_reader :user, :edipi, :vha_facility_hash, :vista_account_numbers
  attr_accessor :errors

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

  ##
  # The schema for validating attribute data
  #
  # @return [Hash]
  #
  def self.statements_schema
    {
      'type' => 'object',
      'additionalProperties' => false,
      'required' => %w[edipi vistaAccountNumbers],
      'properties' => {
        'edipi' => {
          'type' => 'string'
        },
        'vistaAccountNumbers' => {
          'type' => 'array',
          'items' => {
            'type' => 'integer',
            'minLength' => 16,
            'maxLength' => 16
          }
        }
      }
    }
  end

  ##
  # The options to be passed to {JSON::Validator#fully_validate}
  #
  # @return [Hash]
  #
  def self.schema_validation_options
    {
      errors_as_objects: true,
      version: :draft6
    }
  end

  def initialize(opts)
    @user = opts[:user]
    @edipi = user.edipi
    @vha_facility_hash = user.vha_facility_hash
    @vista_account_numbers = MedicalCopays::VistaAccountNumbers.build(data: vha_facility_hash, user: @user)
    @errors = []
  end

  ##
  # The data to be posted to VBS
  #
  # @return [Hash]
  #
  def to_hash
    {
      'edipi' => edipi,
      'vistaAccountNumbers' => Settings.mcp.vbs.mock_vista ? MOCK_VISTA_ACCOUNT_NUMBERS : .list
    }
  end

  ##
  # Determine if the instance is valid based upon attribute data
  #
  # @return [Boolean]
  #
  def valid?
    errors = JSON::Validator.fully_validate(
      self.class.statements_schema,
      to_hash,
      self.class.schema_validation_options
    )

    errors.blank?
  end
end

#userUser

Returns:



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/vbs/request_data.rb', line 16

class RequestData
  MOCK_VISTA_ACCOUNT_NUMBERS = [5_160_000_000_012_345].freeze

  attr_reader :user, :edipi, :vha_facility_hash, :vista_account_numbers
  attr_accessor :errors

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

  ##
  # The schema for validating attribute data
  #
  # @return [Hash]
  #
  def self.statements_schema
    {
      'type' => 'object',
      'additionalProperties' => false,
      'required' => %w[edipi vistaAccountNumbers],
      'properties' => {
        'edipi' => {
          'type' => 'string'
        },
        'vistaAccountNumbers' => {
          'type' => 'array',
          'items' => {
            'type' => 'integer',
            'minLength' => 16,
            'maxLength' => 16
          }
        }
      }
    }
  end

  ##
  # The options to be passed to {JSON::Validator#fully_validate}
  #
  # @return [Hash]
  #
  def self.schema_validation_options
    {
      errors_as_objects: true,
      version: :draft6
    }
  end

  def initialize(opts)
    @user = opts[:user]
    @edipi = user.edipi
    @vha_facility_hash = user.vha_facility_hash
    @vista_account_numbers = MedicalCopays::VistaAccountNumbers.build(data: vha_facility_hash, user: @user)
    @errors = []
  end

  ##
  # The data to be posted to VBS
  #
  # @return [Hash]
  #
  def to_hash
    {
      'edipi' => edipi,
      'vistaAccountNumbers' => Settings.mcp.vbs.mock_vista ? MOCK_VISTA_ACCOUNT_NUMBERS : .list
    }
  end

  ##
  # Determine if the instance is valid based upon attribute data
  #
  # @return [Boolean]
  #
  def valid?
    errors = JSON::Validator.fully_validate(
      self.class.statements_schema,
      to_hash,
      self.class.schema_validation_options
    )

    errors.blank?
  end
end

#vha_facility_hashHash

Returns:

  • (Hash)


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/vbs/request_data.rb', line 16

class RequestData
  MOCK_VISTA_ACCOUNT_NUMBERS = [5_160_000_000_012_345].freeze

  attr_reader :user, :edipi, :vha_facility_hash, :vista_account_numbers
  attr_accessor :errors

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

  ##
  # The schema for validating attribute data
  #
  # @return [Hash]
  #
  def self.statements_schema
    {
      'type' => 'object',
      'additionalProperties' => false,
      'required' => %w[edipi vistaAccountNumbers],
      'properties' => {
        'edipi' => {
          'type' => 'string'
        },
        'vistaAccountNumbers' => {
          'type' => 'array',
          'items' => {
            'type' => 'integer',
            'minLength' => 16,
            'maxLength' => 16
          }
        }
      }
    }
  end

  ##
  # The options to be passed to {JSON::Validator#fully_validate}
  #
  # @return [Hash]
  #
  def self.schema_validation_options
    {
      errors_as_objects: true,
      version: :draft6
    }
  end

  def initialize(opts)
    @user = opts[:user]
    @edipi = user.edipi
    @vha_facility_hash = user.vha_facility_hash
    @vista_account_numbers = MedicalCopays::VistaAccountNumbers.build(data: vha_facility_hash, user: @user)
    @errors = []
  end

  ##
  # The data to be posted to VBS
  #
  # @return [Hash]
  #
  def to_hash
    {
      'edipi' => edipi,
      'vistaAccountNumbers' => Settings.mcp.vbs.mock_vista ? MOCK_VISTA_ACCOUNT_NUMBERS : .list
    }
  end

  ##
  # Determine if the instance is valid based upon attribute data
  #
  # @return [Boolean]
  #
  def valid?
    errors = JSON::Validator.fully_validate(
      self.class.statements_schema,
      to_hash,
      self.class.schema_validation_options
    )

    errors.blank?
  end
end

#vista_account_numbersObject (readonly)

Returns the value of attribute vista_account_numbers.



19
20
21
# File 'app/services/medical_copays/vbs/request_data.rb', line 19

def 
  @vista_account_numbers
end

Class Method Details

.build(opts = {}) ⇒ RequestData

Builds a RequestData instance

Parameters:

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

Returns:



28
29
30
# File 'app/services/medical_copays/vbs/request_data.rb', line 28

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

.schema_validation_optionsHash

The options to be passed to JSON::Validator#fully_validate

Returns:

  • (Hash)


63
64
65
66
67
68
# File 'app/services/medical_copays/vbs/request_data.rb', line 63

def self.schema_validation_options
  {
    errors_as_objects: true,
    version: :draft6
  }
end

.statements_schemaHash

The schema for validating attribute data

Returns:

  • (Hash)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/services/medical_copays/vbs/request_data.rb', line 37

def self.statements_schema
  {
    'type' => 'object',
    'additionalProperties' => false,
    'required' => %w[edipi vistaAccountNumbers],
    'properties' => {
      'edipi' => {
        'type' => 'string'
      },
      'vistaAccountNumbers' => {
        'type' => 'array',
        'items' => {
          'type' => 'integer',
          'minLength' => 16,
          'maxLength' => 16
        }
      }
    }
  }
end

Instance Method Details

#to_hashHash

The data to be posted to VBS

Returns:

  • (Hash)


83
84
85
86
87
88
# File 'app/services/medical_copays/vbs/request_data.rb', line 83

def to_hash
  {
    'edipi' => edipi,
    'vistaAccountNumbers' => Settings.mcp.vbs.mock_vista ? MOCK_VISTA_ACCOUNT_NUMBERS : .list
  }
end

#valid?Boolean

Determine if the instance is valid based upon attribute data

Returns:

  • (Boolean)


95
96
97
98
99
100
101
102
103
# File 'app/services/medical_copays/vbs/request_data.rb', line 95

def valid?
  errors = JSON::Validator.fully_validate(
    self.class.statements_schema,
    to_hash,
    self.class.schema_validation_options
  )

  errors.blank?
end