tencent cloud

Sorting and Searching

Download
Mode fokus
Ukuran font
Terakhir diperbarui: 2026-08-28 16:06:55
Diterjemahkan oleh AI

API Description

This is used to sort FHIR search results by specified fields. The client can initiate a search request via the HTTP GET method and use the _sort parameter to specify the sorting field, thereby adjusting the order of results according to business needs. Sort search supports sorting by a single search field or by a combination of multiple search fields.
This example demonstrates a common method for sorting Patient resources by last name and first name.

Input parameters

Parameter Name
Type
Required
Description
HTTP Method
String
Yes
Fixed as GET.
URL
String
Yes
The search address, in the format [baseUrl]/[resourceType]?[searchParams].
Authorization
String
Yes
The access token, in the format Bearer <AccessToken>. For details on how to obtain it, see Calling Method.
Accept
String
No
The response format. It is recommended to use application/fhir+json.
_sort
String
Yes
The name of the field(s) to sort by. One or multiple fields can be specified, separated by commas.
Note:
_sort=family indicates sorting by last name.
_sort=family,given indicates sorting by last name first, then by first name.
The sort field should typically be a search parameter supported by that resource type.
When you need to specify ascending or descending order for sorting, follow the actual platform-supported rules.

Output Parameters

Upon a successful API call, the HTTP status code 200 OK is typically returned. The response body is usually a Bundle resource, which contains a sorted list of resources and pagination information.
Key Response Body Field Descriptions:
Field
Type
Description
resourceType
String
Returns the resource type, usually Bundle.
id
String
The unique identifier of the current result set.
meta.lastUpdated
String
The generation time of the current result set.
type
String
The Bundle type is usually searchset in search scenarios.
total
Integer
The total number of matched records. This field may not be returned by default and is only returned when the server can efficiently calculate the total number of records. The current server does not support forcing the return of an accurate total via _total=accurate.
entry
Array
The sorted result list.
entry[].fullUrl
String
The complete access URL of the resource.
entry[].resource
Object
The matched resource content.
entry[].resource.id
String
Unique ID of the resource.
entry[].resource.meta
Object
Metadata of the resource, containing fields such as versionId and lastUpdated.
entry[].search.mode
String
Search hit mode.
link
Array
Pagination link information.

Examples

Request Example

Example 1: Sort by a single field.
GET /INSTANCE_ID/fhir/Patient?_sort=family HTTP/1.1
Host: HOSTNAME
Authorization: Bearer <AccessToken>
Accept: application/fhir+json
Example 2: Sort by multiple fields.
GET /INSTANCE_ID/fhir/Patient?_sort=family,given HTTP/1.1
Host: HOSTNAME
Authorization: Bearer <AccessToken>
Accept: application/fhir+json

Response Example

{
"resourceType": "Bundle",
"id": "2d7b3566-1773-40b3-abd4-0c8ebdd6466f",
"meta": {
"lastUpdated": "2026-07-08T21:24:05.941+08:00"
},
"type": "searchset",
"link": [
{
"relation": "self",
"url": "https://HOSTNAME/INSTANCE_ID/fhir/Patient?_sort=family"
},
{
"relation": "next",
"url": "https://HOSTNAME/INSTANCE_ID/fhir?_getpages=2d7b3566-1773-40b3-abd4-0c8ebdd6466f&_getpagesoffset=2&_count=20&_bundletype=searchset"
}
],
"entry": [
{
"fullUrl": "https://HOSTNAME/INSTANCE_ID/fhir/Patient/199963",
"resource": {
"resourceType": "Patient",
"id": "199963",
"meta": {
"versionId": "1",
"lastUpdated": "2022-10-10T07:07:33.086-04:00"
},
"name": [
{
"family": "Chalmers",
"given": [
"James"
]
}
]
},
"search": {
"mode": "match"
}
},
{
"fullUrl": "https://HOSTNAME/INSTANCE_ID/fhir/Patient/199964",
"resource": {
"resourceType": "Patient",
"id": "199964",
"meta": {
"versionId": "1",
"lastUpdated": "2022-10-10T07:07:33.086-04:00"
},
"name": [
{
"family": "Chalmers",
"given": [
"Peter"
]
}
]
},
"search": {
"mode": "match"
}
}
]
}

Error Codes

Common error codes are listed below. For more error codes, see Error Codes.
Error Code
Description
400 Bad Request
The _sort parameter format is incorrect, or the sort field is invalid.
401 Unauthorized
Not authenticated, and valid credentials are missing.
403 Forbidden
Authenticated but not authorized to search the resource.
404 Not Found
The specified resource type does not exist.
422 Unprocessable Entity
The sort parameter syntax is correct, but it fails business or rule validation.
500 Internal Server Error
Internal server processing exception.

Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan