Class: PrescriptionPreference

Inherits:
Common::Base show all
Includes:
ActiveModel::Validations
Defined in:
app/models/prescription_preference.rb

Overview

Models Prescription notification preference

Instance Attribute Summary collapse

Attributes inherited from Common::Base

#errors_hash, #metadata

Instance Method Summary collapse

Methods inherited from Common::Base

#changed, #changed?, #changes, default_sort, filterable_attributes, #initialize, max_per_page, per_page, sortable_attributes

Constructor Details

This class inherits a constructor from Common::Base

Instance Attribute Details

#email_addressString

Returns:

  • (String)


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
# File 'app/models/prescription_preference.rb', line 14

class PrescriptionPreference < Common::Base
  include ActiveModel::Validations

  attribute :email_address, String
  attribute :rx_flag, Boolean

  validates :rx_flag, inclusion: { in: [true, false] }
  validates(
    :email_address,
    presence: true,
    format: { with: EVSS::PCIU::EmailAddress::VALID_EMAIL_REGEX },
    length: { maximum: 255, minimum: 6 }
  )

  ##
  # Build the object for MHV
  #
  # @raise [Common::Exceptions::ValidationErrors] if invalid attributes
  # @return [Hash]
  #
  def mhv_params
    raise Common::Exceptions::ValidationErrors, self unless valid?

    { email_address:, rx_flag: }
  end

  ##
  # Compute a hex-formatted digest of the attributes to be used as an ID
  #
  # @return [String]
  #
  def id
    Digest::SHA256.hexdigest(instance_variable_get(:@original_attributes).to_json)
  end
end

#rx_flagBoolean

Returns:

  • (Boolean)


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
# File 'app/models/prescription_preference.rb', line 14

class PrescriptionPreference < Common::Base
  include ActiveModel::Validations

  attribute :email_address, String
  attribute :rx_flag, Boolean

  validates :rx_flag, inclusion: { in: [true, false] }
  validates(
    :email_address,
    presence: true,
    format: { with: EVSS::PCIU::EmailAddress::VALID_EMAIL_REGEX },
    length: { maximum: 255, minimum: 6 }
  )

  ##
  # Build the object for MHV
  #
  # @raise [Common::Exceptions::ValidationErrors] if invalid attributes
  # @return [Hash]
  #
  def mhv_params
    raise Common::Exceptions::ValidationErrors, self unless valid?

    { email_address:, rx_flag: }
  end

  ##
  # Compute a hex-formatted digest of the attributes to be used as an ID
  #
  # @return [String]
  #
  def id
    Digest::SHA256.hexdigest(instance_variable_get(:@original_attributes).to_json)
  end
end

Instance Method Details

#idString

Compute a hex-formatted digest of the attributes to be used as an ID

Returns:

  • (String)


45
46
47
# File 'app/models/prescription_preference.rb', line 45

def id
  Digest::SHA256.hexdigest(instance_variable_get(:@original_attributes).to_json)
end

#mhv_paramsHash

Build the object for MHV

Returns:

  • (Hash)

Raises:



34
35
36
37
38
# File 'app/models/prescription_preference.rb', line 34

def mhv_params
  raise Common::Exceptions::ValidationErrors, self unless valid?

  { email_address:, rx_flag: }
end