public void WhenMedicationStatementTransformedToHealthVault_MedicationReferenceWillThrowIfNotContained()
        {
            var medicationStatement = new MedicationStatement()
            {
                Medication = new ResourceReference("medication/832475"),
            };

            Assert.ThrowsException <NotImplementedException>(() => medicationStatement.ToHealthVault());
        }
        public void WhenMedicationStatementTransformedToHealthVault_MedicationReferenceReturnsNullIfContainedMedicationIsMissing()
        {
            var medicationStatement = new MedicationStatement()
            {
                Medication = new ResourceReference("#med"),
            };

            Assert.IsNull(medicationStatement.ToHealthVault());
        }
        public void WhenMedicationStatementTransformedToHealthVault_MedicationShouldBeEitherCodeableOrReference()
        {
            var medicationStatement = new MedicationStatement()
            {
                Medication = new Quantity()
                {
                    Value = 10
                }
            };

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => medicationStatement.ToHealthVault());
        }
        public void WhenMedicationStatementTransformedToHealthVault_MedicationCodeableConceptIsUsed()
        {
            const string medicationName      = "Amoxicillin 250mg/5ml Suspension";
            var          medicationStatement = new MedicationStatement()
            {
                Medication = new CodeableConcept()
                {
                    Text = medicationName
                }
            };

            var hvMedication = medicationStatement.ToHealthVault() as HVMedication;

            Assert.AreEqual(medicationName, hvMedication.Name.Text);
        }
        public void WhenMedicationStatementTransformedToHealthVault_ThenDosageIsCopiedToDoseFrequencyAndRoute()
        {
            var embeddedMedication = new FhirMedication()
            {
                Code = new CodeableConcept()
                {
                    Text = "Amoxicillin 250mg/5ml Suspension"
                }
            };
            string embeddedMedicationId = "med" + Guid.NewGuid();

            embeddedMedication.Id = embeddedMedicationId;

            const int    dosage              = 1;
            const int    period              = 8;
            const string routeCode           = "po";
            var          medicationStatement = new MedicationStatement()
            {
                Medication = new ResourceReference(embeddedMedicationId),
                Dosage     = new System.Collections.Generic.List <Dosage>
                {
                    new Dosage
                    {
                        Dose = new SimpleQuantity()
                        {
                            Value  = dosage,
                            Unit   = "Tablets",
                            System = HealthVaultVocabularies.GenerateSystemUrl
                                         (HealthVaultVocabularies.MedicationDoseUnits,
                                         HealthVaultVocabularies.Wc),
                            Code = "tablet"
                        },
                        Timing = new Timing
                        {
                            Repeat = new Timing.RepeatComponent
                            {
                                Period     = period,
                                PeriodUnit = Timing.UnitsOfTime.H
                            }
                        },
                        Route = new CodeableConcept
                        {
                            Text   = "By mouth",
                            Coding = new System.Collections.Generic.List <Coding>
                            {
                                new Coding
                                {
                                    Code   = routeCode,
                                    System = HealthVaultVocabularies.GenerateSystemUrl
                                                 (HealthVaultVocabularies.MedicationRoutes,
                                                 HealthVaultVocabularies.Wc),
                                    Version = "2"
                                }
                            }
                        }
                    }
                }
            };

            medicationStatement.Contained.Add(embeddedMedication);
            medicationStatement.Medication = embeddedMedication.GetContainerReference();

            var hvMedication = medicationStatement.ToHealthVault() as HVMedication;

            Assert.AreEqual(dosage, hvMedication?.Dose?.Structured?.First()?.Value);
            Assert.AreEqual(period, hvMedication?.Frequency?.Structured?.First()?.Value);
            Assert.AreEqual(routeCode, hvMedication?.Route?.First()?.Value);
        }
        public void WhenMedicationStatementTransformedToHealthVault_MedicationReferenceWillThrowIfNull()
        {
            var medicationStatement = new MedicationStatement();

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => medicationStatement.ToHealthVault());
        }