public ActionResult Stop(string dfn)
        {
            // *** Show stop tracking page ***

            ActionResult returnResult;

            CreateTrackingEntry model = GetNewModel(TrackingEntryType.Stop, dfn);

            // model.Pregnancy = PregnancyUtilities.GetPregnancy(this.DashboardRepository, dfn, pregIen);

            PregnancyResult results = this.DashboardRepository.Pregnancy.GetCurrentOrMostRecentPregnancy(dfn);

            if (results.Success)
            {
                if (results.Pregnancy != null)
                {
                    string pregIen = results.Pregnancy.Ien;

                    // *** Get the outcome type ***
                    PregnancyOutcomeType outcomeType = PregnancyUtilities.GetPregnancyOutcome(this.DashboardRepository, dfn, pregIen);

                    model.Outcome = PregnancyUtilities.GetOutcomeDetails(this.DashboardRepository, dfn, pregIen, outcomeType);

                    model.Outcome.OutcomeType = outcomeType;

                    model.Outcome.OutcomeDate = results.Pregnancy.DisplayEndDate;
                }
            }



            returnResult = View("~/Views/Track/Stop.cshtml", model);
            //returnResult = View(model);

            return(returnResult);
        }
        public ActionResult Index(string dfn, LabResultType labType, bool pregFilter, string page)
        {
            // *** Create the model ***
            LabModel model = new LabModel();

            // *** Set the patient ***
            model.Patient = this.CurrentPatient;

            // *** Get the page value ***
            int pageVal = this.GetPage(page);

            // *** Create date range dates ***
            DateTime fromDate = DateTime.MinValue;
            DateTime toDate   = DateTime.MinValue;

            // *** Add the filters to the model ***
            model.LabTypeFilter = labType.ToString();

            PregnancyDetails pregDetails = null;

            PregnancyResult pregResult = this.DashboardRepository.Pregnancy.GetCurrentOrMostRecentPregnancy(dfn);

            if (pregResult.Success)
            {
                if (pregResult.Pregnancy != null)
                {
                    pregDetails = pregResult.Pregnancy;
                }
            }

            if (pregDetails != null)
            {
                if (pregDetails.RecordType == Data.Models.Pregnancy.PregnancyRecordType.Current)
                {
                    model.PregnancyFilterDescription = "Current Pregnancy";
                }
                else
                {
                    model.PregnancyFilterDescription = "Most Recent Pregnancy";
                }

                if (pregFilter)
                {
                    // *** Set the date range dates ***
                    fromDate = pregDetails.StartDate;
                    toDate   = pregDetails.EndDate;

                    // *** Create an approximate date/time for fromDate if needed ***
                    if (fromDate == DateTime.MinValue)
                    {
                        if (toDate != DateTime.MinValue)
                        {
                            fromDate = toDate.AddDays(-280);
                        }
                    }

                    model.FilteredByPregnancy = true;
                }

                model.CanFilterByPregnancy = true;
            }
            else
            {
                model.PregnancyFilterDescription = "Current Pregnancy";
                model.CanFilterByPregnancy       = false;
                model.FilteredByPregnancy        = false;
            }

            // *** Get the list of labs ***
            LabItemsResult labsResult = this.DashboardRepository.Labs.GetList(dfn, labType, pregFilter, fromDate, toDate, pageVal, LabItemsPerPage);

            if (!labsResult.Success)
            {
                this.Error(labsResult.Message);
            }
            else
            if (labsResult.Labs == null)
            {
                model.Items = new List <LabItem>();
            }
            else
            {
                // *** Add lab items ***
                model.Items = labsResult.Labs;

                // *** Paging ***
                model.Paging.SetPagingData(LabItemsPerPage, pageVal, labsResult.TotalResults);
                model.Paging.BaseUrl = Url.Action("Index", new { dfn = dfn, labtype = labType, pregFilter = pregFilter, page = "" });
            }

            return(View(model));
        }
        public ActionResult Enroll(string dfn)
        {
            Text4BabyModel model = new Text4BabyModel();

            // *** Set patient ***
            model.Patient = this.CurrentPatient;

            // *** Add values to enrollment ***
            model.Enrollment.FirstName           = model.Patient.FirstName;
            model.Enrollment.MenstrualPeriodDate = this.CurrentPatient.Lmp;
            model.Enrollment.MobileNumber        = this.CurrentPatient.MobilePhone;
            model.Enrollment.ZipCode             = this.CurrentPatient.ZipCode;
            model.Enrollment.EmailAddress        = this.CurrentPatient.Email;

            // *** Get most recent pregnancy ***
            PregnancyResult pregResult = this.DashboardRepository.Pregnancy.GetCurrentOrMostRecentPregnancy(dfn);

            // *** Check Result ***
            if (pregResult.Success)
            {
                if (pregResult.Pregnancy != null)
                {
                    if (pregResult.Pregnancy.RecordType == PregnancyRecordType.Current)
                    {
                        // *** If current preg has EDD, add data to enrollment ***
                        if (pregResult.Pregnancy.EDD != DateTime.MinValue)
                        {
                            model.Enrollment.DueDateKnown     = true;
                            model.Enrollment.PregnancyDueDate = pregResult.Pregnancy.EDD;
                            model.Enrollment.ParticipantType  = Text4BabyParticipantType.Pregnant;
                        }
                    }
                    else
                    {
                        // *** Get the outcome type ***
                        PregnancyOutcomeType outcomeType = PregnancyUtilities.GetPregnancyOutcome(this.DashboardRepository, dfn, pregResult.Pregnancy.Ien);

                        // *** Display most recent pregnancy outcome ***
                        string outcomeMessage = string.Format("This patient's most recent pregnancy outcome: {0}", PregnancyOutcomeUtility.GetDescription(outcomeType));

                        switch (outcomeType)
                        {
                        case PregnancyOutcomeType.FullTermDelivery:
                        case PregnancyOutcomeType.PretermDelivery:
                        case PregnancyOutcomeType.Unknown:
                            model.Enrollment.ParticipantType = Text4BabyParticipantType.NewMom;
                            model.EnrollmentInfo             = outcomeMessage;
                            break;

                        default:
                            model.EnrollmentWarning = outcomeMessage;
                            break;
                        }

                        if (pregResult.Pregnancy.EndDate != DateTime.MinValue)
                        {
                            model.Enrollment.BabyDateOfBirth = pregResult.Pregnancy.EndDate;
                        }
                    }
                }
            }


            return(View(model));
        }
        public ActionResult Summary(string dfn)
        {
            // *** Create new model ***
            PatientSummary model = new PatientSummary();

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

            // *** Check for success ***
            if (!model.Patient.NotFound)
            {
                PregnancyResult pregResult = this.DashboardRepository.Pregnancy.GetCurrentOrMostRecentPregnancy(dfn);

                if (pregResult.Success)
                {
                    if (pregResult.Pregnancy != null)
                    {
                        if (pregResult.Pregnancy.RecordType == PregnancyRecordType.Current)
                        {
                            model.CurrentPregnancy = pregResult.Pregnancy;

                            PregnancyDetails tempDetails = PregnancyUtilities.GetPregnancyObservationData(this.DashboardRepository, dfn, model.CurrentPregnancy.Ien);

                            model.CurrentPregnancy.Lmp            = tempDetails.Lmp;
                            model.CurrentPregnancy.FetusBabyCount = tempDetails.FetusBabyCount;

                            model.CurrentPregnancy.EddBasis   = tempDetails.EddBasis;
                            model.CurrentPregnancy.EddIsFinal = tempDetails.EddIsFinal;
                        }
                        else
                        {
                            // TODO: Show most recent pregnancy ?
                        }

                        // *** Get pregnancy checklist ***
                        UpdateChecklistSummary(model, dfn, pregResult);
                    }
                }

                // *** Get Pregnancy History ***
                PregnancyHistoryResult histResult = this.DashboardRepository.Pregnancy.GetPregnancyHistory(dfn);

                if (histResult.Success)
                {
                    model.PregnancyHistory = histResult.PregnancyHistory;
                }
                else
                {
                    model.PregnancyHistory = new PregnancyHistory();
                    this.Error(histResult.Message);
                }
            }

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

                TempData.Keep(LastPatientListUrl);

                // *** Indicate how to get back here ***
                TempData[ReturnUrl] = Url.Action("Summary", "Patient", new { dfn = dfn });
            }

            return(View("Summary2", model));
        }