public ProfileProviderOrgUnit(Profile profile, ProviderOrgUnit providerOrgUnit)
        {
            if (profile == null)
            {
                throw new ArgumentNullException("profile");
            }
            if (providerOrgUnit == null)
            {
                throw new ArgumentNullException("providerOrgUnit");
            }

            Profile = profile;
            ProviderOrgUnit = providerOrgUnit;
        }
Beispiel #2
0
        public void maps_providerOrgUnit()
        {
            var provider = new Provider
            {
                Id = 123
            };

            var orgUnit = new OrgUnit
            {
                Id = 1,
                Description = "test desc",
                Name = "test",
                IsEnabled = true
            };

            var providerOrgUnit = new ProviderOrgUnit(provider, orgUnit);

            var providerOrgUnitDto = Mapper.Map<ProviderOrgUnit, ProviderOrgUnitDto>(providerOrgUnit);

            Assert.IsNotNull(providerOrgUnitDto);
        }
Beispiel #3
0
        /// <summary>
        /// Removes a favorite provider location.
        /// </summary>
        /// <param name="providerOrgUnit">The provider location.</param>
        /// <returns>The provider location to be removed.</returns>
        public ProfileProviderOrgUnit RemoveFavorite(ProviderOrgUnit providerOrgUnit)
        {
            if (providerOrgUnit == null)
            {
                throw new ArgumentNullException("providerOrgUnit");
            }

            if (ProfileProviderOrgUnits.Count(ppl => ppl.ProviderOrgUnit.Id.Equals(providerOrgUnit.Id)) == 0)
            {
                throw new BusinessException("The Provider Location is not currently a favorite of this profile.");
            }

            var profileProviderOrgUnit = ProfileProviderOrgUnits.Single(pl => pl.ProviderOrgUnit.Id == providerOrgUnit.Id
                                                                                && pl.Profile.UserName == UserName);
            ProfileProviderOrgUnits.Remove(profileProviderOrgUnit);

            return profileProviderOrgUnit;
        }
Beispiel #4
0
        /// <summary>
        /// Adds a favorite provider location.
        /// </summary>
        /// <param name="providerOrgUnit">The provider location.</param>
        /// <returns>The added provider location.</returns>
        public ProfileProviderOrgUnit AddFavorite(ProviderOrgUnit providerOrgUnit)
        {
            if (providerOrgUnit == null)
            {
                throw new ArgumentNullException("providerOrgUnit");
            }

            if (ProfileProviderOrgUnits.Count(ppl => ppl.ProviderOrgUnit.Id.Equals(providerOrgUnit.Id)) > 0)
            {
                throw new BusinessException("The Provider Location has already been favorited by this profile.");
            }

            var profileProviderOrgUnit = new ProfileProviderOrgUnit(this, providerOrgUnit);
            ProfileProviderOrgUnits.Add(profileProviderOrgUnit);

            return profileProviderOrgUnit;
        }
Beispiel #5
0
 /// <summary>
 /// Sets the primary provider location.
 /// </summary>
 /// <param name="providerOrgUnit">The provider location.</param>
 public void SetPrimaryOrgUnit(ProviderOrgUnit providerOrgUnit)
 {
     providerOrgUnit.IsPrimary = true;
     ProviderOrgUnits.Where(pl => pl.OrgUnit.Id != providerOrgUnit.OrgUnit.Id)
         .ToList()
         .ForEach(pl => pl.IsPrimary = false);
 }
Beispiel #6
0
 /// <summary>
 /// Adds the location.
 /// </summary>
 /// <param name="location">The location.</param>
 /// <returns>A new ProviderOrgUnit instance.</returns>
 public ProviderOrgUnit AddOrgUnit(OrgUnit location)
 {
     if (location == null)
     {
         throw new ArgumentNullException("location");
     }
     if (ProviderOrgUnits.Count(pl => pl.OrgUnit.Id.Equals(location.Id)) > 0)
     {
         throw new BusinessException("The location is already associated with this provider.");
     }
     var providerOrgUnit = new ProviderOrgUnit(this, location);
     ProviderOrgUnits.Add(providerOrgUnit);
     if (ProviderOrgUnits.Count == 1)
     {
         SetPrimaryOrgUnit(providerOrgUnit);
     }
     return providerOrgUnit;
 }
        public static void SetProviderOrgUnits(ObjectContext context, ProviderV2 source, Provider provider)
        {
            if (source.OrgUnits == null)
                return;

            if (source.OrgUnits.Where(o => ConvertToBool(o.IsPrimary, false, "OrgUnit/IsPrimary", provider.FullName)).Count() > 1)
                throw new BusinessException("Only 1 org unit can be specified as the primary org unit.");

            try
            {
                var providerOrgUnits = provider.ProviderOrgUnits.ToArray();
                List<int> currentOrgUnitIds = new List<int>();

                CheckForDuplicateOrgUnits(source);

                foreach (var item in source.OrgUnits)
                {
                    int orgUnitId = 0;

                    if (string.IsNullOrEmpty(item.OrgUnitId) && string.IsNullOrEmpty(item.OrgUnitExternalId))
                        throw new BusinessException("Please supply either the OrgUnitId or the OrgUnitExternalId");

                    if (!string.IsNullOrEmpty(item.OrgUnitExternalId))
                        orgUnitId = LookupInternalId(context, item.OrgUnitExternalId, "OrgUnit");
                    else if (!string.IsNullOrEmpty(item.OrgUnitId))
                        orgUnitId = ConvertToInt(item.OrgUnitId, "OrgUnitId", provider.FullName);

                    currentOrgUnitIds.Add(orgUnitId);

                    var existingProviderOrgUnit = providerOrgUnits.SingleOrDefault(pou => pou.OrgUnitId == orgUnitId);
                    if (existingProviderOrgUnit != null)
                    {
                        existingProviderOrgUnit.Phone = item.Phone;
                        existingProviderOrgUnit.IsPrimary = ConvertToBool(item.IsPrimary, false, "OrgUnit/IsPrimary", provider.FullName);
                        existingProviderOrgUnit.Fax = item.Fax;
                        existingProviderOrgUnit.IsAcceptingNewPatients = ConvertToBool(item.IsAcceptingNewPatients, false, "OrgUnit/IsAcceptingNewPatients", provider.FullName);
                        existingProviderOrgUnit.OrgUnitExternalId = item.OrgUnitExternalId;
                        existingProviderOrgUnit.ProviderOrgUnitInsurances = SetInsurances(context, item, provider, orgUnitId, existingProviderOrgUnit.ProviderOrgUnitInsurances);
                        existingProviderOrgUnit.ProviderOrgUnitServices = SetServices(context, item, provider, existingProviderOrgUnit.ProviderOrgUnitServices);
                        existingProviderOrgUnit.ProviderOrgUnitInsurancesInheritedDisableds = SetDisabledInheritedInsurances(context, item, provider, existingProviderOrgUnit.ProviderOrgUnitInsurancesInheritedDisableds);
                        existingProviderOrgUnit.Schedules = SetSchedules(context, item, existingProviderOrgUnit.Schedules);
                        existingProviderOrgUnit.AllowAppointmentRequests = ConvertToBool(item.AllowAppointmentRequests, true, "OrgUnit/AllowAppointmentRequests", provider.FullName);

                    }
                    else
                    {
                        var orgUnit = context.CreateObjectSet<OrgUnit>().SingleOrDefault(o => o.Id == orgUnitId);

                        if (orgUnit == null)
                            throw new BusinessException("Unable to find Org Unit with Internal Id of " + orgUnitId);

                        var providerOrgUnit = new ProviderOrgUnit(provider, orgUnit)
                        {
                            Phone = item.Phone,
                            IsPrimary = ConvertToBool(item.IsPrimary, false, "OrgUnit/IsPrimary", provider.FullName),
                            Fax = item.Fax,
                            IsAcceptingNewPatients = ConvertToBool(item.IsAcceptingNewPatients, false, "OrgUnit/IsAcceptingNewPatients", provider.FullName),
                            AllowAppointmentRequests = ConvertToBool(item.AllowAppointmentRequests, true, "OrgUnit/AllowAppointmentRequests", provider.FullName),
                            OrgUnitExternalId = item.OrgUnitExternalId,
                            ProviderOrgUnitInsurances = SetInsurances(context, item, provider, orgUnitId, new List<ProviderOrgUnitInsurance>()),
                            ProviderOrgUnitServices = SetServices(context, item, provider, new List<ProviderOrgUnitService>()),
                            ProviderOrgUnitInsurancesInheritedDisableds = SetDisabledInheritedInsurances(context, item, provider, new List<ProviderOrgUnitInsurancesInheritedDisabled>()),
                            Schedules = SetSchedules(context, item, new List<ProviderOrgUnitSchedule>())
                        };
                        provider.ProviderOrgUnits.Add(providerOrgUnit);
                    }
                }

                //Remove necessary org units
                var orgUnitIdsToDelete = providerOrgUnits.Select(o => o.OrgUnitId).Except(currentOrgUnitIds);
                var providerOrgUnitsToDelete = provider.ProviderOrgUnits.Where(o => orgUnitIdsToDelete.Contains(o.OrgUnitId)).ToList();
                foreach (var pou in providerOrgUnitsToDelete)
                    pou.ProfileProviderOrgUnits.ToList().ForEach(p => context.DeleteObject(p));
                providerOrgUnitsToDelete.ForEach(p => context.DeleteObject(p));
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing org units for provider '" + provider.Name + "' - " + ex.Message, ex);
            }
        }