|
2 | 2 | xmlns="http://hl7.org/fhir" |
3 | 3 | xmlns:f="http://hl7.org/fhir" |
4 | 4 | xmlns:xs="http://www.w3.org/2001/XMLSchema" |
| 5 | + xmlns:fn="http://www.w3.org/2005/xpath-functions" |
| 6 | + xmlns:array="http://www.w3.org/2005/xpath-functions/array" |
| 7 | + xmlns:map="http://www.w3.org/2005/xpath-functions/map" |
5 | 8 | xmlns:nts="http://nictiz.nl/xsl/testscript" |
6 | 9 | exclude-result-prefixes="#all"> |
7 | 10 | <xsl:output method="xml" indent="yes"/> |
|
29 | 32 | <!-- Optional string that will be appended verbatim to the verson string. If there is no version element in the |
30 | 33 | input, it will be set to this parameter. --> |
31 | 34 | <xsl:param name="versionAddition" select="''"/> |
| 35 | + |
| 36 | + <!-- Include the machinery to resolve auth tokens from a JSON file. This adds the parameter tokensJSONFile, which |
| 37 | + should hold an URL. --> |
| 38 | + <xsl:include href="resolveAuthTokens.xsl"/> |
32 | 39 |
|
33 | 40 | <!-- The main template, which will call the remaining templates. --> |
34 | 41 | <xsl:template name="generate" match="f:TestScript"> |
|
47 | 54 | <xsl:if test="$scenario = 'server' and not($expectedResponseFormat = ('xml', 'json'))"> |
48 | 55 | <xsl:message terminate="yes" select="concat('Invalid value ''', $expectedResponseFormat, ''' for parameter ''expectedResponseFormat''; should be either ''xml'' or ''json''')"></xsl:message> |
49 | 56 | </xsl:if> |
| 57 | + |
| 58 | + <!-- Extract the authorization tokens specified using the nts:authToken element(s). These tokens can then be used within |
| 59 | + the nts:authHeader element, referenced by their id. --> |
| 60 | + <xsl:if test="count(//nts:authToken[@patientResourceId]) > 0 and not($tokensJsonFile)"> |
| 61 | + <xsl:message terminate="yes">If you use the nts:authToken element, you need to pass in a file containing the tokens using the tokensJsonFile parameter.</xsl:message> |
| 62 | + </xsl:if> |
| 63 | + <xsl:if test="count(//nts:authToken[not(@id)]) > 1"> |
| 64 | + <xsl:message terminate="yes">When using multiple nts:authToken elements, at most one may have the default id. All other instances must be uniquely identified with an id.</xsl:message> |
| 65 | + </xsl:if> |
| 66 | + <xsl:variable name="authTokens" as="element(nts:authToken)*"> |
| 67 | + <xsl:for-each select="//nts:authToken[@patientResourceId]"> |
| 68 | + <xsl:variable name="id" select="if (.[@id]) then ./@id else 'patient-token-id'"/> |
| 69 | + <xsl:copy-of select="nts:resolveAuthToken(./@patientResourceId, $id, true())"/> |
| 70 | + </xsl:for-each> |
| 71 | + </xsl:variable> |
| 72 | + |
| 73 | + <!-- Seed the parameters used during expansion with the id's of nts:authToken declarations. |
| 74 | + The value of these "magic" parameters depend on the scenario. For server scripts, this will be expanded |
| 75 | + to a corresponding TestScript variable. For client scripts, this will contain the literal content of the |
| 76 | + token. --> |
| 77 | + <xsl:variable name="inclusionParameters" as="element(nts:with-parameter)*"> |
| 78 | + <xsl:for-each select="$authTokens"> |
| 79 | + <xsl:if test="$scenario = 'server'"> |
| 80 | + <nts:with-parameter name="{./@id}" value="{concat('${', ./@id, '}')}"/> |
| 81 | + </xsl:if> |
| 82 | + <xsl:if test="$scenario = 'client'"> |
| 83 | + <nts:with-parameter name="{./@id}" value="{./@token}"/> |
| 84 | + </xsl:if> |
| 85 | + </xsl:for-each> |
| 86 | + </xsl:variable> |
| 87 | + |
50 | 88 |
|
51 | 89 | <!-- Expand all the Nictiz inclusion elements to their FHIR representation --> |
52 | 90 | <xsl:variable name="expanded"> |
53 | 91 | <xsl:apply-templates mode="expand" select="."> |
54 | 92 | <xsl:with-param name="scenario" select="$scenario" tunnel="yes"/> |
55 | 93 | <xsl:with-param name="expectedResponseFormat" select="$expectedResponseFormat" tunnel="yes"/> |
56 | 94 | <xsl:with-param name="basePath" select="$basePath" tunnel="yes"/> |
| 95 | + <xsl:with-param name="inclusionParameters" select="$inclusionParameters" tunnel="yes"/> |
| 96 | + <xsl:with-param name="authTokens" select="$authTokens" tunnel="yes"/> |
57 | 97 | </xsl:apply-templates> |
58 | 98 | </xsl:variable> |
59 | 99 |
|
|
376 | 416 | </xsl:choose> |
377 | 417 | </xsl:template> |
378 | 418 |
|
| 419 | + <!-- Expand an nts:authToken element. For server scripts, this will result in a variable with a default value which |
| 420 | + the tester can override. For client scripts, this doesn't result in any output (but the element is used |
| 421 | + beforehand for finding the correct authorization token to use. --> |
| 422 | + <xsl:template match="nts:authToken[@patientResourceId]" mode="expand"> |
| 423 | + <xsl:param name="scenario" tunnel="yes"/> |
| 424 | + <xsl:param name="authTokens" tunnel="yes"/> |
| 425 | + |
| 426 | + <xsl:if test="$scenario='server'"> |
| 427 | + <variable> |
| 428 | + <name value="{if (.[@id]) then ./@id else 'patient-token-id'}"/> |
| 429 | + <defaultValue value="{$authTokens[@id = ./@id]/@token}"/> |
| 430 | + <description value="OAuth Token for current patient"/> |
| 431 | + </variable> |
| 432 | + </xsl:if> |
| 433 | + </xsl:template> |
| 434 | + |
379 | 435 | <!-- Expand an nts:patientTokenFixture element to create a variable called 'patient-token-id'. How this is handled |
380 | 436 | is different for server and client scripts: |
381 | 437 | - for a server script, it will be provided with a default value read from the fixture, which can be overridden |
|
694 | 750 | <xsl:value-of select="$fullFilename"/> |
695 | 751 | </xsl:function> |
696 | 752 |
|
697 | | - |
698 | 753 | <!-- Construct a file path from the elements. |
699 | 754 | param base is the folder where the file resides |
700 | 755 | param filename is the name of the file in the folder including the extension |
|
0 commit comments