Пример #1
0
 public void can_add_insurance()
 {
     var insurance = new Insurance("insurance", true);
     var subject = CreateProviderOrgUnit();
     subject.AddInsurance(insurance);
     Assert.IsTrue(subject.EffectiveInsurances.Select(i => i.Insurance).Contains(insurance));
 }
Пример #2
0
 public void can_tell_effective_insurances_inherited_after_custom()
 {
     var insurance = new Insurance("insurance", true);
     var subject = CreateProviderOrgUnit();
     subject.AddInsurance(insurance);
     subject.OrgUnit.OrgUnitInsurances.Add(new OrgUnitInsurance() { Insurance = insurance });
     Assert.IsTrue(subject.EffectiveInsurances.Count() == 1);
 }
Пример #3
0
 public void can_tell_effective_insurances_inherited()
 {
     var insurance = new Insurance("insurance", true);
     var subject = CreateProviderOrgUnit();
     subject.OrgUnit.OrgUnitInsurances.Add(new OrgUnitInsurance() { Insurance = insurance });
     Assert.IsTrue(subject.EffectiveInsurances.Count() == 1);
     Assert.IsTrue(subject.EffectiveInsurances.Select(i => i.Insurance).Contains(insurance));
 }
 public ProviderOrgUnitInsurance(Insurance insurance)
 {
     if (insurance == null)
     {
         throw new ArgumentNullException("insurance");
     }
     Insurance = insurance;
 }
Пример #5
0
 public void can_tell_effective_insurances_custom_only()
 {
     var insurance = new Insurance("insurance", true);
     var subject = CreateProviderOrgUnit();
     subject.AddInsurance(insurance);
     Assert.IsTrue(subject.EffectiveInsurances.Count() == 1);
     Assert.IsTrue(subject.EffectiveInsurances.Select(i => i.Insurance).Contains(insurance));
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AcceptedInsurance"/> class.
 /// </summary>
 /// <param name="insurance">The insurance.</param>
 /// <param name="isInherited">if set to <c>true</c> is inherited.</param>
 public AcceptedInsurance(Insurance insurance, bool isInherited)
 {
     if (insurance == null)
     {
         throw new ArgumentNullException("insurance");
     }
     Insurance = insurance;
     IsInherited = isInherited;
 }
Пример #7
0
 public void can_remove_custom_added_insurance()
 {
     var insurance = new Insurance("insurance", true);
     var subject = CreateProviderOrgUnit();
     subject.AddInsurance(insurance);
     var result = subject.RemoveInsurance(insurance);
     Assert.IsTrue(subject.EffectiveInsurances.Count() == 0);
     Assert.IsTrue(result.Insurance == insurance);
 }
Пример #8
0
        public static void SetOrgUnitInsurances(ObjectContext context, OrgUnitV2 source, OrgUnit orgUnit)
        {
            //ignore null values
            if (source.OrgUnitInsurances == null)
                return;

            try
            {
                var existingInsurances = orgUnit.OrgUnitInsurances.ToArray();
                foreach (var item in existingInsurances)
                    context.DeleteObject(item);

                var insurances = context.CreateObjectSet<Insurance>();
                var orgUnitInsurances = new List<OrgUnitInsurance>();

                foreach (var item in source.OrgUnitInsurances)
                {
                    //Ensure insurance Exists
                    var insurance = insurances.FirstOrDefault(i => i.Name == item.Name);
                    if (insurance == null)
                    {
                        insurance = new Insurance()
                        {
                            Name = item.Name,
                            IsEnabled = true
                        };
                        insurances.AddObject(insurance);
                    }

                    orgUnitInsurances.Add(new OrgUnitInsurance
                    {
                        Insurance = insurance,
                        OrgUnit = orgUnit
                    });
                }

                orgUnit.OrgUnitInsurances = orgUnitInsurances;
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing insurances for orgUnit '" + orgUnit.Name + "' - " + ex.Message, ex);
            }
        }
        private void FixupInsurance(Insurance previousValue)
        {
            if (previousValue != null && previousValue.ProviderLocationInsurances.Contains(this))
            {
                previousValue.ProviderLocationInsurances.Remove(this);
            }

            if (Insurance != null)
            {
                if (!Insurance.ProviderLocationInsurances.Contains(this))
                {
                    Insurance.ProviderLocationInsurances.Add(this);
                }
                if (InsuranceId != Insurance.Id)
                {
                    InsuranceId = Insurance.Id;
                }
            }
        }
Пример #10
0
 /// <summary>
 /// Removes the insurance.
 /// </summary>
 /// <param name="insurance">The insurance.</param>
 /// <returns>A ProviderOrgUnitInsurance instance if a custom insurance was removed, or null if removing an inherited insurance.</returns>
 public ProviderOrgUnitInsurance RemoveInsurance(Insurance insurance)
 {
     if (insurance == null)
     {
         throw new ArgumentNullException("insurance");
     }
     if (!EffectiveInsurances.Select(i => i.Insurance.Id).Contains(insurance.Id))
     {
         throw new BusinessException("Insurance to be removed is not associated.");
     }
     var providerOrgUnitInsurance = ProviderOrgUnitInsurances.SingleOrDefault(pli => pli.Insurance.Id == insurance.Id);
     if (providerOrgUnitInsurance != null)
     {
         ProviderOrgUnitInsurances.Remove(providerOrgUnitInsurance);
         return providerOrgUnitInsurance;
     }
     else
     {
         throw new BusinessException("Removing an insurance inherited from the location is not supported.");
     }
 }
Пример #11
0
        /// <summary>
        /// Adds the insurance.
        /// </summary>
        /// <param name="insurance">The insurance.</param>
        /// <returns></returns>
        public ProviderOrgUnitInsurance AddInsurance(Insurance insurance)
        {
            if (insurance == null)
            {
                throw new ArgumentNullException("insurance");
            }
            if (EffectiveInsurances.Select(i => i.Insurance.Id).Contains(insurance.Id))
            {
                throw new BusinessException("Insurance is already associated.");
            }
            var providerOrgUnitInsurance = new ProviderOrgUnitInsurance(insurance);

            ProviderOrgUnitInsurances.Add(providerOrgUnitInsurance);

            return providerOrgUnitInsurance;
        }
        public void Test_fixture_setup()
        {
            _insurance1 = new Insurance("1", true);
            _insurance2 = new Insurance("2", true);
            _insurance3 = new Insurance("3", true);

            _insurance1.Id = 1;
            _insurance2.Id = 2;
            _insurance3.Id = 3;
        }
Пример #13
0
        public void can_tell_effective_insurances_inherited_and_custom()
        {
            var insurance1 = new Insurance("insurance1", true);
            insurance1.Id = 1;

            var insurance2 = new Insurance("insurance2", true);
            insurance2.Id = 2;

            var subject = CreateProviderOrgUnit();
            subject.OrgUnit.OrgUnitInsurances.Add(new OrgUnitInsurance() { Insurance = insurance1 });
            subject.AddInsurance(insurance2);
            Assert.IsTrue(subject.EffectiveInsurances.Count() == 2);
        }
Пример #14
0
        private static ICollection<ProviderOrgUnitInsurance> SetInsurances(ObjectContext context, ProviderOrgUnitV2 source, Provider provider, int orgUnitId, ICollection<ProviderOrgUnitInsurance> existingInsurances)
        {
            if (source.Insurances == null)
                return existingInsurances;

            try
            {
                //Delete existing insurances to be sure they are not duplicated.
                existingInsurances.ToList().ForEach(i => context.DeleteObject(i));

                var insurances = context.CreateObjectSet<Insurance>();
                var orgUnits = context.CreateObjectSet<OrgUnit>();
                var providerOrgUnitInsurances = new List<ProviderOrgUnitInsurance>();

                foreach (ProviderOrgUnitInsuranceV2 item in source.Insurances)
                {
                    if (string.IsNullOrEmpty(item.Name))
                        continue;

                    //Ensure Insurance Exists
                    var insurance = insurances.FirstOrDefault(s => s.Name == item.Name);
                    if (insurance == null)
                    {
                        insurance = new Insurance(item.Name, true);
                        insurances.AddObject(insurance);
                    }

                    if (!orgUnits.Single(ou => ou.Id == orgUnitId).OrgUnitPublished.InsurancesOrgUnit.OrgUnitInsurances.Any(i => i.InsuranceId == insurance.Id))
                        providerOrgUnitInsurances.Add(new ProviderOrgUnitInsurance(insurance));
                }

                return providerOrgUnitInsurances;
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing insurances for provider '" + provider.Name + "' - " + ex.Message, ex);
            }
        }
Пример #15
0
 public void throws_exception_when_removing_insurance_inherited_from_location()
 {
     var insurance = new Insurance("insurance", true);
     var subject = CreateProviderOrgUnit();
     subject.OrgUnit.OrgUnitInsurances.Add(new OrgUnitInsurance() { Insurance = insurance });
     var result = subject.RemoveInsurance(insurance);
 }
 internal static IEnumerable<ProviderCacheView> AddInsurance(this IEnumerable<ProviderCacheView> providers, Insurance insurance)
 {
     return AddInsurances(providers, new List<Insurance>() { insurance });
 }
Пример #17
0
 public void throw_exception_when_removing_insurance_not_added()
 {
     var insurance = new Insurance("insurance", true);
     var subject = CreateProviderOrgUnit();
     subject.RemoveInsurance(insurance);
 }
Пример #18
0
 public void throw_exception_when_adding_insurance_already_added()
 {
     var insurance = new Insurance("insurance", true);
     var subject = CreateProviderOrgUnit();
     subject.AddInsurance(insurance);
     subject.AddInsurance(insurance);
 }