Summary

This article covers a script example of checking absolute differences in dates.

Table of Contents


Description

This script ensures that the absolute difference between 2 dates is no more than 4 hours. The script first has to concatenate the date and time questions (for both the Holter Monitor Hook-Up and the First Contrast Injection) and then uses the toDate command to convert it to a date. It passes one date to the “from” parameter and one to the “to” parameter of the dateDiff command. It uses the abs command to get the absolute value of the difference between the two dates and then compares it to 240 mins (4 hours). Listing dependent question paths allow the script to trigger when a dependent variable existing on another form is updated with a new value.

Script

<script scriptId="absVal">
    <body>
        <s:alert>
            <s:expression>
                <s:or>
                    <s:not>
                        <s:isSet>
                            <s:question>
                                <s:question path=".hudt"/>
                            </s:question>
                        </s:isSet>
                    </s:not>
                    <s:not>
                        <s:isSet>
                            <s:question>
                                <s:question path=".hutime"/>
                            </s:question>
                        </s:isSet>
                    </s:not>
                    <s:not>
                        <s:isSet>
                            <s:question>
                                <s:question path=".fcon1dt"/>
                            </s:question>
                        </s:isSet>
                    </s:not>
                    <s:not>
                        <s:isSet>
                            <s:question>
                                <s:question path=".fcon1time"/>
                            </s:question>
                        </s:isSet>
                    </s:not>
                    <s:lte>
                        <s:abs>
                            <s:dateDiff unit="minute" method="integer">
                                <s:from>
                                    <s:toDate>
                                        <s:concat>
                                            <s:toString>
                                                <s:datePath type="date" path=".hudt:value"/>
                                                <s:string value="MM/dd/yyyy"/>
                                            </s:toString>
                                            <s:string value=" " />
                                            <s:toString>
                                                <s:datePath type="date" path=".hutime:value"/>
                                                <s:string value="HH:mm"/>
                                            </s:toString>
                                        </s:concat>
                                        <s:string value="MM/dd/yyyy HH:mm" />
                                    </s:toDate>
                                </s:from>
                                <s:to>
                                    <s:toDate>
                                        <s:concat>
                                            <s:toString>
                                                <s:datePath type="date" path=".fcon1dt:value"/>
                                                <s:string value="MM/dd/yyyy"/>
                                            </s:toString>
                                            <s:string value=" " />
                                            <s:toString>
                                                <s:datePath type="date" path=".fcon1time:value"/>
                                                <s:string value="HH:mm"/>
                                            </s:toString>
                                        </s:concat>
                                        <s:string value="MM/dd/yyyy HH:mm" />
                                    </s:toDate>
                                </s:to>
                            </s:dateDiff>
                        </s:abs>
                        <s:number value="240"/>
                    </s:lte>
                </s:or>
            </s:expression>
            <s:correction>
                <s:string value="optional"/>
            </s:correction>
            <s:text>
                <s:string value="The absolute difference between the 'Holter Monitor
                 Hook-Up' and the 'First Contrast Injection' should be no more than 4
                 hours.  Please verify."/>
            </s:text>
        </s:alert>
    </body>
    <target typeId="fcon1time" when="preprocess" shouldReconcile='true'/>
    <dependent path="/summary/ecgReport[n].hudt"/>
    <dependent path="/summary/ecgReport[n].hutime"/>
    <dependent path="/summary/ecgReport[n].fcon1dt"/>
</script>



Need more help?

Please visit the Fountayn Contact Information page.