Search code examples
hl7-fhirdstu2-fhir

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


Solution

  • 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
       };