internal static Exercise ToExercise(this Observation observation)
        {
            var exercise = observation.ToThingBase <Exercise>();

            if (!observation.Extension.IsNullOrEmpty())
            {
                var detailExtensions = observation.GetExtensions(HealthVaultExtensions.ExerciseDetail);
                foreach (var detail in detailExtensions)
                {
                    ExerciseDetail exerciseDetail;
                    var            key = GetExerciseDetail(detail, out exerciseDetail);

                    if (!string.IsNullOrEmpty(key))
                    {
                        exercise.Details.Add(key, exerciseDetail);
                    }
                }

                var segmentExtensions = observation.GetExtensions(HealthVaultExtensions.ExerciseSegment);
                foreach (var segment in segmentExtensions)
                {
                    exercise.Segments.Add(CreateExerciseSegment(segment));
                }
            }

            foreach (var component in observation.Component)
            {
                if (string.IsNullOrEmpty(component.Code?.Text))
                {
                    continue;
                }

                switch (component.Code.Text)
                {
                case HealthVaultVocabularies.ExerciseDistance:
                    var distanceQuantity = (Quantity)component.Value;
                    if (distanceQuantity?.Value != null)
                    {
                        exercise.Distance = new Length((double)distanceQuantity.Value);
                    }

                    break;

                case HealthVaultVocabularies.ExerciseDuration:
                    var durationQuantity = (Quantity)component.Value;
                    if (durationQuantity?.Value != null)
                    {
                        exercise.Duration = (double)durationQuantity.Value;
                    }

                    break;

                case HealthVaultVocabularies.ExerciseActivity:
                    exercise.Activity = ((CodeableConcept)component.Value).ToCodableValue();

                    break;
                }
            }

            return(exercise);
        }