Sha256: 5c843a873f23d0263a37e871c3d9d64a9914d26f672e468fd69d2f4b2e1c8dbd

Contents?: true

Size: 1.23 KB

Versions: 114

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

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, ward.code].reject.first
        ].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

114 entries across 114 versions & 1 rubygems

Version Path
renalware-core-2.0.147 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.146 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.145 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.144 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.143 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.142 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.141 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.140 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.139 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.138 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.137 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.136 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.135 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.134 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.133 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.132 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.131 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.130 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.129 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.128 app/presenters/renalware/admissions/admission_presenter.rb