Hi! I'm part of a student team at Georgia Tech, and we're working on a prototype that uses FHIR. This prototype is a webapp based on the Django framework, so we're using the Python FHIR client from
. (The FHIR client made it really convenient to get started, by the way - so thank you to anyone who has contributed to that!)
I'm really, really sorry for the length of this e-mail - I tried to sand it down but found that it didn't make a lot of sense without concrete examples.
Some of the records we're saving and retrieving use references. For instance, here's an example of a Communication we're pulling from the FHIR server:
{
"resourceType":"Communication",
"meta":{
"versionId":"1",
"lastUpdated":"2016-03-28T21:17:04.651-04:00"
},
"text":{
"status":"generated",
"div":"<div>Healthy Weight message</div>"
},
"category":{
"coding":[
{
"system":"http://acme.org/messagetypes",
"code":"general"
}
],
"text":"general"
},
"sender":{
"reference":"Practitioner/Practitioner-2189",
"display":"Your Care Coordinator"
},
"recipient":[
{
"reference":"Patient/18791962",
"display":"Diana's parent or guardian"
}
],
"payload":[
{
"contentString":"The YMCA near your home just started a new dance club for girls age 8-10!"
}
],
"status":"completed",
"sent":"2016-03-29T01:17:04-0700",
"reason":[
{
"text":"Resource referral"
}
]
}
We retrieve Communications using a search like this:
try:
search = communication.Communication.where(struct={"recipient":"Patient/"+patientId})
messages = search.perform(smart.server)
if messages.total > 0:
messages = map(lambda(entry): entry.resource, messages.entry)
...
except Exception:
...
The resources are coming back just fine, and the body contents are as we would expect, but when we try to retrieve referenced entities (in this case, the sender), it always fails with "WARNING:root:No `reference` set, cannot resolve." For instance,
>>> messages[0]
<fhirclient.models.communication.Communication object at 0x10d5eeb90>
>>> messages[0].sender
<fhirclient.models.fhirreference.FHIRReference object at 0x10d60ffd0>
>>> messages[0].sender.resolved(practitioner.Practitioner)
WARNING:root:No `reference` set, cannot resolve
None
>>> messages[0].sender.resolvedReference(messages[0].sender.reference)
None
Looking at the source, I see:
|
| refid = self.processedReferenceIdentifier() |
| if not refid: |
| logging.warning("No `reference` set, cannot resolve") |
| return None |
And:
| |
| def processedReferenceIdentifier(self): |
| """ Normalizes the reference-id. |
| """ |
| if not self.reference: |
| return None |
| |
| if '#' == self.reference[0]: |
| return self.reference[1:] |
| |
| # TODO: distinguish absolute (has "://") and relative URLs |
| return None |
But the reference we're getting back is in the format:
>>> messages[0].sender.reference
u'Practitioner/Practitioner-2189'
No leading #, obviously, so it makes sense that processedReferenceIdentifier() is always None.
I'm very new to FHIR, so I have absolutely no idea what to conclude from this. :-)
Is it:
1) The Reference we add when creating the resource is in the wrong format, and is supposed to be prefixed with #? (If so, is it expected behavior that the server allows us to create the resource anyway?)
2) This is the wrong method for us to use to resolve references? (If so, what's the right one to call?)
3) We're supposed to call / set up something else on the resource before resolving references? (If so, what?)
4) Resource resolution isn't implemented yet? (In which case, are there any "gotchas" I should know about before I add it?)
Or something totally different?
Right now we're manually pulling messages[0].sender.reference in our code, stripping it and stuffing it into a .read() call, but that gives me a sinking feeling I'm reinventing the wheel.
--Angela Smiley
P.S.: we're testing against the MiHIN FHIR server, if that makes a difference (e.g. in expected reference format).
P.P.S.: any errors or bad practices you spot in my JSON or code, please mention even if they're not relevant to this specific problem. I'm a shameless FHIR newbie.