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.64 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.63 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.62 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.61 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.60 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.58 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.57 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.56 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.55 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.54 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.53 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.52 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.51 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.50 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.48 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.47 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.46 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.45 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.44 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.43 app/controllers/renalware/renal/registry_preflight_checks_controller.rb