public void WhenHeathVaultApproximateTimeTransformedToFhir_ThenValuesEqual() { var approximateTime = new ApproximateTime(1, 2, 3, 4); var fhirTime = approximateTime.ToFhir(); Assert.IsNotNull(fhirTime); Assert.IsNotNull("01:02:03.004", fhirTime.Value); }
public void WhenHeathVaultApproximateTimeTransformedToFhir_ThenValuesEqual() { var testTime = new LocalTime(10, 17, 16, 115); var approximateTime = new ApproximateTime(testTime); var fhirTime = approximateTime.ToFhir(); Assert.IsNotNull(fhirTime); Assert.AreEqual(testTime.ToString(@"hh\:mm\:ss\.fff", null), fhirTime.Value); }
internal static Time ToFhirInternal(ApproximateTime approximateTime) { var timeSpan = new TimeSpan( 0, approximateTime?.Hour ?? 0, approximateTime?.Minute ?? 0, approximateTime?.Second ?? 0, approximateTime?.Millisecond ?? 0); return(new Time(timeSpan.ToString(@"hh\:mm\:ss\.fff"))); }
internal static ApproximateTime ToAppoximateTime(this Time time) { // Accepted formats for time are found here: https://www.hl7.org/fhir/datatypes.html#time var approximateTime = new ApproximateTime(); var timePortions = time.ToString().Split(':'); approximateTime.Hour = int.Parse(timePortions[0]); approximateTime.Minute = int.Parse(timePortions[1]); approximateTime.Second = int.Parse(timePortions[2].Substring(0, 2)); if (timePortions[2].Contains(".")) { // milliseconds will always start at position 3, but we aren't guaranteed to have 3 digits after. approximateTime.Millisecond = int.Parse(timePortions[2].Substring(3, Math.Min(timePortions[2].Length - 3, 3)).PadRight(3, '0')); } return(approximateTime); }
public static HealthServiceDateTime ToHealthServiceDateTime(this Element effectiveDate) { var dateTime = effectiveDate.ToAproximateDateTime(); if (dateTime.ApproximateDate.Day != null) { var approximateTime = new ApproximateTime(0, 0); if (dateTime.ApproximateTime != null) { approximateTime = new ApproximateTime(dateTime.ApproximateTime.Hour, dateTime.ApproximateTime.Minute, dateTime.ApproximateTime.Second ?? 0, dateTime.ApproximateTime.Millisecond ?? 0); } return(new HealthServiceDateTime( new HealthServiceDate(dateTime.ApproximateDate.Year, dateTime.ApproximateDate.Month.Value, dateTime.ApproximateDate.Day.Value), approximateTime )); } return(null); }
public void WhenHealthVaultApproximateTimePartialTransformedToFhir_ThenValuesEqual() { var testTime0 = new ApproximateTime(); var fhirTime0 = testTime0.ToFhir(); Assert.AreEqual("00:00:00.000", fhirTime0.Value); var testTime1 = new ApproximateTime(1, 1); var fhirTime1 = testTime1.ToFhir(); Assert.AreEqual("01:01:00.000", fhirTime1.Value); var testTime2 = new ApproximateTime(2, 2, 2); var fhirTime2 = testTime2.ToFhir(); Assert.AreEqual("02:02:02.000", fhirTime2.Value); var testTime3 = new ApproximateTime(3, 3, 3, 3); var fhirTime3 = testTime3.ToFhir(); Assert.AreEqual("03:03:03.003", fhirTime3.Value); }
public void WhenHeathVaultApproximateTimePartialTransformedToFhir_ThenValuesEqual() { // Only hours, minutes var approximateTime1 = new ApproximateTime(23, 59); var fhirTime1 = approximateTime1.ToFhir(); Assert.IsNotNull(fhirTime1); Assert.IsNotNull("23:59:00.000", fhirTime1.Value); // Only hours, minutes, seconds var approximateTime2 = new ApproximateTime(23, 59, 59); var fhirTime2 = approximateTime2.ToFhir(); Assert.IsNotNull(fhirTime2); Assert.IsNotNull("23:59:59.000", fhirTime2.Value); // Only hours, minutes, seconds, milliseconds var approximateTime3 = new ApproximateTime(23, 59, 59, 999); var fhirTime3 = approximateTime3.ToFhir(); Assert.IsNotNull(fhirTime3); Assert.IsNotNull("23:59:59.999", fhirTime2.Value); }
/// <summary> /// Creates a new instance of the <see cref="Occurrence"/> class with /// the specified approximate time and duration. /// </summary> /// /// <param name="when"> /// The approximate time for the occurrence. /// </param> /// /// <param name="minutes"> /// The duration of the occurrence in minutes. /// </param> /// /// <exception cref="ArgumentNullException"> /// The <paramref name="when"/> parameter is <b>null</b>. /// </exception> /// /// <exception cref="ArgumentOutOfRangeException"> /// The <paramref name="minutes"/> parameter is negative. /// </exception> /// public Occurrence(ApproximateTime when, int minutes) { this.When = when; this.Minutes = minutes; }
/// <summary> /// Populates the data from the specified XML. /// </summary> /// /// <param name="navigator"> /// The XML containing the occurrence information. /// </param> /// /// <exception cref="ArgumentNullException"> /// The <paramref name="navigator"/> parameter is <b>null</b>. /// </exception> /// public override void ParseXml(XPathNavigator navigator) { Validator.ThrowIfNavigatorNull(navigator); _when = new ApproximateTime(); _when.ParseXml(navigator.SelectSingleNode("when")); _minutes = navigator.SelectSingleNode("minutes").ValueAsInt; }
// Register the type on the generic ItemBaseToFhir partial class public static Time ToFhir(this ApproximateTime approximateTime) { return(ApproximateTimeToFhir.ToFhirInternal(approximateTime)); }
/// <summary> /// Populates the data from the specified XML. /// </summary> /// /// <param name="navigator"> /// The XML containing the address information. /// </param> /// /// <exception cref="ArgumentNullException"> /// The <paramref name="navigator"/> parameter is <b>null</b>. /// </exception> /// public override void ParseXml(XPathNavigator navigator) { Validator.ThrowIfNavigatorNull(navigator); XPathNodeIterator dowIterator = navigator.Select("dow"); foreach (XPathNavigator dowNav in dowIterator) { _daysOfWeek.Add((DayOfWeek)(dowNav.ValueAsInt - 1)); } XPathNodeIterator timeIterator = navigator.Select("time"); foreach (XPathNavigator timeNav in timeIterator) { ApproximateTime time = new ApproximateTime(); time.ParseXml(timeNav); _times.Add(time); } }
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; }
/// <summary> /// Populates this SleepJournalAM instance from the data in the XML. /// </summary> /// /// <param name="typeSpecificXml"> /// The XML to get the morning sleep journal data from. /// </param> /// /// <exception cref="InvalidOperationException"> /// The first node in the <paramref name="typeSpecificXml"/> parameter /// is not a sleep-am node. /// </exception> /// protected override void ParseXml(IXPathNavigable typeSpecificXml) { XPathNavigator sleepNav = typeSpecificXml.CreateNavigator().SelectSingleNode("sleep-am"); Validator.ThrowInvalidIfNull(sleepNav, "SleepJournalAMUnexpectedNode"); _when = new HealthServiceDateTime(); _when.ParseXml(sleepNav.SelectSingleNode("when")); _bedtime = new ApproximateTime(); _bedtime.ParseXml(sleepNav.SelectSingleNode("bed-time")); _wakeTime = new ApproximateTime(); _wakeTime.ParseXml(sleepNav.SelectSingleNode("wake-time")); _sleepMinutes = sleepNav.SelectSingleNode("sleep-minutes").ValueAsInt; _settlingMinutes = sleepNav.SelectSingleNode("settling-minutes").ValueAsInt; XPathNodeIterator awakeningsIterator = sleepNav.Select("awakening"); foreach (XPathNavigator awakeningNav in awakeningsIterator) { Occurrence awakening = new Occurrence(); awakening.ParseXml(awakeningNav); _awakenings.Add(awakening); } XPathNavigator medNav = sleepNav.SelectSingleNode("medications"); if (medNav != null) { _medications = new CodableValue(); _medications.ParseXml(medNav); } _wakeState = (WakeState) sleepNav.SelectSingleNode("wake-state").ValueAsInt; }
/// <summary> /// Creates a new instance of the <see cref="SleepJournalAM"/> class /// specifying the mandatory values. /// </summary> /// /// <param name="when"> /// The date and time when the AM sleep journal entry was taken. /// </param> /// /// <param name="bedtime"> /// The approximate time the person went to bed. /// </param> /// /// <param name="wakeTime"> /// The approximate time the person woke up. /// </param> /// /// <param name="sleepMinutes"> /// The number of minutes the person slept. /// </param> /// /// <param name="settlingMinutes"> /// The number of minutes it took the person to fall asleep after /// going to bed. /// </param> /// /// <param name="wakeState"> /// The state of the person when they awoke. /// </param> /// /// <exception cref="ArgumentNullException"> /// The <paramref name="when"/> parameter is <b>null</b>. /// </exception> /// /// <exception cref="ArgumentOutOfRangeException"> /// The <paramref name="sleepMinutes"/> parameter or /// <paramref name="settlingMinutes"/> parameter is negative. /// </exception> /// public SleepJournalAM( HealthServiceDateTime when, ApproximateTime bedtime, ApproximateTime wakeTime, int sleepMinutes, int settlingMinutes, WakeState wakeState) : base(TypeId) { this.When = when; this.Bedtime = bedtime; this.WakeTime = wakeTime; this.SleepMinutes = sleepMinutes; this.SettlingMinutes = settlingMinutes; this.WakeState = wakeState; }
/// <summary> /// Populates this <see cref="SleepJournalPM"/> instance from the data in the XML. /// </summary> /// /// <param name="typeSpecificXml"> /// The XML to get the evening sleep journal data from. /// </param> /// /// <exception cref="InvalidOperationException"> /// The first node in <paramref name="typeSpecificXml"/> is not /// a sleep-pm node. /// </exception> /// protected override void ParseXml(IXPathNavigable typeSpecificXml) { XPathNavigator sleepNav = typeSpecificXml.CreateNavigator().SelectSingleNode("sleep-pm"); Validator.ThrowInvalidIfNull(sleepNav, "SleepJournalPMUnexpectedNode"); _when = new HealthServiceDateTime(); _when.ParseXml(sleepNav.SelectSingleNode("when")); XPathNodeIterator caffeineNodes = sleepNav.Select("caffeine"); foreach (XPathNavigator caffeineNav in caffeineNodes) { ApproximateTime caffeineTaken = new ApproximateTime(); caffeineTaken.ParseXml(caffeineNav); _caffeine.Add(caffeineTaken); } XPathNodeIterator alcoholNodes = sleepNav.Select("alcohol"); foreach (XPathNavigator alcoholNav in alcoholNodes) { ApproximateTime alcoholTaken = new ApproximateTime(); alcoholTaken.ParseXml(alcoholNav); _alcohol.Add(alcoholTaken); } XPathNodeIterator napNodes = sleepNav.Select("nap"); foreach (XPathNavigator napNav in napNodes) { Occurrence napTaken = new Occurrence(); napTaken.ParseXml(napNav); _naps.Add(napTaken); } XPathNodeIterator exerciseNodes = sleepNav.Select("exercise"); foreach (XPathNavigator exerciseNav in exerciseNodes) { Occurrence exerciseTaken = new Occurrence(); exerciseTaken.ParseXml(exerciseNav); _exercise.Add(exerciseTaken); } _sleepiness = (Sleepiness) sleepNav.SelectSingleNode("sleepiness").ValueAsInt; }