FHIR Data Types
In FHIR, the data types are categorized into ‘primitive’ and ‘complex’ data types.
FHIR Primitives
FHIR provides a comprehensive set of primitive data types, such as string, integer, boolean, etc.
Since every data type in FHIR can be extended, FHIR primitives are not truly atomic (as they are in .NET). To accommodate this, the SDK includes a dedicated FHIR class for each FHIR primitive type.
The class names match the FHIR type names, except when a conflict arises with existing .NET data types. In such cases, the class name is prefixed with “Fhir”. For example, a FHIR string becomes FhirString in .NET.
For properties representing elements with primitive data types, the SDK provides two properties in the class.
The “Helper” Property
One property shares the same name as the corresponding element, such as Active in the Patient class. This property uses the standard .NET data type:
var pat = new Patient();
pat.Active = true;
The “Element” Property
The other property appends the suffix ‘Element’ to the name, such as ActiveElement. This property is used when you need access to the element’s ElementId or Extension. It also has the Value property, which holds the actual primitive value - which is exactly the value returned by the helper property:
pat.ActiveElement = new FhirBoolean(true);
pat.ActiveElement.ElementId = "patActive";
pat.ActiveElement.Extension.Add(...);
pat.ActiveElement.Value.Should().Be(true);
pat.Active.Should().Be(pat.ActiveElement.Value);
The helper property automatically creates a new instance of the data type for the element property and sets the Value property. This allows you to combine both styles:
pat.Active = true;
pat.ActiveElement.Extensions.Add(...);
Complex Data Types
Complex data types in FHIR group related values together, such as Address, Identifier, and Quantity. The FHIR specification defines the elements included in these data types.
The SDK provides classes for each complex data type, with properties for all their elements. Most elements are of primitive data types, but some may also be complex types.
Working with complex data types is similar to working with resources and primitive data types. You can also use C# initializer syntax for convenience:
var id = new Identifier()
{
System = "http://hl7.org/fhir/sid/us-ssn",
Value = "000-12-3456"
};
