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

Character limit problem

Hi all,

I'm trying to use the script to calculate an age by using the script given by Gerben Rienk on http://en.wikibooks.org/wiki/OpenClinica_User_Manual/AgeField
The problem I have is that the lenght of the script exceeds 2000 characters. Is there a work-around or am i missing something?

Thanks in advance for your advice.


Laurens Groenendijkj

Comments

  • sderiddersderidder Posts: 57
    Hi Laurens,
    Yes there are some workarounds:
    * Remove the unnecessary white spaces at the start of the sentences
    Many of the lines start with something like code
    The spaces are not really relevant for the functionality and removing them can save you quite some characters
    * Change the variable names to shorter ones
    E.g. change var dateOfBirth to var d (and all the references as well of course).
    Based on some code I wrote for Maryam a couple of days ago and http://stackoverflow.com/questions/4060004/calculate-age-in-javascript, I rewrote the age calculation. It's probably an improvement. I tested it this morning and it seems to work so far:

    var months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
    jQuery(document).ready(function($) {
    var fieldDate1 = $("#dob").parent().parent().find("input");
    var fieldDate2 = $("#date2").parent().parent().find("input");
    var fieldAge = $("#age").parent().parent().find("input");
    fieldAge.attr("readonly",true);
    $("#seh").focus();
    function parseDate(input){
    var parts = input.split("-");
    // year, month, day
    var myDate = new Date(parts[2], months.indexOf(parts[1].toLowerCase()), parts[0])
    return myDate;
    }
    function calculateAge(birthDate, aDate){
    var age = aDate.getFullYear() - birthDate.getFullYear();
    var m = aDate.getMonth() - birthDate.getMonth();
    if (m < 0 || (m === 0 && aDate.getDate() < birthDate.getDate())) {
    age--;
    }
    return age;
    }
    function calcAge(){
    // retrieve values from the two date fields
    var strDate1 = fieldDate1.val();
    var strDate2 = fieldDate2.val();
    var curAge="";
    var age="";
    if(fieldAge.val()!=="") curAge = Number(fieldAge.val());

    // check whether both fields are filled
    if(strDate1!=="" && strDate2!==""){
    age = Number(calculateAge(parseDate(strDate1), parseDate(strDate2)));
    }
    if(curAge !== age){
    // set outcome field to age
    fieldAge.val(age);
    fieldAge.change();
    }
    }
    fieldDate1.blur(function(){
    calcAge();
    });
    fieldDate2.blur(function(){
    calcAge();
    });
    $("#srl").focus(function(){
    calcAge();
    });
    $("#srh").focus(function(){
    calcAge();
    });
    });

    Finally, if your date of birth is also present in the header of your CRF, you can also access that information (in which case you won't have to create the dob field in your CRF).
    var dob = $("#CRF_infobox_open").find("table :first").children("tr:nth-child(2)").find("table :first").children("tr:nth-child(3)").children("td:nth-child(4)").text();
    var strDate1 = $.trim(dob);
    Cheers,
    Sander
    -----Original Message-----
    Sent: 22 November 2012 18:00
    To: [email protected]
    Subject: Users Digest, Vol 80, Issue 35
    Send Users mailing list submissions to
    [email protected]
    To subscribe or unsubscribe via the World Wide Web, visit
    https://mailman.openclinica.com/listinfo/users
    or, via email, send a message with subject or body 'help' to
    [email protected]
    You can reach the person managing the list at
    [email protected]
    When replying, please edit your Subject line so it is more specific than "Re: Contents of Users digest..."
    Today's Topics:
    1. (no subject) (L. Groenendijk)
    2. Character limit problem (L. Groenendijk)
    ----------------------------------------------------------------------
    Message: 1
    Date: Thu, 22 Nov 2012 09:00:23 +0000
    From: "L. Groenendijk"
    To: "[email protected]"
    Subject: [Users] (no subject)
    Message-ID:

    Content-Type: text/plain; charset="us-ascii"
    Hi all,
    I'm trying to use the script to calculate an age by using the script given by Gerben Rienk on http://en.wikibooks.org/wiki/OpenClinica_User_Manual/AgeField
    The problem I have is that the lenght of the script exceeds 2000 characters. Is there a work-around or am i missing something?
    Thanks in advance for your advice.
    Laurens Groenendijkj
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL:
    ------------------------------
    Message: 2
    Date: Thu, 22 Nov 2012 09:38:53 +0000
    From: "L. Groenendijk"
    To: "'[email protected]'"
    Subject: [Users] Character limit problem
    Message-ID:

    Content-Type: text/plain; charset="us-ascii"
    Hi all,
    I'm trying to use the script to calculate an age by using the script given by Gerben Rienk on http://en.wikibooks.org/wiki/OpenClinica_User_Manual/AgeField
    The problem I have is that the lenght of the script exceeds 2000 characters. Is there a work-around or am i missing something?
    Thanks in advance for your advice.
    Laurens Groenendijkj
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL:
    ------------------------------
  • Dear Sander and Laurens,
    Rather than manually modifying the Javascript, I'd suggest an automated javascript 'minifyer', such as http://jscompress.com/ (other minifyers: http://stackoverflow.com/questions/1737388/how-to-minify-javascript-code and http://closure-compiler.appspot.com/home) . That gives an 844 char length output for the first example (measured using an online character counter http://www.javascriptkit.com/script/script2/charcount.shtml). Have you used one before?
    Yours,
    Michael
    -----Original Message-----
    Sent: 23 November 2012 09:02
    To: [email protected]
    Subject: Re: [Users] Character limit problem
    Hi Laurens,
    Yes there are some workarounds:
    * Remove the unnecessary white spaces at the start of the sentences Many of the lines start with something like code The spaces are not really relevant for the functionality and removing them can save you quite some characters
    * Change the variable names to shorter ones E.g. change var dateOfBirth to var d (and all the references as well of course).
    Based on some code I wrote for Maryam a couple of days ago and http://stackoverflow.com/questions/4060004/calculate-age-in-javascript, I rewrote the age calculation. It's probably an improvement. I tested it this morning and it seems to work so far:

    var months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
    jQuery(document).ready(function($) {
    var fieldDate1 = $("#dob").parent().parent().find("input");
    var fieldDate2 = $("#date2").parent().parent().find("input");
    var fieldAge = $("#age").parent().parent().find("input");
    fieldAge.attr("readonly",true);
    $("#seh").focus();
    function parseDate(input){
    var parts = input.split("-");
    // year, month, day
    var myDate = new Date(parts[2], months.indexOf(parts[1].toLowerCase()), parts[0])
    return myDate;
    }
    function calculateAge(birthDate, aDate){
    var age = aDate.getFullYear() - birthDate.getFullYear();
    var m = aDate.getMonth() - birthDate.getMonth();
    if (m < 0 || (m === 0 && aDate.getDate() < birthDate.getDate())) {
    age--;
    }
    return age;
    }
    function calcAge(){
    // retrieve values from the two date fields
    var strDate1 = fieldDate1.val();
    var strDate2 = fieldDate2.val();
    var curAge="";
    var age="";
    if(fieldAge.val()!=="") curAge = Number(fieldAge.val());
    // check whether both fields are filled
    if(strDate1!=="" && strDate2!==""){
    age = Number(calculateAge(parseDate(strDate1), parseDate(strDate2)));
    }
    if(curAge !== age){
    // set outcome field to age
    fieldAge.val(age);
    fieldAge.change();
    }
    }
    fieldDate1.blur(function(){
    calcAge();
    });
    fieldDate2.blur(function(){
    calcAge();
    });
    $("#srl").focus(function(){
    calcAge();
    });
    $("#srh").focus(function(){
    calcAge();
    });
    });

    Finally, if your date of birth is also present in the header of your CRF, you can also access that information (in which case you won't have to create the dob field in your CRF).
    var dob = $("#CRF_infobox_open").find("table :first").children("tr:nth-child(2)").find("table :first").children("tr:nth-child(3)").children("td:nth-child(4)").text();
    var strDate1 = $.trim(dob);
    Cheers,
    Sander
    -----Original Message-----
    Sent: 22 November 2012 18:00
    To: [email protected]
    Subject: Users Digest, Vol 80, Issue 35
    Send Users mailing list submissions to
    [email protected]
    To subscribe or unsubscribe via the World Wide Web, visit
    https://mailman.openclinica.com/listinfo/users
    or, via email, send a message with subject or body 'help' to
    [email protected]
    You can reach the person managing the list at
    [email protected]
    When replying, please edit your Subject line so it is more specific than "Re: Contents of Users digest..."
    Today's Topics:
    1. (no subject) (L. Groenendijk)
    2. Character limit problem (L. Groenendijk)
    ----------------------------------------------------------------------
    Message: 1
    Date: Thu, 22 Nov 2012 09:00:23 +0000
    From: "L. Groenendijk"
    To: "[email protected]"
    Subject: [Users] (no subject)
    Message-ID:

    Content-Type: text/plain; charset="us-ascii"
    Hi all,
    I'm trying to use the script to calculate an age by using the script given by Gerben Rienk on http://en.wikibooks.org/wiki/OpenClinica_User_Manual/AgeField
    The problem I have is that the lenght of the script exceeds 2000 characters. Is there a work-around or am i missing something?
    Thanks in advance for your advice.
    Laurens Groenendijkj
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL:
    ------------------------------
    Message: 2
    Date: Thu, 22 Nov 2012 09:38:53 +0000
    From: "L. Groenendijk"
    To: "'[email protected]'"
    Subject: [Users] Character limit problem
    Message-ID:

    Content-Type: text/plain; charset="us-ascii"
    Hi all,
    I'm trying to use the script to calculate an age by using the script given by Gerben Rienk on http://en.wikibooks.org/wiki/OpenClinica_User_Manual/AgeField
    The problem I have is that the lenght of the script exceeds 2000 characters. Is there a work-around or am i missing something?
    Thanks in advance for your advice.
    Laurens Groenendijkj
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL:
    ------------------------------
  • sderiddersderidder Posts: 57
    Hi Michael,
    Actually, no I have never used one before; I had never even heard of the word minifyer. For me personally the downside would be that debugging the translated code is a bit of a nightmare. But to save characters it's definitely way more efficient (and fault proof) than doing in manually.
    Cheers,
    Sander
    -----Original Message-----
    Sent: 23 November 2012 18:00
    To: [email protected]
    Subject: Users Digest, Vol 80, Issue 36
    Send Users mailing list submissions to
    [email protected]
    To subscribe or unsubscribe via the World Wide Web, visit
    https://mailman.openclinica.com/listinfo/users
    or, via email, send a message with subject or body 'help' to
    [email protected]
    You can reach the person managing the list at
    [email protected]
    When replying, please edit your Subject line so it is more specific than "Re: Contents of Users digest..."
    Today's Topics:
    1. Re: Character limit problem (Ridder, S. de)
    2. Re: Character limit problem (Michael Bluett)
    ----------------------------------------------------------------------
    Message: 1
    Date: Fri, 23 Nov 2012 09:02:18 +0000
    From: "Ridder, S. de"
    To: "[email protected]"
    Subject: Re: [Users] Character limit problem
    Message-ID:

    Content-Type: text/plain; charset="us-ascii"
    Hi Laurens,
    Yes there are some workarounds:
    * Remove the unnecessary white spaces at the start of the sentences Many of the lines start with something like code The spaces are not really relevant for the functionality and removing them can save you quite some characters
    * Change the variable names to shorter ones E.g. change var dateOfBirth to var d (and all the references as well of course).
    Based on some code I wrote for Maryam a couple of days ago and http://stackoverflow.com/questions/4060004/calculate-age-in-javascript, I rewrote the age calculation. It's probably an improvement. I tested it this morning and it seems to work so far:

    var months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
    jQuery(document).ready(function($) {
    var fieldDate1 = $("#dob").parent().parent().find("input");
    var fieldDate2 = $("#date2").parent().parent().find("input");
    var fieldAge = $("#age").parent().parent().find("input");
    fieldAge.attr("readonly",true);
    $("#seh").focus();
    function parseDate(input){
    var parts = input.split("-");
    // year, month, day
    var myDate = new Date(parts[2], months.indexOf(parts[1].toLowerCase()), parts[0])
    return myDate;
    }
    function calculateAge(birthDate, aDate){
    var age = aDate.getFullYear() - birthDate.getFullYear();
    var m = aDate.getMonth() - birthDate.getMonth();
    if (m < 0 || (m === 0 && aDate.getDate() < birthDate.getDate())) {
    age--;
    }
    return age;
    }
    function calcAge(){
    // retrieve values from the two date fields
    var strDate1 = fieldDate1.val();
    var strDate2 = fieldDate2.val();
    var curAge="";
    var age="";
    if(fieldAge.val()!=="") curAge = Number(fieldAge.val());

    // check whether both fields are filled
    if(strDate1!=="" && strDate2!==""){
    age = Number(calculateAge(parseDate(strDate1), parseDate(strDate2)));
    }
    if(curAge !== age){
    // set outcome field to age
    fieldAge.val(age);
    fieldAge.change();
    }
    }
    fieldDate1.blur(function(){
    calcAge();
    });
    fieldDate2.blur(function(){
    calcAge();
    });
    $("#srl").focus(function(){
    calcAge();
    });
    $("#srh").focus(function(){
    calcAge();
    });
    });

    Finally, if your date of birth is also present in the header of your CRF, you can also access that information (in which case you won't have to create the dob field in your CRF).
    var dob = $("#CRF_infobox_open").find("table :first").children("tr:nth-child(2)").find("table :first").children("tr:nth-child(3)").children("td:nth-child(4)").text();
    var strDate1 = $.trim(dob);
    Cheers,
    Sander
    -----Original Message-----
    Sent: 22 November 2012 18:00
    To: [email protected]
    Subject: Users Digest, Vol 80, Issue 35
    Send Users mailing list submissions to
    [email protected]
    To subscribe or unsubscribe via the World Wide Web, visit
    https://mailman.openclinica.com/listinfo/users
    or, via email, send a message with subject or body 'help' to
    [email protected]
    You can reach the person managing the list at
    [email protected]
    When replying, please edit your Subject line so it is more specific than "Re: Contents of Users digest..."
    Today's Topics:
    1. (no subject) (L. Groenendijk)
    2. Character limit problem (L. Groenendijk)
    ----------------------------------------------------------------------
    Message: 1
    Date: Thu, 22 Nov 2012 09:00:23 +0000
    From: "L. Groenendijk"
    To: "[email protected]"
    Subject: [Users] (no subject)
    Message-ID:

    Content-Type: text/plain; charset="us-ascii"
    Hi all,
    I'm trying to use the script to calculate an age by using the script given by Gerben Rienk on http://en.wikibooks.org/wiki/OpenClinica_User_Manual/AgeField
    The problem I have is that the lenght of the script exceeds 2000 characters. Is there a work-around or am i missing something?
    Thanks in advance for your advice.
    Laurens Groenendijkj
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL:
    ------------------------------
    Message: 2
    Date: Thu, 22 Nov 2012 09:38:53 +0000
    From: "L. Groenendijk"
    To: "'[email protected]'"
    Subject: [Users] Character limit problem
    Message-ID:

    Content-Type: text/plain; charset="us-ascii"
    Hi all,
    I'm trying to use the script to calculate an age by using the script given by Gerben Rienk on http://en.wikibooks.org/wiki/OpenClinica_User_Manual/AgeField
    The problem I have is that the lenght of the script exceeds 2000 characters. Is there a work-around or am i missing something?
    Thanks in advance for your advice.
    Laurens Groenendijkj
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL:
    ------------------------------
  • Dear Sander and Michael,
    Thank you for your excelent help!
    Laurens
    -----Original Message-----
    Sent: vrijdag 23 november 2012 10:02
    To: [email protected]
    Subject: Re: [Users] Character limit problem
    Hi Laurens,
    Yes there are some workarounds:
    * Remove the unnecessary white spaces at the start of the sentences Many of the lines start with something like code The spaces are not really relevant for the functionality and removing them can save you quite some characters
    * Change the variable names to shorter ones E.g. change var dateOfBirth to var d (and all the references as well of course).
    Based on some code I wrote for Maryam a couple of days ago and http://stackoverflow.com/questions/4060004/calculate-age-in-javascript, I rewrote the age calculation. It's probably an improvement. I tested it this morning and it seems to work so far:

    var months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
    jQuery(document).ready(function($) {
    var fieldDate1 = $("#dob").parent().parent().find("input");
    var fieldDate2 = $("#date2").parent().parent().find("input");
    var fieldAge = $("#age").parent().parent().find("input");
    fieldAge.attr("readonly",true);
    $("#seh").focus();
    function parseDate(input){
    var parts = input.split("-");
    // year, month, day
    var myDate = new Date(parts[2], months.indexOf(parts[1].toLowerCase()), parts[0])
    return myDate;
    }
    function calculateAge(birthDate, aDate){
    var age = aDate.getFullYear() - birthDate.getFullYear();
    var m = aDate.getMonth() - birthDate.getMonth();
    if (m < 0 || (m === 0 && aDate.getDate() < birthDate.getDate())) {
    age--;
    }
    return age;
    }
    function calcAge(){
    // retrieve values from the two date fields
    var strDate1 = fieldDate1.val();
    var strDate2 = fieldDate2.val();
    var curAge="";
    var age="";
    if(fieldAge.val()!=="") curAge = Number(fieldAge.val());

    // check whether both fields are filled
    if(strDate1!=="" && strDate2!==""){
    age = Number(calculateAge(parseDate(strDate1), parseDate(strDate2)));
    }
    if(curAge !== age){
    // set outcome field to age
    fieldAge.val(age);
    fieldAge.change();
    }
    }
    fieldDate1.blur(function(){
    calcAge();
    });
    fieldDate2.blur(function(){
    calcAge();
    });
    $("#srl").focus(function(){
    calcAge();
    });
    $("#srh").focus(function(){
    calcAge();
    });
    });

    Finally, if your date of birth is also present in the header of your CRF, you can also access that information (in which case you won't have to create the dob field in your CRF).
    var dob = $("#CRF_infobox_open").find("table :first").children("tr:nth-child(2)").find("table :first").children("tr:nth-child(3)").children("td:nth-child(4)").text();
    var strDate1 = $.trim(dob);
    Cheers,
    Sander
    -----Original Message-----
    Sent: 22 November 2012 18:00
    To: [email protected]
    Subject: Users Digest, Vol 80, Issue 35
    Send Users mailing list submissions to
    [email protected]
    To subscribe or unsubscribe via the World Wide Web, visit
    https://mailman.openclinica.com/listinfo/users
    or, via email, send a message with subject or body 'help' to
    [email protected]
    You can reach the person managing the list at
    [email protected]
    When replying, please edit your Subject line so it is more specific than "Re: Contents of Users digest..."
    Today's Topics:
    1. (no subject) (L. Groenendijk)
    2. Character limit problem (L. Groenendijk)
    ----------------------------------------------------------------------
    Message: 1
    Date: Thu, 22 Nov 2012 09:00:23 +0000
    From: "L. Groenendijk"
    To: "[email protected]"
    Subject: [Users] (no subject)
    Message-ID:

    Content-Type: text/plain; charset="us-ascii"
    Hi all,
    I'm trying to use the script to calculate an age by using the script given by Gerben Rienk on http://en.wikibooks.org/wiki/OpenClinica_User_Manual/AgeField
    The problem I have is that the lenght of the script exceeds 2000 characters. Is there a work-around or am i missing something?
    Thanks in advance for your advice.
    Laurens Groenendijkj
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL:
    ------------------------------
    Message: 2
    Date: Thu, 22 Nov 2012 09:38:53 +0000
    From: "L. Groenendijk"
    To: "'[email protected]'"
    Subject: [Users] Character limit problem
    Message-ID:

    Content-Type: text/plain; charset="us-ascii"
    Hi all,
    I'm trying to use the script to calculate an age by using the script given by Gerben Rienk on http://en.wikibooks.org/wiki/OpenClinica_User_Manual/AgeField
    The problem I have is that the lenght of the script exceeds 2000 characters. Is there a work-around or am i missing something?
    Thanks in advance for your advice.
    Laurens Groenendijkj
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL:
    ------------------------------
This discussion has been closed.