Method: DdeClient::DdeService#void_patient

Defined in:
app/services/dde_client/dde_service.rb

#void_patient(patient, reason) ⇒ Object

Raises:

  • (ArgumentError)


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/services/dde_client/dde_service.rb', line 66

def void_patient(patient, reason)
  raise ArgumentError, "Can't request a Dde void for a non-voided patient" unless patient.voided?
  raise ArgumentError, 'void_reason is required' if reason.blank?

  doc_id = PatientIdentifier.unscoped
                            .where(identifier_type: dde_doc_id_type, patient: patient)
                            .order(:date_voided)
                            .last
                            &.identifier
  return patient unless doc_id

  response, status = dde_client.delete("void_person/#{doc_id}?void_reason=#{reason}")
  raise DdeError, "Failed to void person in Dde: #{status} - #{response}" unless status == 200

  patient
end