module ProtocolsExporterV2 include ProtocolsExporter private def generate_envelope_xml(protocols) envelope_xml = "\n" protocols.each do |protocol| protocol = protocol.latest_published_version_or_self protocol_name = get_protocol_name(protocol) envelope_xml << "#{protocol_name}" \ "\n" end envelope_xml << "\n" envelope_xml end def generate_protocol_xml(protocol) protocol_name = get_protocol_name(protocol) protocol_xml = "\n" \ "\n" \ "#{protocol_name}\n" \ "#{protocol.authors}\n" \ "" \ "" \ "\n" if tiny_mce_asset_present?(protocol) && protocol.description protocol_xml << get_tiny_mce_assets(protocol.description) end protocol_xml << "#{protocol.created_at.as_json}\n" protocol_xml << "#{protocol.updated_at.as_json}\n" # Steps if protocol.steps.any? protocol_xml << "\n" \ "#{protocol.steps.order(:position).map { |s| step_xml(s) }.join}" \ "\n" end protocol_xml << "\n" protocol_xml << '' protocol_xml end def step_xml(step) step_guid = get_guid(step.id) xml = "\n" \ "#{step.name}\n" # Assets xml << "\n#{step.assets.map { |a| asset_xml(a) }.join}\n" if step.assets.any? if step.step_orderable_elements.any? xml << "\n" step.step_orderable_elements.find_each do |step_orderable_element| element = step_orderable_element.orderable element_guid = get_guid(element.id) xml << "" case element when StepText xml << step_text_xml(element) when StepTable xml << table_xml(element.table) when Checklist xml << checklist_xml(element) end xml << "\n" end xml << "\n" end xml << '' xml end def step_text_xml(step_text) xml = "\n" \ "\n" \ ""\ "\n" xml << get_tiny_mce_assets(step_text.text) if step_text.text.present? xml << "\n" end def table_xml(table) "\n" \ "#{table.name}\n" \ "#{table.contents.unpack1('H*')}\n" \ "#{table.metadata.to_json}\n" \ "\n" end def checklist_xml(checklist) xml = "\n" \ "#{checklist.name}\n" if checklist.checklist_items.any? xml << "\n#{checklist.checklist_items.map { |ci| checklist_item_xml(ci) }.join}\n" end xml << "\n" xml end def checklist_item_xml(checklist_item) "\n" \ "#{checklist_item.text}\n" \ "\n" \ end def asset_xml(asset) asset_guid = get_guid(asset.id) asset_file_name = "#{asset_guid}#{File.extname(asset.file_name)}" "#{asset_guid}#{File.extname(asset.file_name)}" \ "\n" \ "#{asset.file_name}\n" \ "#{asset.content_type}\n" \ "\n" \ "\n" end end