Sha256: 4bb0486075d6b7ec9bff6fe4c3a69f233314622071d04d5686d5d1797f16bdcd

Contents?: true

Size: 1.21 KB

Versions: 18

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/pd"

# Captures data used for PET (Peritoneal Equilibration Test) and Adequacy.
module Renalware
  module PD
    class UnifiedPETAdequacyForm
      include ActiveModel::Model
      include Virtus::Model

      attribute :pet, PETResult
      attribute :adequacy, AdequacyResult
      attribute :patient, Patient

      attribute :pet_missing, Boolean
      attribute :adequacy_missing, Boolean

      def valid?
        objects_to_save.each(&:validate).all?(&:valid?)
      end

      def save_by!(user)
        PETResult.transaction do
          objects_to_save.each { |obj| obj.save_by!(user) }
        end
      end

      def objects_to_save
        @objects_to_save ||= begin
          [].tap do |arr|
            arr << pet unless pet_missing
            arr << adequacy unless adequacy_missing
          end
        end
      end

      # This method lets us just use eg simple_form_for in the view without
      # having to specify the url option i.e. PatientPDUnifiedPetAdequacy here will
      # resolve to 'patient_pd_pet_adequacy_results_path'
      def self.model_name
        ActiveModel::Name.new(self, nil, "PatientPDUnifiedPetAdequacy")
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

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