Rule FDA018 in XQuery using RESTful web service
Description: NULL value in variable marked as Required
This rule implementation is very similar to the previous one, but in this case, a "lookup" from a RESTful webservice,
described here is used to find out whether the variable is "required", "expected"
or "permissible". This web service is a precursor of the RESTful web services that will be provided by SHARE in the future.
So in this case, the implementation does NOT rely on whether the "Mandatory" attribute has the correct value in the define.xml
The rule written in XQuery (first part):
Explanation
- Lines 1-9 has some general comments and define the namespaces again
- In line 10-15, we define a function, testing whether a given value is one of the values in a sequence (an array). Hundreds of such useful functions can
be found on the "FunctX XQuery Functions" website
- Line 16-21 define the base path and name of the define.xml. In this example case, they will be passed from the calling program, using the "declare variable" statements
- Lines 22-29 are a bit special: we assume that we want to implement the rule for ALL domains in our submission. If however, you comment line 22 out and
uncomment line 19 "declare variable $domain external", you can pass the single domain for which you want to have the rule executed as an argument
- Lines 26-29 then select all the dataset definitions to which the rule must be applied (either all, or for a single domain)
The second part of the rule in XQuery:
- The version of the SDTM-IG is then captured from the define.xml in line 33, and the corresponding SDS version in lines 35-39.
This is necessary as the information requires/expected/permissible has only been published electronically as function of the SDS version, not as
function of the SDTM-IG version (this will probably change in future)
- Line 40: the address of the RESTful webservice is set
- Line 41-42: we now start iterating over all domain definitions. Remark that even when one single domain was give, there still may be several datasets
for that domain, the so-called "splitted" datasets (essentially this name is incorrect, as most implementers never "split" - they don't let it come so far)
- The dataset name and absolute location is taken in lines 43-47
- Lines 48-58 iterates over all the variables for the current dataset (as defined in the define.xml) and for each of them, asks the webservice what the "core" of that
variable is. The variable name is only kept in the array $requiredvars when the value returned by the web service is "Req". So the array $requiredvars ONLY contains
the variable names of the required variables for the specific dataset/domain.
Remark that the web service takes the SDS version, the domain name and the variable name as arguments.
The third part of the rule in XQuery:
- Lines 61-65: we got the "required" variable names, but we need the OIDs from the define.xml to be used when reading the records in the Dataset-XML.
The OIDs are retrieved in these lines (remark that a "let" statement can have a nested "FLWOR" expression itself)
- Line 67: iteration over all the records in the dataset itself starts
- The record number is taken in line 68
- Line 70: within the record, we start iterating over all the "required" variables (by their OID)
- The variable name is recovered (from the define.xml) in line 71
- Line 74: The "where" statement states that when no data point (ItemData) is found in the record, an error will be generated
- And finally in line 75, an error is returned as XML when the "required" variable data point is not found in the given record in the given dataset in
the given domain
Courtesy of XML4Pharma - last update: May 2016