示例#1
0
        private static void SetPulse(BloodPressure bloodPressure, Observation.ComponentComponent component)
        {
            var pulse = ObservationToHealthVault.GetValueFromQuantity(component.Value as Quantity);

            if (pulse.HasValue)
            {
                bloodPressure.Pulse = (int)pulse.Value;
            }
        }
示例#2
0
        private static void SetSystolic(BloodPressure bloodPressure, Observation.ComponentComponent component)
        {
            var systolic = ObservationToHealthVault.GetValueFromQuantity(component.Value as Quantity);

            if (systolic.HasValue)
            {
                bloodPressure.Systolic = (int)systolic.Value;
            }
        }
        internal static Height ToHeight(this Observation observation)
        {
            var height = observation.ToThingBase <ItemTypes.Height>();

            height.Value = ObservationToHealthVault.GetThingValueFromQuantity <Length>(observation.Value as Quantity);
            height.When  = ObservationToHealthVault.GetHealthVaultTimeFromEffectiveDate(observation.Effective);

            return(height);
        }
        internal static Weight ToWeight(this Observation observation)
        {
            var weight = observation.ToThingBase <ItemTypes.Weight>();

            weight.Value = ObservationToHealthVault.GetThingValueFromQuantity <WeightValue>(observation.Value as Quantity);

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

            return(weight);
        }
示例#5
0
        internal static BodyDimension ToBodyDimension(this Observation observation)
        {
            var bodyDimension = observation.ToThingBase <BodyDimension>();

            bodyDimension.Value = ObservationToHealthVault.GetThingValueFromQuantity <Length>(observation.Value as Quantity);
            bodyDimension.When  = ObservationToHealthVault.GetApproximateDateTimeFromEffectiveDate(observation.Effective);

            if (observation.Method != null)
            {
                bodyDimension.MeasurementName = observation.Method.ToCodableValue();
            }

            return(bodyDimension);
        }
示例#6
0
        internal static BodyComposition ToBodyComposition(this Observation observation)
        {
            var bodyComposition = observation.ToThingBase <ItemTypes.BodyComposition>();

            if (observation.Component != null)
            {
                var bodyCompositionValue = new BodyCompositionValue();

                foreach (var component in observation.Component)
                {
                    var componentValue = component.Value as Quantity;
                    if (componentValue?.Value == null)
                    {
                        if (component.Code != null)
                        {
                            bodyComposition.MeasurementName = component.Code.ToCodableValue();
                        }

                        continue;
                    }

                    switch (componentValue.Unit)
                    {
                    case UnitAbbreviations.Kilogram:
                        bodyCompositionValue.MassValue = new WeightValue((double)componentValue.Value.Value);
                        break;

                    case UnitAbbreviations.Percent:
                        bodyCompositionValue.PercentValue = (double?)componentValue.Value;
                        break;
                    }
                }

                bodyComposition.Value = bodyCompositionValue;
            }

            bodyComposition.When = ObservationToHealthVault.GetApproximateDateTimeFromEffectiveDate(observation.Effective);

            if (observation.BodySite != null)
            {
                bodyComposition.Site = observation.BodySite.ToCodableValue();
            }

            if (observation.Method != null)
            {
                bodyComposition.MeasurementMethod = observation.Method.ToCodableValue();
            }

            return(bodyComposition);
        }
        internal static HeartRate ToHeartRate(this Observation observation)
        {
            var heartRate = observation.ToThingBase <ItemTypes.HeartRate>();

            var observationValue = observation.Value as Quantity;

            if (observationValue?.Value == null)
            {
                throw new ArgumentException("Value quantity must have a value.");
            }

            heartRate.Value = (int)observationValue.Value.Value;
            heartRate.When  = ObservationToHealthVault.GetHealthVaultTimeFromEffectiveDate(observation.Effective);

            return(heartRate);
        }
示例#8
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);
        }
示例#9
0
        internal static VitalSigns ToVitalSigns(this Observation observation)
        {
            var vitalSigns = observation.ToThingBase <VitalSigns>();

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

            foreach (Observation vitalSignObservation in observation.Contained)
            {
                var vitalSignsResult = new VitalSignsResultType();
                vitalSignsResult.Title = vitalSignObservation.Code.ToCodableValue();

                if (vitalSignObservation.ReferenceRange?.Count != 0)
                {
                    var referenceRangeValue = vitalSignObservation.ReferenceRange[0];

                    if (referenceRangeValue == null)
                    {
                        throw new ReferenceRangeNullException("Reference Range object must have a range");
                    }

                    if (referenceRangeValue.Low != null)
                    {
                        vitalSignsResult.ReferenceMinimum = (double)referenceRangeValue.Low.Value;
                    }
                    if (referenceRangeValue.High != null)
                    {
                        vitalSignsResult.ReferenceMaximum = (double)referenceRangeValue.High.Value;
                    }
                }

                var vitalSignValue = vitalSignObservation.Value as Quantity;
                if (vitalSignValue?.Value == null)
                {
                    throw new ArgumentException("Value quantity must have a value.");
                }

                vitalSignsResult.Value = (int)vitalSignValue.Value.Value;
                var vitalSignsUnitExtension = vitalSignValue.GetExtension(HealthVaultExtensions.CodableUnit);
                vitalSignsResult.Unit = vitalSignsUnitExtension.GetExtensionValue <CodeableConcept>(HealthVaultExtensions.CodableUnit).ToCodableValue();
            }

            return(vitalSigns);
        }
示例#10
0
        internal static BloodPressure ToBloodPressure(this Observation observation)
        {
            var bloodPressure = observation.ToThingBase <BloodPressure>();

            bloodPressure.When = ObservationToHealthVault.GetHealthVaultTimeFromEffectiveDate(observation.Effective);

            bloodPressure.IrregularHeartbeatDetected = observation.GetBoolExtension(HealthVaultVocabularies.IrregularHeartBeatExtensionName);

            if (observation.Component != null)
            {
                foreach (var component in observation.Component)
                {
                    if (component.Code != null && component.Code.Coding != null)
                    {
                        foreach (var code in component.Code.Coding)
                        {
                            if (code.Code != null)
                            {
                                if (HealthVaultVocabularies.SystemContainsHealthVaultUrl(code.System))
                                {
                                    if (code.Code == HealthVaultVitalStatisticsCodes.BloodPressureDiastolic.Code)
                                    {
                                        SetDiastolic(bloodPressure, component);
                                    }
                                    else if (code.Code == HealthVaultVitalStatisticsCodes.BloodPressureSystolic.Code)
                                    {
                                        SetSystolic(bloodPressure, component);
                                    }
                                    else if (code.Code == HealthVaultVitalStatisticsCodes.HeartRate.Code)
                                    {
                                        SetPulse(bloodPressure, component);
                                    }
                                }
                                else
                                {
                                    switch (code.Code.ToLowerInvariant())
                                    {
                                    // HeartRate component
                                    case "8867-4":
                                        SetPulse(bloodPressure, component);
                                        break;

                                    // Systolic LOINC, SNOMED, ACME codes
                                    case "8480-6":
                                    case "271649006":
                                    case "bp-s":
                                        SetSystolic(bloodPressure, component);
                                        break;

                                    // Diastolic LOINC code
                                    case "8462-4":
                                        SetDiastolic(bloodPressure, component);
                                        break;

                                    default:
                                        continue;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(bloodPressure);
        }
示例#11
0
        internal static SleepJournalAM ToSleepJournalAM(this Observation observation)
        {
            var sleepJournalAm = observation.ToThingBase<SleepJournalAM>();
            
            sleepJournalAm.When = ObservationToHealthVault.GetWhenFromEffective(observation.Effective);

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

                switch (component.Code.Text)
                {
                    case HealthVaultVocabularies.SleepJournalAMBedtime:
                        if(component.Value.GetType() == typeof(Time))
                        { 
                            sleepJournalAm.Bedtime = ((Time)component.Value).ToAppoximateTime();
                        }

                        break;
                    case HealthVaultVocabularies.SleepJournalAMWaketime:
                        if (component.Value.GetType() == typeof(Time))
                        {
                            sleepJournalAm.WakeTime = ((Time)component.Value).ToAppoximateTime();
                        }

                        break;
                    case HealthVaultVocabularies.SleepJournalAMSleepMinutes:
                        if (component.Value.GetType() == typeof(SimpleQuantity))
                        {
                            var sleepMinutes = (Quantity)component.Value;
                            if (sleepMinutes.Value.HasValue)
                            {
                                sleepJournalAm.SleepMinutes = (int)sleepMinutes.Value.Value;
                            }
                        }

                        break;
                    case HealthVaultVocabularies.SleepJournalAMSettlingMinutes:
                        if (component.Value.GetType() == typeof(SimpleQuantity))
                        {
                            var settlingMinutes = (Quantity)component.Value;
                            if (settlingMinutes.Value.HasValue)
                            {
                                sleepJournalAm.SettlingMinutes = (int)settlingMinutes.Value.Value;
                            }
                        }

                        break;
                    case HealthVaultVocabularies.SleepJournalAMWakeState:
                        if (component.Value.GetType() == typeof(FhirString))
                        {
                            WakeState wakeState;
                            var wakeStateValue = (FhirString)component.Value;

                            if (Enum.TryParse(wakeStateValue.Value, out wakeState))
                            {
                                sleepJournalAm.WakeState = wakeState;
                            }
                        }

                        break;
                    case HealthVaultVocabularies.SleepJournalAMMedication:
                        if (component.Value.GetType() == typeof(CodeableConcept))
                        {

                            sleepJournalAm.Medications = ((CodeableConcept)component.Value).ToCodableValue();
                        }

                        break;
                    case HealthVaultVocabularies.SleepJournalAMAwakening:
                        if (component.Value.GetType() == typeof(Period))
                        {
                            var startTime = ((Period)component.Value).StartElement.ToDateTimeOffset();
                            var endTime = ((Period)component.Value).EndElement.ToDateTimeOffset();

                            var approximateTime = new ApproximateTime
                            {
                                Hour = startTime.Hour,
                                Minute = startTime.Minute,
                                Second = startTime.Second,
                                Millisecond = startTime.Millisecond
                            };

                            var occurrence = new Occurrence
                            {
                                When = approximateTime,
                                Minutes = (endTime - startTime).Minutes
                            };

                            sleepJournalAm.Awakenings.Add(occurrence);
                        }

                        break;
                }
            }

            return sleepJournalAm;
        }