public ActionResult GetStudyByFormID(string FormID)
        {
            //Gets the StudyID that relates to a Form Barcode ID

            CRUDStudySamples cm      = new CRUDStudySamples();
            string           StudyID = cm.GetStudyByFormID(FormID);

            //return Json(StudyID, JsonRequestBehavior.AllowGet);
            return(Json(StudyID));
        }
 public ActionResult AddUrineSample_GU(StudySamples smodel) //In StudySampleHandling.cs
 {
     try
     {
         if (ModelState.IsValid)
         {
             CRUDStudySamples cm = new CRUDStudySamples();
             if (cm.AddUrineSamples(smodel))
             {
                 ViewBag.Message = "Urine Sample Processing Update completed!";
                 //Amend:
                 //ViewBag.Message = xml;  //in test mode, return the xml string to view it
                 ModelState.Clear();
             }
         }
         return(View());
     }
     catch (Exception ex)
     {
         return(View("Error", new HandleErrorInfo(ex, "StudyPersonSample", "AddUrineSample_GU"))); //create error view
     }
 }
        public ActionResult ProcessSample(StudySamples smodel)
        {
            if (ModelState.IsValid)
            {
                CRUDStudySamples cm = new CRUDStudySamples();
                int status          = cm.ProcessSample(smodel);

                if (status == 0)
                {
                    ViewBag.Message = "Sample processing information was not saved. Please try again. If the problem persists contact the data team.";
                    return(null);
                }
                else if (status == 999)
                {
                    if (smodel.Message != "")
                    {
                        ViewBag.Message = smodel.Message;
                    }
                    else
                    {
                        ViewBag.Message = "The system was not able to save your data. Please contact the data team.";
                    }
                    ViewBag.SampleProcessing = "1";
                    ViewBag.PSCID            = smodel.PSCID;
                    ViewBag.StudyName        = smodel.StudyName;
                    ViewBag.StudyID          = smodel.StudyID;
                    return(View(smodel.ViewName));
                }
                else
                {
                    //TODO: smodel.StudyName is not populating - need to bring this over from the model!
                    ViewBag.Message = "The " + smodel.SampleSetType + " sample processing data for " + smodel.PSCID + " on the " + smodel.StudyName + " study has been saved.";
                }

                string wasRedirected;
                wasRedirected = "True";
                //return View ("Index"); //Return to the /StudyPersonSample/Index view so further samples can be added.
                return(RedirectToAction("Index", new { Message = ViewBag.Message, wasRedirected = wasRedirected }));
                //return RedirectToAction("actionresult name", new { PSCID = PSCID, StudyID = StudyID, StudyName = StudyName, wasRedirected = wasRedirected});
            }

            ViewBag.SampleProcessing = "1";
            ViewBag.PSCID            = smodel.PSCID;
            ViewBag.StudyName        = smodel.StudyName;
            ViewBag.StudyID          = smodel.StudyID;

            if (smodel.CollectedSampleID > 0)
            {
                ViewBag.SampleID = smodel.CollectedSampleID;
            }
            // This is the collective bloods sample ID to which the collected samples are related and need to be linked - not needed for Growing Up at the processing stage but this may be so in another context
            if (smodel.EDTASampleID > 0)
            {
                ViewBag.EDTASampleID = smodel.EDTASampleID;
            }

            if (smodel.EDTAProcessed > 0)
            {
                ViewBag.EDTAProcessed = smodel.EDTAProcessed;
            }

            if (smodel.GelSampleID > 0)
            {
                ViewBag.GelSampleID = smodel.GelSampleID;
            }

            if (smodel.GelSerumProcessed > 0)
            {
                ViewBag.GelSerumProcessed = smodel.GelSerumProcessed;
            }

            if (smodel.LitHepSampleID > 0)
            {
                ViewBag.LitHepSampleID = smodel.LitHepSampleID;
            }

            if (smodel.LitHepProcessed > 0)
            {
                ViewBag.LitHepProcessed = smodel.LitHepProcessed;
            }

            if (smodel.OxalateSampleID > 0)
            {
                ViewBag.OxalateSampleID = smodel.OxalateSampleID;
            }

            if (smodel.OxalateProcessed > 0)
            {
                ViewBag.OxalateProcessed = smodel.OxalateProcessed;
            }
            if (smodel.BuccalSampleID > 0)
            {
                ViewBag.BuccalSampleID = smodel.BuccalSampleID;
            }

            if (smodel.BuccalProcessed > 0)
            {
                ViewBag.BuccalProcessed = smodel.BuccalProcessed;
            }

            return(View(smodel.ViewName));
        }
        //public ActionResult CollectSample(CollectSample smodel)  //will need to change this to accept xml construct if it can be done in jQuery
        public ActionResult CollectSample(StudySamples smodel)
        {
            if (ModelState.IsValid)
            {
                CRUDStudySamples cm = new CRUDStudySamples();

                //int status;
                //int sampleID;
                int status = cm.CollectSample(smodel);     //WILL NEED TO BE XML IF IT WORKS!  Try XMLWriter
                                                           //sampleID = cm.CollectSample(smodel.result[2]);
                                                           //status = cm.CollectSample(smodel.result[1]);
                                                           //sampleID = cm.CollectSample(smodel.result[2]);
                if (status == 0)
                {
                    ViewBag.Message = "This sample is already collected and aliquoted. Please add another sample to action.";
                    return(View(smodel.ViewName));
                }
                else if (status == 999)
                {
                    ViewBag.ViewName         = smodel.ViewName;
                    ViewBag.SampleProcessing = "0"; //THIS ENSURES THAT ONLY THE SAMPLE COLLECTION CONTROLS AND HTML DISPLAY
                    ViewBag.PSCID            = smodel.PSCID;
                    ViewBag.StudyName        = smodel.StudyName;
                    ViewBag.StudyID          = smodel.StudyID;
                    //ViewBag.UrineCollected = smodel.UrineCollected;
                    //ViewBag.DateOfCollection = smodel.DateOfCollection;
                    //ViewBag.TimeOfCollection = smodel.TimeOfCollection;
                    ViewBag.Message = "Collection details for this sample could not be saved at this time. Please contact your system's administrator";
                    return(View(smodel.ViewName));
                }
                else
                {
                    ViewBag.SampleProcessing = "1";  //THIS ENSURES THAT ONLY SAMPLE PROCESSING CONTROLS AND HTML DISPLAYS
                    ViewBag.PSCID            = smodel.PSCID;
                    ViewBag.StudyID          = smodel.StudyID;
                    ViewBag.StudyName        = smodel.StudyName;
                    ViewBag.ViewName         = smodel.ViewName;
                    //if ((smodel.SampleType == "Urine") || (smodel.SampleType == "Buccal"))

                    //TODO: MIGHT NEED TO DO A CALL TO SAMPLES PROCESSED PROCEDURE TO GET SAMPLES PROCESSED AS AN INTERMEDIARY VIEW BETWEEEN COLLECTION AND PROCESSING - FOR VERSION (2)???
                    if (smodel.SampleSetType == "Bloods")
                    {
                        if (smodel.EDTASampleID > 0)
                        {
                            smodel.EDTAProcessed = 1;
                        }
                        else
                        {
                            smodel.EDTAProcessed = 0;
                        }
                        if (smodel.GelSampleID > 0)
                        {
                            smodel.GelSerumProcessed = 1;
                        }
                        else
                        {
                            smodel.GelSerumProcessed = 0;
                        }
                        if (smodel.LitHepSampleID > 0)
                        {
                            smodel.LitHepProcessed = 1;
                        }
                        else
                        {
                            smodel.LitHepProcessed = 0;
                        }
                        if (smodel.OxalateSampleID > 0)
                        {
                            smodel.OxalateProcessed = 1;
                        }
                        else
                        {
                            smodel.OxalateProcessed = 0;
                        }
                        if (smodel.BuccalSampleID > 0)
                        {
                            smodel.BuccalProcessed = 1;
                        }
                        else
                        {
                            smodel.BuccalProcessed = 0;
                        }
                        ViewBag.SampleID          = smodel.CollectedSampleID; // This is the collective bloods sample ID to which the collected samples are related and need to be linked - not needed for Growing Up at the processing stage but this may be so in another context
                        ViewBag.EDTASampleID      = smodel.EDTASampleID;
                        ViewBag.EDTAProcessed     = smodel.EDTAProcessed;
                        ViewBag.GelSampleID       = smodel.GelSampleID;
                        ViewBag.GelSerumProcessed = smodel.GelSerumProcessed;
                        ViewBag.LitHepSampleID    = smodel.LitHepSampleID;
                        ViewBag.LitHepProcessed   = smodel.LitHepProcessed;
                        ViewBag.OxalateSampleID   = smodel.OxalateSampleID;
                        ViewBag.OxalateProcessed  = smodel.OxalateProcessed;
                        ViewBag.BuccalSampleID    = smodel.BuccalSampleID;
                        ViewBag.BuccalProcessed   = smodel.BuccalProcessed;
                    }
                    else
                    {
                        ViewBag.SampleID = smodel.CollectedSampleID;  //This is the urine sample ID from which aliquots may be derived
                    }

                    ViewBag.Message = "Result: The " + smodel.SampleSetName + " has been collected for " + smodel.PSCID + " and may now be processed.";
                    return(View(smodel.ViewName));
                }
                //return Json(ds, JsonRequestBehavior.AllowGet);
                //return null;// temporary placeholder return action
            }
            //if ModelState NOT IsValid!
            ViewBag.ViewName         = smodel.ViewName;
            ViewBag.SampleProcessing = "0"; //THIS ENSURES THAT ONLY THE SAMPLE COLLECTION CONTROLS AND HTML DISPLAY
            ViewBag.PSCID            = smodel.PSCID;
            ViewBag.StudyName        = smodel.StudyName;
            ViewBag.StudyID          = smodel.StudyID;

            return(View(smodel.ViewName));
        }