Class: Renalware::UKRDC::SendPatient

Inherits:
Object
  • Object
show all
Defined in:
app/models/renalware/ukrdc/send_patient.rb

Defined Under Namespace

Classes: Payload

Instance Method Summary collapse

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/renalware/ukrdc/send_patient.rb', line 11

def call
  UKRDC::TransmissionLog.with_logging(patient, request_uuid) do |log|
    logger.info "  Patient #{patient.to_param}"
    xml_payload = build_payload(log)
    if xml_payload_same_as_last_sent_payload?(xml_payload)
      logger.info "    skipping as no change in XML file"
      log.unsent_no_change_since_last_send!
    else
      send_file(xml_payload, log)
      # Important we use update_column here so we don't trigger updated_at to change
      # on the patient, which affects the results of PatientsQuery next time.
      patient.update_column(:sent_to_ukrdc_at, Time.zone.now)
      logger.info(
        "    sending file and setting patient.sent_to_ukrdc_at = #{patient.sent_to_ukrdc_at}"
      )
    end
    logger.info "    Status: #{log.status}"
  end
end