public async Task <IActionResult> Create([Bind("Din,Name,Image,MedicationTypeId,DispensingCode,Concentration,ConcentrationCode")] Medication medication)
        {
            //Exception handling for model if user enters duplicate Din
            try
            {
                if (ModelState.IsValid)
                {
                    var existingMedications = await _context.Medication.Include(m => m.ConcentrationCodeNavigation).ToListAsync();

                    //Validation to see whether user entered unique data for Name, Concentration and ConcentrationCode
                    foreach (var em in existingMedications)
                    {
                        if (em.ConcentrationCode == medication.ConcentrationCode && em.Concentration == medication.Concentration && em.Name == medication.Name)
                        {
                            ModelState.AddModelError("", "Please create a unique medication");
                            ModelState.AddModelError("Name", "There is already a medication with this Name");
                            ModelState.AddModelError("Concentration", "There is already a medication with this Concentration");
                            ModelState.AddModelError("ConcentrationCode", "There is already a medication with this Concentration Unit");
                            ViewData["ConcentrationCode"]  = new SelectList(_context.ConcentrationUnit, "ConcentrationCode", "ConcentrationCode", medication.ConcentrationCode);
                            ViewData["DispensingCode"]     = new SelectList(_context.DispensingUnit, "DispensingCode", "DispensingCode", medication.DispensingCode);
                            ViewData["MedicationTypeId"]   = new SelectList(_context.MedicationType.Where(a => a.MedicationTypeId == Convert.ToInt32(HttpContext.Session.GetString("code"))), "MedicationTypeId", "Name", medication.MedicationTypeId);
                            TempData["MedicationTypeName"] = "Create Medication for " + HttpContext.Session.GetString("name");
                            return(View(medication));
                        }
                    }
                    _context.Add(medication);
                    await _context.SaveChangesAsync();

                    TempData["UpdateMessage"] = $"Medications updated: {medication.Name}";
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError("Din", "Din number already exists");
            }
            ViewData["ConcentrationCode"]  = new SelectList(_context.ConcentrationUnit, "ConcentrationCode", "ConcentrationCode", medication.ConcentrationCode);
            ViewData["DispensingCode"]     = new SelectList(_context.DispensingUnit, "DispensingCode", "DispensingCode", medication.DispensingCode);
            ViewData["MedicationTypeId"]   = new SelectList(_context.MedicationType.Where(a => a.MedicationTypeId == Convert.ToInt32(HttpContext.Session.GetString("code"))), "MedicationTypeId", "Name", medication.MedicationTypeId);
            TempData["MedicationTypeName"] = "Create Medication for " + HttpContext.Session.GetString("name");
            return(View(medication));
        }
        public async Task <IActionResult> Create([Bind("PatientId,FirstName,LastName,Address,City,ProvinceCode,PostalCode,Ohip,DateOfBirth,Deceased,DateOfDeath,HomePhone,Gender")] Patient patient)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(patient);
                    await _context.SaveChangesAsync();

                    TempData["message"] = "Patient Added successfully";
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", $"error inserting new patient: {ex.GetBaseException().Message}");
            }
            //ViewData["ProvinceCode"] = new SelectList(_context.Province, "ProvinceCode", "ProvinceCode", patient.ProvinceCode);
            return(View(patient));
        }
        public async Task <IActionResult> Create([Bind("Din,Name,Image,MedicationTypeId,DispensingCode,Concentration,ConcentrationCode")] Medication medication)
        {
            medication.MedicationTypeId = Convert.ToInt32(HttpContext.Session.GetString("code"));
            if (_context.Medication.Any(m => m.Name == medication.Name) && _context.Medication.Any(m => m.Concentration == medication.Concentration) && _context.Medication.Any(m => m.ConcentrationCode == medication.ConcentrationCode))
            {
                ModelState.AddModelError("Name", "Medication already exists");
            }
            if (ModelState.IsValid)
            {
                _context.Add(medication);
                await _context.SaveChangesAsync();

                TempData["Alert"] = "Created successfully";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ConcentrationCode"] = new SelectList(_context.ConcentrationUnit.OrderBy(x => x.ConcentrationCode), "ConcentrationCode", "ConcentrationCode", medication.ConcentrationCode);
            ViewData["DispensingCode"]    = new SelectList(_context.DispensingUnit.OrderBy(x => x.DispensingCode), "DispensingCode", "DispensingCode", medication.DispensingCode);
            //ViewData["MedicationTypeId"] = new SelectList(_context.MedicationType, "MedicationTypeId", "Name", medication.MedicationTypeId);
            return(View(medication));
        }
Example #4
0
        public async Task <IActionResult> Create([Bind("PatientId,FirstName,LastName,Address,City,ProvinceCode,PostalCode,Ohip,DateOfBirth,Deceased,DateOfDeath,HomePhone,Gender")] Patient patient)
        {
            //    if(patient.ProvinceCode)
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Add(patient);
                    await _context.SaveChangesAsync();

                    TempData["message"] = $"Patient({patient.LastName}, {patient.FirstName}) record added into database";
                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", "Exception Occured: " + e.GetBaseException().Message);
                }
            }
            ViewData["ProvinceCode"] = new SelectList(_context.Province, "ProvinceCode", "ProvinceCode", patient.ProvinceCode);
            return(View(patient));
        }
        public async Task <IActionResult> Create([Bind("PatientId,FirstName,LastName,Address,City,ProvinceCode,PostalCode,Ohip,DateOfBirth,Deceased,DateOfDeath,HomePhone,Gender")] Patient patient)
        {
            if (ModelState.IsValid)
            {
                //patient.PatientId = 1022;
                try
                {
                    _context.Add(patient);
                    await _context.SaveChangesAsync();

                    TempData["message"] = $"Patient {patient.FirstName + patient.LastName}'s information created succesfully ";
                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)//04 LinqRequest ppt p6
                {
                    ModelState.AddModelError("", $"Exception happens when creating a patient files:{ ex.GetBaseException().Message}");
                }
            }
            //ViewData["ProvinceCode"] = new SelectList(_context.Province, "ProvinceCode", "ProvinceCode", patient.ProvinceCode);
            return(View(patient));
        }
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Create([Bind("PatientId,FirstName,LastName,Address,City,ProvinceCode,PostalCode,Ohip,DateOfBirth,Deceased,DateOfDeath,HomePhone,Gender")] Patient patient)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(patient);
                    await _context.SaveChangesAsync();

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

            return(View(patient));
        }
Example #7
0
        public async Task <IActionResult> Create([Bind("Din,Name,Image,MedicationTypeId,DispensingCode,Concentration,ConcentrationCode")] Medication medication)
        {
            string MedicationTID = string.Empty;

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

            var MedicationType = _context.MedicationType.Where(m => m.MedicationTypeId.ToString() == MedicationTID).FirstOrDefault();

            ViewData["MedicationTypeName"] = MedicationType.Name;
            //ViewData["MedicationTypeId"] = MedicationTID;

            var isZeroExist = _context.Medication.Where(a => a.Din == medication.Din);

            if (isZeroExist.Any())
            {
                ModelState.AddModelError("", "There is already a same record for this medication. DIN : " + medication.Din);
            }
            medication.MedicationTypeId = Convert.ToInt32(MedicationTID);

            if (ModelState.IsValid)
            {
                //ModelState.AddModelError("", "There is already a same record for this medication. DIN : " + medication.Din);
                _context.Add(medication);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ConcentrationCode"] = new SelectList(_context.ConcentrationUnit.OrderBy(c => c.ConcentrationCode), "ConcentrationCode", "ConcentrationCode", medication.ConcentrationCode);
            ViewData["DispensingCode"]    = new SelectList(_context.DispensingUnit.OrderBy(d => d.DispensingCode), "DispensingCode", "DispensingCode", medication.DispensingCode);
            ViewData["MedicationTypeId"]  = new SelectList(_context.MedicationType, "MedicationTypeId", "Name", medication.MedicationTypeId);
            return(View(medication));
        }
        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));
        }
Example #9
0
        public async Task <IActionResult> Create([Bind("PatientId,FirstName,LastName,Address,City,ProvinceCode,PostalCode,Ohip,DateOfBirth,Deceased,DateOfDeath,HomePhone,Gender")] Patient patient)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    patient.ProvinceCode = patient.ProvinceCode.Substring(0, 2);
                    _context.Add(patient);
                    await _context.SaveChangesAsync();

                    TempData["message"] = $"Record successfully added for patient: {patient.LastName+','+patient.FirstName}";
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.GetBaseException().Message);
            }

            ViewData["ProvinceCode"] = new SelectList(_context.Province, "ProvinceCode", "ProvinceCode", patient.ProvinceCode);
            return(View(patient));
        }
        public async Task <IActionResult> Create([Bind("Din,Name,Image,MedicationTypeId,DispensingCode,Concentration,ConcentrationCode")] Medication medication)
        {
            if (ModelState.IsValid)
            {
                var duplication = _context.Medication.Include(m => m.DispensingCodeNavigation).Include(m => m.MedicationType).
                                  Where(m => m.Name == medication.Name && m.Concentration == medication.Concentration && m.ConcentrationCode == medication.ConcentrationCode);
                if (!duplication.Any())
                {
                    _context.Add(medication);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    TempData["medicationData"] = "Please Enter the Unique Value";
                }
            }
            ViewData["ConcentrationCode"] = new SelectList(_context.ConcentrationUnit, "ConcentrationCode", "ConcentrationCode", medication.ConcentrationCode);
            ViewData["DispensingCode"]    = new SelectList(_context.DispensingUnit, "DispensingCode", "DispensingCode", medication.DispensingCode);
            ViewData["MedicationTypeId"]  = new SelectList(_context.MedicationType, "MedicationTypeId", "Name", medication.MedicationTypeId);
            return(View(medication));
        }
        public async Task <IActionResult> Create([Bind("Din,Name,Image,MedicationTypeId,DispensingCode,Concentration,ConcentrationCode")] Medication medication)
        {
            if (ModelState.IsValid)
            {
                if (MedicationExists(medication.Din) == false)
                {
                    _context.Add(medication);
                    await _context.SaveChangesAsync();

                    HttpContext.Session.SetString(medicationTypeId, medication.MedicationTypeId.ToString());
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    TempData["MedicationexistError"] = "Medication Already exist";
                    return(RedirectToAction("Create", "PSMedication"));
                }
            }
            // Order by Concentration Unit
            ViewData["ConcentrationCode"] = new SelectList(_context.ConcentrationUnit.OrderBy(m => m.ConcentrationCode), "ConcentrationCode", "ConcentrationCode");
            // Order by Dispensing Unit
            ViewData["DispensingCode"] = new SelectList(_context.DispensingUnit.OrderBy(m => m.DispensingCode), "DispensingCode", "DispensingCode");
            return(View(medication));
        }
        public async Task <IActionResult> Create([Bind("Din,Name,Image,MedicationTypeId,DispensingCode,Concentration,ConcentrationCode")] Medication medication)
        {
            if (ModelState.IsValid)
            {
                if (MedicationExists(medication.Din) == false)
                {
                    _context.Add(medication);
                    await _context.SaveChangesAsync();

                    HttpContext.Session.SetString(medId, medication.MedicationTypeId.ToString());
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    TempData["MedicationExistErr"] = "Already Exist, Fill Again";
                    return(RedirectToAction("Create", "LDMedication"));
                }
            }

            ViewData["ConcentrationCode"] = new SelectList(_context.ConcentrationUnit, "ConcentrationCode", "ConcentrationCode", medication.ConcentrationCode);
            ViewData["DispensingCode"]    = new SelectList(_context.DispensingUnit, "DispensingCode", "DispensingCode", medication.DispensingCode);
            // ViewData["MedicationTypeId"] = new SelectList(_context.MedicationType, "MedicationTypeId", "Name", medication.MedicationTypeId);
            return(View(medication));
        }
        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));
        }
Example #14
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("PatientId,FirstName,LastName,Address,City,ProvinceCode,PostalCode,Ohip,DateOfBirth,Deceased,DateOfDeath,HomePhone,Gender")] Patient patient)
        {
            //patient.FirstName = JJValidation.JJCapitalize(patient.FirstName);
            //patient.LastName = JJValidation.JJCapitalize(patient.LastName);
            //patient.Address = JJValidation.JJCapitalize(patient.Address);
            //patient.City = JJValidation.JJCapitalize(patient.City);
            //patient.ProvinceCode = patient.ProvinceCode.ToUpper();
            //string countryCode = "";
            //if(patient.ProvinceCode != null)
            //{
            //    var province = _context.Province.Where(p => p.ProvinceCode == patient.ProvinceCode);

            //    if (!province.Any())
            //    {
            //        ModelState.AddModelError("ProvinceCode", "Province Code is not on file");
            //    }
            //    else
            //    {
            //        countryCode = province.FirstOrDefault().CountryCode;
            //    }
            //}


            //if (patient.PostalCode != null && (patient.ProvinceCode == null || countryCode == ""))
            //{
            //    ModelState.AddModelError("ProvinceCode", "Province Code is required to validate Postal Code");
            //}else if (patient.PostalCode != null)
            //{
            //    if (countryCode == "CA")
            //    {
            //        if (JJValidation.JJPostalCodeValidation(patient.PostalCode))
            //        {

            //            if (JJValidation.JJPostalCodeFirstChar(patient.PostalCode, patient.ProvinceCode))
            //            {
            //                patient.PostalCode = JJValidation.JJPostalCodeFormat(patient.PostalCode);

            //            }
            //            else
            //            {
            //                ModelState.AddModelError("PostalCode", "First letter of Postal Code is not valid for given province");

            //            }
            //        }
            //        else
            //        {
            //            ModelState.AddModelError("ProvinceCode", "Province Code is required to validate Canada Postal Code");
            //        }
            //    }
            //    else
            //    {
            //        string postcode = patient.PostalCode;
            //        if(JJValidation.JJZipCodeValidation(ref postcode))
            //        {
            //            patient.PostalCode = postcode;
            //        }
            //        else
            //        {
            //            ModelState.AddModelError("ProvinceCode", "Province Code is required to validate US Postal Code");
            //        }
            //    }
            //}

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

                TempData["message"] = "The data is successfuly created!";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProvinceCode"] = new SelectList(_context.Province, "ProvinceCode", "ProvinceCode", patient.ProvinceCode);
            return(View(patient));
        }
Example #16
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));
        }