Пример #1
0
        public void WhenDosageCreatedFromHV_FrequencyIsCopiedToTiming()
        {
            var          frequency = new GeneralMeasurement("1 tablet every 8 hrs");
            const int    value     = 8;
            const string unitText  = HealthVaultRecurrenceIntervalCodes.HourCode;
            const string code      = "hour";

            var dosage = HealthVaultCodesToFhir.GetDosage(null, frequency, null);

            Assert.IsNull(dosage.Timing);

            frequency.Structured.Add(
                new StructuredMeasurement(value,
                                          new CodableValue(unitText,
                                                           new CodedValue(code,
                                                                          vocabularyName: HealthVaultVocabularies.RecurrenceIntervals,
                                                                          family: HealthVaultVocabularies.Wc,
                                                                          version: "1"))));

            dosage = HealthVaultCodesToFhir.GetDosage(null, frequency, null);

            var timing = dosage.Timing;

            Assert.IsNotNull(timing);

            Assert.AreEqual(value, timing.Repeat.Period);
            Assert.AreEqual("H", timing.Repeat.PeriodUnit.ToString());
        }
Пример #2
0
        internal static Dosage GetDosage(GeneralMeasurement dose, GeneralMeasurement frequency, CodableValue route)
        {
            var dosage = new Dosage();

            if (route != null)
            {
                dosage.Route = route.ToFhir();
            }

            if (frequency != null)
            {
                dosage.Text = frequency.Display;

                dosage.Timing = GetTiming(frequency);
            }

            if (dose != null)
            {
                dosage.Text = string.Join(Environment.NewLine, dose.Display, dosage.Text);

                dosage.Dose = GetSimpleQuantity(dose);
            }

            return(dosage);
        }
Пример #3
0
        public void WhenDosageCreatedFromHV_DoseIsCopiedToDoseQuantity()
        {
            var          hvDose   = new GeneralMeasurement("3tablets/day");
            const int    value    = 3;
            const string code     = "tablets";
            const string unitText = "Tablets";

            var dosage = HealthVaultCodesToFhir.GetDosage(hvDose, null, null);

            Assert.IsNull(dosage.Dose);

            hvDose.Structured.Add(
                new StructuredMeasurement(value,
                                          new CodableValue(unitText,
                                                           new CodedValue(code,
                                                                          vocabularyName: "medication-dose-units",
                                                                          family: "wc",
                                                                          version: "1"))));

            dosage = HealthVaultCodesToFhir.GetDosage(hvDose, null, null);

            var dose = dosage.Dose;

            Assert.IsNotNull(dose);
            Assert.IsInstanceOfType(dose, typeof(Quantity));

            var doseQuantity = dose as Quantity;

            Assert.AreEqual(value, doseQuantity.Value);
            Assert.AreEqual(code, doseQuantity.Code);
            Assert.AreEqual(unitText, doseQuantity.Unit);
        }
 public static string FormatMedicationDetail(GeneralMeasurement medicationStrength, GeneralMeasurement medicationDose)
 {
     if (medicationStrength == null)
     {
         return(medicationDose?.Display ?? "");
     }
     if (medicationDose == null)
     {
         return(medicationStrength?.Display ?? "");
     }
     return($"{medicationStrength.Display}, {medicationDose.Display}");
 }
        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);
        }
Пример #6
0
        public static ThingBase ToHealthVault(this FhirMedication fhirMedication)
        {
            var hvMedication = new HVMedication();

            var name = fhirMedication.Code.ToCodableValue();

            if (name == null)
            {
                throw new NotSupportedException($"{nameof(FhirMedication)} should" +
                                                $" have {nameof(fhirMedication.Code)}");
            }
            hvMedication.Name = name;

            var medicationExtension = fhirMedication.GetExtension(HealthVaultExtensions.Medication);

            if (medicationExtension != null)
            {
                var genericName = medicationExtension
                                  .GetExtensionValue <CodeableConcept>(HealthVaultExtensions.MedicationGenericName);
                hvMedication.GenericName = genericName?.ToCodableValue();

                var strengthExtension = medicationExtension.GetExtension(HealthVaultExtensions.MedicationStrength);
                if (strengthExtension != null)
                {
                    string display  = strengthExtension.GetStringExtension(HealthVaultExtensions.MedicationStrengthDisplay);
                    var    strength = new GeneralMeasurement(display);
                    foreach (var quantityExtension
                             in strengthExtension.GetExtensions(HealthVaultExtensions.MedicationStrengthQuantity))
                    {
                        var quantity = quantityExtension.Value as Quantity;
                        if (quantity == null)
                        {
                            continue;
                        }
                        strength.Structured.Add(new StructuredMeasurement
                        {
                            Value = (double)quantity.Value,
                            Units = CodeToHealthVaultHelper.CreateCodableValueFromQuantityValues(
                                quantity.System, quantity.Code, quantity.Unit)
                        });
                    }
                    hvMedication.Strength = strength;
                }
            }

            return(hvMedication);
        }
Пример #7
0
        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);
        }
Пример #8
0
        public void WhenDosageCreatedFromHV_UnknownFrequencyThowsError()
        {
            var frequency = new GeneralMeasurement("1 tablet every 8 hrs");

            frequency.Structured.Add(
                new StructuredMeasurement(8,
                                          new CodableValue("Decade",
                                                           new CodedValue("decade", HealthVaultVocabularies.RecurrenceIntervals))));

            Assert.ThrowsException <NotImplementedException>(()
                                                             => HealthVaultCodesToFhir.GetDosage(null, frequency, null));

            frequency.Structured.Add(
                new StructuredMeasurement(8,
                                          new CodableValue("Hour",
                                                           new CodedValue("hour", HealthVaultVocabularies.Fhir))));

            Assert.ThrowsException <NotImplementedException>(()
                                                             => HealthVaultCodesToFhir.GetDosage(null, frequency, null));
        }
Пример #9
0
        public static SimpleQuantity GetSimpleQuantity(GeneralMeasurement measurement)
        {
            if (measurement?.Structured.Any() == true)
            {
                StructuredMeasurement structuredMeasurement = measurement.Structured.First();

                var simpleQuantity = new SimpleQuantity()
                {
                    Value = new decimal(structuredMeasurement.Value),
                    Unit  = structuredMeasurement.Units.Text
                };

                if (structuredMeasurement.Units.Any())
                {
                    CodedValue measurementUnit = structuredMeasurement.Units.First();

                    simpleQuantity.Code   = measurementUnit.Value;
                    simpleQuantity.System = HealthVaultVocabularies.GenerateSystemUrl(measurementUnit.VocabularyName, measurementUnit.Family);
                }

                return(simpleQuantity);
            }
            return(null);
        }
 private static List <Dosage> AddDosage(GeneralMeasurement dose, GeneralMeasurement frequency, CodableValue route)
 {
     return(new List <Dosage> {
         HealthVaultCodesToFhir.GetDosage(dose, frequency, route)
     });
 }