Sha256: 083411d32ae518924d119ae463500c84e1e0b6dd09f176c0900a39e60dc3baea

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

require "renalware/hd"

module Renalware
  module HD
    class PatientPresenter < SimpleDelegator
      # delegate_missing_to :patient # TODO: when rails 5.1, try instead of SimpleDelegator
      delegate :document, to: :hd_profile
      delegate :hospital_unit,
               :transport_summary,
               to: :hd_profile, allow_nil: true
      delegate :unit_code, to: :hospital_unit, allow_nil: true, prefix: true
      delegate :transport, to: :document
      delegate :type, to: :transport, prefix: true
      alias_method :dialysing_at_unit, :hospital_unit_unit_code

      def initialize(patient)
        super(HD.cast_patient(patient.__getobj__))
      end

      def finished_hd_sessions
        # TODO: standardise on a way to get closed sessions - a scope on patient maybe?
        hd_sessions.eager_load(:hospital_unit).where(type: "Renalware::HD::Session::Closed")
      end

      private

      def hd_profile
        @hd_profile ||= HD::ProfilePresenter.new(__getobj__.hd_profile) || NullObject.instance
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.rc1 app/presenters/renalware/hd/patient_presenter.rb
renalware-core-2.0.0.pre.beta12 app/presenters/renalware/hd/patient_presenter.rb