Exemple #1
0
 public void can_add_specialty()
 {
     var subject = new Provider() { Id = 1 };
     var specialty = new Specialty() { Id = 1 };
     var providerSpecialty = subject.AddSpecialty(specialty);
     Assert.IsNotNull(providerSpecialty);
     Assert.AreSame(specialty, providerSpecialty.Specialty);
     Assert.AreSame(subject, providerSpecialty.Provider);
 }
Exemple #2
0
        /// <summary>
        /// Validates a specialty.
        /// </summary>
        public static void ValidateSpecialty(Specialty specialty)
        {
            const int maximumNameLength = 200;

            // Validate all location entity members
            if (specialty == null)
                throw new BusinessException("Specialty cannot be null.");

            if (String.IsNullOrWhiteSpace(specialty.Name))
                throw new BusinessException("Name required");

            if (specialty.Name.Length > maximumNameLength)
                throw new BusinessException("Specialty name too long.");
        }
 public ProviderSpecialty(Provider provider, Specialty specialty)
     : this()
 {
     if (provider == null)
     {
         throw new ArgumentNullException("provider");
     }
     if (specialty == null)
     {
         throw new ArgumentNullException("specialty");
     }
     Provider = provider;
     Specialty = specialty;
 }
        public void TestCreateFilter()
        {
            //setup
            var cardio = new Specialty { Name = "Cardiology", Id = 1, SpecialtyType = SpecialtyType.Specialty };
            var oncology = new Specialty { Name = "Oncology", Id = 2, SpecialtyType = SpecialtyType.Specialty };

            var source = new List<ProviderCacheView>();

            var provider = new ProviderCacheView { Id = 1 };
            provider.AddSpecialty(cardio);
            source.Add(provider);

            provider = new ProviderCacheView { Id = 2 };
            provider.AddSpecialty(cardio);
            source.Add(provider);

            provider = new ProviderCacheView { Id = 3 };
            provider.AddSpecialty(oncology);
            source.Add(provider);

            provider = new ProviderCacheView { Id = 4 };
            source.Add(provider);

            var builder = new SpecialtyFilterBuilder();

            //act
            var filter = builder.CreateFilters(source.AsQueryable()).FirstOrDefault();

            //assert
            Assert.IsNotNull(filter);
            Assert.AreEqual(QueryStringKeys.SpecialtyIdKey, filter.QueryStringParameterName);
            Assert.AreEqual("Specialty", filter.Name);
            Assert.IsNotNull(filter.FilterValues);
            Assert.AreEqual(2, filter.FilterValues.Count());

            var value = filter.FilterValues.ElementAt(0);
            Assert.AreEqual(cardio.Name, value.DisplayName);
            Assert.AreEqual(cardio.Id.ToString(CultureInfo.CurrentCulture), value.QueryStringParameterValue);
            Assert.AreEqual(2, value.Count);

            value = filter.FilterValues.ElementAt(1);
            Assert.AreEqual(oncology.Name, value.DisplayName);
            Assert.AreEqual(oncology.Id.ToString(CultureInfo.CurrentCulture), value.QueryStringParameterValue);
            Assert.AreEqual(1, value.Count);
        }
Exemple #5
0
 /// <summary>
 /// Removes the specialty.
 /// </summary>
 /// <param name="specialty">The specialty.</param>
 /// <returns></returns>
 public ProviderSpecialty RemoveSpecialty(Specialty specialty)
 {
     if (specialty == null)
     {
         throw new ArgumentNullException("specialty");
     }
     var providerSpecialty = ProviderSpecialties.Single(ps => ps.Specialty.Id == specialty.Id);
     if (providerSpecialty.IsPrimary)
     {
         throw new BusinessException("Primary Specialty cannot be removed from the provider.");
     }
     ProviderSpecialties.Remove(providerSpecialty);
     return providerSpecialty;
 }
Exemple #6
0
 /// <summary>
 /// Adds the specialty.
 /// </summary>
 /// <param name="specialty">The specialty.</param>
 /// <returns>A new ProviderSpecialty instance.</returns>
 public ProviderSpecialty AddSpecialty(Specialty specialty)
 {
     if (specialty == null)
     {
         throw new ArgumentNullException("specialty");
     }
     if (ProviderSpecialties.Count(ps => ps.Specialty.Id.Equals(specialty.Id)) > 0)
     {
         throw new BusinessException("The specialty is already associated with this provider.");
     }
     var providerSpecialty = new ProviderSpecialty(this, specialty);
     ProviderSpecialties.Add(providerSpecialty);
     if (ProviderSpecialties.Count == 1)
     {
         SetPrimarySpecialty(providerSpecialty);
     }
     return providerSpecialty;
 }
Exemple #7
0
        public void can_change_primary_specialty()
        {
            var subject = new Provider() { Id = 1 };
            var specialtyA = new Specialty() { Id = 1 };
            var providerSpecialtyA = subject.AddSpecialty(specialtyA);

            var specialtyB = new Specialty() { Id = 2 };
            var providerSpecialtyB = subject.AddSpecialty(specialtyB);

            subject.SetPrimarySpecialty(providerSpecialtyB);

            Assert.IsFalse(providerSpecialtyA.IsPrimary);
            Assert.IsTrue(providerSpecialtyB.IsPrimary);
        }
Exemple #8
0
        public void throws_business_exception_when_removing_primary_specialty()
        {
            var subject = new Provider() { Id = 1 };
            var firstSpecialty = new Specialty() { Id = 1 };
            var secondSpecialty = new Specialty() { Id = 2 };
            subject.AddSpecialty(firstSpecialty);
            subject.AddSpecialty(secondSpecialty);

            subject.RemoveSpecialty(firstSpecialty);
        }
Exemple #9
0
 public void throws_business_exception_when_adding_existing_specialty()
 {
     var subject = new Provider() { Id = 1 };
     var specialty = new Specialty() { Id = 1 };
     subject.AddSpecialty(specialty);
     subject.AddSpecialty(specialty);
 }
Exemple #10
0
 public void makes_first_specialty_primary()
 {
     var subject = new Provider() { Id = 1 };
     var specialty = new Specialty() { Id = 1 };
     var providerSpecialty = subject.AddSpecialty(specialty);
     Assert.IsTrue(providerSpecialty.IsPrimary);
 }
Exemple #11
0
        public void keeps_primary_specialty_when_adding_new_specialty()
        {
            var subject = new Provider() { Id = 1 };
            var specialtyA = new Specialty() { Id = 1 };
            var providerSpecialtyA = subject.AddSpecialty(specialtyA);

            var specialtyB = new Specialty() { Id = 2 };
            var providerSpecialtyB = subject.AddSpecialty(specialtyB);

            Assert.IsTrue(providerSpecialtyA.IsPrimary);
        }
Exemple #12
0
        public void can_remove_specialty()
        {
            var subject = new Provider() { Id = 1 };
            var firstSpecialty = new Specialty() { Id = 1 };
            var secondSpecialty = new Specialty() { Id = 2 };
            subject.AddSpecialty(firstSpecialty);
            subject.AddSpecialty(secondSpecialty);

            var removed = subject.RemoveSpecialty(secondSpecialty);

            Assert.AreEqual(secondSpecialty, removed.Specialty);
            Assert.IsTrue(subject.ProviderSpecialties.Count == 1);
        }
        private static List<Specialty> EnsureParentSpecialtiesExist(IEnumerable<KeyValuePair<string, string>> parentSpecialties, ObjectSet<Specialty> specialtiesObjectSet)
        {
            var specialties = new List<Specialty>();
            foreach (var item in parentSpecialties)
            {
                var specialtyName = item.Key;
                var specialtyType = item.Value;

                var specialty = specialtiesObjectSet.FirstOrDefault(s => s.Name == specialtyName && s.SpecialtyType == specialtyType);

                if (specialty == null)
                {
                    specialty = new Specialty() { Name = specialtyName, IsEnabled = true, SpecialtyType = specialtyType };
                    specialtiesObjectSet.AddObject(specialty);
                }
                specialties.Add(specialty);
            }
            return specialties;
        }
        public static void SetProviderSpecialties(ObjectContext context, ProviderV2 source, Provider provider)
        {
            if (source.Specialties == null)
                return;

            try
            {
                foreach (var item in provider.ProviderSpecialties.ToArray())
                    context.DeleteObject(item);

                var specialtiesObjectSet = context.CreateObjectSet<Specialty>();

                //Get all referenced parent specialties
                var uniqueParentSpecialties = source.Specialties
                    .Where(s => !string.IsNullOrEmpty(s.ParentSpecialtyName))
                    .Select(s => new KeyValuePair<string, string>(s.ParentSpecialtyName, s.SpecialtyType))
                    .Distinct();

                //Ensure parent specialties exist
                var parentSpecialties = EnsureParentSpecialtiesExist(uniqueParentSpecialties, specialtiesObjectSet);

                var providerSpecialties = new List<ProviderSpecialty>();

                foreach (var item in source.Specialties)
                {
                    var specialty = specialtiesObjectSet.FirstOrDefault(s => s.Name == item.SpecialtyName);

                    if (specialty == null)
                    {
                        specialty = parentSpecialties.FirstOrDefault(s => s.Name == item.SpecialtyName);

                        if (specialty == null)
                        {
                            var specialtyType = string.IsNullOrEmpty(item.SpecialtyType) ? SpecialtyType.Specialty : item.SpecialtyType;

                            specialty = new Specialty() { Name = item.SpecialtyName, IsEnabled = true, SpecialtyType = specialtyType };
                            if (!string.IsNullOrEmpty(item.ParentSpecialtyName))
                            {
                                specialty.ParentSpecialty = parentSpecialties.FirstOrDefault(s => s.Name == item.ParentSpecialtyName && s.SpecialtyType == specialtyType);
                            }
                            specialtiesObjectSet.AddObject(specialty);
                        }
                    }

                    providerSpecialties.Add(new ProviderSpecialty(provider, specialty)
                    {
                        IsBoardCertified = ConvertToBool(item.IsBoardCertified, false, "Specialty/IsBoardCertified", provider.FullName),
                        IsPrimary = ConvertToBool(item.IsPrimary, false, "Specialty/IsPrimary", provider.FullName),
                    });
                }

                provider.ProviderSpecialties = providerSpecialties;
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing specialties for provider '" + provider.Name + "' - " + ex.Message, ex);
            }
        }
 internal static ProviderCacheView AddSpecialty(this ProviderCacheView provider, Specialty specialty)
 {
     return AddSpecialties(provider, new List<Specialty>() { specialty }).FirstOrDefault();
 }