Rule FDAC001 in XQuery: Missing DM dataset
Description: Demographics (DM) dataset must be included in every submission
The rule written in XQuery:
Explanation
- The first line is a comment. In XQuery, comments start with "(:" and end with ":)"
- In line 2, it is declared that XQuery version 3.0 is used. This is the most recent version of XQuery
- Lines 3-6 lists the namespaces and their prefixes that will be used, e.g. "def" for the define.xml specific elements and attributes
- Lines 7-9 are commented out. Uncomment them if you would like to pass the values of variable $base, $define from your own program. This is the way the path to the
define.xml is defined in the "Smart Dataset-XML Viewer"
- Lines 10-12 provide the path to the location of the define.xml file. In this case, the define.xml is located in the native XML database in the collection "/db/fda_submissions/cdisc01".
This could also easily be done by the FDA, i.e. use a native XML database and generate a single collection with all the documents in a single collection.
If you want to use a file on Windows, the base path for $base in line 11 will start with something like "file:///C:/..."
- In line 14, we combine the base path and define.xml into a single document using the doc() function
- Line 16 states that within the define.xml document, the location of the DM document is provided by the def:leaf/@xlink:href attribute value,
for which the ItemGroupDef has the value of the "Name" attribute being "DM". Remark that the square brackets provide a condition (officially a "predicate")
and can be read as a "where" statement. So: take the ItemGroupDef in the define.xml document where the "Name" attribute has the value "DM", and of that
ItemGroupDef, take the "def:leaf" child element, and then take the value of the "xlink:href" attribute.
- Line 17: as the result of "xlink:href" is a relative path, we still need to combine it with the base path and then take it as a document
- Line 19: the doc-available() function checks whether the document is available at the given location. If this is not the case, the next line "return" is executed.
Also, if the define.xml itself does not contain a link to a DM document, the error is generated.
- Line 20: in case there is no "DM" document (or not defined in the define.xml), an error is returned as XML.
The advantage of this is that metadata can be passed (such as the date of the last rule update, the dataset or domain, record number, and that the XML can be used/transformed in many ways,
e.g. HTML, PDF report, or can easily be used in any other applications (forget about this damned Excel!).
Also note that XQuery variable values can be returned using "{data()}"
As you might already have noticed, the whole XQuery has the structure "let", "where", "return".
These are part of the so-called FLWOR principle of XQuery (pronounced "flower"): "for", "let", "where", "order by", "return".
For a nice introduction about FLWOR, see here.
Courtesy of XML4Pharma - last update: May 2016