FHIR Chat · Search Parameters and Extensions · hapi

Stream: hapi

Topic: Search Parameters and Extensions


view this post on Zulip Saul Kravitz (May 30 2019 at 14:28):

(Moving here from the Implementers stream...sorry for the duplication)
Any insight into how I am misusing the SearchParameter would be greatly appreciated.

HAPI (I've tested 3.7 and 3.8) implements search parameter definitions.
See http://hapi.fhir.org/baseR4/MedicationKnowledge?productType for a search parameter that allows search against the MedicationKnowledge productType field.
A sample query is:
http://hapi.fhir.org/baseR4/MedicationKnowledge?productType=BRANDX

I'm trying to develop a SearchParameter that will allow me to search against data in extension fields.
The extensions are valueBooleans.
I have two MedicationInformation Objects, one with the extension data, one without: (see http://hapi.fhir.org/baseR4/MedicationKnowledge)
1) http://hapi.fhir.org/baseR4/MedicationKnowledge/SaulExperimentMK1 -- has extensions
2) http://hapi.fhir.org/baseR4/MedicationKnowledge/SaulExperimentMK2

The quantityLimit extension looks like this:
{
"url": "https://api-v8-r4.hspconsortium.org/DrugFormulary2/open/StructureDefinition/usdrugformulary-QuantityLimit-extension",
"valueBoolean": true
}

I have defined a SearchParameter: http://hapi.fhir.org/baseR4/SearchParameter/quantityLimit
{
"resourceType": "SearchParameter",
"id": "quantityLimit",
"meta": {
"versionId": "1",
"lastUpdated": "2019-02-22T08:37:56.297+00:00"
},
"title": "quantityLimit",
"status": "active",
"code": "quantityLimit",
"base": [
"MedicationKnowledge"
],
"type": "string",
"expression": "MedicationKnowledge.extension(\" https://api-v8-r4.hspconsortium.org/DrugFormulary2/open/StructureDefinition/usdrugformulary-QuantityLimit-extension.valueBoolean \")",
"xpathUsage": "normal",
"comparator": [
"eq"
],
"search": {
"mode": "match"
}
}

The SearchParameter is recognized by the server, but doesn't work (as intended).

Searching:
1) http://hapi.fhir.org/baseR4/MedicationKnowledge?quantityLimit - returns two MedicationKnowledge objects... only one object has the quantityLimit extension, so this should return only one object, right?
2) http://hapi.fhir.org/baseR4/MedicationKnowledge?quantityLimit="true" returns zero objects, but should return one object, right?

view this post on Zulip James Agnew (May 31 2019 at 09:52):

That path doesn't look correct to me...

MedicationKnowledge.extension(\" https://api-v8-r4.hspconsortium.org/DrugFormulary2/open/StructureDefinition/usdrugformulary-QuantityLimit-extension.valueBoolean \"

I would have expected something like

MedicationKnowledge.extension('https://api-v8-r4.hspconsortium.org/DrugFormulary2/open/StructureDefinition/usdrugformulary-QuantityLimit-extension').value

view this post on Zulip Saul Kravitz (May 31 2019 at 22:31):

2nd try. A colleague told me to test my FHIRPAth expressions in the fhirpath.js tool, so these expressions work on these resources on the command line.

See http://hapi.fhir.org/baseR4/SearchParameter/drugTier
http://hapi.fhir.org/baseR4/MedicationKnowledge/SaulExperimentMK1
http://hapi.fhir.org/baseR4/MedicationKnowledge/SaulExperimentMK2
http://hapi.fhir.org/baseR4/MedicationKnowledge/cmsip9

The expression has been tested on fhirpath:
~/git/fhirpath.js/bin/fhirpath --expression "MedicationKnowledge.extension.where(url='https://api-v8-r4.hspconsortium.org/DrugFormulary2/open/StructureDefinition/usdrugformulary-DrugTierID-extension').valueCodeableConcept.coding.code" --resourceFile FormularyDrugcmsip9.json
fhirpath(MedicationKnowledge.extension.where(url='https://api-v8-r4.hspconsortium.org/DrugFormulary2/open/StructureDefinition/usdrugformulary-DrugTierID-extension').valueCodeableConcept.coding.code) =>
[
"GENERIC"
]

The drugTier Search Parameter takes the most verbose (and likely to be supported approach).

{
"resourceType": "SearchParameter",
"id": "drugTier",
"meta": {
"versionId": "1",
"lastUpdated": "2019-02-22T08:37:56.297+00:00"
},
"title": "drugTier",
"status": "active",
"code": "drugTier",
"base": [
"MedicationKnowledge"
],
"type": "string",
"expression": "MedicationKnowledge.extension.where(url='https://api-v8-r4.hspconsortium.org/DrugFormulary2/open/StructureDefinition/usdrugformulary-DrugTierID-extension').valueCodeableConcept.coding.code",
"comparator": [
"eq"
],
"search": {
"mode": "exact"
}
}

The extensions look like this:
{
"url": "https://api-v8-r4.hspconsortium.org/DrugFormulary2/open/StructureDefinition/usdrugformulary-DrugTierID-extension",
"valueCodeableConcept": {
"coding": [
{
"code": "GENERIC",
"system": "https://api-v8-r4.hspconsortium.org/DrugFormulary2/open/CodeSystem/usdrugformulary-DrugTierCS",
"display": "GENERIC"
}
]
}
}

GET http://hapi.fhir.org/baseR4/MedicationKnowledge?drugTier=GENERIC returns nothing
GET http://hapi.fhir.org/baseR4/MedicationKnowledge?drugTier returns all 3 MedicationKnowledge resources

Am I configuring the searchParameter wrong, or is this a big?

view this post on Zulip Chris Moesel (Jun 01 2019 at 15:59):

I responded to @Saul Kravitz offline, but will include my response here for completeness and to spark any additional conversation or thoughts (if anyone has some).

I’m not sure exactly what’s going on here, but here is something to try. Usually code-based searches would use the “token” type and the expression need only resolve to the CodeableConcept.

So try this:

  • Change “type” to "token"
  • Change “expression” to "MedicationKnowledge.extension.where(url='https://api-v8-r4.hspconsortium.org/DrugFormulary2/open/StructureDefinition/usdrugformulary-DrugTierID-extension').valueCodeableConcept"

In addition, looking at the R4 SearchParameter documentation, I don’t see “search.mode”. Are you sure that isn’t supposed to be “modifier”? So my last suggestion is:

  • Replace "search": { "mode": "exact" } with "modifier": [ "exact" ]

view this post on Zulip James Agnew (Jun 01 2019 at 23:42):

I'm 70% sure you need .value in the expression and not .valueCodeableConcept

view this post on Zulip Grahame Grieve (Jun 02 2019 at 07:09):

y

view this post on Zulip Chris Moesel (Jun 02 2019 at 22:26):

I'm 70% sure you need .value in the expression and not .valueCodeableConcept

Ah. Right. That's probably true. In that case I guess it's worth noting that fhirpath.js happily worked with valueCodeableConcept.

view this post on Zulip Saul Kravitz (Jun 03 2019 at 03:41):

Made all of the suggested changes...still not working (http://hapi.fhir.org/baseR4/MedicationKnowledge?drugTier=BRAND returns 0 results).

One oddity is that when I PUT:
{
"resourceType": "SearchParameter",
"id": "drugTier",
"meta": {
"versionId": "1",
"lastUpdated": "2019-02-22T08:37:56.297+00:00"
},
"title": "drugTier",
"status": "active",
"code": "drugTier",
"base": [
"MedicationKnowledge"
],
"type": "token",
"expression": "MedicationKnowledge.extension.where(url='https://api-v8-r4.hspconsortium.org/DrugFormulary2/open/StructureDefinition/usdrugformulary-DrugTierID-extension').value",
"comparator": [
"eq"
],
"modifier": {
mode:"exact"
}
}

The "modifier gets lost"... here is GET of the same resource:
{
"resourceType": "SearchParameter",
"id": "drugTier",
"meta": {
"versionId": "12",
"lastUpdated": "2019-06-03T03:32:55.073+00:00"
},
"title": "drugTier",
"status": "active",
"code": "drugTier",
"base": [
"MedicationKnowledge"
],
"type": "token",
"expression": "MedicationKnowledge.extension.where(url='https://api-v8-r4.hspconsortium.org/DrugFormulary2/open/StructureDefinition/usdrugformulary-DrugTierID-extension').value",
"comparator": [
"eq"
]
}

view this post on Zulip Chris Moesel (Jun 03 2019 at 12:11):

Hi @Saul Kravitz -- I think modifier needs to be an array. So:

"modifier": [ "exact" ]

view this post on Zulip James Agnew (Jun 03 2019 at 13:08):

@Saul Kravitz your search parameter appears to work for me:

http://hapi.fhir.org/baseR4/MedicationKnowledge?drugTier=GENERIC

view this post on Zulip Saul Kravitz (Jun 03 2019 at 13:59):

Thanks @James Agnew and @Chris Moesel

view this post on Zulip Paul Lynch (Jun 03 2019 at 17:02):

I'm 70% sure you need .value in the expression and not .valueCodeableConcept

Ah. Right. That's probably true. In that case I guess it's worth noting that fhirpath.js happily worked with valueCodeableConcept.

Yes, that is a shortcoming of fhirpath.js-- it does not know about choice types (yet). For some discussion on that, see https://chat.fhir.org/#narrow/stream/179266-fhirpath/topic/Paths.20for.20choice.20types.

view this post on Zulip nicola (RIO/SS) (Jun 05 2019 at 02:06):

I do not think it should know about this until we fix FHIR json format :)

choice types can (or should) be serialized as {value: {Quantity: ....}} and this will eliminate all of these problems

view this post on Zulip Grahame Grieve (Jun 05 2019 at 09:50):

you have to be realistic - we will not be changing the json format.

view this post on Zulip Grahame Grieve (Jun 05 2019 at 09:51):

yes, you can define a second json format, but it will be voted down and no one will implement it


Last updated: Apr 12 2022 at 19:14 UTC