Class: Renalware::Modalities::ChangePatientModality
- Inherits:
-
Object
- Object
- Renalware::Modalities::ChangePatientModality
- Includes:
- Broadcasting
- Defined in:
- app/models/renalware/modalities/change_patient_modality.rb
Instance Attribute Summary collapse
-
#patient ⇒ Object
readonly
Returns the value of attribute patient.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#call(options) ⇒ Object
Accepts an existing (unsaved) :modality, or builds a new one from the options hash.
-
#initialize(patient:, user:) ⇒ ChangePatientModality
constructor
A new instance of ChangePatientModality.
Methods included from Broadcasting
#broadcasting_to_configured_subscribers
Constructor Details
#initialize(patient:, user:) ⇒ ChangePatientModality
Returns a new instance of ChangePatientModality.
14 15 16 17 |
# File 'app/models/renalware/modalities/change_patient_modality.rb', line 14 def initialize(patient:, user:) @patient = patient @user = user end |
Instance Attribute Details
#patient ⇒ Object (readonly)
Returns the value of attribute patient.
12 13 14 |
# File 'app/models/renalware/modalities/change_patient_modality.rb', line 12 def patient @patient end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
12 13 14 |
# File 'app/models/renalware/modalities/change_patient_modality.rb', line 12 def user @user end |
Instance Method Details
#call(options) ⇒ Object
Accepts an existing (unsaved) :modality, or builds a new one from the options hash. Terminates an existing current modality if once exists, and saves and make the new modality current. Example usage:
result = Modalities::ChangePatientModality
.new(patient: patient, user: curret_user)
.call(
description: HD::ModalityDescription.first!,
started_on: Time.zone.now
)
or
modality = patient.modalities.new(
description: HD::ModalityDescription.first!,
started_on: Time.zone.now
)
result = Modalities::ChangePatientModality
.new(patient: patient, user: curret_user)
.call(modality: modality)
)
A Success or Failure result object is returned and the actual modality can be accessed on the result.object property.
We can broadcast events to inform listeners the modality has changed. See #broadcast_modality_change_event_to_any_listeners for configuration.
48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/renalware/modalities/change_patient_modality.rb', line 48 def call() new_modality = () if new_modality.valid? make_new_modality_the_current_one(new_modality) broadcast_modality_change_event_to_any_listeners(new_modality) ::Renalware::Success.new(new_modality) else ::Renalware::Failure.new(new_modality) end end |