private BrokerOperationResult CompleteItem(PregnancyChecklistItem item)
        {
            BrokerOperationResult result = new BrokerOperationResult();

            switch (item.ItemType)
            {
            // *** For education items, create the education item, and complete the checklist item ***
            case DsioChecklistItemType.EducationItem:

                result = ChecklistUtility.CompleteEducationItem(
                    this.DashboardRepository,
                    item.PatientDfn,
                    item.EducationItemIen,
                    item.Ien);

                break;

            // *** For all other items, complete the checklist item ***
            default:

                result = this.DashboardRepository.Checklist.CompletePregnancyItem(item);

                break;
            }

            // *** Update the next checklist date ***
            if (result.Success)
            {
                result = ChecklistUtility.UpdateNextDates(this.DashboardRepository, item.PatientDfn, item.PregnancyIen);
            }

            return(result);
        }
        private ActionResult PostDeletePregItem(PregnancyChecklistIndex model)
        {
            if (string.IsNullOrWhiteSpace(model.SelectedItemIen))
            {
                this.Error("Please select an item to delete");
            }
            else
            {
                BrokerOperationResult result = this.DashboardRepository.Checklist.DeletePregnancyItem(model.Patient.Dfn, model.SelectedItemIen);

                if (!result.Success)
                {
                    this.Error(result.Message);
                }
                else
                {
                    this.Information("The item has been deleted");

                    // *** Update the next checklist date ***
                    BrokerOperationResult updResult = ChecklistUtility.UpdateNextDates(this.DashboardRepository, model.Patient.Dfn, model.Pregnancy.Ien);

                    if (!updResult.Success)
                    {
                        this.Error("Error updating next dates: " + updResult.Message);
                    }
                }
            }

            return(RedirectToAction("PregnancyIndex", new { dfn = model.Patient.Dfn, pregIen = model.Pregnancy.Ien }));
        }
        private ActionResult PostCancel(PregnancyChecklistIndex model)
        {
            PregnancyChecklistItemResult opResult = this.DashboardRepository.Checklist.GetPregnancyItem(model.Patient.Dfn, model.SelectedItemIen);

            if (!opResult.Success)
            {
                this.Error(opResult.Message);
            }
            else
            {
                PregnancyChecklistItem item = opResult.Item;

                BrokerOperationResult updateResult = this.DashboardRepository.Checklist.CancelPregnancyItem(item);

                if (!updateResult.Success)
                {
                    this.Error(updateResult.Message);
                }
                else
                {
                    // *** Update the next checklist date ***
                    BrokerOperationResult result = ChecklistUtility.UpdateNextDates(this.DashboardRepository, item.PatientDfn, item.PregnancyIen);

                    if (!result.Success)
                    {
                        this.Error("Error updating next dates: " + result.Message);
                    }
                }
            }

            return(RedirectToAction("PregnancyIndex", new { dfn = model.Patient.Dfn, pregIen = model.Pregnancy.Ien, page = model.Paging.CurrentPage }));
        }
        public ActionResult PregnancyIndex(string dfn, string pregIen, string page)
        {
            PregnancyChecklistIndex model = new PregnancyChecklistIndex();

            model.Patient = this.CurrentPatient;

            // TODO: In future add ability to view checklist for a specific pregnancy passed in as parameter
            //       Add a pregnancy selection and display
            //PregnancyDetails preg = PregnancyUtilities.GetWorkingPregnancy(this.DashboardRepository, dfn, pregIen);

            PregnancyDetails preg = PregnancyUtilities.GetWorkingPregnancy(this.DashboardRepository, dfn, "");

            if (preg == null)
            {
                model.NoPregnancies = true;
            }
            else
            {
                if ((preg.EDD == DateTime.MinValue) && (preg.EndDate == DateTime.MinValue))
                {
                    model.NoPregnancyDate = true;
                }

                model.Pregnancy = preg;

                //PregnancyChecklistItemsResult result = this.DashboardRepository.Checklist.GetPregnancyItems(dfn, preg.Ien, "");

                //if (!result.Success)
                //    this.Error(result.Message);
                //else
                //{
                //    model.Items = new PregnancyChecklistItemList();
                //    model.Items.AddRange(result.Items);

                //    model.Items.AddPregnancyDates(preg.EDD, preg.EndDate);

                //    model.Items.Sort(delegate(PregnancyChecklistItem x, PregnancyChecklistItem y)
                //    {
                //        return x.DueDate.CompareTo(y.DueDate);
                //    });
                //}

                PregnancyChecklistItemsResult result = ChecklistUtility.GetSortedPregnancyChecklist(this.DashboardRepository, dfn, preg, DsioChecklistCompletionStatus.Unknown);

                if (!result.Success)
                {
                    this.Error(result.Message);
                }
                else
                {
                    model.Items.AddRange(result.Items);
                }
            }

            // TODO: Paging...

            return(View(model));
        }
        public ActionResult Complete(PatientEducationIndex model)
        {
            //PatientEducationItem patItem = new PatientEducationItem()
            //{
            //    PatientDfn = model.Patient.Dfn,
            //    EducationItemIen = model.SelectedEducationIen,
            //    CompletedOn = DateTime.Now
            //};

            //IenResult saveResult = this.DashboardRepository.Education.SavePatientItem(patItem);

            //if (!saveResult.Success)
            //    this.Error(saveResult.Message);
            //else
            //{
            //    PregnancyChecklistItemsResult result = this.DashboardRepository.Checklist.GetPregnancyItems(model.Patient.Dfn, "", model.SelectedChecklistIen);

            //    if (!result.Success)
            //        this.Error(result.Message);
            //    else
            //    {
            //        if (result.Items != null)
            //            if (result.Items.Count > 0)
            //            {
            //                PregnancyChecklistItem checkItem = result.Items[0];

            //                checkItem.CompletionStatus = DsioChecklistCompletionStatus.Complete;
            //                checkItem.CompletionLink = saveResult.Ien;

            //                IenResult ienResult = this.DashboardRepository.Checklist.SavePregnancyItem(checkItem);

            //                if (!saveResult.Success)
            //                    this.Error(saveResult.Message);

            //                this.Information("Education item completed");
            //            }
            //    }
            //}

            BrokerOperationResult result = ChecklistUtility.CompleteEducationItem(
                this.DashboardRepository,
                model.Patient.Dfn,
                model.SelectedEducationIen,
                model.SelectedChecklistIen);

            if (result.Success)
            {
                this.Information(result.Message);
            }
            else
            {
                this.Error(result.Message);
            }

            return(RedirectToAction("PatientIndex", new { dfn = model.Patient.Dfn }));
        }
        private ActionResult PostAddDefault(PregnancyChecklistIndex model)
        {
            BrokerOperationResult result = this.DashboardRepository.Checklist.AddDefaultPregnancyItems(model.Patient.Dfn, model.Pregnancy.Ien);

            if (!result.Success)
            {
                this.Error(result.Message);
            }
            else
            {
                // *** Update the next checklist date ***
                BrokerOperationResult updResult = ChecklistUtility.UpdateNextDates(this.DashboardRepository, model.Patient.Dfn, model.Pregnancy.Ien);

                if (!updResult.Success)
                {
                    this.Error("Error updating next dates: " + updResult.Message);
                }

                this.Information("The default items have been added to the patient's checklist");
            }

            return(RedirectToAction("PregnancyIndex", new { dfn = model.Patient.Dfn, pregIen = model.Pregnancy.Ien, page = model.Paging.CurrentPage }));
        }
        public ActionResult PregnancyAddEdit(PregnancyChecklistAddEdit model)
        {
            ActionResult result;

            bool ok = false;

            //if (model.Item.ItemType == DsioChecklistItemType.EducationItem)
            //    model.Item.Link = model.EducationItemLink;

            if (model.Item.IsValid())
            {
                model.SetDueVals();

                IenResult saveResult = this.DashboardRepository.Checklist.SavePregnancyItem(model.Item);

                if (!saveResult.Success)
                {
                    this.Error(saveResult.Message);
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(model.Item.Ien))
                    {
                        this.Information("Checklist item created successfully");
                    }
                    else
                    {
                        this.Information("Checklist item updated successfully");
                    }

                    // *** Update the next checklist date ***
                    BrokerOperationResult updResult = ChecklistUtility.UpdateNextDates(this.DashboardRepository, model.Patient.Dfn, model.Item.PregnancyIen);

                    if (!updResult.Success)
                    {
                        this.Error("Error updating next dates: " + updResult.Message);
                    }

                    ok = true;
                }
            }
            else
            {
                this.Error(model.Item.ValidationMessage);
            }

            if (ok)
            {
                result = RedirectToAction("PregnancyIndex", new { dfn = model.Patient.Dfn, pregIen = model.Item.PregnancyIen });
            }
            else
            {
                this.CurrentPatientDfn = model.Patient.Dfn;
                model.Patient          = this.CurrentPatient;

                model.EducationItemSelection = this.DashboardRepository.Education.GetItemSelection();

                result = View(model);
            }

            return(result);
        }