public static ThingBase ToHealthVault(this MedicationStatement medicationStatement) { var fhirMedication = MedicationStatementHelper.ExtractEmbeddedMedication(medicationStatement); if (fhirMedication == null) { return(null); } var hvMedication = fhirMedication.ToHealthVault() as HVMedication; if (medicationStatement.Dosage.Any()) { var dosage = medicationStatement.Dosage.First(); switch (dosage.Dose) { case null: break; case SimpleQuantity doseQuantity: var dose = new GeneralMeasurement { }; dose.Structured.Add(new StructuredMeasurement { Value = (double)doseQuantity.Value, Units = CodeToHealthVaultHelper.CreateCodableValueFromQuantityValues(doseQuantity.System, doseQuantity.Code, doseQuantity.Unit) }); hvMedication.Dose = dose; break; case Range doseRange: throw new NotImplementedException(); } Timing.RepeatComponent repeat = dosage.Timing?.Repeat; if (repeat?.Period != null && repeat?.PeriodUnit != null) { var frequency = new GeneralMeasurement { }; frequency.Structured.Add(new StructuredMeasurement { Value = (double)repeat.Period, Units = CodeToHealthVaultHelper.GetRecurrenceIntervalFromPeriodUnit(repeat.PeriodUnit.Value) }); hvMedication.Frequency = frequency; } var route = dosage.Route.ToCodableValue(); hvMedication.Route = route; } return(hvMedication); }
private static Timing GetTiming(GeneralMeasurement frequency) { if (frequency.Structured.Any()) { StructuredMeasurement frequencyMeasurement = frequency.Structured.First(); var repeatComponent = new Timing.RepeatComponent(); repeatComponent.Period = new decimal(frequencyMeasurement.Value); repeatComponent.PeriodUnit = GetPeriodUnitFromFromRecurrenceIntervals(frequencyMeasurement.Units); return(new Timing() { Repeat = repeatComponent }); } return(null); }