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

[Developers] Age calculation

Hi Mithun,

I attached to this email a rule that will calculate the patient's age by calculating the days between: Date of visit – Date of birth.

What bothers me is that I can't add this rule to the 'Add New Subject' pop up window. If it will be possible subjects that are not in the allowed age will not be added to the system. Or even better the age prevention could be automatically available after defining the allowed minimum and maximum subject age in the build study section.


Regards,


Liora Bosch - Hommfor
Clinical Data Manager
****************************************
A. Stein - Regulatory Affairs Consulting
Beit Hapaamon (Suite 102)
20 HaTaas Str. (P.O.B. 124)
Kfar Saba 44425 ISRAEL
Tel: +972-9-7670117
Fax: +972-9-7668534
E-mail: [email protected]
****************************************
Sent: Tuesday, February 14, 2012 5:04 PM
To: [email protected]; [email protected]
Subject: [Developers] Age calculation

Hi,

Please can you help me to derive the age from “Date of birth” and “date of assessment” fields.

I have 3 fields, DOB, DOA, and Age. The difference of DOB and DOA should reflect in Age text box. I am using date format of “dd/mm/yyyy”. I tried doing this using functions and also rules, but no success.


Kind Regards,
Mithun Sortur

Attachments:
1. DOB22to68.xml 1.0 KB

Comments

  • Dear M Manjula,

    Would this thread be of any help to you?

    https://mailman.openclinica.com/pipermail/developers/2012-February/003674.html

    Best, Tom

    Tom Hickerson | Senior Tier-2 Engineer
    [email protected]
    Register now for the 2012 OpenClinica Conference!
    http://community.openclinica.com/conference
    Sent: Mon 2/27/2012 6:58
    To: users; [email protected]
    Subject: [Developers] AGE Calculation
    Hi All,
    Can someone please help me,
    How to do age calculation in OC. I have tried IEDAT – BRTHDAT. But I didn’t get proper age calculation.




    Thanks & Regards,
    Manjula. M

    ******************* CAUTION ******************* This e-mail is intended exclusively for the individual(s) to whom it is addressed and may contain information that is PRIVILEGED and CONFIDENTIAL. If you are not the intended recipient, please notify the sender and delete the original message. Further, you are not to copy, disclose or disseminate this e-mail or the information contained to any other person and any such actions are unlawful. Zifo Technologies has taken every reasonable precaution to ensure that this e-mail and attachment(s) has been swept for viruses, but is not liable for any damage you may sustain as a result of any virus in this e-mail. You should carry out your own virus checks before opening the e-mail or attachment(s). Zifo Technologies is neither liable for the proper and complete transmission of the information contained in this e-mail nor for any delay in its receipt. *************************************************
  • 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
    >
    >
    >
  • 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
This discussion has been closed.