Search code examples
hl7-fhir

FHIR - Contained Resources and Referencing


I am still new to FHIR and trying to connect the dots.

If I have a resource that I want to contain other resources, can I refer to it by element name (#myElementName) or do I need to use the contained resource id? (#myDeviceId).

I've included sample code below. What I would like to accomplish is to have a Basic resource that has two extensions: TestConfiguration(Device) and DigitalSample(ImagingStudy). I would like for both of these resources to be contained.

PS: I generated the code below using custom classes and the .net API.

Thank you much!

{
  "resourceType": "TestInput",
  "contained": [
    {
      "resourceType": "TestConfiguration",
      "id": "TestConfigurationId",
      "contained": [
        {
          "resourceType": "DeviceDefinition",
          "modelNumber": "ABC123"
        }
      ],
      "definition": {
        "reference": "#definition"
      }
    },
    {
      "resourceType": "DigitalSample",
      "id": "DigitalSampleId"
    }
  ],
  "extension": [
    {
      "url": "http://MyOrganization.com/fhir/R4/StructureDefinition/Basic-TestConfiguration",
      "valueReference": {
        "reference": "#testConfiguration"
      }
    },
    {
      "url": "http://MyOrganization.com/fhir/R4/StructureDefinition/Basic-DigitalSample",
      "valueReference": {
        "reference": "#digitalSampleId"
      }
    }
  ]
}

Solution

  • Every local reference must point to an id of a contained resource. In your case it should be:

    "reference": "#TestConfigurationId"
    "reference":"#DigitalSampleId"
    

    Always check https://www.hl7.org/fhir/ for what you need to do. Always check the FHIR version