New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use read and compartment search in same provider #242

am202 opened this Issue Oct 13, 2015 · 4 comments


None yet
2 participants

am202 commented Oct 13, 2015

I'm trying to create a resource provider with a read and with compartment searches, but I can't get it to work. I can get either to work by itself, but the server seems to pick the wrong method when I try to support both. This is my provider:

public class TempPatientResourceProvider implements IResourceProvider {
    public Class<Patient> getResourceType() {
        return Patient.class;

    public Patient getResourceById(final @IdParam IdDt id) {
        System.out.println("Patient read");
        Patient patient = new Patient();
        return patient;

    public List<Encounter> searchEncounter(final @IdParam IdDt id) {
        System.out.println("Encounter compartment search");
        List<Encounter> encounters = new ArrayList<Encounter>();
        Encounter encounter = new Encounter();
        encounter.setPatient(new ResourceReferenceDt(id));
        return encounters;

This is my client code:

        FhirContext ctx = FhirContext.forDstu2();
        IGenericClient client = ctx.newRestfulGenericClient("http://localhost:8081/hapi-fhir/fhir");
        Bundle bundle = client
            .withIdAndCompartment("1", "Encounter")

It calls this URL like I expected:


But the server output shows that it entered the read method instead of the compartment search:

Patient read

And the client gets this error:

Expecting outer element called 'Bundle', found: Patient

Am I doing something wrong, or is there a bug causing the server to pick the wrong method to handle the request?


This comment has been minimized.


jamesagnew commented Oct 13, 2015

That is weird! Sounds like a bug to me. I'll see if I can reproduce.

Out of curiosity, if you put the two methods in the other order does it work? That's not a good solution obviously, but might be a workaround while we fix..


This comment has been minimized.

am202 commented Oct 13, 2015

That's a good question about the order of the two methods. I actually first noticed this issue weeks ago, and I decided to switch the order at that time. It did work for me after that. But I just noticed today that it was no longer working. I'm not sure what I changed to cause that. I upgraded to HAPI FHIR 1.2 (DSTU2 QA) a few weeks ago. Maybe today was the first time that I tried running the server since then, so that might be why it's not working for me now. Maybe something changed in 1.2.

Anyway, I tried switching the order again today, and it's still not working for me. So changing the order of the methods used to work for me. Now I'm having this issue either way.


This comment has been minimized.


jamesagnew commented Oct 21, 2015

Hi @am202 , thanks for reporting, I was able to reproduce so this is fixed now. The fix will appear in the next snapshot build.

@jamesagnew jamesagnew reopened this Oct 21, 2015

@jamesagnew jamesagnew closed this Oct 21, 2015


This comment has been minimized.

am202 commented Oct 21, 2015

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment