Sha256: 51bfb96c342809567bf9c15b14e3afbf5d9c846a891b4287fd13990b6b4b8746

Contents?: true

Size: 1.92 KB

Versions: 105

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

require_dependency("renalware/renal")
require "collection_presenter"

module Renalware
  module Renal
    class RegistryPreflightChecksController < BaseController
      include Renalware::Concerns::Pageable

      class PatientPresenter < SimpleDelegator
        def missing_data
          Registry::PreflightChecks::PatientsQuery.missing_data_for(__getobj__)
        end

        def hd_unit
          if current_modality.description.name == "HD"
            Renalware::HD.cast_patient(__getobj__)&.hd_profile&.hospital_unit&.unit_code
          end
        end

        def renal_profile
          Renalware::Renal.cast_patient(__getobj__).profile
        end
      end

      class DeceasedPatientPresenter < SimpleDelegator
        def missing_data
          Registry::PreflightChecks::DeathsQuery.missing_data_for(__getobj__)
        end

        def hd_unit; end

        def renal_profile
          Renalware::Renal.cast_patient(__getobj__).profile
        end
      end

      def patients
        authorize [:renalware, :renal, :registry_preflight_check], :patients?
        query = Registry::PreflightChecks::PatientsQuery.new(query_params: query_params)
        patients = query.call.page(page).per(per_page)
        patients = CollectionPresenter.new(patients, PatientPresenter)
        render locals: { patients: patients, query: query.search }
      end

      def deaths
        authorize [:renalware, :renal, :registry_preflight_check], :deaths?
        query = Registry::PreflightChecks::DeathsQuery.new(query_params: query_params)
        patients = query.call.page(page).per(per_page)
        patients = CollectionPresenter.new(patients, DeceasedPatientPresenter)
        render locals: { patients: patients, query: query.search }
      end

      private

      def query_params
        qparams = params.fetch(:q, {})
        qparams[:profile_esrf_on_gteq] ||= 3.years.ago
        qparams
      end
    end
  end
end

Version data entries

105 entries across 105 versions & 1 rubygems

Version Path
renalware-core-2.0.149 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.148 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.147 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.146 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.145 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.144 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.143 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.142 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.141 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.140 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.139 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.138 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.137 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.136 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.135 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.134 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.133 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.132 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.131 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.130 app/controllers/renalware/renal/registry_preflight_checks_controller.rb