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.1.1 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.1.0 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.167 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.166 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.165 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.164 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.163 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.162 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.161 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.160 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.159 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.158 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.157 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.156 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.155 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.153 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.152 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.151 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.149 app/presenters/renalware/admissions/admission_presenter.rb
renalware-core-2.0.148 app/presenters/renalware/admissions/admission_presenter.rb