public IActionResult AddEdit(PatientRxView pPatientRx)
        {
            try
            {
                if (pPatientRx != null && (!string.IsNullOrEmpty(pPatientRx.ProviderId)))
                {
                    if (ModelState.IsValid)
                    {
                        if (!string.IsNullOrEmpty(pPatientRx.RxId))
                        {
                            pPatientRx.DateModified = DateTime.Now;
                            PatientRx lpatientRx = PatientRxExtension.PatientRxViewToPatientRxModel(pPatientRx);

                            User lUser = lIUserRepository.getUser(lpatientRx.PatientId.ToString());
                            if (lUser != null && lpatientRx.Patient != null)
                            {
                                lIPatientRxRepository.UpdatePatientRx(lpatientRx);
                            }
                            else
                            {
                                lIPatientRxRepository.UpdatePatientRx(lpatientRx);
                            }

                            return(RedirectToAction("Dashboard", "Provider", new { id = lpatientRx.ProviderId }));
                        }
                        else
                        {
                            PatientRx lpatientRx = lIPatientRxRepository.getByPatientIdAndEquipmentTypeAndProviderId(pPatientRx.ProviderId, pPatientRx.PatientId, pPatientRx.EquipmentType.Trim());

                            if (lpatientRx == null)
                            {
                                pPatientRx.RxId         = Guid.NewGuid().ToString();
                                pPatientRx.DateCreated  = DateTime.Now;
                                pPatientRx.DateModified = DateTime.Now;


                                lpatientRx = PatientRxExtension.PatientRxViewToPatientRxModel(pPatientRx);
                                User lUser = lIUserRepository.getUser(pPatientRx.PatientId);
                                if (lUser == null && lpatientRx.Patient != null)
                                {
                                    lIPatientRxRepository.InsertPatientRx(lpatientRx);
                                }
                                else
                                {
                                    lIPatientRxRepository.InsertPatientRx(lpatientRx);
                                }
                                return(RedirectToAction("Dashboard", "Provider", new { id = lpatientRx.ProviderId }));
                            }
                            else
                            {
                                TempData["msg"] = "<script>alert('Patient already registered with the surgery type');</script>";
                                getDetails();
                            }
                        }
                    }
                    else
                    {
                        getDetails();
                    }
                }
                else
                {
                    getDetails();
                }
            }
            catch (Exception ex)
            {
                logger.LogDebug("Patent Rx Error: " + ex);
            }
            return(View(pPatientRx));
        }