Tedford
Tedford

Reputation: 2932

How to represent a contained resource in the .NET FHIR DSTU 2 Model

I am trying to construct an Order resource for the purpose of the EvaluateOrder transaction for GAO. According to the spec it is using contained resources as shown below. The problem I am having is that the .NET object model seems to require a resource reference. Is there any way to contain the data within the reference or is this use case outside of the intent of the model?

Order order = new Order 
{
    Identifier = new List<Identifier>{ new Identifier("mysystem", "8ea608db-ce55-41ea-936c-38195ae9b245") },
    DateElement = new FhirDateTime(DateTimeOffset.Now),
    Subject = new ResourceReference { /*???*/ }, 
};

GAO Order Spec

GAO Spec Fragment

Upvotes: 2

Views: 369

Answers (2)

BENBUN Coder
BENBUN Coder

Reputation: 4881

We don't have the exact same requirements, but where we use "contained" resources we use code along the lines of :

Order myOrder = new Order();
Patient myPatient = new Patient();
myPatient.Id = Guid.NewGuid().ToString();

myOrder.Contained.Add(myPatient);
myOrder.Subject = new ResourceReference()
   {
    Reference = "#" + myPatient.Id
   };

Upvotes: 2

Lloyd McKenzie
Lloyd McKenzie

Reputation: 6793

I expect it's outside the model because the same "contained" resource could potentially be referenced from multiple places. That said, a helper function that allows inline definition (and resolution) might be possible. You can make the suggestion on github.

In terms of what goes over the wire, the convenience of allowing inline substitution of references with the referenced content is outweighed by the complexity of resources now being able to appear absolutely anywhere, unlimited nesting, etc.

Upvotes: 0

Related Questions