Categories
CMS Drupal Mastering Development

Migrating content from RSS feed to populate multiple Entity reference media field

In the Drupal 8 site I’m working on, I’ve currently set up some migration configurations which import content from an external RSS feed. The file urls references in this RSS feed are imported into the site as media entities and then referenced in the generated node. All is well, except for when there are multiple file urls.

So here is the configuration for the node import:

id: rss_innovations
label: 'Import Innovations feed'
status: true

source:
  plugin: url
  data_fetcher_plugin: http
  urls: 'https://www.innovationagencyexchange.org.uk/feeds/innovations'
  data_parser_plugin: simple_xml

  item_selector: /rss/channel/item
  fields:
    -
      name: guid
      label: GUID
      selector: guid
    -
      name: title
      label: Title
      selector: title
    -
      name: pub_date
      label: 'Publication date'
      selector: pubDate
    -
      name: link
      label: 'Origin link'
      selector: link
    -
      name: description
      label: Description
      selector: 'description'
    -
      name: image
      label: Image
      selector: 'featured_image'
    -
      name: content
      label: Content
      selector: 'content'
    -
      name: organisation
      label: Organisation
      selector: 'organisation'
    -
      name: ahsnid
      label: AHSN ID
      selector: 'ahsn'
    -

  ids:
    guid:
      type: string

  constants:
    file_destination: 'public://images/'

destination:
  plugin: 'entity:node'

process:
  title: title
  field_remote_url: link
  body/value: content
  body/format:
    plugin: default_value
    default_value: basic_html
  field_ahsn: ahsnid
  field_company: organisation
  field_introduction: description
  field_image:
    plugin: image_import
    source: image
    destination: 'constants/file_destination'
    alt: !title
  uid:
    plugin: default_value
    default_value: 17
  created:
    plugin: format_date
    from_format: 'D, d M Y H:i:s O'
    to_format: 'U'
    source: pub_date
  status:
    plugin: default_value
    default_value: 1
  type:
    plugin: default_value
    default_value: innovation
  field_media:
    plugin: migration_lookup
    migration: rss_resources_files
    source: guid
    no_stub: true

migration_dependencies:
  required:
    - rss_resources_files

And here is the configuration for the file importing:

id: rss_resources_files
label: 'Import Innovation files'
status: true

source:
  plugin: url
  data_fetcher_plugin: http
  urls: 'https://www.innovationagencyexchange.org.uk/feeds/innovations'
  data_parser_plugin: simple_xml

  item_selector: /rss/channel/item
  fields:
    -
      name: guid
      label: GUID
      selector: guid
    -
      name: resourcefile
      label: Resource file
      selector: 'file'

  ids:
    guid:
      type: string

  constants:
    file_destination: 'public://resources/'

process:
  field_media_file:
    -
      plugin: skip_on_empty
      method: row
      source: resourcefile
      message: 'No file found'
    -
      plugin: explode
      source: resourcefile
      delimiter: '|'
    -
      plugin: file_import
      destination: 'constants/file_destination'
destination:
  plugin: 'entity:media'
  default_bundle: file

So these both work at the moment in terms of importing all the content and all the files. All the files are imported files as file entities (using the plugin: file_import after the explode) but then only one media entity is generated per RSS item, so only one media entity per RSS item / node. Which makes sense as the file import is running separately to the entity media generation. I guess I need to use the sub_process plugin to generate the media entities? However when I try with that it only accepts associative arrays and the array from the explode plugin does not seem to be accepted by it. If someone could point me in the right direction I’d be ever so grateful!

This is an example of the RSS feed if needed:

<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.healthinnovationexchange.org.uk/feeds/innovations" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Innovations</title>
    <link>https://www.healthinnovationexchange.org.uk/feeds/innovations</link>
    <description></description>
    <language>en</language>
     <atom:link href="https://www.healthinnovationexchange.org.uk/feeds/innovations" rel="self" type="application/rss+xml" />
      <item>
    <title>Intelligent workforce solution and indoor location technology</title>
    <link>https://www.healthinnovationexchange.org.uk/%3Ca%20href%3D%22/solutions/intelligent-workforce-solution-and-indoor-location-technology%22%3Eview%3C/a%3E</link>
    <description><![CDATA[Many have tried to change the way clinical teams work to be more efficient; but few have focused on optimising the supporting teams that provide the logistics which underpin the flow of patients throughout the hospital.&nbsp;Navenio has done just that. By looking at the teams working within a hospital, they have proven that knowing where people are, indoors in real-time, unlocks significant improvements in their workflow and efficiency. This improves patient flow and patient care. &nbsp;]]></description>
     <pubDate>Wed, 10 Jun 2020 10:29:37 +0100</pubDate>
 <dc:creator />
 <guid isPermaLink="true">https://www.healthinnovationexchange.org.uk/%3Ca%20href%3D%22/solutions/intelligent-workforce-solution-and-indoor-location-technology%22%3Eview%3C/a%3E</guid><featured_image>https://www.healthinnovationexchange.org.uk/sites/default/files/FB6E45F5-4557-4027-9517-4E48C704E6A6_1.png</featured_image>
        <content><![CDATA[<p style="text-align:justify"><span style="font-size:12pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:14.0pt"><span style="color:black">Navenio has pioneered frictionless, accurate and robust indoor location solutions, built on award-winning science from the University of Oxford – enabled simply using sensors in existing smartphones. Unlike other RTLS, RFID, Bluetooth and Wi-Fi solutions, the Navenio technology </span></span><span style="font-size:14.0pt">requires <span style="color:black">no new investment in infrastructure</span> at all; is easily scalable and accurate to within 1 to 3 metres.</span></span></span></p><p style="text-align:justify"><span style="font-size:12pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:14.0pt">The Navenio solution is available in three forms:</span></span></span></p><ul><li style="text-align:justify; margin-left:8px"><span style="font-size:12pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:14.0pt">Intelligent Workforce Solution (IWS)</span></span></span><ul style="list-style-type:circle"><li style="margin-left:8px; text-align:justify"><span style="font-size:12pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:14.0pt">automates the prioritisation and allocation of tasks to ensure </span><span style="font-size:14.0pt">the right person is helping in the right location every time</span></span></span></li></ul></li><li style="text-align:justify; margin-left:8px"><span style="font-size:12pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:14.0pt">Location only solution</span></span></span><ul style="list-style-type:circle"><li style="margin-left:8px; text-align:justify"><span style="font-size:12pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:14.0pt">provides details of current and past movements of staff via their smartphones </span></span></span></li></ul></li><li style="text-align:justify; margin-left:8px"><span style="font-size:12pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:14.0pt">as a fully integrated location solution that feeds into other clinical/non-clinical solutions/applications</span></span></span><ul style="list-style-type:circle"><li style="margin-left:8px; text-align:justify"><span style="font-size:12pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:14.0pt">can provide valuable data to aid and improve patient consultations, discharge and referrals; and provide confirmation of where a staff member at infection risk has travelled between over a period of time</span></span></span></li></ul></li></ul>]]></content>
    <organisation>Navenio Limited</organisation>
    <ahsn>2</ahsn>                                                                                                                                                                                                                                                                                     <video>https://www.navenio.com/dr-harpreet-sood</video>                        <file>https://www.healthinnovationexchange.org.uk/sites/default/files/Navenio%20Briefing%20Doc%20-%20Covid-19%20Assistance%20Briefing%20Doc%20-%2027mar20.pdf|https://www.healthinnovationexchange.org.uk/sites/default/files/AHSNsubmission%5B1%5DMT.pdf|https://www.healthinnovationexchange.org.uk/sites/default/files/Navenio%20IWS%204pp%20June%202020.pdf|https://www.healthinnovationexchange.org.uk/sites/default/files/Hospital%20Impact%20Study-MT-11.pdf</file>
</item>  
<item>
    <title>MediShout: A Logistical Brain For Healthcare </title>
    <link>https://www.healthinnovationexchange.org.uk/%3Ca%20href%3D%22/solutions/medishout-logistical-brain-healthcare%22%3Eview%3C/a%3E</link>
    <description><![CDATA[www.MediShout.co.ukMediShout uses digital and AI technology to provide a “logistical brain” to health and social care organisations. Currently, logistical issues (e.g. faulty equipment, no PPE, broken IT, estates and facilities issues) delay staff and prevent best care. MediShout solves this problem by integrating all logistical departments onto one App, where a single-interface lets staff instantly report any non-clinical issue. Staff can track the progress of their report whilst organisations get operational oversight of all issues. AI-algorithms allows organisations to predict future problems, like broken equipment.]]></description>
     <pubDate>Sat, 30 May 2020 08:32:37 +0100</pubDate>
 <dc:creator />
 <guid isPermaLink="true">https://www.healthinnovationexchange.org.uk/%3Ca%20href%3D%22/solutions/medishout-logistical-brain-healthcare%22%3Eview%3C/a%3E</guid>
        <content><![CDATA[<p style="margin-bottom:11px"><strong>THE STORY:&nbsp;</strong><br>MediShout's founder is a surgeon and one afternoon, had to cancel three operations as a theatre lightbulb was broken. Staff had known for days but not reported it because no effective communication channels existed.</p><p style="margin-bottom:11px"><br><strong>THE HEALTHCARE PROBLEM:&nbsp;</strong><br>All clinicians are delayed daily by similar problems because healthcare buildings are poorly automated and not digitally connective. Staff get delayed by logistical and infra-structure problems e.g. forgotten passwords, broken equipment, low stock, lack of PPE.</p><p style="margin-bottom:11px"><br><strong>THE IMPACT IS HUGE:&nbsp;</strong><br>1. Journal of Nursing Times reported a third of NHS Nurses waste two hours per shift looking for equipment, costing the NHS almost £1billion annually.<br>2. There's been a 32% increase in cancelled NHS procedures due to equipment and staffing issues</p><p style="margin-bottom:11px"><br><strong>THE SOLUTION:&nbsp;</strong><br>MediShout is on the NHS Innovation Accelerator and provides the first platform in healthcare to integrate all logistical departments e.g. IT, estates, facilities, stock, equipment, suppliers. The MediShout App provides a single-interface for staff to instantly report any non-clinical issue. Staff can track the progress of their report whilst organisations get operational oversight and can see what issues are most impacting patient care and need fixing first. Artificial intelligence (AI) allows organisations to predict future problems, like broken equipment.</p><p style="margin-bottom:11px"><br><strong>BENEFITS:&nbsp;</strong><br>Health economists have shown MediShout can save NHS Trusts £1million annually (see attached report) and save 15 minutes per clinician daily. By sending staff reports directly to equipment suppliers, MediShout can improve output of surgical theatres and endoscopy departments.</p>]]></content>
    <organisation>MediShout</organisation>
    <ahsn>2</ahsn>                                                                      <file>https://www.healthinnovationexchange.org.uk/sites/default/files/MediShout%20-%20Health%20Economic%20Impact%20Report%20%28HEE%29.pdf</file>
          </item>  </channel>
</rss>

Leave a Reply

Your email address will not be published. Required fields are marked *