Contemplating compartments in FHIR

This is one of those posts that I am really writing for myself, so I know where go when I (again) get confused by FHIR compartments.

Now, a compartment is really a rather a neat idea.

It’s part of the REST interface, and started out as a form of ‘syntactic sugar’ – instead of a query like:

[baseurl]/Condition?subject=100

you can type:

[baseurl]/Patient/100/Condition

which is rather tidier (The ‘Patient’ in this query refers to the name of the compartment rather then the Patient Resource – which can be a bit confusing). The actual definition is a bit more complex than that – you can read it up in the spec if you want to – the documentation for a compartment is here for DSTU-1 with further notes on searches here.

That’s all very good but there’s an even neater use.

One of the issues of the base REST interface is that it is a relatively simple CRUD style interface – you query one resource at a time. But often, having found your patient, you often want to know lots of details about them – conditions, allergies, alerts, medications, DiagnosticReports etc – and each one is a separate REST call, which can be a bit tedious. And this is where the compartment can help.

Theres’s a specific syntax for compartment that allows you to retrieve ALL the resources about a patient (at least a big subset of them, and dependant on what the server is storing of course). Here it is:

[baseurl]/Patient/100/*

The star (*) at the end of the url indicates all resources for that patient.

So, for a compliant server – all the data for a patient is just a single url away!

Not all resources can be retrieved in this way – each resource needs to have defined a search parameter that the server can use to link the resource to the patient. There’s a list of the DSTU-2 resources that can be returned in this way here.

And this syntax doesn’t change the value of the List resource, which is a way for a user to specifically describe lists like current medications, problem list or known allergies.

But it’s certainly a very useful addition to the FHIR toolbox (though I suspect that there will be more discussion about how it should work!)

Oh, and just as a comment, these urls will certainly change as FHIR moves into preparing for DSTU-2 so the links may not work once that happens – I’ll try to change the URLs when that happens.

And sorry about the title – I just couldn’t help myself…

About David Hay
I'm an independent contractor working with a number of Organizations in the health IT space. I'm an HL7 Fellow, Chair Emeritus of HL7 New Zealand and a co-chair of the FHIR Management Group. I have a keen interest in health IT, especially health interoperability with HL7 and the FHIR standard. I'm the author of a FHIR training and design tool - clinFHIR - which is sponsored by InterSystems Ltd.

One Response to Contemplating compartments in FHIR

  1. Pingback: The Circle of Care in FHIR | Hay on FHIR

Leave a Reply

%d bloggers like this: