示例#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
        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);
        }
示例#3
0
        public void WhenDosageCreatedFromHV_RouteIsCopied()
        {
            const string routeText = "By mouth";
            var          hvRoute   = new CodableValue(routeText);

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

            Assert.AreEqual(routeText, dosage.Route.Text);
        }
        internal static MedicationRequest ToFhirInternal(Prescription prescription, MedicationRequest medicationRequest)
        {
            medicationRequest.SetIntentAsInstanceOrder();
            medicationRequest.AuthoredOnElement = prescription.DatePrescribed?.ToFhir();
            if (prescription.AmountPrescribed != null ||
                prescription.Refills.HasValue ||
                prescription.DaysSupply.HasValue ||
                prescription.PrescriptionExpiration != null)
            {
                medicationRequest.DispenseRequest = new MedicationRequest.DispenseRequestComponent
                {
                    Quantity = HealthVaultCodesToFhir.GetSimpleQuantity(prescription.AmountPrescribed),
                    NumberOfRepeatsAllowed = prescription.Refills,
                    ExpectedSupplyDuration = new Duration()
                    {
                        Value = prescription.DaysSupply,
                        Code  = nameof(UnitsNet.Units.DurationUnit.Day)
                    },
                    ValidityPeriod = new Period
                    {
                        EndElement = prescription.PrescriptionExpiration?.ToFhir()
                    }
                };
            }

            if (prescription.Substitution != null)
            {
                bool?isAllowed = IsAllowed(prescription.Substitution);
                if (isAllowed.HasValue)
                {
                    medicationRequest.Substitution = new MedicationRequest.SubstitutionComponent
                    {
                        Allowed = isAllowed
                    };
                }
            }

            if (prescription.Instructions != null)
            {
                var dosage = new Dosage();
                dosage.AdditionalInstruction.Add(prescription.Instructions.ToFhir());
                medicationRequest.DosageInstruction.Add(dosage);
            }

            return(medicationRequest);
        }
示例#5
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));
        }
 private static List <Dosage> AddDosage(GeneralMeasurement dose, GeneralMeasurement frequency, CodableValue route)
 {
     return(new List <Dosage> {
         HealthVaultCodesToFhir.GetDosage(dose, frequency, route)
     });
 }