Class: Renalware::PD::Regime

Inherits:
ApplicationRecord show all
Extended by:
Enumerize
Defined in:
app/models/renalware/pd/regime.rb

Direct Known Subclasses

APDRegime, CAPDRegime

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#total_potential_fluid_available_for_overnight_exchangesObject

Returns the value of attribute total_potential_fluid_available_for_overnight_exchanges.



109
110
111
# File 'app/models/renalware/pd/regime.rb', line 109

def total_potential_fluid_available_for_overnight_exchanges
  @total_potential_fluid_available_for_overnight_exchanges
end

Class Method Details

.currentObject



49
50
51
# File 'app/models/renalware/pd/regime.rb', line 49

def self.current
  Regime.order("pd_regimes.created_at DESC").limit(1).with_bags.first
end

.policy_classObject



61
62
63
# File 'app/models/renalware/pd/regime.rb', line 61

def self.policy_class
  RegimePolicy
end

Instance Method Details

#anything_changed?Boolean

changed_for_autosave? is an AR method that will recursively check the in-memory regime and its bags for changes or any bags marked for destruction.

Returns:

  • (Boolean)


95
96
97
# File 'app/models/renalware/pd/regime.rb', line 95

def anything_changed?
  changed_for_autosave?
end

#apd?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/models/renalware/pd/regime.rb', line 65

def apd?
  pd_type == :apd
end

#capd?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/models/renalware/pd/regime.rb', line 69

def capd?
  pd_type == :capd
end

#current?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/renalware/pd/regime.rb', line 53

def current?
  Regime.current == self
end

#deep_dupObject



81
82
83
84
85
# File 'app/models/renalware/pd/regime.rb', line 81

def deep_dup
  regime = dup
  regime.bags = bags.map(&:dup)
  regime
end

#deep_restore_attributesObject



87
88
89
90
91
# File 'app/models/renalware/pd/regime.rb', line 87

def deep_restore_attributes
  restore_attributes
  bags.reload
  with_bag_destruction_marks_removed
end

#has_additional_manual_exchange_bag?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'app/models/renalware/pd/regime.rb', line 77

def has_additional_manual_exchange_bag?
  false
end

#pd_typeObject

Raises:

  • (NotImplementedError)


73
74
75
# File 'app/models/renalware/pd/regime.rb', line 73

def pd_type
  raise NotImplementedError
end

#terminate(by:, terminated_on: Date.current) ⇒ Object



104
105
106
107
# File 'app/models/renalware/pd/regime.rb', line 104

def terminate(by:, terminated_on: Date.current)
  build_termination(by: by, terminated_on: terminated_on)
  self
end

#terminated?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'app/models/renalware/pd/regime.rb', line 57

def terminated?
  termination.present?
end

#with_bag_destruction_marks_removedObject



99
100
101
102
# File 'app/models/renalware/pd/regime.rb', line 99

def with_bag_destruction_marks_removed
  bags.select(&:marked_for_destruction?).each(&:reload)
  self
end