You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/healthcare-apis/fhir/how-to-do-custom-search.md
+34-30Lines changed: 34 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,19 +5,19 @@ author: ginalee-dotcom
5
5
ms.service: healthcare-apis
6
6
ms.subservice: fhir
7
7
ms.topic: reference
8
-
ms.date: 06/06/2022
8
+
ms.date: 08/22/2022
9
9
ms.author: mikaelw
10
10
---
11
11
# Defining custom search parameters
12
12
13
-
The FHIR specification defines a set of search parameters for all resources and search parameters that are specific to a resource(s). However, there are scenarioswhere you might want to search against an element in a resource that isn’t defined by the FHIR specification as a standard search parameter. This article describes how you can define your own [search parameters](https://www.hl7.org/fhir/searchparameter.html)to be used in the FHIR service in Azure Health Data Services (hereby called FHIR service).
13
+
The FHIR specification defines a set of search parameters that apply to all resources. Additionally, FHIR defines many search parameters that are specific to certain resources. There are scenarios, however, where you might want to search against an element in a resource that isn’t defined by the FHIR specification as a standard search parameter. This article describes how you can define your own custom [search parameters](https://www.hl7.org/fhir/searchparameter.html)for use in the FHIR service in Azure Health Data Services.
14
14
15
15
> [!NOTE]
16
-
> Each time you create, update, or delete a search parameter you’ll need to run a [reindex job](how-to-run-a-reindex.md) to enable the search parameter to be used in production. Below we will outline how you can test search parameters before reindexing the entire FHIR service.
16
+
> Each time you create, update, or delete a search parameter, you’ll need to run a [reindex job](how-to-run-a-reindex.md) to enable the search parameter for live production. Below we will outline how you can test search parameters before reindexing the entire FHIR service database.
17
17
18
18
## Create new search parameter
19
19
20
-
To create a new search parameter, you `POST`the`SearchParameter` resource to the database. The code example below shows how to add the [US Core Race SearchParameter](http://hl7.org/fhir/us/core/STU3.1.1/SearchParameter-us-core-race.html) to the `Patient` resource.
20
+
To create a new search parameter, you `POST`a`SearchParameter` resource to the FHIR service database. The code example below shows how to add the [US Core Race search parameter](http://hl7.org/fhir/us/core/STU3.1.1/SearchParameter-us-core-race.html) to the `Patient` resource type in your FHIR service database.
21
21
22
22
```rest
23
23
POST {{FHIR_URL}}/SearchParameter
@@ -64,25 +64,25 @@ POST {{FHIR_URL}}/SearchParameter
64
64
```
65
65
66
66
> [!NOTE]
67
-
> The new search parameter will appear in the capability statement of the FHIR service after you POST the search parameter to the database **and** reindex your database. Viewing the `SearchParameter` in the capability statement is the only way tell if a search parameter is supported in your FHIR service. If you can find the search parameter by searching for the search parameter but cannot see it in the capability statement, you still need to index the search parameter. You can POST multiple search parameters before triggering a reindex operation.
67
+
> The new search parameter will appear in the capability statement of the FHIR service after you `POST` the search parameter to the database **and** reindex your database. Viewing the `SearchParameter` in the capability statement is the only way to tell if a search parameter is supported in your FHIR service. If you cannot find the `SearchParameter`in the capability statement, then you still need to reindex your database to activate the search parameter. You can `POST` multiple search parameters before triggering a reindex operation.
68
68
69
-
Important elements of a `SearchParameter`:
69
+
Important elements of a `SearchParameter` resource:
70
70
71
-
***url**: A unique key to describe the search parameter. Many organizations, such as HL7, use a standard URL format for the search parameters that they define, as shown above in the US Core race search parameter.
71
+
*`url`: A unique key to describe the search parameter. Organizations such as HL7 use a standard URL format for the search parameters that they define, as shown above in the US Core Race search parameter.
72
72
73
-
***code**: The value stored in **code** is what you’ll use when searching. For the example above, you would search with `GET {FHIR_URL}/Patient?race=<code>` to get all patients of a specific race. The code must be unique for the resource(s) the search parameter applies to.
73
+
*`code`: The value stored in **code** is what you’ll use when searching. For the example above, you would search with `GET {{FHIR_URL}}/Patient?race=<code>` to retrieve all patients of a certain race. The coding system must be unique for the resource type(s) that the search parameter applies to.
74
74
75
-
***base**: Describes which resource(s) the search parameter applies to. If the search parameter applies to all resources, you can use `Resource`; otherwise, you can list all the relevant resources.
75
+
*`base`: Describes which resource type(s) the search parameter applies to. If the search parameter applies to all resources, you can use `Resource`; otherwise, you can list all the relevant resource types.
76
76
77
-
***type**: Describes the data type for the search parameter. Type is limited by the support for the FHIR service. This means that you can’t define a search parameter of type Special or define a [composite search parameter](overview-of-search.md) unless it's a supported combination.
77
+
*`type`: Describes the data type for the search parameter. Type is limited by the support for data types in the FHIR service. This means that you can’t define a search parameter of type Special or define a [composite search parameter](overview-of-search.md) unless it's a supported combination.
78
78
79
-
***expression**: Describes how to calculate the value for the search. When describing a search parameter, you must include the expression, even though it isn't required by the specification. This is because you need either the expression or the xpath syntax and the FHIR service ignores the xpath syntax.
79
+
*`expression`: Describes how to calculate the value for the search. When describing a search parameter, you must include the expression, even though it isn't required by the specification. This is because you need either the expression or the xpath syntax and the FHIR service ignores the xpath syntax.
80
80
81
-
## Test search parameters
81
+
## Test new search parameters
82
82
83
-
While you can’t use the search parameters in production until you run a reindex job, there are a few ways to test your search parameters before reindexing the entire database.
83
+
While you can’t use the new search parameters in production until you run a reindex job, there are a few ways to test your custom search parameters before reindexing the entire database.
84
84
85
-
First, you can test your new search parameter to see what values will be returned. By running the command below against a specific resource instance (by inputting their ID), you'll get back a list of value pairs with the search parameter name and the value stored. This will include all of the search parameters for the resource and you can scroll through to find the search parameter you created. Running this command won't change any behavior in your FHIR service.
85
+
First, you can test a new search parameter to see what values will be returned. By running the command below against a specific resource instance (by supplying the resource ID), you'll get back a list of value pairs with the search parameter name and the value stored in the corresponding element. This will include all of the search parameters for the resource. You can scroll through to find the search parameter you created. Running this command won't change any behavior in your FHIR service.
86
86
87
87
```rest
88
88
GET https://{{FHIR_URL}}/{{RESOURCE}}/{{RESOUCE_ID}}/$reindex
@@ -116,45 +116,49 @@ The result will look like this:
116
116
{
117
117
"name": "race",
118
118
"valueString": "2028-9"
119
-
},
120
-
...
119
+
}
120
+
]
121
+
...}
121
122
```
122
-
Once you see that your search parameter is displaying as expected, you can reindex a single resource to test searching with the element. First you'll reindex a single resource:
123
+
124
+
Once you see that your search parameter is displaying as expected, you can reindex a single resource to test searching with your new search parameter. To reindex a single resource:
123
125
124
126
```rest
125
127
POST https://{{FHIR_URL}/{{RESOURCE}}/{{RESOURCE_ID}}/$reindex
126
128
```
127
129
128
-
Running this, sets the indices for any search parameters for the specific resource that you defined for that resource type. This does make an update to the FHIR service. Now you can search and set the usepartialindices header to true, which means that it will return results where any of the resources has the search parameter indexed, even if not all resources of that type have it indexed.
130
+
Running this`POST` call sets the indices for any search parameters defined for the resource instance specified in the request. This call does make a change to the FHIR service database. Now you can search and set the `x-ms-use-partial-indices` header to `true`, which causes the FHIR service to return results for any of the resources that have the search parameter indexed, even if not all resource instances of that type have it indexed.
129
131
130
132
Continuing with our example above, you could index one patient to enable the US Core Race `SearchParameter`:
131
133
132
134
```rest
133
-
POST https://{{FHIR_URL}/Patient/{{PATIENT_ID}}/$reindex
135
+
POST {{FHIR_URL}}/Patient/{{PATIENT_ID}}/$reindex
134
136
```
135
137
136
-
And then search for patients that have a specific race:
138
+
And then do a test search for the patient by race:
137
139
138
140
```rest
139
-
GET https://{{FHIR_URL}}/Patient?race=2028-9
141
+
GET {{FHIR_URL}}/Patient?race=2028-9
140
142
x-ms-use-partial-indices: true
141
143
```
142
144
143
-
After you have tested and are satisfied that your search parameter is working as expected, run or schedule your reindex job so the search parameters can be used in the FHIR service for production use cases.
145
+
After you have tested your new search parameter and confirmed that it is working as expected, run or schedule your reindex job so the new search parameter(s) can be used in live production.
146
+
147
+
See [Running a reindex job](../fhir/how-to-run-a-reindex.md) for information on how to re-index your FHIR service database.
144
148
145
149
## Update a search parameter
146
150
147
-
To update a search parameter, use `PUT` to create a new version of the search parameter. You must include the `SearchParameter ID` in the `id` element of the body of the `PUT` request and in the `PUT` call.
151
+
To update a search parameter, use `PUT` to create a new version of the search parameter. You must include the `SearchParameter` ID in the `id`field in the body of the `PUT` request as well as the `PUT`request string.
148
152
149
153
> [!NOTE]
150
-
> If you don't know the ID for your search parameter, you can search for it. Using `GET {{FHIR_URL}}/SearchParameter`will return all custom search parameters, and you can scroll through the search parameter to find the search parameter you need. You could also limit the search by name. With the example below, you could search for name using `USCoreRace: GET {{FHIR_URL}}/SearchParameter?name=USCoreRace`.
154
+
> If you don't know the ID for your search parameter, you can search for it using`GET {{FHIR_URL}}/SearchParameter`. This will return all custom search parameters, and you can scroll through the search parameter list to find the search parameter you need. You could also limit the search by name. With the example response below, you could search by name using `USCoreRace`: `GET {{FHIR_URL}}/SearchParameter?name=USCoreRace`.
151
155
152
156
```rest
153
-
PUT {{FHIR_URL}}/SearchParameter/{SearchParameter ID}
157
+
PUT {{FHIR_URL}}/SearchParameter/{{SearchParameter_ID}}
@@ -196,22 +200,22 @@ PUT {{FHIR_URL}}/SearchParameter/{SearchParameter ID}
196
200
The result will be an updated `SearchParameter` and the version will increment.
197
201
198
202
> [!Warning]
199
-
> Be careful when updating SearchParameters that have already been indexed in your database. Changing an existing SearchParameter’s behavior could have impacts on the expected behavior. We recommend running a reindex job immediately.
203
+
> Be careful when updating search parameters. Changing an existing search parameter could have impacts on the expected behavior. We recommend running a reindex job immediately.
200
204
201
205
## Delete a search parameter
202
206
203
207
If you need to delete a search parameter, use the following:
> Be careful when deleting SearchParameters that have already been indexed in your database. Changing an existing SearchParameter’s behavior could have impacts on the expected behavior. We recommend running a reindex job immediately.
214
+
> Be careful when deleting search parameters. Changing an existing search parameter could have impacts on the expected behavior. We recommend running a reindex job immediately.
211
215
212
216
## Next steps
213
217
214
-
In this article, you’ve learned how to create a search parameter. Next you can learn how to reindex your FHIR service. For more information, see
218
+
In this article, you’ve learned how to create a custom search parameter. Next you can learn how to reindex your FHIR service database. For more information, see
215
219
216
220
>[!div class="nextstepaction"]
217
221
>[How to run a reindex job](how-to-run-a-reindex.md)
0 commit comments