Sha256: 74000768e4495e3b7a2cd7b8ca75cba301aac3cfd6c98dc0a00d5de1d742cd93

Contents?: true

Size: 1.62 KB

Versions: 52

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/pathology"

module Renalware
  module Pathology
    # We maintain current observations for each patient in their #current_observation_set.
    # CurrentObservationSet#values is a hash (stored as jsonb) where the OBX code
    # is the key and the result value and observation date are themselves a hash.
    # So values looks like this
    # {
    #   "HGB": {
    #     "result": 123,
    #     observed_at: "2017-12-12 12:12:12"
    #   },
    #   "CRE": {
    #     ...
    #   }
    # }
    # and *always* contains the very latest pathology result for any code.
    # We store all incoming OBX codes, not just a restricted list.
    # Legacy data might only contain a subset of codes, so #values should not be relied on
    # to cover current observations for the patients entire history, just key ones.
    # When displaying or using a patient's current_observation_set the consuming code
    # must filter out the codes it wants.
    class CurrentObservationSet < ApplicationRecord
      belongs_to :patient,
                 class_name: "Renalware::Pathology::Patient",
                 inverse_of: :current_observation_set
      validates :patient, presence: true
      serialize :values, ObservationsJsonbSerializer

      def values_for_codes(codes)
        codes = Array(codes)
        values.select { |code, _| codes.include?(code) }
      end

      def self.null_values_hash
        HashWithIndifferentAccess.new.extend(ObservationSetMethods)
      end
    end

    class NullObservationSet
      def values
        ObservationsJsonbSerializer.load({})
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
renalware-core-2.0.132 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.131 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.130 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.129 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.128 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.127 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.126 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.125 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.124 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.123 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.121 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.120 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.119 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.118 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.117 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.116 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.115 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.113 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.112 app/models/renalware/pathology/current_observation_set.rb
renalware-core-2.0.111 app/models/renalware/pathology/current_observation_set.rb