public ActionResult AddEdit(string ien)
        {
            EducationItemAddEditModel model = new EducationItemAddEditModel();

            if (!string.IsNullOrWhiteSpace(ien))
            {
                EducationItemsResult result = this.DashboardRepository.Education.GetEducationItems(ien, "", EducationItemType.Unknown, 0, 0, EducationItemSort.Type);

                if (!result.Success)
                {
                    this.Error(result.Message);
                }
                else
                if (result.EducationItems != null)
                {
                    if (result.EducationItems.Count > 0)
                    {
                        model.Item = result.EducationItems[0];
                    }
                }
            }

            model.ItemTypeSelection = GetItemTypeSelection();

            // *** Load category selection box ***
            model.CategorySelection = GetCategorySelection();

            //model.CodeSelection = GetCodeSelection();

            return(View(model));
        }
        public ActionResult PatientSelect(string dfn)
        {
            PatientEducationSelect model = new PatientEducationSelect();

            model.Patient = this.CurrentPatient;

            EducationItemsResult result = this.DashboardRepository.Education.GetEducationItems("", "", EducationItemType.Unknown, 0, 0, EducationItemSort.Type);

            if (!result.Success)
            {
                this.Error(result.Message);
            }
            else if (result.EducationItems != null)
            {
                if (result.EducationItems.Count > 0)
                {
                    result.EducationItems.Sort(delegate(EducationItem x, EducationItem y)
                    {
                        int returnVal = 0;

                        if (x.Category == y.Category)
                        {
                            returnVal = x.Description.CompareTo(y.Description);
                        }
                        else
                        {
                            returnVal = x.Category.CompareTo(y.Category);
                        }

                        return(returnVal);
                    });
                    string currentCategory = "";
                    foreach (EducationItem item in result.EducationItems)
                    {
                        if (item.Category != currentCategory)
                        {
                            PatientEducationSelectItemRow catRow = new PatientEducationSelectItemRow()
                            {
                                CategoryRow = true, Category = item.Category
                            };
                            model.AddRow(catRow);
                            currentCategory = item.Category;
                        }

                        PatientEducationSelectItemRow itemRow = new PatientEducationSelectItemRow()
                        {
                            Ien                 = item.Ien,
                            ItemType            = item.ItemType,
                            ItemTypeDescription = item.ItemTypeDescription,
                            Description         = item.Description,
                            Category            = item.Category
                        };

                        model.AddRow(itemRow);
                    }
                }
            }

            return(View(model));
        }
        private void DeleteAll()
        {
            EducationItemsResult result = this.DashboardRepository.Education.GetEducationItems("", "", EducationItemType.Unknown, -1, -1, EducationItemSort.Category);

            if (result.Success)
            {
                BrokerOperationResult delResult = null;

                foreach (EducationItem item in result.EducationItems)
                {
                    delResult = this.DashboardRepository.Education.DeleteEducationItem(item.Ien);

                    if (!delResult.Success)
                    {
                        break;
                    }
                }

                if (delResult != null)
                {
                    if (!delResult.Success)
                    {
                        this.Error(delResult.Message);
                    }
                }
                else
                {
                    this.Information("All items deleted");
                }
            }
        }
        public ActionResult Index(string page, string sort)
        {
            EducationItemList model = new EducationItemList();

            int pageVal = this.GetPage(page);

            EducationItemSort sortVal = EducationItemSort.Type;

            Enum.TryParse <EducationItemSort>(sort, out sortVal);

            model.Sort = sortVal;

            EducationItemsResult result = this.DashboardRepository.Education.GetEducationItems("", "", EducationItemType.Unknown, pageVal, EducationItemsPerPage, sortVal);

            if (!result.Success)
            {
                this.Error(result.Message);
            }
            else
            {
                if (result.EducationItems.Count == 0)
                {
                    result = this.DashboardRepository.Education.LoadDefaults();

                    if (result.Success)
                    {
                        result = this.DashboardRepository.Education.GetEducationItems("", "", EducationItemType.Unknown, pageVal, EducationItemsPerPage, sortVal);
                    }
                }

                model.EducationItems = result.EducationItems;

                model.Paging.SetPagingData(EducationItemsPerPage, pageVal, result.TotalResults);

                model.Paging.BaseUrl = Url.Action("Index", new { page = "", sort = (int)sortVal });
            }

            return(View(model));
        }
        private List <string> GetCategorySelection()
        {
            // *** Get category selection list ***

            List <string> returnList = new List <string>();

            // *** Get all ed items ***
            EducationItemsResult result = this.DashboardRepository.Education.GetEducationItems("", "", EducationItemType.Unknown, -1, -1, EducationItemSort.Category);

            // *** Add initially shown item ***
            returnList.Add("(Select)");

            // *** Check if successful ***
            if (!result.Success)
            {
                this.Error(result.Message);
            }
            else // *** Add items ***
            if (result.EducationItems != null)
            {
                foreach (var item in result.EducationItems)
                {
                    if (!string.IsNullOrWhiteSpace(item.Category))
                    {
                        if (!returnList.Contains(item.Category))
                        {
                            returnList.Add(item.Category);
                        }
                    }
                }
            }

            // *** Use this to enter new ***
            returnList.Add("(Enter New)");

            return(returnList);
        }
        private void GetMergedList(PatientEducationIndex model, PregnancyDetails preg)
        {
            PregnancyChecklistItemsResult result = this.DashboardRepository.Checklist.GetPregnancyItems(model.Patient.Dfn, preg.Ien, "");

            if (!result.Success)
            {
                this.Error(result.Message);
            }
            else
            {
                // *** Create view items ***

                if (result.Items != null)
                {
                    foreach (PregnancyChecklistItem item in result.Items)
                    {
                        if (item.ItemType == DsioChecklistItemType.EducationItem)
                        {
                            PatientEducationChecklistItem newItem = new PatientEducationChecklistItem();
                            newItem.PregnancyChecklistItem = item;
                            model.ItemList.Add(newItem);
                        }
                    }
                }

                // *** Get patient education items ***

                PatientEducationItemsResult edResult = this.DashboardRepository.Education.GetPatientItems(
                    model.Patient.Dfn,
                    "",
                    DateTime.MinValue,
                    DateTime.MinValue,
                    EducationItemType.Unknown,
                    1,
                    1000
                    );

                if (!edResult.Success)
                {
                    this.Error(edResult.Message);
                }
                else
                {
                    Dictionary <string, PatientEducationItem> patEdItems = new Dictionary <string, PatientEducationItem>();

                    // *** Place patient education items in dictionary for lookup ***

                    if (edResult.Items != null)
                    {
                        foreach (PatientEducationItem patEdItem in edResult.Items)
                        {
                            patEdItems.Add(patEdItem.Ien, patEdItem);
                        }
                    }

                    // *** Go through checklist to find links to patient education ***

                    foreach (PatientEducationChecklistItem finalItem in model.ItemList)
                    {
                        if (finalItem.PregnancyChecklistItem != null)
                        {
                            if (finalItem.PregnancyChecklistItem.CompletionStatus == DsioChecklistCompletionStatus.Complete)
                            {
                                if (!string.IsNullOrWhiteSpace(finalItem.PregnancyChecklistItem.CompletionLink))
                                {
                                    if (patEdItems.ContainsKey(finalItem.PregnancyChecklistItem.CompletionLink))
                                    {
                                        // *** If found add to final ***
                                        finalItem.PatientEducationItem = patEdItems[finalItem.PregnancyChecklistItem.CompletionLink];

                                        // *** Remove since already added ***
                                        patEdItems.Remove(finalItem.PregnancyChecklistItem.CompletionLink);
                                    }
                                }
                            }
                        }
                    }

                    // *** Now that we've added all items that are linked, add remainder ***
                    foreach (PatientEducationItem patEdItem in patEdItems.Values)
                    {
                        PatientEducationChecklistItem newItem = new PatientEducationChecklistItem();
                        newItem.PatientEducationItem = patEdItem;
                        model.ItemList.Add(newItem);
                    }

                    // *** Finally get education items linked by a checklist but incomplete ***
                    foreach (PatientEducationChecklistItem finalItem in model.ItemList)
                    {
                        if (finalItem.PregnancyChecklistItem != null)
                        {
                            if (finalItem.PregnancyChecklistItem.CompletionStatus != DsioChecklistCompletionStatus.Complete)
                            {
                                if (!string.IsNullOrWhiteSpace(finalItem.Link))
                                {
                                    EducationItemsResult edItemsResult = this.DashboardRepository.Education.GetEducationItems(finalItem.Link, "", EducationItemType.Unknown, 0, 0, EducationItemSort.Type);

                                    if (edItemsResult.Success)
                                    {
                                        if (edItemsResult.EducationItems != null)
                                        {
                                            if (edItemsResult.EducationItems.Count > 0)
                                            {
                                                finalItem.EducationItem = edItemsResult.EducationItems[0];
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                model.ItemList.AddPregnancyDates(preg.EDD, preg.EndDate);

                model.ItemList.Sort(delegate(PatientEducationChecklistItem x, PatientEducationChecklistItem y)
                {
                    return(x.CompareDate.CompareTo(y.CompareDate));
                });
            }
        }