示例#1
0
        /// <summary>
        /// Parses a bindeable type (code, Coding, CodeableConcept, Quantity, string, uri) into a FHIR coded datatype.
        /// Extensions will be parsed from the 'value' of the (simple) extension.
        /// </summary>
        /// <param name="instance"></param>
        /// <returns>An Element of a coded type (code, Coding or CodeableConcept) dependin on the instance type,
        /// or null if no bindable instance data was found</returns>
        /// <remarks>The instance type is mapped to a codable type as follows:
        ///   'code' => code
        ///   'Coding' => Coding
        ///   'CodeableConcept' => CodeableConcept
        ///   'Quantity' => Coding
        ///   'Extension' => depends on value[x]
        ///   'string' => code
        ///   'uri' => code
        /// </remarks>
        public static Element ParseBindable(this ITypedElement instance)
        {
            var instanceType = ModelInfo.FhirTypeNameToFhirType(instance.InstanceType);

            switch (instanceType)
            {
            case FHIRDefinedType.Code:
                return(instance.ParsePrimitive <Code>());

            case FHIRDefinedType.Coding:
                return(instance.ParseCoding());

            case FHIRDefinedType.CodeableConcept:
                return(instance.ParseCodeableConcept());

            case FHIRDefinedType.Quantity:
                return(parseQuantity(instance));

            case FHIRDefinedType.String:
                return(new Code(instance.ParsePrimitive <FhirString>()?.Value));

            case FHIRDefinedType.Uri:
                return(new Code(instance.ParsePrimitive <FhirUri>()?.Value));

            case FHIRDefinedType.Extension:
                return(parseExtension(instance));

            case null:
            //HACK: fall through - IElementNav did not provide a type
            //should not happen, and I have no intention to handle it.
            default:
                // Not bindable
                return(null);
            }

            Coding parseQuantity(ITypedElement nav)
            {
                var newCoding = new Coding();
                var q         = instance.ParseQuantity();

                newCoding.Code   = q.Unit;
                newCoding.System = q.System ?? "http://unitsofmeasure.org";
                return(newCoding);
            }

            Element parseExtension(ITypedElement nav)
            {
                // HACK: For now, assume this is a typed navigator, so we have "value",
                // not the unparsed "valueCode" etc AND we have Type (in ParseBindable())
                var valueChild = instance.Children("value").FirstOrDefault();

                return(valueChild?.ParseBindable());
            }
        }
示例#2
0
 /// <summary>
 /// Parses a bindeable type (code, Coding, CodeableConcept, Quantity, string, uri) into a FHIR coded datatype.
 /// Extensions will be parsed from the 'value' of the (simple) extension.
 /// </summary>
 /// <param name="instance"></param>
 /// <returns>An Element of a coded type (code, Coding or CodeableConcept) dependin on the instance type,
 /// or null if no bindable instance data was found</returns>
 /// <remarks>The instance type is mapped to a codable type as follows:
 ///   'code' => code
 ///   'Coding' => Coding
 ///   'CodeableConcept' => CodeableConcept
 ///   'Quantity' => Coding
 ///   'Extension' => depends on value[x]
 ///   'string' => code
 ///   'uri' => code
 /// </remarks>
 public static Element ParseBindable(this ITypedElement instance)
 {
     return(instance.InstanceType switch
     {
         FhirTypeConstants.CODE => instance.ParsePrimitive <Code>(),
         FhirTypeConstants.STRING => new Code(instance.ParsePrimitive <FhirString>()?.Value),
         FhirTypeConstants.URI => new Code(instance.ParsePrimitive <FhirUri>()?.Value),
         FhirTypeConstants.CODING => instance.ParseCoding(),
         FhirTypeConstants.CODEABLE_CONCEPT => instance.ParseCodeableConcept(),
         FhirTypeConstants.QUANTITY => parseQuantity(),
         FhirTypeConstants.EXTENSION => parseExtension(),
         _ => null,
     });