예제 #1
0
        public async Task <IActionResult> Create([Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            string diagnosisId = string.Empty;

            if (Request.Cookies["PatientDiagnosisId"] != null)
            {
                diagnosisId = Request.Cookies["PatientDiagnosisId"].ToString();
            }
            else if (HttpContext.Session.GetString("PatientDiagnosisId") != null)
            {
                diagnosisId = HttpContext.Session.GetString("PatientDiagnosisId").ToString();
            }

            var patientName = _context.PatientDiagnosis.Include(p => p.Diagnosis).Include(p => p.Patient)
                              .Where(a => a.PatientDiagnosisId.ToString() == diagnosisId).FirstOrDefault();

            ViewData["patientLastName"]  = patientName.Patient.LastName;
            ViewData["patientFirstName"] = patientName.Patient.FirstName;
            ViewData["treatmentFor"]     = patientName.Diagnosis.Name;

            if (ModelState.IsValid)
            {
                _context.Add(patientTreatment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PatientDiagnosisId"] = new SelectList(_context.PatientDiagnosis, "PatientDiagnosisId", "PatientDiagnosisId", patientTreatment.PatientDiagnosisId);
            ViewData["TreatmentId"]        = new SelectList(_context.Treatment.Where(a => a.DiagnosisId.ToString() == diagnosisId), "TreatmentId", "Name", patientTreatment.TreatmentId);
            return(View(patientTreatment));
        }
        public async Task <IActionResult> Edit(int id, [Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            string diagnosisId = GetPatientDiagnosisIdPersistance();

            if (id != patientTreatment.PatientTreatmentId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(patientTreatment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PatientTreatmentExists(patientTreatment.PatientTreatmentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.DateTime = patientTreatment.DatePrescribed.ToString("dd MMMM yyyy HH:mm");
            ViewData["PatientDiagnosisId"] = new SelectList(_context.PatientDiagnosis, "PatientDiagnosisId", "PatientDiagnosisId", patientTreatment.PatientDiagnosisId);
            ViewData["TreatmentId"]        = new SelectList(_context.Treatment.Where(x => x.DiagnosisId == Convert.ToInt32(diagnosisId)), "TreatmentId", "Name", patientTreatment.TreatmentId);
            return(View(patientTreatment));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            string PDiagnosisId = string.Empty;

            if (Request.Cookies["PatientDiagnosisId"] != null)
            {
                PDiagnosisId = Request.Cookies["PatientDiagnosisId"].ToString();
            }

            patientTreatment.PatientDiagnosisId = Int32.Parse(PDiagnosisId);


            //  patientTreatment.DatePrescribed = myDateTime;
            // patientTreatment.DatePrescribed = dateValue.ToString("MM/dd/yyyy hh:mm:ss tt");
            //dateValue.;
            patientTreatment.DatePrescribed = DateTime.Now;
            ViewBag.DateTime = patientTreatment.DatePrescribed.ToString("dd MMMM yyyy HH:mm");
            if (ModelState.IsValid)
            {
                // _context.Add(PatientDiagnosisId);
                _context.Add(patientTreatment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PatientDiagnosisId"] = new SelectList(_context.PatientDiagnosis, "PatientDiagnosisId", "PatientDiagnosisId", patientTreatment.PatientDiagnosisId);
            ViewData["TreatmentId"]        = new SelectList(_context.Treatment, "TreatmentId", "Name", patientTreatment.TreatmentId);
            return(View(patientTreatment));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            int DID = getDID();

            if (getDID() < 0)
            {
                ModelState.AddModelError("DiagnosId", "No Diagnos to create.");
                return(RedirectToAction("Index", "HKPatientDiagnosis"));
            }

            patientTreatment.PatientDiagnosisId = (int)HttpContext.Session.GetInt32("PDID");

            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(patientTreatment);
                    await _context.SaveChangesAsync();

                    TempData["Message"] = $"New record is created.";
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.GetBaseException().Message);
            }

            ViewData["PatientDiagnosisId"] = new SelectList(_context.PatientDiagnosis, "PatientDiagnosisId", "PatientDiagnosisId", patientTreatment.PatientDiagnosisId);
            ViewData["TreatmentId"]        = new SelectList(_context.Treatment.Where(b => b.DiagnosisId == DID).OrderBy(a => a.Name), "TreatmentId", "Name");

            return(View(patientTreatment));
        }
        public async Task <IActionResult> Edit(int id, [Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            if (id != patientTreatment.PatientTreatmentId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(patientTreatment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PatientTreatmentExists(patientTreatment.PatientTreatmentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PatientDiagnosisId"] = new SelectList(_context.PatientDiagnosis, "PatientDiagnosisId", "PatientDiagnosisId", patientTreatment.PatientDiagnosisId);
            ViewData["TreatmentId"]        = new SelectList(_context.Treatment, "TreatmentId", "Name", patientTreatment.TreatmentId);
            return(View(patientTreatment));
        }
예제 #6
0
        public async Task <IActionResult> Edit(int id, [Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            string patientDiagnosisId = string.Empty;
            string patientId          = string.Empty;
            string firstName          = string.Empty;
            string lastName           = string.Empty;
            string diagnosisName      = string.Empty;

            if (Request.Cookies["patientDiagnosisId"] != null)
            {
                patientDiagnosisId = Request.Cookies["patientDiagnosisId"];
                patientId          = Request.Cookies["patientId"];
                firstName          = Request.Cookies["firstName"];
                lastName           = Request.Cookies["lastName"];
                diagnosisName      = Request.Cookies["diagnosisName"];
            }
            else if (HttpContext.Session.GetString("patientDiagnosisId") != null)
            {
                patientDiagnosisId = HttpContext.Session.GetString("patientDiagnosisId");
                patientId          = HttpContext.Session.GetString("patientId");
                firstName          = HttpContext.Session.GetString("firstName");
                lastName           = HttpContext.Session.GetString("lastName");
                diagnosisName      = HttpContext.Session.GetString("diagnosisName");
            }

            TempData["firstName"] = firstName;
            TempData["lastName"]  = lastName;

            TempData["diagnosisName"] = diagnosisName;
            if (id != patientTreatment.PatientTreatmentId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //if modelstate is valid then update the record
                    _context.Update(patientTreatment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PatientTreatmentExists(patientTreatment.PatientTreatmentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            ViewData["PatientDiagnosisId"] = new SelectList(_context.PatientDiagnosis, "PatientDiagnosisId", "PatientDiagnosisId", patientTreatment.PatientDiagnosisId);
            ViewData["TreatmentId"]        = new SelectList(_context.Treatment, "TreatmentId", "Name", patientTreatment.TreatmentId);
            return(View(patientTreatment));
        }
        public async Task <IActionResult> Create([Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(patientTreatment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            var PatientDiagnosisContext = _context.PatientDiagnosis.Where(p => p.PatientDiagnosisId == patientTreatment.PatientDiagnosisId).FirstOrDefault();
            //var DiagnosisId = PatientDiagnosisContext.DiagnosisId;

            string PatientName   = String.Empty;
            string DiagnosisName = String.Empty;

            if (Request.Cookies["PatientName"] != null)
            {
                PatientName = Request.Cookies["PatientName"].ToString();
            }
            if (Request.Cookies["DiagnosisName"] != null)
            {
                DiagnosisName = Request.Cookies["DiagnosisName"].ToString();
            }
            ViewData["DiagnosisName"] = DiagnosisName;
            ViewData["PatientName"]   = PatientName;

            ViewData["PatientDiagnosisId"] = new SelectList(_context.PatientDiagnosis, "PatientDiagnosisId", "PatientDiagnosisId", patientTreatment.PatientDiagnosisId);
            ViewData["TreatmentId"]        = new SelectList(_context.Treatment.Where(p => p.DiagnosisId == patientTreatment.PatientDiagnosisId), "TreatmentId", "Name", patientTreatment.TreatmentId);

            return(View());
        }
        public async Task <IActionResult> Create([Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(patientTreatment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PatientDiagnosisId"] = new SelectList(_context.PatientDiagnosis, "PatientDiagnosisId", "PatientDiagnosisId", patientTreatment.PatientDiagnosisId);
            ViewData["TreatmentId"]        = new SelectList(_context.Treatment.Where(x => x.DiagnosisId == Convert.ToInt32(HttpContext.Session.GetString("sessionDid"))), "TreatmentId", "Name", patientTreatment.TreatmentId);
            return(View(patientTreatment));
        }
예제 #9
0
        public async Task <IActionResult> Create([Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            //declare and initialize string variables
            string patientDiagnosisId = string.Empty;
            string patientId          = string.Empty;
            string firstName          = string.Empty;
            string lastName           = string.Empty;
            string diagnosisName      = string.Empty;

            //checks if patientDiagnosisId is stored in cookies
            if (Request.Cookies["patientDiagnosisId"] != null)
            {
                //if not null,get all the information like patientDiagnosisId,patientId,firstName,etc from cookies and store value in string variables
                patientDiagnosisId = Request.Cookies["patientDiagnosisId"];
                patientId          = Request.Cookies["patientId"];
                firstName          = Request.Cookies["firstName"];
                lastName           = Request.Cookies["lastName"];
                diagnosisName      = Request.Cookies["diagnosisName"];
            }
            //checks if patientDiagnosisId is stored in session
            else if (HttpContext.Session.GetString("patientDiagnosisId") != null)
            {
                //if not null,get all the information like patientDiagnosisId,patientId,firstName,etc from session variables and store value in string variables
                patientDiagnosisId = HttpContext.Session.GetString("patientDiagnosisId");
                patientId          = HttpContext.Session.GetString("patientId");
                firstName          = HttpContext.Session.GetString("firstName");
                lastName           = HttpContext.Session.GetString("lastName");
                diagnosisName      = HttpContext.Session.GetString("diagnosisName");
            }

            TempData["firstName"] = firstName;
            TempData["lastName"]  = lastName;

            TempData["diagnosisName"] = diagnosisName;

            var patientDiagnosis = _context.PatientDiagnosis.Where(a => a.PatientDiagnosisId.ToString() == patientId).FirstOrDefault();

            if (ModelState.IsValid)
            {
                //if data entered is valid, add it to context class
                _context.Add(patientTreatment);
                //save changes in database
                await _context.SaveChangesAsync();

                //redirect to list of all records with new added record, i.e. index action of this controller
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PatientDiagnosisId"] = new SelectList(_context.PatientDiagnosis, "PatientDiagnosisId", "PatientDiagnosisId", patientTreatment.PatientDiagnosisId);
            ViewData["TreatmentId"]        = new SelectList(_context.Treatment.Where(a => a.DiagnosisId == patientDiagnosis.DiagnosisId).OrderBy(a => a.Name), "TreatmentId", "Name", patientTreatment.TreatmentId);
            return(View(patientTreatment));
        }
        public async Task <IActionResult> Create([Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            var PatientDiagnosisId = Request.Cookies["PatientDiagnosisId"];

            patientTreatment.PatientDiagnosisId = Convert.ToInt32(PatientDiagnosisId);
            if (ModelState.IsValid)
            {
                _context.Add(patientTreatment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PatientDiagnosisId"] = new SelectList(_context.PatientDiagnosis, "PatientDiagnosisId", "PatientDiagnosisId", patientTreatment.PatientDiagnosisId);
            ViewData["TreatmentId"]        = new SelectList(_context.Treatment, "TreatmentId", "Name", patientTreatment.TreatmentId);
            return(View(patientTreatment));
        }
        public async Task <IActionResult> Edit(int id, [Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            if (id != patientTreatment.PatientTreatmentId)
            {
                return(NotFound());
            }

            // Get PatientDiagnosisId from session since it's deleted from View
            patientTreatment.PatientDiagnosisId = (int)HttpContext.Session.GetInt32("PatientDiagnosisId");

            // Add current time to DatePrescribed
            patientTreatment.DatePrescribed = DateTime.Now;


            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(patientTreatment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PatientTreatmentExists(patientTreatment.PatientTreatmentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            // Get only Treatment for selected Diagnosis and send to View
            var treatment = _context.Treatment
                            .Include(a => a.Diagnosis)
                            .Include(a => a.PatientTreatment)
                            .Where(a => a.Diagnosis.Name == HttpContext.Session.GetString("PatientDiagnosisName").ToString());

            ViewData["TreatmentId"] = new SelectList(treatment, "TreatmentId", "Name");

            return(View(patientTreatment));
        }
예제 #12
0
        // Setup Create
        // Provide an empty page for user to enter a new treatment
        // GET: HKPatientTreatment/Create
        public IActionResult Create()
        {
            int DID = getDID();

            if (getDID() < 0)
            {
                return(RedirectToAction("Index", "HKPatients"));
            }

            ViewData["PatientDiagnosisId"] = new SelectList(_context.PatientDiagnosis, "PatientDiagnosisId", "PatientDiagnosisId");
            ViewData["TreatmentId"]        = new SelectList(_context.Treatment.Where(b => b.DiagnosisId == DID).OrderBy(a => a.Name), "TreatmentId", "Name");

            PatientTreatment pt = new PatientTreatment();

            pt.DatePrescribed = DateTime.Now;

            return(View(pt));
        }
예제 #13
0
        public async Task <IActionResult> Create([Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            //PatientDiagnosisId id rerieved from session
            patientTreatment.PatientDiagnosisId = Convert.ToInt32(HttpContext.Session.GetString("patientDiagnosisId"));
            if (ModelState.IsValid)
            {
                _context.Add(patientTreatment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            int diagnosisId = Convert.ToInt32(HttpContext.Session.GetString("diagnosisId"));

            ViewData["TreatmentId"]            = new SelectList(_context.Treatment.Where(a => a.DiagnosisId == diagnosisId), "TreatmentId", "Name", patientTreatment.TreatmentId);
            ViewData["Date"]                   = DateTime.Now;
            TempData["PatientTreatmentHeader"] = "Add a Treatment for " + HttpContext.Session.GetString("diagnosisName") + ", Patient: " + HttpContext.Session.GetString("patientName");
            return(View(patientTreatment));
        }
예제 #14
0
        public async Task <IActionResult> Edit(int id, [Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            if (id != patientTreatment.PatientTreatmentId)
            {
                return(NotFound());
            }

            string PDiagnosisId = string.Empty;

            if (Request.Cookies["PatientDiagnosisId"] != null)
            {
                PDiagnosisId = Request.Cookies["PatientDiagnosisId"].ToString();
            }

            patientTreatment.PatientDiagnosisId = Int32.Parse(PDiagnosisId);

            int cvasdtyasug = patientTreatment.PatientDiagnosisId;



            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(patientTreatment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PatientTreatmentExists(patientTreatment.PatientTreatmentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PatientDiagnosisId"] = new SelectList(_context.PatientDiagnosis, "PatientDiagnosisId", "PatientDiagnosisId", patientTreatment.PatientDiagnosisId);
            ViewData["TreatmentId"]        = new SelectList(_context.Treatment, "TreatmentId", "Name", patientTreatment.TreatmentId).Where(m => id == patientTreatment.PatientDiagnosisId);
            return(View(patientTreatment));
        }
        public async Task <IActionResult> Create([Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            string patientID = string.Empty;

            if (Request.Cookies["patientDiagnosisID"] != null)
            {
                patientID = Request.Cookies["patientDiagnosisID"];
            }
            ViewData["patientDiagnosisID"] = patientID;

            if (ModelState.IsValid)
            {
                _context.Add(patientTreatment);
                patientTreatment.DatePrescribed = DateTime.Now;
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PatientDiagnosisId"] = new SelectList(_context.PatientDiagnosis, "PatientDiagnosisId", "PatientDiagnosisId", patientTreatment.PatientDiagnosisId);
            ViewData["TreatmentId"]        = new SelectList(_context.Treatment, "TreatmentId", "Name", patientTreatment.TreatmentId);
            return(View(patientTreatment));
        }
        public ActionResult CompletedApp(FormCollection collection)
        {
            int treatmentID = Convert.ToInt32(collection["Treatment"]);
            int appID       = Convert.ToInt32(TempData["appID"]);

            TempData.Remove("appID");
            PatientTreatment patTreatment = new PatientTreatment();

            try
            {
                int toothID = Convert.ToInt32(collection["Tooth"]);
                patTreatment.patienttoothID = toothID;
            }
            catch (Exception e)
            {
            }
            patTreatment.appointmentID = appID;
            patTreatment.treatmentID   = treatmentID;
            dentistContext.patientTreatment.Add(patTreatment);
            dentistContext.SaveChanges();
            return(View());
        }
예제 #17
0
        public async Task <IActionResult> Edit(int id, [Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            if (id != patientTreatment.PatientTreatmentId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                //PatientDiagnosisId id rerieved from session
                patientTreatment.PatientDiagnosisId = Convert.ToInt32(HttpContext.Session.GetString("patientDiagnosisId"));
                try
                {
                    _context.Update(patientTreatment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PatientTreatmentExists(patientTreatment.PatientTreatmentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            int diagnosisId = Convert.ToInt32(HttpContext.Session.GetString("diagnosisId"));

            ViewData["TreatmentId"]            = new SelectList(_context.Treatment.Where(a => a.DiagnosisId == diagnosisId), "TreatmentId", "Name", patientTreatment.TreatmentId);
            ViewData["Date"]                   = patientTreatment.DatePrescribed;
            TempData["PatientTreatmentHeader"] = "Edit a Treatment for " + HttpContext.Session.GetString("diagnosisName") + ", Patient: " + HttpContext.Session.GetString("patientName");
            return(View(patientTreatment));
        }
예제 #18
0
        public async Task <IActionResult> Create([Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            string PatientDiagnosisId = string.Empty;

            if (Request.Cookies["PatientDiagnosisId"] != null)
            {
                PatientDiagnosisId = Request.Cookies["PatientDiagnosisId"].ToString();
            }
            else if (HttpContext.Session.GetString("PatientDiagnosisId") != null)
            {
                PatientDiagnosisId = HttpContext.Session.GetString("PatientDiagnosisId");
            }
            patientTreatment.PatientDiagnosisId = Convert.ToInt32(PatientDiagnosisId);
            if (ModelState.IsValid)
            {
                _context.Add(patientTreatment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PatientDiagnosisId"] = new SelectList(_context.PatientDiagnosis, "PatientDiagnosisId", "PatientDiagnosisId", patientTreatment.PatientDiagnosisId);
            ViewData["TreatmentId"]        = new SelectList(_context.Treatment, "TreatmentId", "Name", patientTreatment.TreatmentId);
            return(View(patientTreatment));
        }
        public async Task <IActionResult> Create([Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            // Get PatientDiagnosisId from session
            patientTreatment.PatientDiagnosisId = (int)HttpContext.Session.GetInt32("PatientDiagnosisId");

            // Add current time to DatePrescribed
            patientTreatment.DatePrescribed = DateTime.Now;

            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(patientTreatment);
                    await _context.SaveChangesAsync();

                    TempData["message"] = "New treatment for patient added successfully!";

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.GetBaseException().Message);
                TempData["message"] = ex.GetBaseException().Message;
            }

            // Get only Treatment for selected Diagnosis and send to View
            var treatment = _context.Treatment
                            .Include(a => a.Diagnosis)
                            .Include(a => a.PatientTreatment)
                            .Where(a => a.Diagnosis.Name == HttpContext.Session.GetString("PatientDiagnosisName").ToString());

            ViewData["TreatmentId"] = new SelectList(treatment, "TreatmentId", "Name");

            return(View(patientTreatment));
        }
예제 #20
0
        public async Task <IActionResult> Edit(int id, [Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            string patientDiagnosisId;
            string diagnosisName;
            string lastName;
            string firstName;

            if (HttpContext.Session.GetString("patientDiagnosisId") != null)
            {
                patientDiagnosisId = HttpContext.Session.GetString("patientDiagnosisId");
                diagnosisName      = HttpContext.Session.GetString("diagnosisName");
                lastName           = HttpContext.Session.GetString("lastName");
                firstName          = HttpContext.Session.GetString("firstName");
            }
            else if (Request.Cookies["patientDiagnosisId"] != null)
            {
                patientDiagnosisId = Request.Cookies["patientDiagnosisId"];
                diagnosisName      = Request.Cookies["diagnosisName"];
                lastName           = Request.Cookies["lastName"];
                firstName          = Request.Cookies["firstName"];
            }
            else
            {
                TempData["message"] = "Please select a patient’s diagnosis";
                return(RedirectToAction("Index", "YKPatientDiagnosis"));
            }

            ViewData["patientDiagnosisId"] = patientDiagnosisId;
            ViewData["lastName"]           = lastName;
            ViewData["firstName"]          = firstName;
            ViewData["diagnosisName"]      = diagnosisName;

            if (id != patientTreatment.PatientTreatmentId)
            {
                TempData["message"] = "The chosen treatment is not the same as the treatment revised";
                return(RedirectToAction("Index", "YKPatientTreatment"));
                //return NotFound();
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(patientTreatment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PatientTreatmentExists(patientTreatment.PatientTreatmentId))
                    {
                        TempData["message"] = "The treatment is not on the file";
                        return(RedirectToAction("Index", "YKPatientTreatment"));
                        //return NotFound();
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            //to show treatments related to diagnosis name
            var dignosisValue = _context.Diagnosis.Where(m => m.Name == diagnosisName).FirstOrDefault();

            if (dignosisValue != null)
            {
                ViewData["TreatmentId"] = new SelectList(_context.Treatment.Where(m => m.DiagnosisId == dignosisValue.DiagnosisId)
                                                         .OrderBy(m => m.Name), "TreatmentId", "Name", patientTreatment.TreatmentId);
            }
            else
            {
                TempData["message"] = "There is an error of the diagnosis id from the Diagnosis Table";
                return(RedirectToAction("Index", "YKPatientTreatment"));
            }

            return(View(patientTreatment));
        }
예제 #21
0
        public async Task <IActionResult> Create([Bind("PatientTreatmentId,TreatmentId,DatePrescribed,Comments,PatientDiagnosisId")] PatientTreatment patientTreatment)
        {
            string patientDiagnosisId;
            string diagnosisName;
            string lastName;
            string firstName;
            int    patientId;

            if (HttpContext.Session.GetString("patientDiagnosisId") != null)
            {
                patientDiagnosisId = HttpContext.Session.GetString("patientDiagnosisId");
                diagnosisName      = HttpContext.Session.GetString("diagnosisName");
                patientId          = Convert.ToInt32(HttpContext.Session.GetInt32("patientId"));
                lastName           = HttpContext.Session.GetString("lastName");
                firstName          = HttpContext.Session.GetString("firstName");
            }
            else if (Request.Cookies["patientDiagnosisId"] != null)
            {
                patientDiagnosisId = Request.Cookies["patientDiagnosisId"];
                diagnosisName      = Request.Cookies["diagnosisName"];
                patientId          = Convert.ToInt32(Request.Cookies["diagnosisId"]);
                lastName           = Request.Cookies["lastName"];
                firstName          = Request.Cookies["firstName"];
            }
            else
            {
                TempData["message"] = "Please select a patient’s diagnosis";
                return(RedirectToAction("Index", "YKPatientDiagnosis"));
            }

            ViewData["patientDiagnosisId"] = patientDiagnosisId;
            ViewData["lastName"]           = lastName;
            ViewData["firstName"]          = firstName;
            ViewData["diagnosisName"]      = diagnosisName;

            if (ModelState.IsValid)
            {
                _context.Add(patientTreatment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            TempData["message"] = "There is an error for entering inputs";

            //to show treatments related to diagnosis name
            var dignosisValue = _context.Diagnosis.Where(m => m.Name == diagnosisName).FirstOrDefault();

            if (dignosisValue != null)
            {
                ViewData["TreatmentId"] = new SelectList(_context.Treatment.Where(m => m.DiagnosisId == dignosisValue.DiagnosisId)
                                                         .OrderBy(m => m.Name), "TreatmentId", "Name");
            }
            else
            {
                TempData["message"] = "There is an error of the diagnosis id from the Diagnosis Table";
                return(RedirectToAction("Index", "YKPatientTreatment"));
            }

            return(View(patientTreatment));
        }