Sha256: 767b325d65401428839fdebd3fc85d4efc010a75b46e1ccd39c5bc348ce46c14

Contents?: true

Size: 1.29 KB

Versions: 17

Compression:

Stored size: 1.29 KB

Contents

require_dependency "renalware/letters"

module Renalware
  module Letters
    module LetterPathology
      extend ActiveSupport::Concern

      # Filters a set of observations using a specific set of OBX codes
      class FilteredObservationSet
        EMPTY_SNAPSHOT = {}.freeze

        def initialize(observation_set:, codes: nil)
          @codes = codes || RelevantObservationDescription.all.map(&:code)
          @observation_set = observation_set
        end

        # Returns a hash of the filtered observations e.g.
        # {
        #   "NA"=>{"result"=>"139", "observed_at"=>"2016-03-15T03:28:00"},
        #   "ALB"=>{"result"=>"49", "observed_at"=>"2016-03-15T03:28:00"},
        #   ...
        # }
        def to_h
          return if observation_set.blank?
          hash = observation_set.values.select { |code, _| codes.include?(code.to_s) }
          hash.empty? ? nil : hash
        end

        private

        attr_reader :observation_set, :codes
      end

      # Update a letter's pathology snapshot to the current point in time
      def build_pathology_snapshot(patient)
        FilteredObservationSet.new(
          observation_set: patient.current_observation_set,
          codes: Renalware::Letters::RelevantObservationDescription.all.map(&:code)
        ).to_h
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
renalware-core-2.0.8 app/models/concerns/renalware/letters/letter_pathology.rb
renalware-core-2.0.7 app/models/concerns/renalware/letters/letter_pathology.rb
renalware-core-2.0.5 app/models/concerns/renalware/letters/letter_pathology.rb
renalware-core-2.0.4 app/models/concerns/renalware/letters/letter_pathology.rb
renalware-core-2.0.3 app/models/concerns/renalware/letters/letter_pathology.rb
renalware-core-2.0.2 app/models/concerns/renalware/letters/letter_pathology.rb
renalware-core-2.0.1 app/models/concerns/renalware/letters/letter_pathology.rb
renalware-core-2.0.0 app/models/concerns/renalware/letters/letter_pathology.rb
renalware-core-2.0.0.pre.rc13 app/models/concerns/renalware/letters/letter_pathology.rb
renalware-core-2.0.0.pre.rc11 app/models/concerns/renalware/letters/letter_pathology.rb
renalware-core-2.0.0.pre.rc10 app/models/concerns/renalware/letters/letter_pathology.rb
renalware-core-2.0.0.pre.rc9 app/models/concerns/renalware/letters/letter_pathology.rb
renalware-core-2.0.0.pre.rc8 app/models/concerns/renalware/letters/letter_pathology.rb
renalware-core-2.0.0.pre.rc7 app/models/concerns/renalware/letters/letter_pathology.rb
renalware-core-2.0.0.pre.rc6 app/models/concerns/renalware/letters/letter_pathology.rb
renalware-core-2.0.0.pre.rc5 app/models/concerns/renalware/letters/letter_pathology.rb
renalware-core-2.0.0.pre.rc4 app/models/concerns/renalware/letters/letter_pathology.rb