Search code examples
c#hl7-fhir

FHIR Client - How do I create a "valueReference"


I am using the NuGet package Hl7.Fhir.R4 to connect to the NHS ERS API. Part of the "CreateReferral" method requires an extension like this:

"extension": [
      {
        "url": "https://fhir.nhs.uk/STU3/StructureDefinition/Extension-eRS-Shortlist-SearchCriteria-1",
        "valueReference": {
          "reference": "#ServiceSearchCriteria-1"
        }
      }
    ]

I can't seem to find a model class that will create this output. Any ideas?


Solution

  • You should be able to add an extension to an element/resource with the AddExtension method. As parameters, you fill in the extension's url and a value of any FHIR datatype. For your extension, that would be a Reference, which is modelled by the ResourceReference class:

    element.AddExtension("https://fhir.nhs.uk/STU3/StructureDefinition/Extension-eRS-Shortlist-SearchCriteria-1",
                         new ResourceReference("#ServiceSearchCriteria-1"));
    

    When looking at the referral API, it seems to use FHIR STU3, so you may need to change your library to Hl7.Fhir.Stu3 as well to avoid mismatches in the resource's fields and other version differences. The above method should still work for adding your extension though.