View on GitHub


The official .NET API for HL7 FHIR

Download this project as a .zip file Download this project as a tar.gz file

Working with ResourceIdentity

Resources have two pieces of metadata involved in identifying a Resource: its Logical Id and its Version Id. Both of these are expressed in the Url that forms a Resource’s identifier and version-specific identifier:

These Resource identifiers are kept in the Id and SelfLink property of a BundleEntry respectively. As is clear from the examples, these urls are not opaque, and contain the resource’s type, it’s logical id and its version id. The .NET API provides the ResourceIdentity class to either build these uris or split them up into their components:

var base = new Uri("");
entry.Id = ResourceIdentity.Build(base,"Patient", "213");
entry.SelfLink = ResourceIdentity.Build(base,"Patient","213","2");

These Build() methods return a new ResourceIdentity with the given logical id and version id. Note that ResourceIdentity is a subclass of the standard .NET Uri class, so it can directly be assigned to entry’s Id and SelfLink properties. Note that you do not need to specify a base url, and produce relative resource references instead:


Conversely, to extract this information from an existing url:

var identity = new ResourceIdentity("");
Console.WriteLine("Logical Id: " + identity.Id);
Console.WriteLine("Type: " + identity.Collection);

It’s also possible to make an existing ResourceIdentity version specific, or change its version id:

var originalId = new ResourceIdentity(entry.Id);
var withVersion = originalId.WithVersion("2");

or the other way around:

var originalVersionId = new ResourceIdentity(entry.SelfLink);
var resourceId = originalVersionId.WithoutVersion();

Finally, we can turn absolute identifiers into Uri’s relative to the service base (in this case:

var identity = new ResourceIdentity("");
var operationPath = identity.OperationPath;
// operationPath is "Patient/213"