Class: Renalware::Patients::IdempotentCreatePatient

Inherits:
Object
  • Object
show all
Defined in:
app/models/renalware/patients/idempotent_create_patient.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ IdempotentCreatePatient

Returns a new instance of IdempotentCreatePatient.



10
11
12
# File 'app/models/renalware/patients/idempotent_create_patient.rb', line 10

def initialize(user)
  @user = user
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



8
9
10
# File 'app/models/renalware/patients/idempotent_create_patient.rb', line 8

def params
  @params
end

Instance Method Details

#call(params) ⇒ Object

TODO: Support different local_patient_id columns



15
16
17
18
19
20
21
# File 'app/models/renalware/patients/idempotent_create_patient.rb', line 15

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