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

javascript on a crf

I have a question ask for you,It is about prepopulate repeating group with answers from previous CRF on openclinica ,how can I do use javascript on a crf to do a rest query and place the values when auser views the target crf?

Comments

  • GerbenRienkGerbenRienk Posts: 838 ✭✭✭
    <script src="includes/jmesa/jquery.min.js"></script>
    <script lang="Javascript">
    $.noConflict();
    jQuery(document).ready(function($) { 
    var urlStart = "rest/clinicaldata/xml/view/S_DEFAULTS1/";
    var urlTail = "/SE_EV1/*";
    var subjOID = "${studySubjectOID}";
    var urlComplete = urlStart + subjOID + urlTail;
    console.log(urlComplete); 
    var ItemOID = "I_TDSRI_MEDNAME";
    var RIGOID = "IG_TDSRI_RIG";
    var inputName = "input1102";

    var medNames = [10];
    var lineNr;

    $.ajax({
    type: "GET",
    url: urlComplete,
    dataType: "xml",
    success: parseXML
    });
    function parseXML(xml){
     $(xml).find("ItemGroupData").each(function(){
      if($(this).attr("ItemGroupOID") == RIGOID){
       lineNr = $(this).attr("ItemGroupRepeatKey");
       $(this).find("ItemData").each(function(){
        if($(this).attr("ItemOID") == ItemOID){
         medNames[lineNr] =  $(this).attr("Value");
        }
       });
      }
     })
         //iterate through the array
         for(i=1; i < 10; i++){
          if (medNames[i]){
           console.log(medNames[i]);
           $("#" + RIGOID + "_" + (i-1) + inputName).val(medNames[i]);
          }
         }
    };
    })
    </script>
  • GerbenRienkGerbenRienk Posts: 838 ✭✭✭
    Hi,

    This can be done, but it's not easy ;-)
    See the script above, which is a bit rough, but serves as a proof of concept.

    The idea is to take a RepeatingItemGroup with a set length of 10 rows, say Medication.
    You compose the URL for the REST and loop through the output. As opposed to the example on http://www.trialdatasolutions.com/tds/howto/itemsfromotherevents.jsp we must go one level deeper, because our ItemData can have more than one occurrence/ItemGroupRepeatKey. We use this to fill the array medNames. (We must use the ItemGroupRepeatKey, because we do not know in which order the REST-output is presented.)
    Now we have the array and for this example I made life easy and just noted the last bit of the ID of the input to copy the mednames into: input1102.
    To get the actual target, we prefix the OID of the RepeatingItemGroup, plus the index, which starts with 0, so we must subtract 1.

    As I said: this is just a proof of concept. In production you would like to check the actual Event, so you would know if a copy is needed and if yes, from which event to take the copy. Furthermore you would like to compare the values already present and if there's something there, don't touch it, etc.

    I hope this helps,

    Gerben Rienk
  • lindsay.stevenslindsay.stevens Posts: 404 ✭✭✭
    via Email
    great work Gerben, thanks
    Hi,




    This can be done, but it's not easy ;-)

    See the script above, which is a bit rough, but serves as a proof of
    concept.




    The idea is to take a RepeatingItemGroup with a set length of 10 rows, say
    Medication.

    You compose the URL for the REST and loop through the output. As opposed to
    the example on
    http://www.trialdatasolutions.com/tds/howto/itemsfromotherevents.jsp we
    must go one level deeper, because our ItemData can have more than one
    occurrence/ItemGroupRepeatKey. We use this to fill the array medNames. (We
    must use the ItemGroupRepeatKey, because we do not know in which order the
    REST-output is presented.)

    Now we have the array and for this example I made life easy and just noted
    the last bit of the ID of the input to copy the mednames into: input1102.

    To get the actual target, we prefix the OID of the RepeatingItemGroup, plus
    the index, which starts with 0, so we must subtract 1.




    As I said: this is just a proof of concept. In production you would like to
    check the actual Event, so you would know if a copy is needed and if yes,
    from which event to take the copy. Furthermore you would like to compare
    the values already present and if there's something there, don't touch it,
    etc.




    I hope this helps,




    Gerben Rienk
  • haenselhaensel Posts: 602 ✭✭✭
    This is indeed an interessting use case for the REST-API and Gerben's proof of concept is a good start. But don't forget to ensure that the script does not overwrite any value. There is a lot work to do until this is bullet-proof and I'm really interessted in seeing the result.

    Regards,
    Christian
This discussion has been closed.