Class: Renalware::Patients::IdempotentCreatePatient
- Inherits:
-
Object
- Object
- Renalware::Patients::IdempotentCreatePatient
- Defined in:
- app/models/renalware/patients/idempotent_create_patient.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#call(params) ⇒ Object
TODO: Support different local_patient_id columns.
-
#initialize(user) ⇒ IdempotentCreatePatient
constructor
A new instance of IdempotentCreatePatient.
Constructor Details
#initialize(user) ⇒ IdempotentCreatePatient
Returns a new instance of IdempotentCreatePatient.
11 12 13 |
# File 'app/models/renalware/patients/idempotent_create_patient.rb', line 11 def initialize(user) @user = user end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
9 10 11 |
# File 'app/models/renalware/patients/idempotent_create_patient.rb', line 9 def params @params end |
Instance Method Details
#call(params) ⇒ Object
TODO: Support different local_patient_id columns
16 17 18 19 20 21 22 |
# File 'app/models/renalware/patients/idempotent_create_patient.rb', line 16 def call(params) patient_params = params.fetch(:patient).merge(by: @user) local_patient_id = patient_params.fetch(:local_patient_id) ::Renalware::Patient.create_with(patient_params) .find_or_create_by!(local_patient_id: local_patient_id) end |