Adding extensions to a resource
March 29, 2017 Leave a comment
So a colleague of mine asked me this morning if the clinFHIR scenario builder supported modifier extensions.
If you’re not familiar with these, they are extensions that actually change the meaning of the resource to which they are attached. For example, if you wanted to indicate that a patient did not have a particular condition, then you could attach a ‘negation’ extension to the Condition to indicate that you looked for – but did not find – that particular condition. Or, a statement that indicates that a patient is not taking a particular medication.
Now, it’s obviously really important that a recipient of that resource understands what the extension means – it would be clinically unsafe to ignore it – and so it is represented in FHIR as a ‘modifierExtension’. You can read more about them in the spec.
(As an aside, it should be noted that the ‘proper’ way to deal with negation in general is one that is not really well established yet, and there are a number of different ways that this can be done. I don’t want to go there in this post!)
The reason my colleague wanted to know about this, is that they wanted to be able to represent “No breathing difficulties” – a negated Observation – in a training course they are giving tomorrow.
My initial response was that at the moment clinFHIR doesn’t support modifierExtensions – the approach I have been taking is that you first create a profile which contains the possible extensions for a conformant resource, and clinFHIR uses that to generate the User Interface that allows the user to create the resource instance. No real reason that these couldn’t be modifierExtensions – I just hadn’t got around to it yet.
But the question got me thinking. Why do you have to create a profile first? Why not simply allow the user to add any extension – normal or modifier – to a resource they are building?
So I added the functionality – or at least a step towards it.
If you load the Scenario builder and select a resource type, you will see a tree of the elements within the type to the right hand side. Selecting an element in the tree displays its details and allows you to enter a value for it. If you click on the ‘root’ element (‘Condition’ in the example below) you will now see a link labelled ‘AddExtension’). Oh, and you do have to actually click on the node – it doesn’t appear automatically.
If you click on that element, you’ll get a dialog box that allows you to add an ‘ad hoc’ extension to the resource you are currently building. There’s a dropdown control with a list of all applicable extension definitions for that element on the current conformance server (they are ones where the ‘context’ of use includes the resource type you are editing). Here’s a screen shot:
Select the one you want, and an input form appears to the right of the dropdown. This allows you to:
- Enter a value for the extension. Right now, this is only a string value but eventually it will display a datatype appropriate to the extension selected.
- Indicate if the extension is a modifier extension
Once you’ve entered a value, an ‘Add’ button appears to the upper right. Clicking that button closes the dialog, and adds the extension to the resource – which you can then see in the Json or Tree view of the resource as shown here:
I do have to put more work into this – as I said above the datatype should really come from the extension definition, and at the moment the extension can only be applied to the root of the resource, but hopefully it should be enough for my colleague to complete the training tomorrow!
And do note that this does not mean that profiles are not needed – far from it! But the goal of clinFHIR is to allow people to learn FHIR, and also for the designers of resources and profiles to be able to make modifications ‘on the fly’ to test out ideas – so it seems a worthwhile addition.