Sha256: 2e5ca9f0c3bee1743f573160f98b543c06be9373f14b09c48342cf084523b638

Contents?: true

Size: 1.74 KB

Versions: 5

Compression:

Stored size: 1.74 KB

Contents

module HealthDataStandards
  module CQM
    class PatientCache
      include Mongoid::Document
      include Mongoid::Timestamps
      store_in collection: 'patient_cache'
      index "value.last" => 1
      index "bundle_id" => 1
      index "value.medical_record_id" => 1
      embeds_one :value, class_name: "HealthDataStandards::CQM::PatientCacheValue", inverse_of: :patient_cache

      def record
        Record.where(:medical_record_number => value['medical_record_id'], :test_id => value["test_id"]).first
      end

      def self.smoking_gun_rational(hqmf_id, sub_ids=nil, filter ={})

        match = {"value.IPP" => {"$gt" => 0},
                 "value.measure_id" => hqmf_id
        }.merge filter

        if sub_ids
          match["value.sub_id"] = {"$in" => sub_ids}
        end

        group = {"$group" => {"_id" => "$value.medical_record_id", "rational" => {"$push"=> "$value.rationale"}}}
        aggregate = self.mongo_session.command(:aggregate => 'patient_cache', :pipeline => [{"$match" =>match},group])

        merged = {}
        aggregate["result"].each do |agg|
          mrn = agg["_id"]
          rational = {}
          merged[mrn] = rational
          agg["rational"].each do |r|
            rational.merge! r
          end
        end

        merged
      end
    end

    class PatientCacheValue

      include Mongoid::Document

      embedded_in :patient_cache, inverse_of: :value

      field :DENOM, type: Integer
      field :NUMER, type: Integer
      field :DENEX, type: Integer
      field :DENEXCEP, type: Integer
      field :MSRPOPL, type: Integer
      field :OBSERV
      field :antinumerator, type: Integer
      field :IPP, type: Integer
      field :measure_id, type: String
      field :sub_id, type: String
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
health-data-standards-3.6.1 lib/health-data-standards/models/cqm/patient_cache.rb
health-data-standards-3.5.3 lib/health-data-standards/models/cqm/patient_cache.rb
health-data-standards-3.5.2 lib/health-data-standards/models/cqm/patient_cache.rb
health-data-standards-3.5.1 lib/health-data-standards/models/cqm/patient_cache.rb
health-data-standards-3.5.0 lib/health-data-standards/models/cqm/patient_cache.rb