Rule FDAC085: Inconsistent value for --TEST within --TESTCD
Description: All values of Name of Measurement, Test or Examination (--TEST) should be the same for a given value of Short Name of Measurement, Test or Examination (--TESTCD)
The rule written in XQuery:
Explanation
- As before, lines 1-10 contain general comments and the necessary namespace declarations
- Uncomment lines 11-12 (and comment out lines 13-14) if you want to pass the define.xml path and name from your own application
- Lines 13 and 14 define.xml path and name, in this case from the native XML database.
- Line 16 starts iterating over all the dataset definitions in the define.xml
- Line 17: the name of the dataset is taken
- Line 18-19: the location of the dataset is taken from the def:leaf element
- Lines 20-31: the OIDs of the --TESTCD and --TEST are captured. Note the FLWOR expression within the "let" statement. If there are no --TESTCD and --TEST
variables defined for the dataset, the $testcdoid and $testoid will be null (empty)
The second part of the XQuery:
- Line 32 sets the name of the --TEST variable for later use (e.g. VSTEST, LBTEST)
- Line 34-41: this are probably the most complicated in the XQuery. What is does is that it groups ALL records within the dataset by the value
of the --TESTCD variable. This means that in each group, all values of --TESTCD are identical. Each element in the group is an "ItemGroupData" element, i.e. a record.
The third part of the XQuery:
- Line 42-44: we now start iterating over all the groups (each group having all values for --TESTCD equal). Ideally, within each group, the number of different
values for --TEST is also 1. If not, the combination of --TESTCD and --TEST is not unique.
- Line 45: the value of the --TESTCD variable is taken from the first record (all are equal within the group anyway)
- Line 46: starting from the second record in the group, an iteration is started over all records in the group
- Line 47: the record number is captured
- Line 48: the value of the --TEST variable for this record is taken
- Line 49-53: the previous record in the same group is taken, and the record number ($recnum2), and the value of the --TEST variable
($testvalue2) are captured
- Line 54: the values of the --TEST variable in both records are captured. If they are not equal, an error message will be generated
- Line 54-60: the error message when both --TEST values within the group (with records all with the same value for --TESTCD) are different
Courtesy of XML4Pharma - last update: May 2016