public async Task <ActionResult> DeleteConfirmed(int id)
        {
            ReferralSourceModel referralSourceModel = await db.ReferralSourceModel.FindAsync(id);

            db.ReferralSourceModel.Remove(referralSourceModel);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit([Bind(Include = "ReferralSourceId,ReferralSource")] ReferralSourceModel referralSourceModel)
        {
            if (ModelState.IsValid)
            {
                db.Entry(referralSourceModel).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(referralSourceModel));
        }
        public async Task <ActionResult> Create([Bind(Include = "ReferralSourceId,ReferralSource")] ReferralSourceModel referralSourceModel)
        {
            if (ModelState.IsValid)
            {
                db.ReferralSourceModel.Add(referralSourceModel);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(referralSourceModel));
        }
        // GET: ReferralSourceModels/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ReferralSourceModel referralSourceModel = await db.ReferralSourceModel.FindAsync(id);

            if (referralSourceModel == null)
            {
                return(HttpNotFound());
            }
            return(View(referralSourceModel));
        }
        /// <summary>
        /// To the view model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public static ReferralSourceViewModel ToViewModel(this ReferralSourceModel model)
        {
            if (model == null)
            {
                return(null);
            }

            var entity = new ReferralSourceViewModel
            {
                ReferralSourceID = model.ReferralSourceID,
                ReferralSource   = model.ReferralSource
            };

            return(entity);
        }
        /// <summary>
        /// To the model.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public static ReferralSourceModel ToModel(this ReferralSourceViewModel entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var model = new ReferralSourceModel
            {
                ReferralSourceID = entity.ReferralSourceID,
                ReferralSource   = entity.ReferralSource
            };

            return(model);
        }
Ejemplo n.º 7
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." }));
        }
Ejemplo n.º 8
0
        public JsonResult DetailEntity(long?id)
        {
            if (id == null || id == 0)
            {
                return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "Invalid ID Specification." }, JsonRequestBehavior.AllowGet));
            }

            if (!HasContextRole(new string[] { "CRO", "CEO", "DBD", "AVP" }))
            {
                return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "Unauthorized." }, JsonRequestBehavior.AllowGet));
            }

            var query = (from c in _dataContext.ReferralSources.Include("ReferralSourceType") where c.Deleted == false select c);

            var query2 = (from c in _dataContext.CHGSiteReferralSources join d in query on c.ReferralSourceId equals d.ReferralSourceId where c.Deleted == false && c.Deleted == false select new { ReferralSource = d, CHGSite = c.CHGSite }).ToList();

            var results = (from c in query2 join d in _dataContext.GetUserSites(_dataContext.UserId.Value) on c.CHGSite.CHGSiteId equals d.CHGSiteId where c.ReferralSource.ReferralSourceId == id select c.ReferralSource).ToList();

            if (results.Count() <= 0)
            {
                return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "Unauthorized." }, JsonRequestBehavior.AllowGet));
            }

            var entity = _dataContext.ReferralSources.Where(p => p.ReferralSourceId == id && p.Deleted == false).SingleOrDefault();

            if (entity == null)
            {
                return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "Referral source not found. Invalid referral source." }));
            }

            ReferralSourceModel model = new ReferralSourceModel()
            {
                FullName  = entity.FullName,
                ShortName = entity.ShortName,
                BedCount  = entity.BedCount,
                OperationalICUBedCount         = entity.OperationalICUBedCount,
                CCUBedCount                    = entity.CCUBedCount,
                SkilledNursingBedCount         = entity.SkilledNursingBedCount,
                SICUBedCount                   = entity.SICUBedCount,
                RehabBedCount                  = entity.RehabBedCount,
                ConfirmedBedsCodingICURevCodes = entity.ConfirmedBedsCodingICURevCodes,
                ICUBedCount                    = entity.ICUBedCount,
                LTACHBedCount                  = entity.LTACHBedCount,
                MICUBedCount                   = entity.MICUBedCount,
                NeuroICUBedCount               = entity.NeuroICUBedCount,
                ReferralSourceTypeId           = entity.ReferralSourceTypeId,
                ReferralSourceId               = entity.ReferralSourceId,
                ReferralSourceTypeName         = entity.ReferralSourceType.Name,
                IsApproved = entity.IsApproved,
                Sites      = _dataContext.CHGSiteReferralSources.Where(p => p.ReferralSourceId == id.Value).Select(p => new ReferralSourceCHGSiteModel()
                {
                    CHGSiteId = p.CHGSiteId,
                    Selected  = true
                }).ToList(),
                ElectronicReferralTypes = _dataContext.ReferralSourceElectronicReferralTypes.Where(p => p.ReferralSourceId == id.Value).Select(p => new ReferralSourceElectronicReferralTypeModel()
                {
                    ElectronicReferralTypeId = p.ElectronicReferralTypeId,
                    Selected = true
                }).ToList(),
                CommercialPayorTypes = _dataContext.ReferralSourceCommercialPayorTypes.Where(p => p.ReferralSourceId == id.Value).Select(p => new ReferralSourceCommercialPayorTypeModel()
                {
                    CommercialPayorTypeId = p.CommercialPayorTypeId,
                    Selected = true
                }).ToList(),
                ManagedMedicarePayorTypes = _dataContext.ReferralSourceManagedMedicarePayorTypes.Where(p => p.ReferralSourceId == id.Value).Select(p => new ReferralSourceManagedMedicarePayorTypeModel()
                {
                    ManagedMedicarePayorTypeId = p.ManagedMedicarePayorTypeId,
                    Selected = true
                }).ToList()
            };


            var task = (from t in _dataContext.UserTasks join p in _dataContext.UserTaskParameters on t.UserTaskId equals p.UserTaskId where t.Deleted == false && p.Deleted == false && p.Key == "REFERRAL_SOURCE_ID" && t.UserId == _dataContext.UserId.Value && t.Status == "Created" && p.Value == entity.ReferralSourceId.ToString() select t).Distinct().Take(1).SingleOrDefault();


            return(Json(new { Status = Constant.RESPONSE_OK, Data = model, PendingTask = task }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 9
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." }));
        }