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.



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

def total_potential_fluid_available_for_overnight_exchanges
  @total_potential_fluid_available_for_overnight_exchanges
end

Class Method Details

.currentObject



36
37
38
# File 'app/models/renalware/pd/regime.rb', line 36

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

.policy_classObject



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

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)


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

def anything_changed?
  changed_for_autosave?
end

#apd?Boolean

Returns:

  • (Boolean)


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

def apd?
  pd_type == :apd
end

#capd?Boolean

Returns:

  • (Boolean)


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

def capd?
  pd_type == :capd
end

#current?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/models/renalware/pd/regime.rb', line 40

def current?
  Regime.current == self
end

#deep_dupObject



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

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

#deep_restore_attributesObject



74
75
76
77
78
# File 'app/models/renalware/pd/regime.rb', line 74

def deep_restore_attributes
  restore_attributes
  bags.reload
  with_bag_destruction_marks_removed
end

#has_additional_manual_exchange_bag?Boolean

Returns:

  • (Boolean)


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

def has_additional_manual_exchange_bag?
  false
end

#pd_typeObject

Raises:

  • (NotImplementedError)


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

def pd_type
  raise NotImplementedError
end

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



91
92
93
94
# File 'app/models/renalware/pd/regime.rb', line 91

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

#terminated?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/models/renalware/pd/regime.rb', line 44

def terminated?
  termination.present?
end

#with_bag_destruction_marks_removedObject



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

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