Sha256: 234a2c0da2feeb533dec5d8b6439f44d013412fafd682508ac00c965e478d425

Contents?: true

Size: 931 Bytes

Versions: 43

Compression:

Stored size: 931 Bytes

Contents

# frozen_string_literal: true

require_dependency "renalware/pathology/requests"

module Renalware
  module Pathology
    module Requests
      class GlobalRule
        class PrescriptionDrugType < GlobalRule
          validate :drug_type_present

          def observation_required_for_patient?(patient, _date)
            patient
              .prescriptions.current.joins(drug: :classifications)
              .where("drug_types_drugs.drug_type_id = ?", param_id)
              .count > 0
          end

          def to_s
            "prescribed drugs include #{drug_type.name}"
          end

          private

          def drug_type
            @drug_type ||= Drugs::Type.find_by(id: param_id)
          end

          def drug_type_present
            return if Drugs::Type.exists?(param_id)

            errors.add(:param_id, "param_id must be the id of a DrugType")
          end
        end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.1.0 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.167 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.166 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.165 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.164 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.163 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.162 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.161 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.160 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.159 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.158 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.157 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.156 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.155 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.153 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.152 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.151 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.149 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb
renalware-core-2.0.148 app/models/renalware/pathology/requests/global_rule/prescription_drug_type.rb