microsoft / fhir-server

A service that implements the FHIR standard
MIT License
1.17k stars 500 forks source link

Creating Search Parameters for Extensions #2487

Closed nickmcsimpson closed 2 years ago

nickmcsimpson commented 2 years ago

Question My team has started down the path of using Extensions to store various pieces of data in our server. In order to enable searching by these values, my understanding is that the fields must be indexed. In order to do so I attempted to create Search Parameters for one such field called 'result-status'

Here is how we are storing the value on a ServiceRequest document:

...
"extension": [
        {
            "url": "{SYSTEM_URI}/service-request/result-status-extension",
            "valueCodeableConcept": {
                "coding": [
                    {
                        "system": "{SYSTEM_URI}/service-request/result-status",
                        "code": "open",
                        "display": "open"
                    }
                ],
                "text": "open"
            }
        }
    ],
...

Here is how I am attempting to define a SearchParameter:

{
  "resourceType" : "SearchParameter",
  "id" : "result-status",
  "url" : "{SYSTEM_URI}/service-request/result-status-extension",
  "name" : "result-status",
  "status" : "active",
  "date" : "2022-02-14",
  "publisher" : "Exquisite Publisher",
  "contact" : [
    {
      "telecom" : [
        {
          "system" : "other",
          "value" : "{SYSTEM_URI}"
        }
      ]
    }
  ],
  "description" : "Returns Service Requests with a result status extension matching the specified code.",
  "jurisdiction" : [
    {
      "coding" : [
        {
          "system" : "urn:iso:std:iso:3166",
          "code" : "US",
          "display" : "United States of America"
        }
      ]
    }
  ],
  "code" : "result-status",
  "base" : [
    "ServiceRequest"
  ],
  "type" : "token",
  "expression" : "ServiceRequest.extension.where(url = '{SYSTEM_URI}/service-request/result-status-extension').extension.value.text"
}

Ultimately, this expression is not what we are after, we want the 'code' value nested in the extension's codeable concept value. I've tried multiple different iterations of the expression trying to get anything to work. I'm able to create the Search Parameters, but when running GET {{fhirUrl}}/ServiceRequest/:UUID/$reindex I'd expect the new search parameter to be evaluated and shown in the output. Running a 'POST' here to reindex a single item also doesn't change anything. Either way, the new search parameter isn't evaluated looking at the /$reindex output of the single record:

"parameter": [
        {
            "name": "specimen",
            "valueString": "Specimen/a192f33a-4fa5-4b52-ba53-43c6bbc76b80"
        },
        {
            "name": "intent",
            "valueString": "http://hl7.org/fhir/request-intent|order"
        },
        {
            "name": "subject",
            "valueString": "Patient/8920831b-4aa9-4244-88b0-2f28f57fc028"
        },
        {
            "name": "_lastUpdated",
            "valueString": "2022-02-03T16:53:54.3240000+00:00"
        },
        {
            "name": "status",
            "valueString": "http://hl7.org/fhir/request-status|completed"
        },
        {
            "name": "identifier",
            "valueString": "https://hl7-definition.caristix.com/v2/HL7v2.5.1/Fields/ORC.2|LAB REF00001"
        },
        {
            "name": "identifier",
            "valueString": "https://hl7-definition.caristix.com/v2/HL7v2.5.1/Fields/ORC.3|CB029108A"
        },
        {
            "name": "patient",
            "valueString": "Patient/8920831b-4aa9-4244-88b0-2f28f57fc028"
        },
        {
            "name": "encounter",
            "valueString": "Encounter/afa1f3a5-1c82-43a1-94a9-7900ee45db1b"
        },
        {
            "name": "_id",
            "valueString": "79900618-0501-48b9-a4d3-97bd9639ad74"
        }
    ]

Is my understanding of how to test my new search parameters incorrect? Meaning, when it's created, it will attempt to evaluate when running the '/$reindex' route? If it fails, will I see anything? Is there an Azure Portal or service configuration that would prevent reindexing? Is this nested value expression even supported?

I've been following the Azure Documentation

CaitlinV39 commented 2 years ago

From @feordin:

I think there is a slight change needed to the Expression property of the new search parameter. I was able to index the value with the following SearchParameter:

{ "resourceType" : "SearchParameter", "id" : "72aa994c-ed25-4b05-99a3-4168d295299f", "url" : "http://test/service-request/result-status-extension", "name" : "result-status", "status" : "active", "date" : "2022-02-14", "publisher" : "Exquisite Publisher", "contact" : [ { "telecom" : [ { "system" : "other", "value" : "http://test/" } ] } ], "description" : "Returns Service Requests with a result status extension matching the specified code.", "jurisdiction" : [ { "coding" : [ { "system" : "urn:iso:std:iso:3166", "code" : "US", "display" : "United States of America" } ] } ], "code" : "result-status", "base" : [ "ServiceRequest" ], "type" : "token", "expression" : "ServiceRequest.extension.where(url = 'http://test/service-request/result-status-extension').value.coding" }

nickmcsimpson commented 2 years ago

@CaitlinV39

Thanks for the help! Using .value.coding did fix my issue. I incorrectly assumed the structure of the example (Race) used in the documentation. As this example, contrary to my implementation, is pulling an extension inside an extension.

It does seem peculiar that Search Parameters can be created and never resolved though. Maybe not showing invalid Search Parameters values in the $reindex output is intentional, but it would be nice for troubleshooting this as a newbie if these search parameters could show even if they didn't find a value.

Much appreciated.