Reverse chaining in FHIR - hl7-fhir

I want to do a search in HAPI FHIR server as follows:
Retrive Observation resources that are referenced in .has-member of other Observation resources that have a specific .device id.
Example:
"resourceType": "Observation",
"device": {
"reference": "Device/2412"
},
"hasMember": [
{
"reference": "Observation/1"
},
{
"reference": "Observation/2"
},
{
"reference": "Observation/3"
}
]
And I'd like to get Observation/1, Observation/2, and Observation/3

Using reverse chaining (_has):
Observation?_has:Observation:has-member:device=Device/2412
That is, get Observation resources where another Observation with device=Device/2412 refers to this resource through has-member.
This uses the definition of _has http://hl7.org/fhir/search.html#has and the search parameters on Observation http://hl7.org/fhir/observation.html#search

Related

Search criteria for appointment slots in Epic FHIR

I'm using Epic's FHIR API (with Argonaut) to search for available appointments, in their private sandbox:
POST /api/FHIR/STU3/Appointment/$find
{
"resourceType": "Parameters",
"parameter": [
{
"name": "startTime",
"valueDateTime": "2022-03-22T08:15:00Z"
},
{
"name": "endTime",
"valueDateTime": "2022-04-02T08:15:00Z"
}
]
}
And this gives me some temporary appointments starting at the desired date and time. No problem. However, if I add service-type as a parameter in the body:
POST /api/FHIR/STU3/Appointment/$find
{
"resourceType": "Parameters",
"parameter": [
{
"name": "startTime",
"valueDateTime": "2022-03-23T15:30:00Z"
},
{
"name": "endTime",
"valueDateTime": "2022-04-02T15:30:00Z"
},
{
"name": "service-type",
"valueCodeableConcept": {
"coding": [
{
"system": "urn:oid:1.2.840.114350.1.13.861.1.7.3.808267.11",
"code": "40111223"
}
]
}
}
]
}
I get a slightly different response. I see temporary appointments with the same slot IDs (different appointment IDs of course), but also see an OperationOutcome at the end of the Bundle:
{
"fullUrl": "urn:uuid:00000000-0007-792f-cd9b-f1f44af2c17c",
"resource": {
"resourceType": "OperationOutcome",
"issue": [
{
"severity": "information",
"code": "value",
"details": {
"coding": [
{
"system": "urn:oid:1.2.840.114350.1.13.0.1.7.2.657369",
"code": "59109",
"display": "An element value is invalid."
}
],
"text": "An element value is invalid."
},
"diagnostics": "1.2.840.114350.1.13.861.1.7.3.808267.11",
"location": [
"/f:service-type(oid)"
],
"expression": [
"service-type (oid)"
]
}
]
},
"search": {
"mode": "outcome"
}
}
The service-type system and code I used here were taken right from the example on Epic's page on the $find API. I see similar results when I use service-types from actual Slots in the Epic sandbox. And if I put in a location-reference, it seems to be ignored and appointments at other locations are sometimes returned. The net result of all this is that it seems only the start and end time are honored when finding appointments.
How can I narrow down the results of a $find call using criteria other than the start and end date?
The source of truth for this API should be the fhir.epic.com documentation, but since this is a common question, I'll post some information here:
$find is not a good option for patient open scheduling. I don't know if that is your use case or not, but it is a common question, so I'll address it anyway.
$find invokes a rules engine that is defined by each healthcare organization. The logic of that rules engine is 100% up to the healthcare organization to define. In order for $find to work for you, you'll need very specific pre-coordination to build the logic in that engine.
The Epic sandboxes only have a very basic rules engine built out. It isn't particularly "real-world"-y. And it is probably good that it isn't, as it serves as an early warning that this API may not be the API you are looking for.
The $find API is a way to support cross-organization scheduling. For example, if you want front desk staff to be able to schedule a follow up visit at another organization across town that they have an established business relationship. For example, if a PCP office wants to schedule a dermatology visit for you at an external org. Note that the user in this case is the organization's scheduling staff, not the patient.
Specifically, Epic's $find support is based on Use Case 1 and 2 in the Argonaut Implementation Guide.

Searching for Patient within a Bundle

We use Bundles to contain other resources. I want to search for bundles based on these nested resources. e.g. I have bundles that look like this:
{
"resourceType": "Bundle",
"type": "collection",
"entry": [
{
"resource": {
"resourceType": "Patient",
"identifier": [
{
"type": {
"coding": [
{
"code": "foo"
}
]
},
"value": "12345"
},
{
"type": {
"coding": [
{
"code": "bar"
}
]
},
"value": "abcde"
}
]
}
},
{
"resource": {
"resourceType": "SomeOtherResource"
}
}
]
}
I want to find all bundles which have Patient with "bar" == "abcde". There will be many such bundles and each Patient will have many identifiers other than "bar"
I've looked through https://www.hl7.org/fhir/search.html, but all the examples I find assume that (e.g.) Patient is at the top level and I can search with [base]/Patient?..., but I am looking for Bundles. I've looked through the search parameters here but those don't include any "contained" entries.
I've tried all the combinations of bundle/patient/identifier I can think of with no luck. Is this even supported?
If your Bundle is a FHIR Document or FHIR Message, you can search by chaining through the 'composition' or 'message' search parameter. Otherwise, there's no standard way to search. In general, content within a Bundle is opaque.

FHIR - Contained Resources and Referencing

I am still new to FHIR and trying to connect the dots.
If I have a resource that I want to contain other resources, can I refer to it by element name (#myElementName) or do I need to use the contained resource id? (#myDeviceId).
I've included sample code below. What I would like to accomplish is to have a Basic resource that has two extensions: TestConfiguration(Device) and DigitalSample(ImagingStudy). I would like for both of these resources to be contained.
PS: I generated the code below using custom classes and the .net API.
Thank you much!
{
"resourceType": "TestInput",
"contained": [
{
"resourceType": "TestConfiguration",
"id": "TestConfigurationId",
"contained": [
{
"resourceType": "DeviceDefinition",
"modelNumber": "ABC123"
}
],
"definition": {
"reference": "#definition"
}
},
{
"resourceType": "DigitalSample",
"id": "DigitalSampleId"
}
],
"extension": [
{
"url": "http://MyOrganization.com/fhir/R4/StructureDefinition/Basic-TestConfiguration",
"valueReference": {
"reference": "#testConfiguration"
}
},
{
"url": "http://MyOrganization.com/fhir/R4/StructureDefinition/Basic-DigitalSample",
"valueReference": {
"reference": "#digitalSampleId"
}
}
]
}
Every local reference must point to an id of a contained resource.
In your case it should be:
"reference": "#TestConfigurationId"
"reference":"#DigitalSampleId"
Always check https://www.hl7.org/fhir/ for what you need to do. Always check the FHIR version

How to search birthData in fhir using _content?

When I search with only birthData in fhir I am getting results.
For example: http://localhost:8080/hapi-fhir-jpaserver/fhir/Patient?_pretty=true&birthdate=2020-03-16 will return patient who has birthdate as 2020-03-16.
When I am searching with _content I am not getting any results. Something like this:
http://localhost:8080/hapi-fhir-jpaserver/fhir/Patient?_content=2019-09-05
_content is for searching text content.
If you want to search for dates you need to use a date search parameter. E.g.:
http://localhost:8080/hapi-fhir-jpaserver/fhir/Patient?birthDate=2019-09-05
This can be achieved using Search Parameters.
Search parameters are essentially named paths within resources that are indexed by the system so that they can be used to find resources that match a given criteria.
Using Search parameter
we can add additional search parameters that will index fields that do not have a standard search parameter defined.
we can add additional search parameters that will index extensions used by your clients.
we can disable search parameters
Example:
Lets say I have a PractitionerRole
"resourceType": "PractitionerRole",
"id": "6639",
"meta": {
"versionId": "1",
"lastUpdated": "2020-03-19T13:26:34.748+05:30",
"source": "#aYyeIlv9Yutudiwy"
},
"text": {
"status": "generated",
"div": "<div xmlns=\"<http://www.w3.org/1999/xhtml\">foo</div>">
},
"active": true,
"practitioner": {
"reference": "Practitioner/6607"
},
"organization": {
"reference": "Organization/6528"
},
"specialty": [
{
"coding": [
{
"system": "<http://snomed.info/sct",>
"code": "42343242",
"display": "Clinical immunology"
}
]
}
]
}
PractitionerRole has thier own search parameters. Apart from those search parameters we wanted to have a search parameter which will filter all practitioner roles based on practitioner.reference. We can achieve this using Search parameters. All we need to do is creating a new search parameter just like below.
{
"resourceType": "SearchParameter",
"title": "Practitioner Referecene",
"base": [ "PractitionerRole" ],
"status": "active",
"code": "practitioner_reference",
"type": "token",
"expression": "PractitionerRole.practitioner.reference",
"xpathUsage": "normal"
}
Here what fhir tells is when user wanted to filter with practitioner_reference then look for PractitionerRole.practitioner.reference.
This looks something like this:
http://localhost:8080/hapi-fhir-jpaserver/fhir/PractitionerRole?practitioner_reference=Practitioner/6607
We can also extend this to search with multiple parameters. We can create a search parameter with or condition so that it can search with multi parameters.
"resourceType": "SearchParameter",
"title": "Patient Multi Search",
"base": [ "Patient" ],
"status": "active",
"code": "pcontent",
"type": "token",
"expression": "Patient.managingOrganization.reference|Patient.birthDate|Patient.address[0].city",
"xpathUsage": "normal"
}
Above SearchParameter will search withPatient.managingOrganization.reference or Patient.birthDate or Patient.address[0].city.
The query looks like this:
Search With City → http://localhost:8080/hapi-fhir-jpaserver/fhir/Patient?pcontent=Bruenmouth
Search With Birth Date → http://localhost:8080/hapi-fhir-jpaserver/fhir/Patient?pcontent=2019-04-06

FHIR DSTU2: What is the correct way to represent an extension value as a collection?

I'm currently looking into creating a FHIR DSTU2 extension. I need the extension to return a collection of values. What is the correct way to represent this in FHIR DSTU2?
Should it be a list of extensions within an extension:
"resource": {
"resourceType": "Medication",
"extension": [
{
"url": "http://www.myextension.com/strengths",
"extension": [
{
"url": "http://www.myextension.com/strength",
"valueStrength": "5mg"
},
{
"url": "http://www.myextension.com/strength",
"valueStrength": "20mg"
}
]
}
],
}
Or should it be one extension with a collection on the value?
"resource": {
"resourceType": "Medication",
"extension": [
{
"url": "http://www.emis-online.com/strengths",
"valueStrengths": [
"5mg",
"20mg"
],
}
],
}
Thanks.
It would actually look like this:
"resource": {
"resourceType": "Medication",
"extension": [
{
"url": "http://www.myextension.com/strength",
"valueString": "5mg"
},
{
"url": "http://www.myextension.com/strength",
"valueString": "20mg"
}
]}
As well, it'd be better to use valueQuantity than valueString - to split the value and the unit.
That said, there's no reason to use an extension for drug strengths at all. Medication.product.ingredient.amount is strength - if the ingredient is an active ingredient. (I see that the resource doesn't currently allow distinguishing active from excipient ingredients, so I'd encourage raising a change request on that.)

Resources