Sha256: ab2af565cd29d598251d97ae63af17687307b04cc8edac0488ef9900f67b0683

Contents?: true

Size: 1.18 KB

Versions: 15

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/hd"

module Renalware
  module HD
    class Patient < ActiveType::Record[Renalware::Patient]
      has_one :hd_profile, class_name: "Profile"
      has_one :hd_preference_set, class_name: "PreferenceSet"
      has_many :hd_sessions, class_name: "Session"
      has_many :prescription_administrations
      scope :with_profile, lambda {
        includes(hd_profile: :hospital_unit)
        .joins(<<-SQL.squish)
          LEFT OUTER JOIN hd_profiles ON hd_profiles.patient_id = patients.id
          LEFT OUTER JOIN hospital_units ON hd_profiles.hospital_unit_id = hospital_units.id
        SQL
        .where("hd_profiles.deactivated_at is NULL")
      }

      def treated?
        modality_descriptions.exists?(type: "Renalware::HD::ModalityDescription")
      end

      def has_ever_been_on_hd?
        @has_ever_been_on_hd ||=
          modality_descriptions.exists?(type: "Renalware::HD::ModalityDescription")
      end

      def current_modality_hd?
        return false if current_modality.blank?

        current_modality.description.is_a?(HD::ModalityDescription)
      end

      def __getobj__
        self
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/models/renalware/hd/patient.rb
renalware-core-2.1.0 app/models/renalware/hd/patient.rb
renalware-core-2.0.167 app/models/renalware/hd/patient.rb
renalware-core-2.0.166 app/models/renalware/hd/patient.rb
renalware-core-2.0.165 app/models/renalware/hd/patient.rb
renalware-core-2.0.164 app/models/renalware/hd/patient.rb
renalware-core-2.0.163 app/models/renalware/hd/patient.rb
renalware-core-2.0.162 app/models/renalware/hd/patient.rb
renalware-core-2.0.161 app/models/renalware/hd/patient.rb
renalware-core-2.0.160 app/models/renalware/hd/patient.rb
renalware-core-2.0.159 app/models/renalware/hd/patient.rb
renalware-core-2.0.158 app/models/renalware/hd/patient.rb
renalware-core-2.0.157 app/models/renalware/hd/patient.rb
renalware-core-2.0.156 app/models/renalware/hd/patient.rb
renalware-core-2.0.155 app/models/renalware/hd/patient.rb