FHIR / sql-on-fhir-v2

This project provides the source for the SQL on FHIR v2.0 Implementation Guide
https://build.fhir.org/ig/FHIR/sql-on-fhir-v2/
MIT License
100 stars 27 forks source link

Tests for getResourceKey and getReferenceKey are implementation-specific #202

Closed johngrimes closed 7 months ago

johngrimes commented 8 months ago

The following tests have expectations that are implementation-specific. The expectations should be weakened to reflect the fact that implementations can return any values from these functions, as long as they match up.

Also, there seem to be two tests with the same name (getReferenceKey(<type>)). We should fix this, the test name should be unique within the suite.

mput commented 8 months ago

@johngrimes, do you have any ideas on how we can express the fact that the value returned by getResourceKey() and getReferenceKey() matches in the JSON test representation?

I have two ideas, both of which are quite cumbersome:

  1. To use a self-referencing resource. The issue is that it's artificial, and I'm not sure if FHIR allows self-references.

    {
    "title": "forEach, forEachOrNull",
    "resources": [
    {
      "resourceType": "Patient",
      "id": "p1",
      "link": [{"other": "Patient/p1"}]
    }
    ],
    "tests": [
    {
      "title": "forEach matching some",
      "view": {
        "resource": "Patient",
        "select": [
          {
            "column": [{ "path": "getResourceKey() == link.other.getReferenceKey()", "name": "key_equal_ref" }]
          }
        ]
      },
      "expect": [{ "key_equal_ref": true }]
    }
    ]
    }
  2. Add new syntax to the test definition that allows comparing different views. I'm not sure if we want to add new syntax, and I don't see any other use for it right now.

    {
    "title": "reference keys",
    "resources": [
    {
      "resourceType": "Patient",
      "id": "p1",
      "link": [{"other": "Person/per1"}]
    },
    {
      "resourceType": "Person",
      "id": "per1"
    }
    ],
    "tests": [
    {
      "title": "forEach matching some",
      "expectViewEqual": [
        {
          "resource": "Patient",
          "select": [
            {"column": [{ "path": "link.other.getReferenceKey()", "name": "key" }]}
          ]
        },
        {
          "resource": "Person",
          "select": [
            {"column": [{ "path": "getResourceKey()", "name": "key" }]}
          ]
        }
      ]
    }
    ]
    }
johngrimes commented 8 months ago

As discussed in the meeting this morning, let's go with option 1 for now.

The data in your test is not quite right, and there is a minor problem with the FHIRPath expression. Something like this should work:

{
  "title": "references",
  "resources": [
    {
      "resourceType": "Patient",
      "id": "p1",
      "link": [
        {
          "other": {
            "reference": "Patient/p1"
          }
        }
      ]
    }
  ],
  "tests": [
    {
      "title": "getReferenceKey result matches getResourceKey",
      "view": {
        "resource": "Patient",
        "select": [
          {
            "column": [
              {
                "path": "getResourceKey() = link.other.getReferenceKey()",
                "name": "key_equal_ref"
              }
            ]
          }
        ]
      },
      "expect": [
        {
          "key_equal_ref": true
        }
      ]
    }
  ]
}