So I can query on identifier-SYSTEM's.
And I can "trim the return payload" by specifying values for _elements.
But when an _element is a collection of values (like "identifiers"), is there anyway to further tweaks the items in that return collection?
Given I have the following patients.
{
"resourceType": "Bundle",
"id": "4b3dc536-fb3a-4468-8aae-ba89b4d6aea2",
"meta": {
"lastUpdated": "2025-06-20T17:47:39.815+00:00"
},
"type": "searchset",
"total": 4,
"link": [
{
"relation": "self",
"url": "https://hapi.fhir.org/baseR4/Patient?identifier=coolGym201%7C"
}
],
"entry": [
{
"fullUrl": "https://hapi.fhir.org/baseR4/Patient/47049445",
"resource": {
"resourceType": "Patient",
"id": "47049445",
"meta": {
"versionId": "1",
"lastUpdated": "2025-04-24T17:58:23.858+00:00",
"source": "#rbUGIwrJDsczSSJD"
},
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><div class=\"hapiHeaderText\">JOHN STEVE <b>SMITH </b></div><table class=\"hapiPropertyTable\"><tbody><tr><td>Identifier</td><td>urn:id:999991</td></tr><tr><td>Date of birth</td><td><span>01 January 1950</span></td></tr></tbody></table></div>"
},
"identifier": [
{
"system": "coolGym201",
"value": "cg44444201"
},
{
"system": "groceryStoreSystem101",
"value": "gs44444201"
},
{
"system": "usaSSN",
"value": "ssn-001"
}
],
"name": [
{
"family": "PATEL",
"given": [
"MARY",
"CATHERINE"
]
}
],
"gender": "female",
"birthDate": "1950-01-01"
},
"search": {
"mode": "match"
}
},
{
"fullUrl": "https://hapi.fhir.org/baseR4/Patient/47049446",
"resource": {
"resourceType": "Patient",
"id": "47049446",
"meta": {
"versionId": "1",
"lastUpdated": "2025-04-24T17:59:08.138+00:00",
"source": "#1iovHZuXgrrYEC22"
},
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><div class=\"hapiHeaderText\">JOHN STEVE <b>SMITH </b></div><table class=\"hapiPropertyTable\"><tbody><tr><td>Identifier</td><td>urn:id:999991</td></tr><tr><td>Date of birth</td><td><span>01 January 1950</span></td></tr></tbody></table></div>"
},
"identifier": [
{
"system": "coolGym201",
"value": "cg444442012"
},
{
"system": "groceryStoreSystem101",
"value": "gs444442012"
},
{
"system": "usaSSN",
"value": "ssn-002"
}
],
"name": [
{
"family": "Smity",
"given": [
"Srini",
"Ford"
]
}
],
"gender": "female",
"birthDate": "1950-01-01"
},
"search": {
"mode": "match"
}
},
{
"fullUrl": "https://hapi.fhir.org/baseR4/Patient/47049451",
"resource": {
"resourceType": "Patient",
"id": "47049451",
"meta": {
"versionId": "1",
"lastUpdated": "2025-04-24T17:59:46.897+00:00",
"source": "#jedMZMj0EiTAPnhL"
},
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><div class=\"hapiHeaderText\">JOHN STEVE <b>SMITH </b></div><table class=\"hapiPropertyTable\"><tbody><tr><td>Identifier</td><td>urn:id:999991</td></tr><tr><td>Date of birth</td><td><span>01 January 1950</span></td></tr></tbody></table></div>"
},
"identifier": [
{
"system": "coolGym201",
"value": "cg444442013"
},
{
"system": "groceryStoreSystem101",
"value": "gs444442013"
},
{
"system": "usaSSN",
"value": "ssn-003"
}
],
"name": [
{
"family": "Jones",
"given": [
"Jordy",
"Sporty"
]
}
],
"gender": "female",
"birthDate": "1950-01-01"
},
"search": {
"mode": "match"
}
},
{
"fullUrl": "https://hapi.fhir.org/baseR4/Patient/47971748",
"resource": {
"resourceType": "Patient",
"id": "47971748",
"meta": {
"versionId": "1",
"lastUpdated": "2025-06-20T14:17:05.192+00:00",
"source": "#jk1xgWbkvb1OmN32"
},
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><div class=\"hapiHeaderText\">JOHN STEVE <b>SMITH </b></div><table class=\"hapiPropertyTable\"><tbody><tr><td>Identifier</td><td>urn:id:999991</td></tr><tr><td>Date of birth</td><td><span>01 January 1950</span></td></tr></tbody></table></div>"
},
"identifier": [
{
"system": "coolGym201",
"value": "cg444442014"
},
{
"system": "groceryStoreSystem101",
"value": "gs444442014"
},
{
"system": "usaSSN",
"value": "ssn-004"
}
],
"name": [
{
"family": "Cotton",
"given": [
"Peter",
"Tail"
]
}
],
"gender": "male",
"birthDate": "1951-01-01"
},
"search": {
"mode": "match"
}
}
]
}
Note the identifiers.
I have a "system" of coolGym201
and I have a second "system" of groceryStoreSystem101
....
If I run this query:
https://hapi.fhir.org/baseR4/Patient?identifier=coolGym201|
Then I get back (only) Patients who have an identifier that is based on the system "coolGym201"
...
If I run this query:
https://hapi.fhir.org/baseR4/Patient?_elements=identifier,name,birthDate
then I get back the (all Patients) ... but I have "trimmed" the results and specifically the return _elements to only identifier,name,birthDate.
But I get ALL identifiers. so when any of my 4 Patients above show up.. they have:
"system": "coolGym201",
and
"system": "groceryStoreSystem101",
identifiers values show up
...
My Question:
If there anyway to limit the _elements to be only be a specific identifier in the return.
The below syntax is not correct, but it is the idea I am going after:
So that... even though my 4 patients have 2 identifiers defined for each Patient, I only want to retrieve a single identifier (for coolGym201)
If my silly example, let's say I only want gym-identifier values because I only care to find people who are coolGym201 members.
....
This is more than just academic for me.
In my plain-server, facade .. implementation.
Let's say it is a different "backend system" query for each identifier.
So my implementation, I find the Patients.
But then I have to ping a
gym.lookup.service.com
and then a separate
grocery.store.service.com
for each identifier.
I know there are issues with the filtering.
In my actual use case, I have something more like this:
Query on family=Smith. But I only want a specific identifier (and name and birthDate)
https://hapi.fhir.org/baseR4/Patient?family=Smith&_elements=identifier[coolGym201|],name,birthDate
..
I'm trying to "do the correct FHIR way" .. of having the outsider ask for only the identifiers they need .. instead of getting all of them every time...... because of the "expense" of looking for every single identifer.
So the below return would be what I am trying to construct:
{
"resourceType": "Bundle",
"id": "4b3dc536-fb3a-4468-8aae-ba89b4d6aea2",
"meta": {
"lastUpdated": "2025-06-20T17:47:39.815+00:00"
},
"type": "searchset",
"total": 4,
"link": [
{
"relation": "self",
"url": "https://hapi.fhir.org/baseR4/Patient?identifier=coolGym201%7C"
}
],
"entry": [
{
"fullUrl": "https://hapi.fhir.org/baseR4/Patient/47049445",
"resource": {
"resourceType": "Patient",
"id": "47049445",
"identifier": [
{
"system": "coolGym201",
"value": "cg44444201"
}
],
"name": [
{
"family": "PATEL",
"given": [
"MARY",
"CATHERINE"
]
}
],
"birthDate": "1950-01-01"
},
"search": {
"mode": "match"
}
},
{
"fullUrl": "https://hapi.fhir.org/baseR4/Patient/47049446",
"resource": {
"resourceType": "Patient",
"id": "47049446",
"identifier": [
{
"system": "coolGym201",
"value": "cg444442012"
}
],
"name": [
{
"family": "Smity",
"given": [
"Srini",
"Ford"
]
}
],
"birthDate": "1950-01-01"
},
"search": {
"mode": "match"
}
},
{
"fullUrl": "https://hapi.fhir.org/baseR4/Patient/47049451",
"resource": {
"resourceType": "Patient",
"id": "47049451",
"identifier": [
{
"system": "coolGym201",
"value": "cg444442013"
}
],
"name": [
{
"family": "Jones",
"given": [
"Jordy",
"Sporty"
]
}
],
"birthDate": "1950-01-01"
},
"search": {
"mode": "match"
}
},
{
"fullUrl": "https://hapi.fhir.org/baseR4/Patient/47971748",
"resource": {
"resourceType": "Patient",
"id": "47971748",
"identifier": [
{
"system": "coolGym201",
"value": "cg444442014"
}
],
"name": [
{
"family": "Cotton",
"given": [
"Peter",
"Tail"
]
}
],
"birthDate": "1951-01-01"
},
"search": {
"mode": "match"
}
}
]
}
I am currently writing R4 FHIR servers, FYI.
You can use something like SQL-on-FHIR. However, in terms of base RESTful queries, there's no ability to filter elements except by root name. I guess custom operations could also work, though that's essentially a proprietary interface.