Sha256: d87062c20195df525d0b17601f023ed7f5a7d23a1c994b78f3b3766271a3ff17

Contents?: true

Size: 818 Bytes

Versions: 18

Compression:

Stored size: 818 Bytes

Contents

# frozen_string_literal: true

module Renalware
  module HD
    # Find the lastest PrescriptionAdministration for a particular prescription - ie the last time
    # it was given.
    class PrescriptionLastAdministrationQuery
      pattr_initialize [:prescription!]
      delegate :patient, to: :prescription

      def self.call(prescription:)
        new(prescription: prescription).call
      end

      def call
        raise ArgumentError if prescription.blank?
        raise ArgumentError if patient.blank?

        hd_patient
          .prescription_administrations
          .where(prescription: prescription, administered: true)
          .order(recorded_on: :desc, created_at: :desc)
          .first
      end

      private

      def hd_patient
        HD.cast_patient(patient)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/models/renalware/hd/prescription_last_administration_query.rb
renalware-core-2.1.0 app/models/renalware/hd/prescription_last_administration_query.rb
renalware-core-2.0.167 app/models/renalware/hd/prescription_last_administration_query.rb
renalware-core-2.0.166 app/models/renalware/hd/prescription_last_administration_query.rb
renalware-core-2.0.165 app/models/renalware/hd/prescription_last_administration_query.rb
renalware-core-2.0.164 app/models/renalware/hd/prescription_last_administration_query.rb
renalware-core-2.0.163 app/models/renalware/hd/prescription_last_administration_query.rb
renalware-core-2.0.162 app/models/renalware/hd/prescription_last_administration_query.rb
renalware-core-2.0.161 app/models/renalware/hd/prescription_last_administration_query.rb
renalware-core-2.0.160 app/models/renalware/hd/prescription_last_administration_query.rb
renalware-core-2.0.159 app/models/renalware/hd/prescription_last_administration_query.rb
renalware-core-2.0.158 app/models/renalware/hd/prescription_last_administration_query.rb
renalware-core-2.0.157 app/models/renalware/hd/prescription_last_administration_query.rb
renalware-core-2.0.156 app/models/renalware/hd/prescription_last_administration_query.rb
renalware-core-2.0.155 app/models/renalware/hd/prescription_last_administration_query.rb
renalware-core-2.0.153 app/models/renalware/hd/prescription_last_administration_query.rb
renalware-core-2.0.152 app/models/renalware/hd/prescription_last_administration_query.rb
renalware-core-2.0.151 app/models/renalware/hd/prescription_last_administration_query.rb