Please join your peers on either March 26 (8pm GMT) or March 28 (8am GMT) to watch as user extraordinaire and forum legend @"lindsay.stevens" demonstrates OpenClinica Insight.

See preview and register at https://openclinica.com/insight-webinar

Insight makes it easy to ask questions of ALL of your clinical and operational data and visualize answers via interactive reports and dashboards. The idea is simple, but the results are powerful: ask your questions, choose your visualizations, then return often for updated, interactive results that link you to all of the underlying data.

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:
<ProductList>
    <Product Code="001">
        <Description>Product1</Description>
        <Strength>765</Strength>
    </Product>
    <Product Code="002">
        <Description>Product 2</Description>
        <Strength>987</Strength>
    </Product>
</ProductList>


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">
   $.noConflict();
   jQuery(document).ready(function($) {
      var ProdList3Field = $("#ProdList3").parent().parent().find("select");
      var StrengthField = $("#Strength").parent().parent().find("input");
 
      ProdList3Field.change(function(){
         
         $.ajax({
            type: "GET",
            url: "includes/productlist3.xml",
            dataType: "xml",
            success: function(xml){
               $(xml).find("Product").each(function(){
                   if ($(this).find("Description").text() == ProdList3Field.val()) {
                      StrengthField.val($(this).find("Strength").text());
                   };
                });
            };
         });
      });
   });
</script><span id="Strength"></span>

Tagged:

Best Answer

Answers

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

    Good luck!
  • billingibillingi Posts: 28
    Sander,

    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.