FHIR
FHIR copied to clipboard
SearchParameters created with REST API don't work
Describe the bug
The server returns the error message Search parameter 'favorite-color' for resource type 'Patient' was not found. after creating the search parameter from the example.
Environment 4.11.1
To Reproduce Steps to reproduce the behavior:
- Create the SearchParameter:
POST https://your_fhir_server/api/v4/SearchParameter
{
"resourceType": "SearchParameter",
"id": "Patient-favorite-color",
"url": "http://example.com/fhir/SearchParameter/Patient-favorite-color",
"version": "4.0.0",
"name": "favorite-color",
"status": "draft",
"experimental": false,
"date": "2018-12-27T22:37:54+11:00",
"publisher": "LinuxForHealth FHIR Server Test",
"contact": [{
"telecom": [{
"system": "url",
"value": "http://linuxforhealth.org"
}]
},
{
"telecom": [{
"system": "url",
"value": "http://linuxforhealth.org"
}]
}],
"description": "the patient's favorite color",
"code": "favorite-color",
"base": ["Patient"],
"type": "string",
"xpathUsage": "normal",
"xpath": "f:Patient/f:extension[@url='http://example.com/fhir/extension/Patient/favorite-color']/f:valueString",
"expression": "Patient.extension.where(url='http://example.com/fhir/extension/Patient/favorite-color').value",
"multipleOr": true,
"multipleAnd": true,
"modifier": []
}
- Search with it:
GET https://your_fhir_server/api/v4/Patient?favorite-color:exact=pink
We have tests for this. Please provide more info about how you've configured your server. I assume you're following https://linuxforhealth.github.io/FHIR/guides/FHIRSearchConfiguration ? Did you restart your server after adding the search parameter?
Yeah, I created a SearchParameter, then I restarted the server and performed reindexing. Those actions were made on 5.0.0 (I upgraded the server today, but SearchParameters still don't work). Reindexing didn't work on 4.11.1 though, but works fine on 5.0.0. Is fhir-search module needed to be enabled explicitly? I didn't do any configurations about fhir-search.
Ok, I think you are assuming that posting a SearchParameter via our REST API will cause the server to pick it up and apply it to resources, but we actually have a config setting for that (and its off by default).
In most of our deployments, we don't want users creating their own search parameters and so we more typically consider that part of the configuration done by the server admin / operator. The guide I linked above covers a couple ways to package up a set of search parameters as part of the server config. Basically we have an internal registry and you need to make the search parameter available to that registry.
If you really want to be able to create search parameters just by posting them to the server then you need to set
fhirServer/core/serverRegistryResourceProviderEnabled to true in your fhir-server-config.json
What that does is make conformance resources in the operational datastore (e.g. postgres) available to the registry.
Setting fhirServer/core/serverRegistryResourceProviderEnabled=true hasn't worked out. Also I just tried to add the SearchParameter to /config/config/default/extension-search-parameters.json, but Patient's search still returns Search parameter 'favorite-color' for resource type 'Patient' was not found.
I forgot to wrap the SearchParameter into Bundle inside extension-search-parameters.json. Now it works with extension-search-parameters.json configuration provided.
I renamed the issue to be more precise what doesn't work as intended.
Glad you got it working with extension-search-parameters.json.
SearchParameter resources from the database should be loaded on server start if you set fhirServer/core/serverRegistryResourceProviderEnabled=true.
However, previously ingested resources will need to be reindexed for this new search parameter to take effect. I believe that part is working, but if you find otherwise please open an issue.