Sha256: 54a530a96a40ed877849b37b5285f61f3d70472cc37d44ec6bd25f62750dedac

Contents?: true

Size: 1.18 KB

Versions: 8

Compression:

Stored size: 1.18 KB

Contents

require_dependency "renalware/admissions"

module Renalware
  module Admissions
    class AdmissionPresenter < SimpleDelegator
      delegate :nhs_number,
               :hospital_identifiers,
               :age,
               :sex,
               :current_modality,
               to: :patient,
               prefix: true,
               allow_nil: true

      def patient
        @patient ||= Renalware::PatientPresenter.new(__getobj__.patient)
      end

      def unit_and_ward
        ward = hospital_ward || NullObject.instance
        [
          ward.hospital_unit.unit_code,
          ward.name
        ].compact.join(" / ")
      end

      def patient_name
        __getobj__.patient&.to_s
      end

      # Returns elapsed days as an integer
      def length_of_stay
        return 0 if admitted_on.blank?
        return length_of_stay_if_discharged if discharged_on.present?
        length_of_stay_if_currently_admitted
      end

      private

      def length_of_stay_if_currently_admitted
        (Time.zone.now.to_date - admitted_on.to_date).to_i
      end

      def length_of_stay_if_discharged
        (discharged_on.to_date - admitted_on.to_date).to_i
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.rc11 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.0.pre.rc10 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.0.pre.rc9 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.0.pre.rc8 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.0.pre.rc7 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.0.pre.rc6 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.0.pre.rc5 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.0.pre.rc4 app/presenters/renalware/admissions/admission_presenter.rb