Summary

This article covers a script example to calculate age.

Table of Contents


Description

This script takes inputs of birth date and an informed consent date and calculates the age of the patient in years. That age is then assigned to a field within the casebook. The first part of the script checks to make sure that the birth date and visit date questions are set. Next, the script uses the dateDiff command to calculate the difference between the two dates and then assigns the new calculated number to the age question.

Note: Please note the second instance of the ‘assign’ command. This is necessary to assign a blank value if the dependent question is not set.


Script

<script scriptId="set-age">
    <body>
        <s:if>
            <s:and>
                <s:isSet>
                    <s:question>
                        <s:question path="/baseline/dm.dobdtc"/>
                    </s:question>
                </s:isSet>
                <s:isSet>
                    <s:question>
                        <s:question path="/baseline/ic.icdtc"/>
                    </s:question>
                </s:isSet>
            </s:and>
            <s:assign>
                <s:question path="/baseline/dm.age"/>
                <s:toString>
                    <s:dateDiff unit="year" method="integer" last="hour">
                        <s:from>
                            <s:datePath path="/baseline/dm.dobdtc:value"/>
                        </s:from>
                        <s:to>
                            <s:datePath path="/baseline/ic.icdtc:value"/>
                        </s:to>
                    </s:dateDiff>
                </s:toString>
            </s:assign>
            <s:assign>
                <s:question path="/baseline/dm.age"/>
                <s:string value="" />
            </s:assign>
        </s:if>
    </body>
    <target typeId="dobdtc" when="preprocess" shouldReconcile="true"/>
    <target typeId="icdtc" when="preprocess" shouldReconcile="true"/>
</script>



Need more help?

Please visit the Fountayn Contact Information page.