Пример #1
0
        private ObservableCollection <TEntity> Load <TEntity>(string filePath)
        {
            HospitalRegistryService <ObservableCollection <TEntity> > hospitalRegistryService =
                new HospitalRegistryService <ObservableCollection <TEntity> >();

            return(hospitalRegistryService.Read(filePath, FileMode.Open));
        }
Пример #2
0
        private void Save <TEntity>(ObservableCollection <TEntity> entities, string filePath)
        {
            HospitalRegistryService <ObservableCollection <TEntity> > hospitalRegistryService =
                new HospitalRegistryService <ObservableCollection <TEntity> >();

            hospitalRegistryService.Write(entities, filePath, FileMode.Truncate);
        }
        public HospitalMappingReference DefaultReferenceMapping()
        {
            var abbrvs = HospitalRegion.Default.DefaultStates.OfType <string>().ToArray();
            var states = abbrvs.Count() == 0
                ? Enumerable.Empty <State>()
                : HospitalRegistryService.GetStates(abbrvs);

            return(HospitalRegion.Default.SelectedRegionType == typeof(HealthReferralRegion)
                ? HospitalRegistryService.GenerateMappingReference <HealthReferralRegion>(states)
                : HospitalRegistryService.GenerateMappingReference <HospitalServiceArea>(states));
        }
 /// <summary>
 /// Gets the existing region.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="queryExpression">The query expression.</param>
 /// <returns></returns>
 /// <exception cref="Monahrq.Sdk.Services.Import.Exceptions.ExistingEntityLookupException">null</exception>
 protected T GetExistingRegion <T>(Expression <Func <T, bool> > queryExpression) where T : Region
 {
     try
     {
         return(HospitalRegistryService.Get(queryExpression));
     }
     catch (Exception ex)
     {
         throw new ExistingEntityLookupException(ExportAttribute, null, ex);
     }
 }
 /// <summary>
 /// Gets the state.
 /// </summary>
 /// <param name="abbrev">The abbrev.</param>
 /// <returns></returns>
 /// <exception cref="StateLookupFailed">
 /// </exception>
 protected State GetState(string abbrev)
 {
     try
     {
         return(HospitalRegistryService.GetStates(new[] { abbrev }).Single());
     }
     catch (InvalidOperationException ex)
     {
         throw new StateLookupFailed(string.Format("State not found: {0}", abbrev.ToUpper()), ex);
     }
     catch (Exception ex)
     {
         throw new StateLookupFailed(string.Format("State lookup failed: {0}", ex.Message), ex);
     }
 }
Пример #6
0
        /// <summary>
        /// Processes the values.
        /// </summary>
        /// <param name="vals">The vals.</param>
        /// <param name="errors">The errors.</param>
        protected override void ProcessValues(string[] vals, IList <ImportError> errors)
        {
            vals.ToList().ForEach(TestForEmpty);

            dynamic dynRegion = new { RegionID = int.Parse(vals[0].Trim()), RegionName = vals[1].Trim(), State = vals[2].Trim() };

            State state        = GetState(dynRegion.State.ToString());
            var   customRegion = HospitalRegistryService.CreateRegion();

            customRegion.Name           = dynRegion.RegionName;
            customRegion.State          = state.Abbreviation;
            customRegion.ImportRegionId = dynRegion.RegionID;
            customRegion.Code           = string.Format("CUS{0}{1}", dynRegion.RegionID, state.Abbreviation);

            ProcessRegion(customRegion, errors);
        }
        /// <summary>
        /// Processes the region population strats.
        /// </summary>
        /// <param name="regionPopulationStrats">The region population strats.</param>
        /// <param name="errors">The errors.</param>
        private void ProcessRegionPopulationStrats(RegionPopulationStrats regionPopulationStrats, IList <ImportError> errors)
        {
            try
            {
                if (errors.Any())
                {
                    return;
                }

                HospitalRegistryService.Save(regionPopulationStrats);
            }
            catch (Exception exc)
            {
                errors.Add(ImportError.Create(typeof(RegionPopulationStrats).Name, regionPopulationStrats.RegionID.ToString(), (exc.InnerException ?? exc).Message));
            }
        }
Пример #8
0
        /// <summary>
        /// Processes the region.
        /// </summary>
        /// <param name="region">The region.</param>
        /// <param name="errors">The errors.</param>
        private void ProcessRegion(CustomRegion region, IList <ImportError> errors)
        {
            var criteria      = PredicateBuilder.False <CustomRegion>().Or(r => r.ImportRegionId == region.ImportRegionId);
            var stateCriteria = PredicateBuilder.False <CustomRegion>();

            CurrentStatesBeingManaged.ToList().ForEach(abbr => stateCriteria = stateCriteria.Or(r => region.State.ToUpper() == abbr.ToUpper()));
            criteria = criteria.And(stateCriteria);

            var reg = GetExistingRegion(criteria);

            if (reg != null)
            {
                // if the found region is custom type, overwrite it in the database with the attributes being imported
                region.Code        = region.Code;
                reg.Name           = region.Name;
                reg.State          = region.State;
                reg.ImportRegionId = region.ImportRegionId;
            }
            else
            {
                reg = region;
            }

            if (CurrentStatesBeingManaged.All(s => s.ToLower() != reg.State.ToLower()))
            {
                var errorMessage =
                    string.Format(
                        "The region \"{0}\" can't be added because it is not in the correct geo context state. CMS NUMBER: {0}",
                        reg.Name);

                errors.Add(ImportError.Create("CustomRegion", reg.Name, errorMessage));
                return;
            }

            if (errors.Any())
            {
                return;
            }

            HospitalRegistryService.Save(reg);

            Events.GetEvent <EntityImportedEvent <CustomRegion> >().Publish(reg);
        }
        /// <summary>
        /// Called when [imports satisfied].
        /// </summary>
        public override void OnImportsSatisfied()
        {
            base.OnImportsSatisfied();

            CurrentMappingBasis = ConfigurationService.HospitalRegion;
            ReferenceExists     = !IsInitialMapping;

            AddStateToContextCommand      = new DelegateCommand(OnAddState, CanAddState);
            RemoveStateFromContextCommand = new DelegateCommand <SelectListItem>(OnRemoveStateCommand, CanRemoveState);
            ApplyContextCommand           = new DelegateCommand(OnApplyContextCommand, CanApplyContextCommand);
            NavigateBackCommand           = new DelegateCommand(OnNavigateBackCommand);
            SelectedStates = CollectionHelper.EmptyListCollectionView <SelectListItem>();
            var crit = PredicateBuilder.True <State>();

            ListExtensions.ForEach(CurrentMappingBasis.DefaultStates.OfType <string>().ToList(),
                                   ab => crit = crit.And(st => st.Abbreviation != ab));

            var availStates = new List <SelectListItem>();

            availStates.Add(SELECT_STATE);

            var allStates = HospitalRegistryService.GetStates(null).ToList();

            availStates.AddRange(allStates.AsQueryable()
                                 .Where(crit)
                                 .Select(state => new SelectListItem {
                Model = state, Text = state.Abbreviation, Value = state.Abbreviation
            })
                                 //.Concat(new[] { SELECT_STATE })
                                 .OrderBy(item => item.Text).ToList());

            AvailableStates = availStates.ToListCollectionView();

            crit = PredicateBuilder.False <State>();

            ListExtensions.ForEach(CurrentMappingBasis.DefaultStates
                                   .OfType <string>(), ab => crit = crit.Or(st => st.Abbreviation == ab));

            var selectedStates = allStates.AsQueryable().Where(crit).Select(st => new SelectListItem {
                Text = st.Abbreviation, Value = st.Abbreviation, Model = st
            }).ToList();

            // Setting the Selected Reporting States for Global use.
            //if (!MonahrqContext.ReportingStatesContext.Any(s => selectedStates.Any(s1 => s.In(s1)) ))
            //    MonahrqContext.ReportingStatesContext.AddRange(selectedStates);
            MonahrqContext.ReportingStatesContext.AddRange(selectedStates.Select(s => s.Text).ToList());

            SelectedStates = selectedStates.ToListCollectionView();
            SelectedStates.CommitNew();
            AvailableStates.CommitEdit();
            AvailableStates.MoveCurrentToFirst();

            SelectedState = SELECT_STATE;

            // Regions for combo box, Object type return "SELECT" on display, and NULL on return using
            RegionTypes = (new[] {
                typeof(object),
                typeof(CustomRegion),
                typeof(HealthReferralRegion),
                typeof(HospitalServiceArea)
            }).ToListCollectionView();

            SelectedRegionType = CurrentMappingBasis.SelectedRegionType;
        }