public ActionResult CreateNote(string dfn)
        {
            // *** Create a new dashboard note ***

            TiuNoteModel model = new TiuNoteModel();

            model.Patient = this.CurrentPatient;

            // *** Get a list of pregnancies ***
            List <PregnancyDetails> pregList = PregnancyUtilities.GetPregnancies(this.DashboardRepository, dfn);

            // *** Get pregnancy selection dictionary ***
            model.Pregnancies = PregnancyUtilities.GetPregnanciesSelection(pregList, false);

            // *** Default to current pregnancy ***
            foreach (PregnancyDetails preg in pregList)
            {
                if (preg.RecordType == PregnancyRecordType.Current)
                {
                    model.Note.PregnancyIen = preg.Ien;
                }
            }

            // *** Set return url ***
            if (TempData.ContainsKey(ReturnUrl))
            {
                model.ReturnUrl     = TempData[ReturnUrl].ToString();
                TempData[ReturnUrl] = TempData[ReturnUrl];
            }

            return(View(model));
        }
        public ActionResult CreateAddendum(TiuNoteModel model)
        {
            // *** Post data ***

            ActionResult returnResult;

            bool needPatDemo = false;

            if (ModelState.IsValid)
            {
                BrokerOperationResult result = this.DashboardRepository.Notes.CreateAddendum(model.Note.Ien, model.Note.NoteText, model.Note.Subject, new Dictionary <string, string>());

                if (!result.Success)
                {
                    this.Error(result.Message);

                    returnResult = View(model);

                    needPatDemo = true;
                }
                else
                {
                    this.Information("Addendum Created");
                    if (TempData.ContainsKey(ReturnUrl))
                    {
                        returnResult = Redirect(TempData.Peek(ReturnUrl).ToString());
                    }
                    else
                    {
                        returnResult = RedirectToAction("Index", new { dfn = model.Patient.Dfn, filter = model.Note.PregnancyIen, page = "1" });
                    }

                    needPatDemo = false;
                }
            }
            else
            {
                this.Error("Please enter note details");
                returnResult = View(model);
                needPatDemo  = true;
            }

            if (needPatDemo)
            {
                this.CurrentPatientDfn = model.Patient.Dfn;
                model.Patient          = this.CurrentPatient;
            }

            // *** Set return url ***
            if (TempData.ContainsKey(ReturnUrl))
            {
                model.ReturnUrl     = TempData[ReturnUrl].ToString();
                TempData[ReturnUrl] = TempData[ReturnUrl];
            }

            return(returnResult);
        }
        public ActionResult CreateNote(TiuNoteModel model)
        {
            // *** Post data ***

            ActionResult returnResult;

            bool needPatDemo = false;

            if (ModelState.IsValid)
            {
                BrokerOperationResult result = this.DashboardRepository.Notes.CreateNote(TiuNoteTitle.MccDashboardNote, model.Patient.Dfn, model.Note.NoteText, model.Note.Subject, new Dictionary <string, string>(), model.Note.PregnancyIen);

                if (!result.Success)
                {
                    this.Error(result.Message);

                    returnResult = View(model);

                    needPatDemo = true;
                }
                else
                {
                    this.Information("Dashboard Note Created");
                    returnResult = RedirectToAction("Index", new { dfn = model.Patient.Dfn, filter = model.Note.PregnancyIen, page = "1" });
                    needPatDemo  = false;
                }
            }
            else
            {
                this.Error("Please enter note details");
                returnResult = View(model);
                needPatDemo  = true;
            }

            // *** Get patient demographics ***
            if (needPatDemo)
            {
                this.CurrentPatientDfn = model.Patient.Dfn;
                model.Patient          = this.CurrentPatient;

                // *** Pregnancies are needed also ***
                // *** Get a list of pregnancies ***
                List <PregnancyDetails> pregList = PregnancyUtilities.GetPregnancies(this.DashboardRepository, this.CurrentPatientDfn);

                // *** Get pregnancy selection dictionary ***
                model.Pregnancies = PregnancyUtilities.GetPregnanciesSelection(pregList, false);
            }

            // *** Set return url ***
            if (TempData.ContainsKey(ReturnUrl))
            {
                model.ReturnUrl     = TempData[ReturnUrl].ToString();
                TempData[ReturnUrl] = TempData[ReturnUrl];
            }

            return(returnResult);
        }
        public ActionResult Edit(string dfn, string ien)
        {
            // *** Create a new dashboard note ***

            TiuNoteModel model = new TiuNoteModel();

            model.Patient = this.CurrentPatient;

            if (!model.Patient.NotFound)
            {
                TiuNoteResult headerResult = this.DashboardRepository.Notes.GetNoteHeader(dfn, ien);

                if (headerResult.Success)
                {
                    model.Note = headerResult.Note;
                    TiuNoteResult noteResult = this.DashboardRepository.Notes.GetNoteBody(ien);

                    if (!noteResult.Success)
                    {
                        this.Error(noteResult.Message);
                    }
                    else
                    {
                        model.Note.NoteText = noteResult.Note.NoteText;
                    }
                }
                else
                {
                    this.Error(headerResult.Message);
                }
            }

            // *** Get pregnancies ***
            model.Pregnancies = PregnancyUtilities.GetPregnanciesSelection(this.DashboardRepository, dfn);

            // *** Set return url ***
            if (TempData.ContainsKey(ReturnUrl))
            {
                model.ReturnUrl     = TempData[ReturnUrl].ToString();
                TempData[ReturnUrl] = TempData[ReturnUrl];
            }

            return(View("CreateNote", model));
        }
        public ActionResult CreateAddendum(string dfn, string ien)
        {
            // *** Create addendum to existing dashboard note ***

            TiuNoteModel model = new TiuNoteModel();

            model.Patient = this.CurrentPatient;

            model.Note.Ien = ien;

            // *** Set return url ***
            if (TempData.ContainsKey(ReturnUrl))
            {
                model.ReturnUrl     = TempData[ReturnUrl].ToString();
                TempData[ReturnUrl] = TempData[ReturnUrl];
            }

            return(View(model));
        }
        public ActionResult ProgressNote(string dfn, string ien)
        {
            // *** Show last progress note ***

            ActionResult returnValue;
            TiuNoteModel model = new TiuNoteModel();

            // *** Get patient demographics ***
            model.Patient = this.CurrentPatient;

            // *** Check for success ***
            if (!model.Patient.NotFound)
            {
                // *** Get latest progress note ***
                //TiuNoteResult noteResult = this.DashboardRepository.Notes.GetProgressNote(ien);
                TiuNoteResult noteResult = this.DashboardRepository.Notes.GetNote(ien);

                if (noteResult.Success)
                {
                    model.Note = noteResult.Note;
                }
                else
                {
                    model.Note.NoteText = "Not Found";
                }
            }

            // *** Set return url ***
            if (TempData.ContainsKey(ReturnUrl))
            {
                model.ReturnUrl     = TempData[ReturnUrl].ToString();
                TempData[ReturnUrl] = TempData[ReturnUrl];
            }

            // *** Set return url so next page knows how to get back ***
            //TempData[ReturnUrl] = Url.Action("Details", "FlaggedPatients", new {@dfn=dfn });

            returnValue = View(model);

            return(returnValue);
        }
        public ActionResult Details(string dfn, string ien)
        {
            // *** Show details of a dashboard note ***

            TiuNoteModel model = new TiuNoteModel();

            model.Patient = this.CurrentPatient;

            if (!model.Patient.NotFound)
            {
                TiuNoteResult headerResult = this.DashboardRepository.Notes.GetNoteHeader(dfn, ien);

                if (headerResult.Success)
                {
                    if (headerResult.Note == null)
                    {
                        this.Error("Could not retrieve note data");
                    }
                    else
                    {
                        model.Note = headerResult.Note;

                        TiuNoteResult noteResult = this.DashboardRepository.Notes.GetNote(ien);

                        if (!noteResult.Success)
                        {
                            this.Error(noteResult.Message);
                        }
                        else
                        {
                            model.Note.NoteText = noteResult.Note.NoteText;
                        }
                    }
                }
                else
                {
                    this.Error(headerResult.Message);
                }
            }

            // *** Get pregnancies ***
            List <PregnancyDetails> pregList = PregnancyUtilities.GetPregnancies(this.DashboardRepository, dfn);

            // *** Get pregnancy description ***
            if (!string.IsNullOrWhiteSpace(model.Note.PregnancyIen))
            {
                foreach (PregnancyDetails preg in pregList)
                {
                    if (preg.Ien == model.Note.PregnancyIen)
                    {
                        model.PregnancyDescription = preg.Description;
                    }
                }
            }

            // *** Set default description ***
            if (string.IsNullOrWhiteSpace(model.PregnancyDescription))
            {
                model.PregnancyDescription = PregnancyUtilities.NotAssociatedMessage;
            }

            // *** Set return url ***
            if (TempData.ContainsKey(ReturnUrl))
            {
                model.ReturnUrl     = TempData[ReturnUrl].ToString();
                TempData[ReturnUrl] = TempData[ReturnUrl];
            }

            return(View(model));
        }