Sha256: 2f0d1eaf67b514f9b9f2c1987dae007b1bf150044a54fe950d143db5f64d8a16

Contents?: true

Size: 1.59 KB

Versions: 21

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/low_clearance"

module Renalware
  module LowClearance
    class MDMPatientsQuery
      include ModalityScopes
      DEFAULT_SEARCH_PREDICATE = "hgb_date DESC"
      attr_reader :query, :relation, :named_filter

      def initialize(relation: Patient.all, query: nil, named_filter: nil)
        @query = query || {}
        @named_filter = named_filter || :none
        @query[:s] = DEFAULT_SEARCH_PREDICATE if @query[:s].blank?
        @relation = relation
      end

      def call
        search.result
      end

      def search
        @search ||= begin
          relation
            .extending(PatientPathologyScopes)
            .extending(ModalityScopes)
            .extending(NamedFilterScopes)
            .with_current_pathology
            .left_outer_joins(:current_observation_set)
            .with_current_modality_of_class(LowClearance::ModalityDescription)
            .public_send(named_filter.to_s)
            .search(query)
        end
      end

      module NamedFilterScopes
        def none
          self # NOOP
        end

        def on_worryboard
          joins("RIGHT OUTER JOIN patient_worries ON patient_worries.patient_id = patients.id")
        end

        def tx_candidates
          self
        end

        def urea
          where("cast(values->'URE'->>'result' as float) >= 30.0")
        end

        def hgb_low
          where("cast(values->'HGB'->>'result' as float) < 100.0")
        end

        def hgb_high
          where("cast(values->'HGB'->>'result' as float) > 130.0")
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
renalware-core-2.0.39 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.38 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.37 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.36 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.35 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.34 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.33 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.32 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.31 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.30 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.28 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.27 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.26 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.25 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.24 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.23 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.22 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.21 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.20 app/models/renalware/low_clearance/mdm_patients_query.rb
renalware-core-2.0.18 app/models/renalware/low_clearance/mdm_patients_query.rb