Compare related instances
Check a value for a matching instance in a repeating form.
Rule description: severity (a radio control) must be different from the previous one for the same related Adverse Event (AENUM).
Rule expression
//variable declaration
var rc; //Radio Control - severity
var ins; //placeholder for Repeating Form instance
var outc=''; //placeholder for severity label value
var cnt=0; //counter variable
//function definition to identify number of instances matching the severity value
function functi(item,index)
{
if(item.deleted===false && item.value!==null && index!==(ins-1) && index<ins-1)
{
if(item.value===aenum1val) //Checks if the passed-in instance has a matching AE number value with the current instance
{
if(newsev[index]!==null && sevval!==null)
{
outc=JSON.parse(newsev[index].value)[0].label; //Retrieves label from severity selection made by the user in the related instance
if(outc===sevval) //Checks if the severity value in the related instance is matching in the current instance
{
cnt=cnt+1; //Updates the number of identified matching instances
}
else
{
cnt=cnt;
}
}
else
{
cnt=cnt;
}
}
else
{
cnt=cnt;
}
}
else
{
cnt=cnt;
}
}
try
{
//variable declaration
ins = GetCurrentRFInstance(); //Retrieves instance of the current AE form
var aenum1val=aenum1; //Adverse event number item
var sevval=getStringFromChoice(newsev1); //Variable for severity item to retrieve the label for the severity choice item selected by the user
rc=getValues('aenum','newsev'); //Gets values entered for AE number and severity items
if(rc===true && aenum1val!==null && sevval!==null && ins>1) //Checks if getValues function retrieved results array, if AE number and severity values are not null and if current instance is not the first instance of the form
{
aenum.forEach(functi); //Execute the function code for all AE number values entered in the form
if(cnt>0 )
{
return false; //System sends query when return false condition is met
}
else
{
return true;
}
}
else
{
return true;
}
}
catch(err)
{
setQueryMessage(err); //set query message to display an encountered error
return false; //System sends query when return false condition is met
}
Query: The new severity is the same as the previous one. Please check.
Definitions
- newsev
-
Created variable for the Severity item from rule description.
- aenum
-
Corresponds to the Adverse Event Number item from the rule description.
- GetCurrentRFInstance( )
-
Gets the form instance number of the current repeating form.
- getStringFromChoice( )
-
Converts selected label for the choice element (drop-down, radio buttons or checkboxes) to a string or a comma-separated value. Takes in the choice element as parameter.
- getValues( )
-
Fetches values for one or more variables across multiple visits, in an array format ordered by visits. In this case takes aenum and newsev variables described above.
- setQueryMessage( )
-
Specify dynamic query text passed in as a parameter.
- functi(item,index)
-
Function declared in code. Identifies number of instances matching the giving severity value.
Return value
Verification steps
- Using a subject for testing, go to the given visit and form
containing the iems to check, in this example the Adverse Event
number <
aenumval> and severity <sevval>in the specified repeating form instance. - Update the form items
aenumvalandsevvalas in the following table and verify the result is as listed:Step Notes Result a. In the first repeating form (1RF) instance enter the
aenumvalitem as '1' (AE1) and selectsevvalas 'Grade 1'.Only one repeating form instance. No query.
b. Go to a second repeating form (2RF) instance and enter the
aenumvalitem as '1' (AE1) and selectsevvalas 'Grade 1' (same as in previous step).Matching values in 1RF and 2RF: - 1RF:
- AE1
- Severity Grade 1
- 2RF:
- AE1
- Severity Grade 1
Query in 2RF.
c. Update
sevvalitem in 2RF instance as 'Grade 2'.Different values in 1RF and 2RF: - 1RF:
- AE1
- Severity Grade 1
- 2RF:
- AE1
- Severity Grade 2
No queries.
d. Update
sevvalitem in 2RF instance back as 'Grade 1'.Matching values in 1RF and 2RF: - 1RF:
- AE1
- Severity Grade 1
- 2RF:
- AE1
- Severity Grade 1
Query in 2RF.
e. Update
aenumvalitem in 2RF instance as '2' (AE2).Different values in 1RF and 2RF: - 1RF:
- AE1
- Severity Grade 1
- 2RF:
- AE2
- Severity Grade 1
No queries.
f. Create a thrid repeating form (3RF) instance and enter
aenumvalitem as '1' (AE1) andsevvalas 'Grade 1'.Matching values in 1RF and 3RF: - 1RF:
- AE1
- Severity Grade 1
- 2RF:
- AE2
- Severity Grade 1
- 3RF:
- AE1
- Severity Grade 1
Query in 3RF.
g. Update
aenumvalin 3RF as '3' (AE3).Different values in all repeating form instances: - 1RF:
- AE1
- Severity Grade 1
- 2RF:
- AE2
- Severity Grade 1
- 3RF:
- AE3
- Severity Grade 1
No queries.
h. Update the
aenumvalitem in 3RF as '2' (AE2).Matching values in 2RF and 3RF: - 1RF:
- AE1
- Severity Grade 1
- 2RF:
- AE2
- Severity Grade 1
- 3RF:
- AE2
- Severity Grade 1
Query in 3RF.
i. Update the
sevvalitem in 2RF as 'Grade 3'.Different values in all repeating form instances: - 1RF:
- AE1
- Severity Grade 1
- 2RF:
- AE2
- Severity Grade 3
- 3RF:
- AE2
- Severity Grade 1
No queries.
- 1RF:
Other examples
Example 4-28 The start date of the treatment must be after or the same as the stop date of treatment for the previous prescription of the same drug
var rc;
var ins;
var ind=-1;
var res='';
function functi(item,index)
{
if(item.deleted===false && item.value!==null && index!==(ins-1) && index<ins-1)
{
if(item.value===trtname1)
{
if(stpdt[index]!==null && stdt[ins-1]!==null)
{
if(getDatesCompareResult(stdt[ins-1].value,true,stpdt[index].value,true,'>='))
{
ind=1;
}
else{ ind = 0;}
}
}
}
}
ins = GetCurrentRFInstance();
rc=getValues("trtname","stdt","stpdt");
if(rc===true && ins!==1)
{
trtname.forEach(functi);
if(ind===0)
{
return false;
}
else { return true; }
}
else
{
return true;
}
Query message: Start date is prior to stop date of previous prescription. Please correct or confirm.
Parent topic: Repeating form examples