31 Dec 2018: Thank you to our knowledgeable and friendly forums users for another great year. We are aware of the uptick in spam accounts and are doing our best to ban these at first sight. Thank you for your patience!

Token as DEFAULT_VALUE

I do Serious Adverse Event reporting via OpenClinica. I want to assign unique numbers to the SAE, in the form op SAE-(subjectID)-(SAEnr). I want to display these numbers in the CRF and save them in the database.

I've tried adding SAE-${studySubject}-${eventOrdinal} to the DEFAULT_VALUE and in the RESPONSE_VALUES_OR_CALCULATIONS column, but that doesn't render the information. I understand that tokens aren't parsed if they are in these columns, correct?

What would be the easiest way to do this? Do I need Javascript?

Comments

  • GerbenRienkGerbenRienk Posts: 793 ✭✭✭
    edited July 2016
    Hi,
    Your finding is correct: you can not use tokens in default_value or calculations and yes, you can use javascript to generate an SAE-ID.
    I've attached the xls to download, but the script is this:
    <div id="B"></div>
    <script src="includes/jmesa/jquery.min.js"></script>
    <script> $.noConflict();
    jQuery(document).ready(function($) {
    var fieldAEID = $("#B").parent().parent().find("input");
    //set the item read-ony
    fieldAEID.attr("readonly",true);
    //start with taking the event ordinal/number and adding 2 zero's
    var uniqueAEID = "00" + "${eventOrdinal}";
    //now take only the last 3 characters
    uniqueAEID = uniqueAEID.slice(-3);
    //and put the studysubjectID in front
    uniqueAEID = "SAE-" + "${studySubject}" + "-" + uniqueAEID;
    //define the function that sets the ID
    function setAEID(){
    //only do something if the ID is not correct already
    if (fieldAEID.val() != uniqueAEID){
    //set the value
    fieldAEID.val(uniqueAEID);
    //set the status of the item to changed, otherwise it will not be saved
    fieldAEID.change();
    }
    };
    //when the document is ready, run the function once
    setAEID();
    }) </script>
    Hope this helps,
    Gerben Rienk
  • koenvnkoenvn Posts: 9
    It works like a charm. Thank you so much!
Sign In or Register to comment.