NonFHIRPath

NonFhirPath assertions (comprising of XPath and JSONPath) can be evaluated against payloads of both request and response variables offered by the Touchstone Rules-Engine. Both XPath assertions and JsonPath assertions run significantly faster than FHIRPath assertions.

Both XPath and JSONPath expressions are needed for nonFhirPath assertions. Touchstone will use the XPath expression if the payload is XML and will use the JSONPath expression if it’s JSON. This relieves the rule author from checking the content type of the payload which needs to be done for XPath assertion and JsonPath assertion.

  • assertNonFhirPathContains(xpath, jsonpath, expectedValue)

    • Asserts that the evaluated value of the provided xpath or jsonpath expression contains the provided expectedValue. Touchstone will use xpath if the payload is XML and jsonpath if it is JSON.

    • Example:

      // Asserts that the value of the family element of the second entry contains 'Chalmers'
      response.assertNonFhirPathContains("entry[2]/resource/Patient/name/family", "entry[1].resource.name.family", "Chalmers")
      
    • Equivalent to each of these:

      • assertNonFhirPathContains("entry[2]/resource/Patient/name/family", "entry[1].resource.name.family", "Chalmers", response)
        
      • // jsonPath, expectedValue, and operator can be passed as parameters from test script.
        assertNonFhirPath("entry[2]/resource/Patient/name/family", "entry[1].resource.name.family", "Chalmers", "contains", response)
        
      • def family = response.getNonFhirPathValue("entry[2]/resource/Patient/name/family", "entry[1].resource.name.family")
        
        assert family.contains("Chalmers"): "The actual value \""+family+"\" did not contain the expected value
           \"Chalmers\" for \"entry[1].resource.name.family\" in response."
        
      • def family = response.nonFhirPath("entry[2]/resource/Patient/name/family", "entry[1].resource.name.family").value
        
        assert contains("Chalmers", family): "The actual value \""+family+"\" did not contain the expected value
           \"Chalmers\"  for \"entry[1].resource.name.family\" in response."
        

        Notice how the value of NonFhirPath evaluation can be stored in a variable. This is useful when you want to develop more complicated rule scripts where the assertions involve multiple comparisons.

  • assertNonFhirPathNotContains(xpath, jsonpath, expectedValue)

    • Asserts that the evaluated value of the provided xpath or jsonpath expression does not contain the provided expectedValue. Touchstone will use xpath if the payload is XML and jsonpath if it is JSON.

    • Example:

      // Asserts that the value of the family element of the second entry contains 'Chalmers'
      response.assertNonFhirPathNotContains("entry[2]/resource/Patient/name/family", "entry[1].resource.name.family", "Chalmers")
      
    • Equivalent to each of these:

      • assertNonFhirPathNotContains("entry[2]/resource/Patient/name/family", "entry[1].resource.name.family", "Chalmers", response)
        
      • // jsonPath, expectedValue, and operator can be passed as parameters from test script.
        assertNonFhirPath("entry[2]/resource/Patient/name/family", "entry[1].resource.name.family", "Chalmers", "notContains", response)
        
      • def family = response.getNonFhirPathValue("entry[2]/resource/Patient/name/family", "entry[1].resource.name.family")
        
        assert !family.contains("Chalmers"): "The actual value \""+family+"\" contained the expected value
           \"Chalmers\" for \"entry[1].resource.name.family\" with operator 'notContains' in response."
        
      • def family = response.nonFhirPath("entry[2]/resource/Patient/name/family", "entry[1].resource.name.family").value
        
        assert notContains("Chalmers", family): "The actual value \""+family+"\" contained the expected value
           \"Chalmers\"  for \"entry[1].resource.name.family\" with operator 'notContains' in response."
        
  • assertNonFhirPathEmpty(jsonpath)

    • Asserts that the evaluated value of the provided xpath or jsonpath expression is absent or empty.

    • Example:

      response.assertNonFhirPathEmpty("entry[1]/resource/Patient/photo/title", "entry[0].resource.photo.title")
      
    • Equivalent to these:

      assertNonFhirPathEmpty("entry[1]/resource/Patient/photo/title", "entry[0].resource.photo.title", response)
      
      response.jsonPath("entry[1]/resource/Patient/photo/title", "entry[0].resource.photo.title").empty();
      
      def title = response.getNonFhirPathValue("entry[1]/resource/Patient/photo/title", "entry[0].resource.photo.title")
      
      assert !title: "Expected title to be absent but was present in response"
      
      def title = response.jsonPath("entry[1]/resource/Patient/photo/title", "entry[0].resource.photo.title").value
      
      assert empty(title): "Expected title to be absent but was present in response"
      
  • assertNonFhirPathNotEmpty(jsonpath)

    • Asserts that the evaluated value of the provided xpath or jsonpath expression is present and not empty. Touchstone will use xpath if the payload is XML and jsonpath if it is JSON.

    • Example:

      response.assertNonFhirPathNotEmpty("entry[1]/resource/Patient/birthDate", "entry[0].resource.birthDate")
      
    • Equivalent to these:

      assertNonFhirPathNotEmpty("entry[1]/resource/Patient/birthDate", "entry[0].resource.birthDate", response)
      
      response.nonFhirPath("entry[1]/resource/Patient/birthDate", "entry[0].resource.birthDate").notEmpty();
      
      def title = response.getNonFhirPathValue("entry[1]/resource/Patient/birthDate", "entry[0].resource.birthDate")
      
      assert title: "Expected birthDate to be absent but was present in response"
      
      def title = response.nonFhirPath("entry[1]/resource/Patient/birthDate", "entry[0].resource.birthDate").value
      
      assert notEmpty(title): "Expected birthDate to be absent but was present in response"
      
  • assertNonFhirPathEquals(xpath, jsonpath, expectedValue)

    • Asserts that the evaluated value of the provided xpath or jsonpath expression matches the provided expectedValue. Touchstone will use xpath if the payload is XML and jsonpath if it is JSON.

    • Example:

      // Asserts that the value of the family element of the first entry is 'Chalmers'
      response.assertNonFhirPathEquals("entry[1]/resource/Patient/name/family", "Chalmers")
      
    • Equivalent to each of these:

      • assertNonFhirPathEquals("entry[1]/resource/Patient/name/family", "Chalmers", response)
        
      • // xPath, expectedValue, and operator can be passed as parameters from test script.
        assertNonFhirPath("entry[1]/resource/Patient/name/family", "Chalmers", "equals", response)
        
      • def family = response.getNonFhirPathValue("entry[1]/resource/Patient/name/family")
        
        assert family.equals("Chalmers"): "The actual value \""+family+"\" did not match the expected value
        \"Chalmers\" for \"entry[1]/resource/Patient/name/family\" in response."
        
      • def family = response.nonFhirPath("entry[1]/resource/Patient/name/family").getValue()
        
        assert family == "Chalmers": "The actual value \""+family+"\" did not match the expected value
           \"Chalmers\" for \"entry[1]/resource/Patient/name/family\" in response."
        
      • def family = response.xPath("entry[1]/resource/Patient/name/family").value
        
        assert equals("Chalmers", family): "The actual value \""+family+"\" did not match the expected value
           \"Chalmers\"  for \"entry[1]/resource/Patient/name/family\" in response."
        
  • assertNonFhirPathEquals(xpath, jsonpath, expectedValue)

    • Asserts that the evaluated value of the provided xpath or jsonpath expression matches the provided expectedValue. Touchstone will use xpath if the payload is XML and jsonpath if it is JSON.

    • Example:

      // Asserts that the value of the family element of the first entry is 'Chalmers'
      response.assertNonFhirPathEquals("entry[1]/resource/Patient/name/family", "entry[0].resource.name.family", "Chalmers")
      
    • Equivalent to each of these:

      • assertNonFhirPathEquals("entry[1]/resource/Patient/name/family", "entry[0].resource.name.family", "Chalmers", response)
        
      • // jsonPath, expectedValue, and operator can be passed as parameters from test script.
        assertNonFhirPath("entry[1]/resource/Patient/name/family", "entry[0].resource.name.family", "Chalmers", "equals", response)
        
      • def family = response.getNonFhirPathValue("entry[1]/resource/Patient/name/family", "entry[0].resource.name.family")
        
        assert family.equals("Chalmers"): "The actual value \""+family+"\" did not match the expected value
        \"Chalmers\" for \"entry[0].resource.name.family\" in response."
        
      • def family = response.nonFhirPath("entry[1]/resource/Patient/name/family", "entry[0].resource.name.family").getValue()
        
        assert family == "Chalmers": "The actual value \""+family+"\" did not match the expected value
           \"Chalmers\" for \"entry[0].resource.name.family\" in response."
        
      • def family = response.nonFhirPath("entry[1]/resource/Patient/name/family", "entry[0].resource.name.family").value
        
        assert equals("Chalmers", family): "The actual value \""+family+"\" did not match the expected value
           \"Chalmers\"  for \"entry[0].resource.name.family\" in response."
        
  • assertNonFhirPathNotEquals(xpath, jsonpath, expectedValue)

    • Asserts that the evaluated value of the provided xpath or jsonpath expression does not match the provided expectedValue. Touchstone will use xpath if the payload is XML and jsonpath if it is JSON.

    • Example:

      // Asserts that values of the family element of the first entry is not 'Chalmers'
      response.assertNonFhirPathNotEquals("entry[1]/resource/Patient/name/family", "entry[0].resource.name.family", "Chalmers")
      
    • Equivalent to each of these:

      • assertNonFhirPathNotEquals("entry[1]/resource/Patient/name/family", "entry[0].resource.name.family", "Chalmers", response)
        
      • // jsonPath, expectedValue, and operator can be passed as parameters from test script.
        assertNonFhirPath("entry[1]/resource/Patient/name/family", "entry[0].resource.name.family", "Chalmers", "notEquals", response)
        
      • def family = response.getNonFhirPathValue("entry[1]/resource/Patient/name/family", "entry[0].resource.name.family")
        
        assert !family.equals("Chalmers"): "The actual value \""+family+"\" matched
           the expected value \"Chalmers\" for \"entry[0].resource.name.family\" with operator
              'notEquals' in response."
        
      • def family = response.nonFhirPath("entry[1]/resource/Patient/name/family", "entry[0].resource.name.family").getValue()
        
        assert family != "Chalmers": "The actual value \""+family+"\" matched
           the expected value \"Chalmers\" for \"entry[0].resource.name.family\" with operator
              'notEquals' in response."
        
      • def family = response.nonFhirPath("entry[1]/resource/Patient/name/family", "entry[0].resource.name.family").value
        
        assert notEquals("Chalmers", family): "The actual value \""+family+"\" matched
           the expected value \"Chalmers\" for \"entry[0].resource.name.family\" with operator
              'notEquals' in response."
        
  • assertNonFhirPathGreaterThan(xpath, jsonpath, expectedValue)

    • Asserts that the evaluated value of the provided xpath or jsonpath expression is greater than the provided expectedValue. Touchstone will use xpath if the payload is XML and jsonpath if it is JSON.

    • Example:

      // Asserts that resource id of the second entry is greater than 1100 in the response
      response.assertNonFhirPathGreaterThan("entry[2]/resource/Patient/id", "entry[1].resource.id", 1100)
      
    • Equivalent to each of these:

      • assertNonFhirPathGreaterThan("entry[2]/resource/Patient/id", "entry[1].resource.id", 1100, response)
        
      • // jsonPath, expectedValue, and operator can be passed as parameters from test script.
        assertNonFhirPath("entry[2]/resource/Patient/id", "entry[1].resource.id", "1100", "greaterThan", response)
        
      • def id = response.getNonFhirPathValue("entry[2]/resource/Patient/id", "entry[1].resource.id")
        
        assert id.toInteger() > 1100: "Expected \"entry[1].resource.id\" to be greater than 5000
            but was "+id+" in response"
        
      • def id = response.nonFhirPath("entry[2]/resource/Patient/id", "entry[1].resource.id").getValue()
        
        assert (id as Integer) > 1100: "Expected \"entry[1].resource.id\" to be greater than 5000
           but was "+id+" in response"
        
      • def id = response.nonFhirPath("entry[2]/resource/Patient/id", "entry[1].resource.id").value
        
        assert greaterThan(1100, id): "Expected \"entry[1].resource.id\" to be greater than 5000
           but was "+id+" in response"
        
  • assertNonFhirPathLessThan(xpath, jsonpath, expectedValue)

    • Asserts that the evaluated value of the provided xpath or jsonpath expression is less than the provided expectedValue. Touchstone will use xpath if the payload is XML and jsonpath if it is JSON.

    • Example:

      // Asserts that resource id of the first entry is less than 1100 in the response
      response.assertNonFhirPathLessThan("entry[1]/resource/Patient/id", "entry[0].resource.id", 1100)
      
    • Equivalent to each of these:

      • assertNonFhirPathLessThan("entry[1]/resource/Patient/id", "entry[0].resource.id", 1100, response)
        
      • // jsonPath, expectedValue, and operator can be passed as parameters from test script.
        assertNonFhirPath("entry[1]/resource/Patient/id", "entry[0].resource.id", "1100", "lessThan", response)
        
      • def id = response.getNonFhirPathValue("entry[1]/resource/Patient/id", "entry[0].resource.id")
        
        assert id.toInteger() < 1100: "Expected \"entry[0].resource.id\" to be less than 5000
            but was "+id+" in response"
        
      • def id = response.nonFhirPath("entry[1]/resource/Patient/id", "entry[0].resource.id").getValue()
        
        assert (id as Integer) < 1100: "Expected \"entry[0].resource.id\" to be less than 5000
           but was "+id+" in response"
        
      • def id = response.nonFhirPath("entry[1]/resource/Patient/id", "entry[0].resource.id").value
        
        assert lessThan(1100, id): "Expected \"entry[0].resource.id\" to be less than 5000
           but was "+id+" in response"
        
  • assertNonFhirPathIn(xpath, jsonpath, expectedValues)

    • Asserts that the evaluated value of the provided xpath or jsonpath expression is one of the provided expectedValues where each value is separated by a comma. Touchstone will use xpath if the payload is XML and jsonpath if it is JSON.

    • Example:

      // Asserts that resource id of the second entry is either 1100 or 1101 or 1102
      response.assertNonFhirPathIn("entry[2]/resource/Patient/id", "entry[1].resource.id", "1100,1101,1102")
      
    • Equivalent to each of these:

      • assertNonFhirPathIn("entry[2]/resource/Patient/id", "entry[1].resource.id", "1100,1101,1102", response)
        
      • // jsonPath, expectedValue, and operator can be passed as parameters from test script.
        assertNonFhirPath("entry[2]/resource/Patient/id", "entry[1].resource.id", "1100,1101,1102", "in", response)
        
      • def id = response.getNonFhirPathValue("entry[2]/resource/Patient/id", "entry[1].resource.id")
        
        assert id in ["1100", "1101", "1102"]: "Expected one of the values in [1100, 1101, 1102]
           for \"entry[1].resource.id\" but encountered \""+id+"\" in response."
        
      • def id = response.nonFhirPath("entry[2]/resource/Patient/id", "entry[1].resource.id").value
        
        assert isIn("1100,1101,1102", id): "Expected one of the values in [1100, 1101, 1102] for
           \"entry[1].resource.id\" but encountered \""+id+"\" in response."
        
  • assertNonFhirPathNotIn(xpath, jsonpath, expectedValues)

    • Asserts that the evaluated value of the provided xpath or jsonpath expression is none of the provided expectedValues where each value is separated by a comma. Touchstone will use xpath if the payload is XML and jsonpath if it is JSON.

    • Example:

      // Asserts that resource id of the second entry is either 1100 or 1101 or 1102
      response.assertNonFhirPathNotIn("entry[2]/resource/Patient/id", "entry[1].resource.id", "1100,1101,1102")
      
    • Equivalent to each of these:

      • assertNonFhirPathNotIn("entry[2]/resource/Patient/id", "entry[1].resource.id", "1100,1101,1102", response)
        
      • // jsonPath, expectedValue, and operator can be passed as parameters from test script.
        assertNonFhirPath("entry[2]/resource/Patient/id", "entry[1].resource.id", "1100,1101,1102", "notIn", response)
        
      • def id = response.getNonFhirPathValue("entry[2]/resource/Patient/id", "entry[1].resource.id")
        
        assert !(id in ["1100", "1101", "1102"]): "Expected none of the values in [1100, 1101, 1102]
           for \"entry[1].resource.id\" but encountered \""+id+"\" with operator 'notIn' in response."
        
      • def id = response.nonFhirPath("entry[2]/resource/Patient/id", "entry[1].resource.id").value
        
        assert isNotIn("1100,1101,1102", id): "Expected none of the values in [1100, 1101, 1102] for
           \"entry[1].resource.id\" but encountered \""+id+"\" with operator 'notIn' in response."