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

Age calculation

2

Comments

  • sderiddersderidder Posts: 57
    Hi,
    Xdate.js, sounds interesting, I'll look it up. I guess you'd have to download it, store it on the server and refer to it?
    By the way, I discovered a small (but fatal) problem in my script. Apparently the age did get calculated but did not get saved to the database. I did some searching through a form's source code and apparently an onChange event has to be fired for the field for the data to actually get stored. So after the :
    // set outcome field to age
    $("#input2439").val(age);
    Add the line
    $("#input2439").change();
    Sorry about that.
    Cheers,
    Sander
    -----Original Message-----
    Sent: 05 April 2012 13:48
    To: [email protected]
    Subject: Developers Digest, Vol 235, Issue 10
    Send Developers mailing list submissions to
    [email protected]
    To subscribe or unsubscribe via the World Wide Web, visit
    https://mailman.openclinica.com/listinfo/developers
    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 Developers digest..."
    Today's Topics:
    1. Re: Age calculation (Anton Gr?nberg)
    2. suggestion for -ws: remove schemaLocation (Christian Samsel)
    3. Re: suggestion for -ws: remove schemaLocation (Christian Samsel)
    ----------------------------------------------------------------------
    Message: 1
    Date: Wed, 4 Apr 2012 19:07:08 +0200
    From: Anton Gr?nberg
    To: "[email protected]"
    Cc: "[email protected]" ,
    "[email protected]"
    Subject: Re: [Developers] Age calculation
    Message-ID:
    <[email protected]>
    Content-Type: text/plain; charset="utf-8"
    Hi
    You could use xdate.js which is much easier for date and time calculations.
    Best Regards
    Toni
    Am 04.04.2012 um 17:13 schrieb "Ridder, S. de" :
    > > Hi Mithun,
    > >
    > > I had pretty much the same problem (2 date fields and the age which has to be calculated). To tackle the problem I created the following script:
    > >
    > >
    > > var months = ["jan", "feb", "mar", "apr", "may", "jun", "jul",
    > > "aug", "sep", "oct", "nov", "dec"];
    > >
    > > jQuery(document).ready(function($) {
    > > function calculateAge(){
    > > // retrieve values from the two date fields
    > > var value = $("#input2437").val();
    > > var value2 = $("#input2438").val();
    > >
    > > // check whether both fields are filled
    > > if(value!="" && value2!=""){
    > >
    > > // split and deterimine day month and year of birthday
    > > var splitString = value.split("-");
    > > var day1 = splitString[0];
    > > var year1 = splitString[2];
    > > var mon1 = months.indexOf(splitString[1].toLowerCase())+1;
    > >
    > > // split and deterimine day month and year of other field
    > > splitString = value2.split("-");
    > > var day2 = splitString[0];
    > > var year2 = splitString[2];
    > > var mon2 = months.indexOf(splitString[1].toLowerCase())+1;
    > >
    > > // calculate age
    > > var age=year2-year1;
    > > if((mon2==mon1 && day2 > // set outcome field to age
    > > $("#input2439").val(age);
    > > }
    > > }
    > >
    > > // fire when save is pressed
    > > $("#srl").focus(function(){
    > > calculateAge();
    > > });
    > >
    > > });
    > >
    > >
    > > So basically what this does is, when the save button ($("#srl")) is pressed, it:
    > > 1) retrieves the value at the date of birth field $("#input2437")
    > > 2) retrieves the value at the second date field $("#input2438")
    > > 3) splits the fields using ?-?
    > > 4) extracts the day and year and converts the month to a number
    > > 5) calculates the age
    > > 6) writes the age to the output field $("#input2439")
    > >
    > > To find the identifiers I used a different script:
    > >
    > >
    > > jQuery(document).ready(function($) {
    > > $("input").focus(function(){
    > > alert($(this).attr('id'));
    > > });
    > > });
    > >
    > >
    > > Using that script you can click on the relevant fields to find the IDs.
    > > Perhaps there are easier solutions, but this is the first time I?ve used jQuery. Wrote and tested it today and (so far) it seems to do the trick.
    > >
    > > Cheers,
    > > Sander
    > >
    > > Sander de Ridder
    > > MSc Informatica, MSc Bioinformatica
    > > VU University Medical Centre
    > >
    > >
  • sderiddersderidder Posts: 57
    Hi,
    Xdate.js, sounds interesting, I'll look it up. I guess you'd have to download it, store it on the server and refer to it?
    By the way, I discovered a small (but fatal) problem in my script. Apparently the age did get calculated but did not get saved to the database. I did some searching through a form's source code and apparently an onChange event has to be fired for the field for the data to actually get stored. So after the :
    // set outcome field to age
    $("#input2439").val(age);
    Add the line
    $("#input2439").change();
    Sorry about that.
    Cheers,
    Sander
    -----Original Message-----
    Sent: 05 April 2012 13:48
    To: [email protected]
    Subject: Developers Digest, Vol 235, Issue 10
    Send Developers mailing list submissions to
    [email protected]
    To subscribe or unsubscribe via the World Wide Web, visit
    https://mailman.openclinica.com/listinfo/developers
    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 Developers digest..."
    Today's Topics:
    1. Re: Age calculation (Anton Gr?nberg)
    2. suggestion for -ws: remove schemaLocation (Christian Samsel)
    3. Re: suggestion for -ws: remove schemaLocation (Christian Samsel)
    ----------------------------------------------------------------------
    Message: 1
    Date: Wed, 4 Apr 2012 19:07:08 +0200
    From: Anton Gr?nberg
    To: "[email protected]"
    Cc: "[email protected]" ,
    "[email protected]"
    Subject: Re: [Developers] Age calculation
    Message-ID:
    <[email protected]>
    Content-Type: text/plain; charset="utf-8"
    Hi
    You could use xdate.js which is much easier for date and time calculations.
    Best Regards
    Toni
    Am 04.04.2012 um 17:13 schrieb "Ridder, S. de" :
    > > Hi Mithun,
    > >
    > > I had pretty much the same problem (2 date fields and the age which has to be calculated). To tackle the problem I created the following script:
    > >
    > >
    > > var months = ["jan", "feb", "mar", "apr", "may", "jun", "jul",
    > > "aug", "sep", "oct", "nov", "dec"];
    > >
    > > jQuery(document).ready(function($) {
    > > function calculateAge(){
    > > // retrieve values from the two date fields
    > > var value = $("#input2437").val();
    > > var value2 = $("#input2438").val();
    > >
    > > // check whether both fields are filled
    > > if(value!="" && value2!=""){
    > >
    > > // split and deterimine day month and year of birthday
    > > var splitString = value.split("-");
    > > var day1 = splitString[0];
    > > var year1 = splitString[2];
    > > var mon1 = months.indexOf(splitString[1].toLowerCase())+1;
    > >
    > > // split and deterimine day month and year of other field
    > > splitString = value2.split("-");
    > > var day2 = splitString[0];
    > > var year2 = splitString[2];
    > > var mon2 = months.indexOf(splitString[1].toLowerCase())+1;
    > >
    > > // calculate age
    > > var age=year2-year1;
    > > if((mon2==mon1 && day2 > // set outcome field to age
    > > $("#input2439").val(age);
    > > }
    > > }
    > >
    > > // fire when save is pressed
    > > $("#srl").focus(function(){
    > > calculateAge();
    > > });
    > >
    > > });
    > >
    > >
    > > So basically what this does is, when the save button ($("#srl")) is pressed, it:
    > > 1) retrieves the value at the date of birth field $("#input2437")
    > > 2) retrieves the value at the second date field $("#input2438")
    > > 3) splits the fields using ?-?
    > > 4) extracts the day and year and converts the month to a number
    > > 5) calculates the age
    > > 6) writes the age to the output field $("#input2439")
    > >
    > > To find the identifiers I used a different script:
    > >
    > >
    > > jQuery(document).ready(function($) {
    > > $("input").focus(function(){
    > > alert($(this).attr('id'));
    > > });
    > > });
    > >
    > >
    > > Using that script you can click on the relevant fields to find the IDs.
    > > Perhaps there are easier solutions, but this is the first time I?ve used jQuery. Wrote and tested it today and (so far) it seems to do the trick.
    > >
    > > Cheers,
    > > Sander
    > >
    > > Sander de Ridder
    > > MSc Informatica, MSc Bioinformatica
    > > VU University Medical Centre
    > >
    > >
  • sderiddersderidder Posts: 57
    Hi,
    Together with Gerben Rienk we've improved the age calculation script and he's created a page at the OC User Manual wiki:
    http://en.wikibooks.org/wiki/OpenClinica_User_Manual/AgeField
    It contains the script as well as an explanation. Suggestions and remarks are, of course, very welcome.
    Cheers,
    Sander
    MSc Computer Science, MSc Bioinformatics
    VU University Medical Centre
    Department of Pathology
  • sderiddersderidder Posts: 57
    Hi,
    Together with Gerben Rienk we've improved the age calculation script and he's created a page at the OC User Manual wiki:
    http://en.wikibooks.org/wiki/OpenClinica_User_Manual/AgeField
    It contains the script as well as an explanation. Suggestions and remarks are, of course, very welcome.
    Cheers,
    Sander
    MSc Computer Science, MSc Bioinformatics
    VU University Medical Centre
    Department of Pathology
  • Thank you Toni, Gerben and Sander for your efforts. It is really helpful.


    Kind Regards,
    Mithun Sortur
    Sent: 04 April 2012 16:14
    To: [email protected]
    Cc: [email protected]
    Subject: Re: [Users] Age calculation

    Hi Mithun,

    I had pretty much the same problem (2 date fields and the age which has to be calculated). To tackle the problem I created the following script:


    var months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];

    jQuery(document).ready(function($) {
    function calculateAge(){
    // retrieve values from the two date fields
    var value = $("#input2437").val();
    var value2 = $("#input2438").val();

    // check whether both fields are filled
    if(value!="" && value2!=""){

    // split and deterimine day month and year of birthday
    var splitString = value.split("-");
    var day1 = splitString[0];
    var year1 = splitString[2];
    var mon1 = months.indexOf(splitString[1].toLowerCase())+1;

    // split and deterimine day month and year of other field
    splitString = value2.split("-");
    var day2 = splitString[0];
    var year2 = splitString[2];
    var mon2 = months.indexOf(splitString[1].toLowerCase())+1;

    // calculate age
    var age=year2-year1;
    if((mon2==mon1 && day2

    So basically what this does is, when the save button ($("#srl")) is pressed, it:
    1) retrieves the value at the date of birth field $("#input2437")
    2) retrieves the value at the second date field $("#input2438")
    3) splits the fields using “-“
    4) extracts the day and year and converts the month to a number
    5) calculates the age
    6) writes the age to the output field $("#input2439")

    To find the identifiers I used a different script:


    jQuery(document).ready(function($) {
    $("input").focus(function(){
    alert($(this).attr('id'));
    });
    });


    Using that script you can click on the relevant fields to find the IDs.
    Perhaps there are easier solutions, but this is the first time I’ve used jQuery. Wrote and tested it today and (so far) it seems to do the trick.

    Cheers,
    Sander

    Sander de Ridder
    MSc Informatica, MSc Bioinformatica
    VU University Medical Centre
  • willilx9willilx9 Posts: 40
    Do you have the Excel sheet that demonstrates how to use the script?
    Sent: Wednesday, April 04, 2012 8:15 AM
    To: [email protected]
    Cc: [email protected]
    Subject: Re: [Developers] Age calculation

    Hi Mithun,

    I had pretty much the same problem (2 date fields and the age which has to be calculated). To tackle the problem I created the following script:


    var months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];

    jQuery(document).ready(function($) {
    function calculateAge(){
    // retrieve values from the two date fields
    var value = $("#input2437").val();
    var value2 = $("#input2438").val();

    // check whether both fields are filled
    if(value!="" && value2!=""){

    // split and deterimine day month and year of birthday
    var splitString = value.split("-");
    var day1 = splitString[0];
    var year1 = splitString[2];
    var mon1 = months.indexOf(splitString[1].toLowerCase())+1;

    // split and deterimine day month and year of other field
    splitString = value2.split("-");
    var day2 = splitString[0];
    var year2 = splitString[2];
    var mon2 = months.indexOf(splitString[1].toLowerCase())+1;

    // calculate age
    var age=year2-year1;
    if((mon2==mon1 && day2

    So basically what this does is, when the save button ($("#srl")) is pressed, it:
    1) retrieves the value at the date of birth field $("#input2437")
    2) retrieves the value at the second date field $("#input2438")
    3) splits the fields using “-“
    4) extracts the day and year and converts the month to a number
    5) calculates the age
    6) writes the age to the output field $("#input2439")

    To find the identifiers I used a different script:


    jQuery(document).ready(function($) {
    $("input").focus(function(){
    alert($(this).attr('id'));
    });
    });


    Using that script you can click on the relevant fields to find the IDs.
    Perhaps there are easier solutions, but this is the first time I’ve used jQuery. Wrote and tested it today and (so far) it seems to do the trick.

    Cheers,
    Sander

    Sander de Ridder
    MSc Informatica, MSc Bioinformatica
    VU University Medical Centre
  • shamiltonshamilton Posts: 4
    Hi everyone,
    I am using the age calculation script found on the wikibooks link in order to calculate an age based on two fields – “Patient DOB” and a “Date Form Completed.” I have the calculated age field hidden, but I’ve found that the derived age is only saving to the database if I unhide the field. Any thoughts as to why this may be happening, or if there is another way to calculate age?
    Thanks!
    Stephanie Hamilton
    Assistant Manager, Clinical Affairs
    Myriad Genetic Laboratories, Inc.
  • vic-avic-a Posts: 20
    Stephanie,
    If this is an input field with type="hidden" , don't see why it would not save on submit.
    Do you want to share with your field looks like?
    Thanks
    Vic
    On Tue, Oct 1, 2013 at 1:22 PM, Stephanie Hamilton wrote:
    Hi everyone,
    I am using the age calculation script found on the wikibooks link in order to calculate an age based on two fields – “Patient DOB” and a “Date Form Completed.” I have the calculated age field hidden, but I’ve found that the derived age is only saving to the database if I unhide the field. Any thoughts as to why this may be happening, or if there is another way to calculate age?
    Thanks!
    Stephanie Hamilton
    Assistant Manager, Clinical Affairs
    Myriad Genetic Laboratories, Inc.
  • yfarooqyfarooq Posts: 41
    Hi Stephanie,
    which method are you using to hide?
    On Tue, Oct 1, 2013 at 9:22 PM, Stephanie Hamilton wrote:
    Hi everyone,
    I am using the age calculation script found on the wikibooks link in order to calculate an age based on two fields – “Patient DOB” and a “Date Form Completed.” I have the calculated age field hidden, but I’ve found that the derived age is only saving to the database if I unhide the field. Any thoughts as to why this may be happening, or if there is another way to calculate age?
    Thanks!
    Stephanie Hamilton
    Assistant Manager, Clinical Affairs
    Myriad Genetic Laboratories, Inc.
  • shamiltonshamilton Posts: 4
    Hi,
    I am using the “Hide” option in the “ITEM_DISPLAY_STATUS” column in the actual CRF.

    On the Sections tab, I have copied the script from the wikibooks page in the Instructions field for that section.
    On the Items tab, I have these entries:
    DESCRIPTION_LABEL

    LEFT_ITEM_TEXT
    Today's Date

    Today's Date:
    Patient's Date of Birth

    Patient's Date of Birth:
    Patient's Age Derived

    Derived Age:


    I appreciate your feedback!
    Stephanie
    Sent: Tuesday, October 01, 2013 3:11 PM
    To: [email protected]
    Subject: Re: [Users] Age calculation

    Hi Stephanie,

    which method are you using to hide?

    On Tue, Oct 1, 2013 at 9:22 PM, Stephanie Hamilton wrote:
    Hi everyone,
    I am using the age calculation script found on the wikibooks link in order to calculate an age based on two fields – “Patient DOB” and a “Date Form Completed.” I have the calculated age field hidden, but I’ve found that the derived age is only saving to the database if I unhide the field. Any thoughts as to why this may be happening, or if there is another way to calculate age?
    Thanks!
    Stephanie Hamilton
    Assistant Manager, Clinical Affairs
    Myriad Genetic Laboratories, Inc.
This discussion has been closed.