internal static T ToThingBase <T>(this Observation observation) where T : ThingBase, new()
        {
            T baseThing = new T();

            Guid id;

            if (Guid.TryParse(observation.Id, out id))
            {
                baseThing.Key = new ThingKey(id);
            }

            Guid version;

            if (observation.Meta != null && observation.Meta.VersionId != null && Guid.TryParse(observation.Meta.VersionId, out version))
            {
                baseThing.Key.VersionStamp = version;
            }

            ThingFlags flags;
            var        extensionFlag = observation.GetExtension(HealthVaultExtensions.FlagsFhirExtensionName);

            if (extensionFlag != null)
            {
                if (extensionFlag.Value is FhirString && Enum.TryParse <ThingFlags>((extensionFlag.Value as FhirString).ToString(), out flags))
                {
                    baseThing.Flags = flags;
                }
            }

            return(baseThing);
        }
Ejemplo n.º 2
0
        internal static BloodGlucose ToBloodGlucose(this Observation observation)
        {
            var bloodGlucose = observation.ToThingBase <BloodGlucose>();

            bloodGlucose.Value = ObservationToHealthVault.GetThingValueFromQuantity <BloodGlucoseMeasurement>(observation.Value as Quantity);

            bloodGlucose.When = ObservationToHealthVault.GetWhenFromEffective(observation.Effective);

            var bloodGlucoseExtension = observation.GetExtension(HealthVaultExtensions.BloodGlucose);

            if (bloodGlucoseExtension != null)
            {
                bloodGlucose.MeasurementContext          = bloodGlucoseExtension.GetExtensionValue <CodeableConcept>(HealthVaultExtensions.BloodGlucoseMeasurementContext).ToCodableValue();
                bloodGlucose.OutsideOperatingTemperature = bloodGlucoseExtension.GetBoolExtension(HealthVaultExtensions.OutsideOperatingTemperatureExtensionName);
                bloodGlucose.IsControlTest = bloodGlucoseExtension.GetBoolExtension(HealthVaultExtensions.IsControlTestExtensionName);

                Normalcy normalcy;
                if (Enum.TryParse <Normalcy>(bloodGlucoseExtension.GetStringExtension(HealthVaultExtensions.ReadingNormalcyExtensionName), out normalcy))
                {
                    bloodGlucose.ReadingNormalcy = normalcy;
                }
            }

            if (observation.Code != null && observation.Code.Coding != null)
            {
                foreach (var code in observation.Code.Coding)
                {
                    if (HealthVaultVocabularies.SystemContainsHealthVaultUrl(code.System))
                    {
                        bloodGlucose.GlucoseMeasurementType = observation.Method.ToCodableValue();
                    }
                    else
                    {
                        bloodGlucose.SetGlucoseMeasurementType(
                            code.Display,
                            code.Code,
                            HealthVaultVocabularies.Fhir,
                            code.System,
                            code.Version);
                    }
                }
            }

            return(bloodGlucose);
        }