Class: Renalware::Medications::RevisePrescription

Inherits:
Object
  • Object
show all
Defined in:
app/models/renalware/medications/revise_prescription.rb

Constant Summary collapse

NEW_PRESCRIPTION_ATTRS =
%w(dose_amount dose_unit frequency).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prescription) ⇒ RevisePrescription

Returns a new instance of RevisePrescription.



12
13
14
# File 'app/models/renalware/medications/revise_prescription.rb', line 12

def initialize(prescription)
  @prescription = prescription
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



8
9
10
# File 'app/models/renalware/medications/revise_prescription.rb', line 8

def params
  @params
end

#prescriptionObject (readonly)

Returns the value of attribute prescription.



8
9
10
# File 'app/models/renalware/medications/revise_prescription.rb', line 8

def prescription
  @prescription
end

Instance Method Details

#call(params) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/renalware/medications/revise_prescription.rb', line 16

def call(params)
  @prescription.assign_attributes(params)
  return false unless @prescription.valid?

  if new_prescription_required?
    @prescription.reload
    TerminateExistingAndCreateNewPescription.new(@prescription, params).call
  else
    @prescription.save
  end
end