コード例 #1
0
        public JsonResult Edit(long?id, ReferralSourceModel model)
        {
            if (id == null || id == 0)
            {
                return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "Invalid ID Specification." }));
            }

            if (!HasContextRole(new string[] { "CRO" })) //Only CRO can edit.
            {
                return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "Unauthorized." }));
            }



            if (ModelState.IsValid)
            {
                if (model.Sites == null || model.Sites.Where(p => p.Selected == true).Count() <= 0)

                {
                    return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "Please select at least one site to associate the referral source to." }));
                }

                using (var transaction = _dataContext.Database.BeginTransaction())
                {
                    if (_dataContext.ReferralSources.Where(p => p.FullName == model.FullName && p.ReferralSourceId != id && p.Deleted == false).Count() <= 0)
                    {
                        var entity = _dataContext.ReferralSources.Where(p => p.ReferralSourceId == id).SingleOrDefault();
                        if (entity == null)
                        {
                            return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "Referral source not found. Invalid referral source." }));
                        }

                        entity.FullName  = model.FullName;
                        entity.ShortName = model.ShortName;

                        entity.BedCount = model.BedCount;
                        entity.OperationalICUBedCount         = model.OperationalICUBedCount;
                        entity.CCUBedCount                    = model.CCUBedCount;
                        entity.SkilledNursingBedCount         = model.SkilledNursingBedCount;
                        entity.SICUBedCount                   = model.SICUBedCount;
                        entity.RehabBedCount                  = model.RehabBedCount;
                        entity.ConfirmedBedsCodingICURevCodes = model.ConfirmedBedsCodingICURevCodes;
                        entity.ICUBedCount                    = model.ICUBedCount;
                        entity.LTACHBedCount                  = model.LTACHBedCount;
                        entity.MICUBedCount                   = model.MICUBedCount;
                        entity.NeuroICUBedCount               = model.NeuroICUBedCount;
                        entity.ReferralSourceTypeId           = model.ReferralSourceTypeId;
                        entity.IsApproved = true;
                        _dataContext.SaveChanges();

                        _dataContext.CHGSiteReferralSources.RemoveRange(_dataContext.CHGSiteReferralSources.Where(p => p.ReferralSourceId == id.Value));
                        _dataContext.SaveChanges();

                        foreach (var site in model.Sites.Where(p => p.Selected == true))
                        {
                            CHGSiteReferralSource siteReferralSource = new CHGSiteReferralSource()
                            {
                                CHGSiteId = site.CHGSiteId,

                                ReferralSource = entity
                            };

                            _dataContext.CHGSiteReferralSources.Add(siteReferralSource);
                        }

                        _dataContext.SaveChanges();


                        _dataContext.ReferralSourceElectronicReferralTypes.RemoveRange(_dataContext.ReferralSourceElectronicReferralTypes.Where(p => p.ReferralSourceId == id.Value));
                        _dataContext.SaveChanges();

                        if (model.ElectronicReferralTypes != null)
                        {
                            foreach (var electronicReferralType in model.ElectronicReferralTypes.Where(p => p.Selected == true))
                            {
                                ReferralSourceElectronicReferralType item = new ReferralSourceElectronicReferralType()
                                {
                                    ElectronicReferralTypeId = electronicReferralType.ElectronicReferralTypeId,
                                    ReferralSource           = entity
                                };

                                _dataContext.ReferralSourceElectronicReferralTypes.Add(item);
                            }
                        }

                        _dataContext.SaveChanges();

                        _dataContext.ReferralSourceCommercialPayorTypes.RemoveRange(_dataContext.ReferralSourceCommercialPayorTypes.Where(p => p.ReferralSourceId == id.Value));
                        _dataContext.SaveChanges();


                        if (model.CommercialPayorTypes != null)
                        {
                            foreach (var commercialPayorType in model.CommercialPayorTypes.Where(p => p.Selected == true))
                            {
                                ReferralSourceCommercialPayorType item = new ReferralSourceCommercialPayorType()
                                {
                                    CommercialPayorTypeId = commercialPayorType.CommercialPayorTypeId,
                                    ReferralSource        = entity
                                };

                                _dataContext.ReferralSourceCommercialPayorTypes.Add(item);
                            }
                        }

                        _dataContext.SaveChanges();

                        _dataContext.ReferralSourceManagedMedicarePayorTypes.RemoveRange(_dataContext.ReferralSourceManagedMedicarePayorTypes.Where(p => p.ReferralSourceId == id.Value));
                        _dataContext.SaveChanges();


                        if (model.ManagedMedicarePayorTypes != null)
                        {
                            foreach (var ManagedMedicarePayorType in model.ManagedMedicarePayorTypes.Where(p => p.Selected == true))
                            {
                                ReferralSourceManagedMedicarePayorType item = new ReferralSourceManagedMedicarePayorType()
                                {
                                    ManagedMedicarePayorTypeId = ManagedMedicarePayorType.ManagedMedicarePayorTypeId,
                                    ReferralSource             = entity
                                };

                                _dataContext.ReferralSourceManagedMedicarePayorTypes.Add(item);
                            }
                        }

                        _dataContext.SaveChanges();

                        transaction.Commit();

                        return(Json(new { Status = Constant.RESPONSE_OK, Description = "Referral source saved successfully." }));
                    }
                    else
                    {
                        return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "The referral source with the same full name already exists. Please enter a different name." }));
                    }
                }
            }

            return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "One or more fields failed validation." }));
        }
コード例 #2
0
        public JsonResult Create(ReferralSourceModel model)
        {
            if (!HasContextRole(new string[] { "CRO", "CEO", "DBD", "AVP" }))
            {
                return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "Unauthorized." }));
            }

            if (ModelState.IsValid)
            {
                if (model.Sites == null || model.Sites.Where(p => p.Selected == true).Count() <= 0)
                {
                    return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "Please select at least one site to associate the referral source to." }));
                }

                using (var transaction = _dataContext.Database.BeginTransaction())
                {
                    if (_dataContext.ReferralSources.Where(p => p.FullName == model.FullName && p.Deleted == false).Count() <= 0)
                    {
                        ReferralSource entity = new ReferralSource()
                        {
                            FullName  = model.FullName,
                            ShortName = model.ShortName,
                            BedCount  = model.BedCount,
                            OperationalICUBedCount         = model.OperationalICUBedCount,
                            CCUBedCount                    = model.CCUBedCount,
                            SkilledNursingBedCount         = model.SkilledNursingBedCount,
                            SICUBedCount                   = model.SICUBedCount,
                            RehabBedCount                  = model.RehabBedCount,
                            ConfirmedBedsCodingICURevCodes = model.ConfirmedBedsCodingICURevCodes,
                            ICUBedCount                    = model.ICUBedCount,
                            LTACHBedCount                  = model.LTACHBedCount,
                            MICUBedCount                   = model.MICUBedCount,
                            NeuroICUBedCount               = model.NeuroICUBedCount,
                            ReferralSourceTypeId           = model.ReferralSourceTypeId
                        };

                        _dataContext.ReferralSources.Add(entity);
                        _dataContext.SaveChanges();

                        foreach (var site in model.Sites.Where(p => p.Selected == true))
                        {
                            CHGSiteReferralSource siteReferralSource = new CHGSiteReferralSource()
                            {
                                CHGSiteId = site.CHGSiteId,

                                ReferralSource = entity
                            };

                            _dataContext.CHGSiteReferralSources.Add(siteReferralSource);
                        }

                        _dataContext.SaveChanges();

                        if (model.ElectronicReferralTypes != null)
                        {
                            foreach (var electronicReferralType in model.ElectronicReferralTypes.Where(p => p.Selected == true))
                            {
                                ReferralSourceElectronicReferralType item = new ReferralSourceElectronicReferralType()
                                {
                                    ElectronicReferralTypeId = electronicReferralType.ElectronicReferralTypeId,
                                    ReferralSource           = entity
                                };

                                _dataContext.ReferralSourceElectronicReferralTypes.Add(item);
                            }
                        }

                        _dataContext.SaveChanges();


                        if (model.CommercialPayorTypes != null)
                        {
                            foreach (var commercialPayorType in model.CommercialPayorTypes.Where(p => p.Selected == true))
                            {
                                ReferralSourceCommercialPayorType item = new ReferralSourceCommercialPayorType()
                                {
                                    CommercialPayorTypeId = commercialPayorType.CommercialPayorTypeId,
                                    ReferralSource        = entity
                                };

                                _dataContext.ReferralSourceCommercialPayorTypes.Add(item);
                            }
                        }

                        _dataContext.SaveChanges();


                        if (model.ManagedMedicarePayorTypes != null)
                        {
                            foreach (var ManagedMedicarePayorType in model.ManagedMedicarePayorTypes.Where(p => p.Selected == true))
                            {
                                ReferralSourceManagedMedicarePayorType item = new ReferralSourceManagedMedicarePayorType()
                                {
                                    ManagedMedicarePayorTypeId = ManagedMedicarePayorType.ManagedMedicarePayorTypeId,
                                    ReferralSource             = entity
                                };

                                _dataContext.ReferralSourceManagedMedicarePayorTypes.Add(item);
                            }
                        }



                        _dataContext.SaveChanges();

                        ApprovalProcess(entity.ReferralSourceId);

                        transaction.Commit();

                        return(Json(new { Status = Constant.RESPONSE_OK, Description = "Referral source created successfully." }));
                    }
                    else
                    {
                        return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "The referral source with the same full name already exists. Please enter a different name." }));
                    }
                }
            }

            return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "One or more fields failed validation." }));
        }