We hope you'll join us for our 4/23 webinar on using data tables to apply reference ranges and AE codes in OC4. For more information and to register, visit https://register.gotowebinar.com/register/2882170018956684555

Loading data from external XML file

I need to calculate a total strength, based upon the strength of a (selected) product and a (selected) volume.  The list of products could change, so I thought it would be useful to store the name / strength in an external XML file with the following format:
    <Product Code="001">
    <Product Code="002">
        <Description>Product 2</Description>

I am able to select the product names from the XML file, as described here : http://en.wikibooks.org/wiki/OpenClinica_User_Manual/LongLists

However, having selected the relevant product name, I also want to retrieve the 'Strength' for the same product and load it into a second field on the CRF.  I have tried to do this by 're-reading' the same XML file, finding the relevant product (which is successfully selected into a separate item) and then extracting the Strength value.  I'm not sure if this is the best way to do this, and I can't get it to work anyway!

The following is the code I'm using to re-read the XML file.  This appears in the RIGHT_ITEM_TEXT for the 'Strength' Item.  Any thoughts / assistance would e gratefully received...

script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script lang="Javascript">
   jQuery(document).ready(function($) {
      var ProdList3Field = $("#ProdList3").parent().parent().find("select");
      var StrengthField = $("#Strength").parent().parent().find("input");
            type: "GET",
            url: "includes/productlist3.xml",
            dataType: "xml",
            success: function(xml){
                   if ($(this).find("Description").text() == ProdList3Field.val()) {
</script><span id="Strength"></span>


Best Answer


  • kristiakkristiak Posts: 1,339 ✭✭✭
    via Email
    I'm sure that XML-gurus like Gerben or Christian can help you!!

    Good luck!
  • billingibillingi Posts: 28

    Thanks for the brilliant suggestion!  I had already got the list part working, and I could return either the code or description or strength from the drop-down list, but I wanted all three!

    I ended up putting the 3 fields in the 'val()' of the code list, so that this additional information wasn't displayed in the list itself. The format I ended up using was "[001]Product 1{765}".  I was then able to use the javascript .indexOf() and .slice(<from>,<to>) to extract the relevant part of the val() string & out it into the relevant OpenClinica Items.

This discussion has been closed.