FHIRPathΒΆ

FHIRPath assertions can be evaluated against payloads of both request and response variables offered by the Touchstone Rules-Engine. The same FHIRPath expression will work against both XML and JSON content. However, FHIRPath assertions run significantly slower than XPath assertions and JsonPath assertions.

  • assertFhirPathBoolean(fhirpath)

    • Asserts that the evaluated value of the provided fhirpath expression is true

    • Example:

      // Asserts that the number of resource id elements in the response is 10
      response.assertFhirPathBoolean("entry.resource.id.count() = 10")
      
    • Equivalent to each of these:

      • assertFhirPathBoolean("entry.resource.id.count() = 10", response)
        
      • assert response.getFhirPathBoolean("entry.resource.id.count() = 10") : "The
           expression \"entry.resource.id.count() != 10\" evaluated to false"
        
      • assert response.fhirPathBoolean("entry.resource.id.count() = 10") : "The
           expression \"entry.resource.id.count() != 10\" evaluated to false"
        
  • assertFhirPathContains(fhirpath, expectedValue)

    • Asserts that the evaluated value of the provided fhirpath expression contains the provided expectedValue.

    • Example:

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

      • assertFhirPathContains("entry[1].resource.name.family", "Chalmers", response)
        
      • // fhirPath, expectedValue, and operator can be passed as parameters from test script.
        assertFhirPath("entry[1].resource.name.family", "Chalmers", "contains", response)
        
      • def family = response.getFhirPathValue("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.fhirPathValue("entry[1].resource.name.family")
        
        assert containsIgnoreCase("chalmers", family): "The actual value \""+family+"\" did not contain the expected value
           \"Chalmers\"  for \"entry[1].resource.name.family\" in response."
        
      • def family = response.fhirPath("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 a FHIRPath 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.

  • assertFhirPathNotContains(fhirpath, expectedValue)

    • Asserts that the evaluated value of the provided fhirpath expression does not contain the provided expectedValue.

    • Example:

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

      • assertFhirPathNotContains("entry[1].resource.name.family", "Chalmers", response)
        
      • // fhirPath, expectedValue, and operator can be passed as parameters from test script.
        assertFhirPath("entry[1].resource.name.family", "Chalmers", "notContains", response)
        
      • def family = response.getFhirPathValue("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.fhirPathValue("entry[1].resource.name.family")
        
        assert notContainsIgnoreCase("chalmers", family): "The actual value \""+family+"\" contained the expected value
           \"Chalmers\"  for \"entry[1].resource.name.family\" with operator 'notContains' in response."
        
      • def family = response.fhirPath("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."
        
  • assertFhirPathEmpty(fhirpath)

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

    • Example:

      response.assertFhirPathEmpty("entry[0].resource.photo.title")
      
    • Equivalent to these:

      assertFhirPathEmpty("entry[0].resource.photo.title", response)
      
      response.fhirPath("entry[0].resource.photo.title").empty();
      
      def title = response.getFhirPathValue("entry[0].resource.photo.title")
      
      assert !title: "Expected title to be absent but was present in response"
      
      def title = response.fhirPathValue("entry[0].resource.photo.title")
      
      assert title==null: "Expected title to be absent but was present in response"
      
      def title = response.fhirPath("entry[0].resource.photo.title").value
      
      assert empty(title): "Expected title to be absent but was present in response"
      
  • assertFhirPathNotEmpty(fhirpath)

    • Asserts that the evaluated value of the provided fhirpath expression is present and not empty.

    • Example:

      response.assertFhirPathNotEmpty("entry[0].resource.birthDate")
      
    • Equivalent to these:

      assertFhirPathNotEmpty("entry[0].resource.birthDate", response)
      
      response.fhirPath("entry[0].resource.birthDate").notEmpty();
      
      def title = response.getFhirPathValue("entry[0].resource.birthDate")
      
      assert title: "Expected birthDate to be absent but was present in response"
      
      def title = response.fhirPathValue("entry[0].resource.birthDate")
      
      assert title!=null: "Expected birthDate to be absent but was present in response"
      
      def title = response.fhirPath("entry[0].resource.birthDate").value
      
      assert notEmpty(title): "Expected birthDate to be absent but was present in response"
      
  • assertFhirPathEquals(fhirpath, expectedValue)

    • Asserts that the evaluated value of the provided fhirpath expression matches the provided expectedValue.

    • Example:

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

      • assertFhirPathEquals("entry[0].resource.name.family", "Chalmers", response)
        
      • // fhirPath, expectedValue, and operator can be passed as parameters from test script.
        assertFhirPath("entry[0].resource.name.family", "Chalmers", "equals", response)
        
      • def family = response.getFhirPathValue("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.fhirPathValue("entry[0].resource.name.family")
        
        assert equalsIgnoreCase("chalmers", family): "The actual value \""+family+"\" did not match the expected value
           \"Chalmers\"  for \"entry[0].resource.name.family\" in response."
        
      • def family = response.fhirPath("entry[0].resource.name.family").getValue()
        
        assert equals("Chalmers", family): "The actual value \""+family+"\" did not match the expected value
           \"Chalmers\"  for \"entry[0].resource.name.family\" in response."
        
      • def family = response.fhirPath("entry[0].resource.name.family").value
        
        assert family == "Chalmers": "The actual value \""+family+"\" did not match the expected value
           \"Chalmers\" for \"entry[0].resource.name.family\" in response."
        
  • assertFhirPathNotEquals(fhirpath, expectedValue)

    • Asserts that the evaluated value of the provided fhirpath expression does not match the provided expectedValue.

    • Example:

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

      • assertFhirPathNotEquals("entry[0].resource.name.family", "Chalmers", response)
        
      • // fhirPath, expectedValue, and operator can be passed as parameters from test script.
        assertFhirPath("entry[0].resource.name.family", "Chalmers", "notEquals", response)
        
      • def family = response.getFhirPathValue("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.fhirPathValue("entry[0].resource.name.family")
        
        assert notEqualsIgnoreCase("chalmers", family): "The actual value \""+family+"\" matched
           the expected value \"Chalmers\" for \"entry[0].resource.name.family\" with operator
              'notEquals' in response."
        
      • def family = response.fhirPath("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.fhirPath("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."
        
  • assertFhirPathGreaterThan(fhirpath, expectedValue)

    • Asserts that the evaluated value of the provided fhirpath expression is greater than the provided expectedValue.

    • Example:

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

      • assertFhirPathGreaterThan("entry[1].resource.id", 1100, response)
        
      • // fhirPath, expectedValue, and operator can be passed as parameters from test script.
        assertFhirPath("entry[1].resource.id", "1100", "greaterThan", response)
        
      • def id = response.getFhirPathValue("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.fhirPathValue("entry[1].resource.id")
        
        assert (id as Integer) > 1100: "Expected \"entry[1].resource.id\" to be greater than 5000
           but was "+id+" in response"
        
      • def id = response.fhirPath("entry[1].resource.id").value
        
        assert greaterThan(1100, id): "Expected \"entry[1].resource.id\" to be greater than 5000
           but was "+id+" in response"
        
  • assertFhirPathLessThan(fhirpath, expectedValue)

    • Asserts that the evaluated value of the provided fhirpath expression is less than the provided expectedValue.

    • Example:

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

      • assertFhirPathLessThan("entry[1].resource.id", 1100, response)
        
      • // fhirPath, expectedValue, and operator can be passed as parameters from test script.
        assertFhirPath("entry[1].resource.id", "1100", "lessThan", response)
        
      • def id = response.getFhirPathValue("entry[1].resource.id")
        
        assert id.toInteger() < 1100: "Expected \"entry[1].resource.id\" to be less than 5000
            but was "+id+" in response"
        
      • def id = response.fhirPath("entry[1].resource.id").getValue()
        
        assert (id as Integer) < 1100: "Expected \"entry[1].resource.id\" to be less than 5000
           but was "+id+" in response"
        
      • def id = response.fhirPath("entry[1].resource.id").value
        
        assert lessThan(1100, id): "Expected \"entry[1].resource.id\" to be less than 5000
           but was "+id+" in response"
        
  • assertFhirPathIn(fhirpath, expectedValues)

    • Asserts that the evaluated value of the provided fhirpath expression is one of the provided expectedValues where each value is separated by a comma.

    • Example:

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

      • assertFhirPathIn("entry[1].resource.id", "1100,1101,1102", response)
        
      • // fhirPath, expectedValue, and operator can be passed as parameters from test script.
        assertFhirPath("entry[1].resource.id", "1100,1101,1102", "in", response)
        
      • def id = response.getFhirPathValue("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.fhirPath("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."
        
  • assertFhirPathNotIn(fhirpath, expectedValues)

    • Asserts that the evaluated value of the provided fhirpath expression is none of the provided expectedValues where each value is separated by a comma.

    • Example:

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

      • assertFhirPathNotIn("entry[1].resource.id", "1100,1101,1102", response)
        
      • // fhirPath, expectedValue, and operator can be passed as parameters from test script.
        assertFhirPath("entry[1].resource.id", "1100,1101,1102", "notIn", response)
        
      • def id = response.getFhirPathValue("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.fhirPath("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."