Sha256: 8e660b9d74737d62ace178fcd2a20d7b854d1e75e6c6519c0b8790d15f242234

Contents?: true

Size: 1.98 KB

Versions: 8

Compression:

Stored size: 1.98 KB

Contents

require_dependency "renalware/transplants"
require "document/base"

module Renalware
  module Transplants
    class Donation < ApplicationRecord
      include PatientScope
      extend Enumerize

      belongs_to :patient, touch: true
      belongs_to :recipient, class_name: "Patient", foreign_key: "recipient_id"

      has_paper_trail class_name: "Renalware::Transplants::Version"

      scope :ordered, -> { order(created_at: :asc) }
      scope :reversed, -> { order(created_at: :desc) }
      scope :for_recipient, ->(recipient) { where(recipient_id: recipient.id) }

      enumerize :state, in: %i(volunteered seen_in_clinic investigating handed_over unsuitable)
      enumerize :relationship_with_recipient, in: %i(
        son_or_daughter mother_or_father sibling_2_shared
        sibling_1_shared sibling_0_shared sibling
        monozygotic_twin dizygotic_twin other_living_related
        living_non_related_spouse living_non_related_partner
        pooled_paired altruistic_non_directed other_living_non_related
      )
      enumerize :blood_group_compatibility, in: %i(yes no)
      enumerize :paired_pooled_donation, in: %i(
        n_a information_given consented to_enroll_in_next_matching_un
      )

      validates :state, presence: true
      validates :relationship_with_recipient, presence: true
      validates :relationship_with_recipient_other, presence: true,
        if: ->(o) { o.relationship_with_recipient.try(:other_living_non_related?) }
      validates :volunteered_on, timeliness: { type: :date, allow_blank: true }
      validates :first_seen_on, timeliness: { type: :date, allow_blank: true }
      validates :workup_completed_on, timeliness: { type: :date, allow_blank: true }
      validates :donated_on, timeliness: { type: :date, allow_blank: true }
      validate :validate_recipient

      private

      def validate_recipient
        if recipient_id.present? && (recipient_id == patient_id)
          errors.add(:recipient_id, :invalid)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.beta11 app/models/renalware/transplants/donation.rb
renalware-core-2.0.0.pre.beta10 app/models/renalware/transplants/donation.rb
renalware-core-2.0.0.pre.beta9 app/models/renalware/transplants/donation.rb
renalware-core-2.0.0.pre.beta8 app/models/renalware/transplants/donation.rb
renalware-core-2.0.0.pre.beta7 app/models/renalware/transplants/donation.rb
renalware-core-2.0.0.pre.beta6 app/models/renalware/transplants/donation.rb
renalware-core-2.0.0.pre.beta5 app/models/renalware/transplants/donation.rb
renalware-core-2.0.0.pre.beta4 app/models/renalware/transplants/donation.rb