Skip to content
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

Reference resolution for Composition Bundle #11

Open
johncneal opened this issue May 18, 2017 · 3 comments
Open

Reference resolution for Composition Bundle #11

johncneal opened this issue May 18, 2017 · 3 comments

Comments

@johncneal
Copy link

Sorry if this is a naive newbie question. I'm loading a Composition bundle from a file but when processing the sections, I'm running into problems resolving the section references to other resources in the bundle. In the Bundle I'm provided with, the references in the Sections have the form "resource_type/guid" - eg
"reference": "Condition/98d29b5a-da2b-4f48-99b8-53924642c9fd".

If I call the resolve() method on the section.entry[n], eg;

sec.entry![0].resolve(SMART.Condition, callback: { (resolvedResource: Resource?) -> Void in

I get the following from SwiftFHIR -

SwiftFHIR [Reference+Resolving.swift:128] resolve(_:callback:) WARNING: reference does not have a server instance, cannot resolve «Condition/e3d96a2e-abbe-4e78-93dd-e5870fc4f796»

Is this because the bundle has been loaded directly from a file - using bundle.instantiate() - rather than being loaded using the SMART.Client approach etc???

Removing the 'Condition/' from the reference in the file JSON makes no difference - the resolve() method still expects to find a server associated with the bundle.

So, is this just a current constraint of the Swift-FHIR library when processing file based bundles?

Investigating this also made me wonder how I would set the type: parameter of the resolve() method IF the reference only contained a GUID reference to the bundled resource. The Composition.section.references I'm provided with are of the form below but if they didn't have the 'resource type' part how would I set the 'expected type' parameter in the call to resolve() ???

"entry": [
{
"reference": "Condition/e3d96a2e-abbe-4e78-93dd-e5870fc4f796",
"display": "COFE-Diagnosis-Condition-Example-1"
},
{
"reference": "Condition/98d29b5a-da2b-4f48-99b8-53924642c9fd",
"display": "COFE-Diagnosis-Condition-Example-2"
}
]

And, by extension, does this mean that for a file based bundle, the section references should really be provided as 'contained' references/resources using the # prefix?

As always, the wisdom of the experienced would be appreciated
john

@p2
Copy link
Member

p2 commented May 19, 2017

References in the form resourceType/id are relative references, meaning they reference resources that live on the same server. So, in order to resolve them, you need to know which server the original reference lives on. Hence the error.

There is an exception however, which is when all the related resources are delivered in the same bundle, e.g. via specifying _include. The Swift client should actually handle this case (see Reference+Resolving.swift:52-73. You could set breakpoints and step through to see why it's not working for you. Note that resolve() first calls resolved(), which contains that piece of code.

@johncneal
Copy link
Author

johncneal commented May 22, 2017

Hi Pascal
I spent some time debugging through the code and found part of the cause of the problem but also found something else.

The resource references in my bundles Composition.sections conform to 'relative reference' but Resolved() fails to resolve them because the bundle isn't associated with a server and it can't derive the base part of the url. SwiftFHIR still attempts to resolve these by looking for the reference in the fullUrl elements of the resources in the bundle. However, none of the resources in the bundle have the fullUrl element present so they remain unresolved.

While the reference values in my Composition.section(s) clearly aren't identity values - they are resourcetype/identity - given we are processing a Bundle, extracting the 'identity' part of the reference would permit a search of the bundle entries for resource.id. I note the FHIR spec documentation says "Applications reading a bundle should always look for a resource by its identity in the bundle first before trying to access it by its URL." Is this a possible future enhancement to Swift-FHIR??

I'm temporarily implementing it locally (by extending the code in Resolved() to additionally search on the ID part of the reference. However one thing I'm struggling with is how to provide a 'type' parameter value for the call to Resolve(). At the point I call this I know the type it should be but only have this as a String (from the first part of the reference) - how should I generate a Resource.Type value from a String - is there some clever Swift technique to do this?

@p2
Copy link
Member

p2 commented May 23, 2017

I see. I would experiment with these lines; I'd probably do an else after this block (which will fail since there's no fullUrl) and compare refUrl (which is still Type/id at this point, i.e. == refid) to some other value on entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants