How to add search object (Bundle.EntrySearch) in HAPI FHIR?

92 views
Skip to first unread message

Hemant Patidar

unread,
Sep 26, 2017, 12:03:00 PM9/26/17
to HAPI FHIR

Hi,


Currently I have a method with below signature which returns list of resources (document references) when a GET request (http://localhost:8090/fhir/DocumentReference?subject.identifier=DEFAULT|1000) is made.


@Search
public List<BaseResource> findDocumentReferencesById(@RequiredParam(
            name = DocumentReference.SP_SUBJECT,
            chainWhitelist = {Patient.SP_IDENTIFIER, Practitioner.SP_IDENTIFIER}
        )) {
    ...
    List<BaseResource> response = new ArrayList<>();
    response.add(documentReference);
    ... 
    return  response;

}

This returns all the document references but I want to add a fake search object with random score like below for each of document references (for testing purposes, since this does not include all the search match code) :

"search":{  
    "mode":"match",
        "score":1
}

Current output:

{
"resourceType": "Bundle",
...
"entry": [
    {
        "fullUrl": "some generated url",
        "resource": {
            "resourceType": "DocumentReference",
            "id": "1",
            "subject": {
                "reference": "Patient/1"
            }
        }
    }
]

}

Desired output:

{
"resourceType": "Bundle",
...
"entry": [
    {
        "fullUrl": "some generated url",
        "resource": {
            "resourceType": "DocumentReference",
            "id": "1",
            "subject": {
                "reference": "Patient/1"
            },
        "search":{  
            "mode":"match",
            "score":1
            }
        }
    }
  ]
}


 I cannot add a bundle to the response since it will just create another bundle and would not add the search object at the resource level.


Any ideas?

James Agnew

unread,
Sep 26, 2017, 2:53:15 PM9/26/17
to Hemant Patidar, HAPI FHIR
Hi Hemant,

You can set the search mode on responses by providing it in metadata on resources you return, e.g.:

ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(resource, "match");

This gets applied right here (this link is the DSTU3 bundle facotry, it's in a similar spot for DSTU2/R4): https://github.com/jamesagnew/hapi-fhir/blob/master/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/hapi/rest/server/Dstu3BundleFactory.java#L210

There is no corresponding way to set the score attribute right now, but if you wanted to add this we would certainly welcome the patch!

Cheers,
James

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+unsubscribe@googlegroups.com.
To post to this group, send email to hapi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/8a24d5fd-3dc5-46d2-89d3-68cacc0b566e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hemant

unread,
Sep 26, 2017, 4:50:12 PM9/26/17
to HAPI FHIR
Thanks James, by adding the ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE, I am getting the search mode as part of the bundle metadata.

Since for the scores, I do not care about any actual match score but just want to fake any scores between 0 and 1 in the response for testing purposes.

I wonder if there is another way to add fake scores as part of the response other than patching Dstu3BundleFactory.java?

With below logic, it just creates another bundle rather than adding search attributes to existing document reference resource.

Bundle bundle = new Bundle();
List<Bundle.Entry> entryList=new ArrayList<Bundle.Entry>();

Bundle.Entry entry = new Bundle.Entry();
Bundle.EntrySearch entrySearch = new Bundle.EntrySearch();
entrySearch.setMode(SearchEntryModeEnum.MATCH);
entrySearch.setScore(1.0);

entry.setSearch(entrySearch);
entryList.add(entry);

bundle.setEntry(entryList);
response.add(bundle);

Thanks,
Hemant
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.

James Agnew

unread,
Sep 26, 2017, 4:56:22 PM9/26/17
to Hemant, HAPI FHIR
Hi Hemant,

If you just want something quick and dirty, a using a server interceptor and manually changing the bundle on the way out would be another way to do it.

Cheers,
James

To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+unsubscribe@googlegroups.com.

To post to this group, send email to hapi...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages