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.129 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.128 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.127 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.126 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.125 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.124 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.123 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.121 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.120 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.119 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.118 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.117 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.116 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.115 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.113 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.112 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.111 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.110 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.109 app/controllers/renalware/renal/registry_preflight_checks_controller.rb
renalware-core-2.0.108 app/controllers/renalware/renal/registry_preflight_checks_controller.rb