// Added test for 'No information available' 1.2.0 RMB 7/8/2018
        private void checktheListsarevalidforapatientwithlegacyendReason()
        {
            List <List> resolved = Lists.Where(list => list.Title.Equals(FhirConst.ListTitles.kResolvedAllergies)).ToList();

            if (resolved.Count > 0)
            {
                List <Resource> resolvedAllergies = resolved.First().Contained.Where(resource => resource.ResourceType.Equals(ResourceType.AllergyIntolerance)).ToList();
                resolvedAllergies.ForEach(resource =>
                {
                    AllergyIntolerance endedAllergy = (AllergyIntolerance)resource;
                    Extension endAllergy            = endedAllergy.GetExtension(FhirConst.StructureDefinitionSystems.kAllergyEndExt);
                    endAllergy.ShouldNotBeNull();
                    Extension endReason = endAllergy.GetExtension("reasonEnded");
                    endReason.Value.ShouldNotBeNull();
                    endReason.Value.ToString().ShouldBe("No information available");
                });
            }
        }
        public static Allergy ToHealthVault(this AllergyIntolerance allergyIntolerance)
        {
            if (allergyIntolerance.Code.IsNullOrEmpty())
            {
                throw new System.ArgumentException($"Can not transform a {typeof(AllergyIntolerance)} with no code into {typeof(Allergy)}");
            }

            var allergy = allergyIntolerance.ToThingBase <Allergy>();

            string allergenType     = string.Empty;
            var    allergyExtension = allergyIntolerance.GetExtension(HealthVaultExtensions.Allergy);

            if (allergyExtension != null)
            {
                allergenType         = allergyExtension.GetStringExtension(HealthVaultExtensions.AllergenType);
                allergy.AllergenCode = allergyExtension.GetExtensionValue <CodeableConcept>(HealthVaultExtensions.AllergenCode)?.ToCodableValue();
                allergy.Treatment    = allergyExtension.GetExtensionValue <CodeableConcept>(HealthVaultExtensions.AllergyTreatement)?.ToCodableValue();
            }

            var coding = allergyIntolerance.Code.Coding.FirstOrDefault();

            if (coding != null)
            {
                if (HealthVaultVocabularies.SystemContainsHealthVaultUrl(coding.System))
                {
                    allergy.Name = allergyIntolerance.Code.ToCodableValue();
                }
                else
                {
                    allergy.SetAllergyName(
                        coding.Display,
                        coding.Code,
                        HealthVaultVocabularies.Fhir,
                        coding.System,
                        coding.Version);
                }
            }

            if (allergyIntolerance.Reaction != null && allergyIntolerance.Reaction.Count > 0)
            {
                var code = allergyIntolerance.Reaction.First().Manifestation.First().Coding.FirstOrDefault();
                if (code != null)
                {
                    if (HealthVaultVocabularies.SystemContainsHealthVaultUrl(code.System))
                    {
                        allergy.Reaction = allergyIntolerance.Reaction.First().Manifestation.First().ToCodableValue();
                    }
                    else
                    {
                        allergy.SetAllergyReaction(
                            code.Display,
                            code.Code,
                            HealthVaultVocabularies.Fhir,
                            code.System,
                            code.Version);
                    }
                }
            }

            if (allergyIntolerance.Onset != null)
            {
                allergy.FirstObserved = allergyIntolerance.Onset.ToAproximateDateTime();
            }

            if (!string.IsNullOrWhiteSpace(allergenType))
            {
                allergy.AllergenType = new CodableValue(allergenType)
                {
                    new CodedValue(allergenType, HealthVaultVocabularies.AllergenType, HealthVaultVocabularies.Wc, "1")
                };
            }
            else if (allergyIntolerance.Category != null && allergyIntolerance.Category.Count() > 0)
            {
                allergy.AllergenType = new CodableValue(allergyIntolerance.Category.First().Value.ToString())
                {
                    new CodedValue(allergyIntolerance.Category.First().Value.ToString(), FhirCategories.HL7Allergy, HealthVaultVocabularies.Fhir, "")
                };
            }

            if (allergyIntolerance.ClinicalStatus.HasValue)
            {
                if ((allergyIntolerance.ClinicalStatus.Value == (AllergyIntoleranceClinicalStatus.Resolved)) || (allergyIntolerance.ClinicalStatus.Value == (AllergyIntoleranceClinicalStatus.Inactive)))
                {
                    allergy.IsNegated = true;
                }
                else
                {
                    allergy.IsNegated = false;
                }
            }

            if (allergyIntolerance.Asserter != null)
            {
                allergy.TreatmentProvider = GetProvider(allergyIntolerance);
            }

            return(allergy);
        }