Class: Renalware::UKRDC::CreateEncryptedPatientXMLFiles

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

Overview

Using a working folder with a timestamp name, find matching patients and for each, generate an XML file (see UKRDC Schema) containing changes since the last time we sent the URDC data about them. Encrypt the xml files and copy to an outgoing folder which might for example be a symlink to an outgoing folder in /media/ukrdc which in turn is mount on a remote share for example on an SFTP server.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(changed_since: nil, patient_ids: nil, logger: nil, force_send: false) ⇒ CreateEncryptedPatientXMLFiles

Returns a new instance of CreateEncryptedPatientXMLFiles.



26
27
28
29
30
31
32
33
34
35
# File 'app/models/renalware/ukrdc/create_encrypted_patient_xml_files.rb', line 26

def initialize(changed_since: nil, patient_ids: nil, logger: nil, force_send: false)
  @changed_since = Time.zone.parse(changed_since) if changed_since.present?
  @patient_ids = Array(patient_ids)
  @logger = logger || Rails.logger
  @request_uuid = SecureRandom.uuid # helps group logs together
  @timestamp = Time.zone.now.strftime("%Y%m%d%H%M%S%L")
  @batch_number ||= BatchNumber.next.number
  @summary = ExportSummary.new
  @force_send = force_send
end

Instance Attribute Details

#batch_numberObject (readonly)

Returns the value of attribute batch_number.



15
16
17
# File 'app/models/renalware/ukrdc/create_encrypted_patient_xml_files.rb', line 15

def batch_number
  @batch_number
end

#changed_sinceObject (readonly)

Returns the value of attribute changed_since.



15
16
17
# File 'app/models/renalware/ukrdc/create_encrypted_patient_xml_files.rb', line 15

def changed_since
  @changed_since
end

#force_sendObject (readonly)

Returns the value of attribute force_send.



15
16
17
# File 'app/models/renalware/ukrdc/create_encrypted_patient_xml_files.rb', line 15

def force_send
  @force_send
end

#loggerObject (readonly)

Returns the value of attribute logger.



15
16
17
# File 'app/models/renalware/ukrdc/create_encrypted_patient_xml_files.rb', line 15

def logger
  @logger
end

#patient_idsObject (readonly)

Returns the value of attribute patient_ids.



15
16
17
# File 'app/models/renalware/ukrdc/create_encrypted_patient_xml_files.rb', line 15

def patient_ids
  @patient_ids
end

#request_uuidObject (readonly)

Returns the value of attribute request_uuid.



15
16
17
# File 'app/models/renalware/ukrdc/create_encrypted_patient_xml_files.rb', line 15

def request_uuid
  @request_uuid
end

#summaryObject (readonly)

Returns the value of attribute summary.



15
16
17
# File 'app/models/renalware/ukrdc/create_encrypted_patient_xml_files.rb', line 15

def summary
  @summary
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



15
16
17
# File 'app/models/renalware/ukrdc/create_encrypted_patient_xml_files.rb', line 15

def timestamp
  @timestamp
end

Instance Method Details

#callObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/renalware/ukrdc/create_encrypted_patient_xml_files.rb', line 37

def call
  logger.tagged(request_uuid) do
    summary.milliseconds_taken = Benchmark.ms do
      create_patient_xml_files
      encrypt_patient_xml_files
      copy_encrypted_xml_files_into_the_outgoing_folder
    end
    paths.create_symlink_to_latest_timestamped_folder_so_it_is_easier_to_eyeball
    build_summary
    print_summary
    email_summary
  end
rescue StandardError => e
  # TODO: if fails before copying to outgoing then we should roll back BatchNumber
  Engine.exception_notifier.notify(e)
  raise e
end