Sha256: 1fbc05e7a57f6d6b71926bba9bfa9ab349c3930cbc720947f0721a2bc66b0d02

Contents?: true

Size: 800 Bytes

Versions: 1

Compression:

Stored size: 800 Bytes

Contents

require_dependency "renalware/pathology"

module Renalware
  module Pathology
    class Observation < ApplicationRecord
      belongs_to :request, class_name: "ObservationRequest", touch: true, inverse_of: :observations
      belongs_to :description, class_name: "ObservationDescription"

      validates :description, presence: true
      validates :result, presence: true, unless: ->(obs) { obs.cancelled? }
      validates :observed_at, presence: true

      scope :ordered, -> { order(observed_at: :desc) }
      scope :for_description, ->(description) { where(description: description) }
      scope :having_a_loinc_code, -> { joins(:description).where("loinc_code is not null") }

      def observed_on
        observed_at.to_date
      end

      delegate :to_s, to: :result
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.rc11 app/models/renalware/pathology/observation.rb