Exemple #1
0
        public List <PatientView> GetAllCurrentPatients()
        {
            var allPatients = new List <PatientView>();
            // dummy data
            var p1 = new PatientView
            {
                FirstName = "Richard",
                LastName  = "Grayson"
            };
            var p2 = new PatientView
            {
                FirstName = "Wally",
                LastName  = "West"
            };
            var p3 = new PatientView
            {
                FirstName = "Roy",
                LastName  = "Harper"
            };

            allPatients.Add(p1);
            allPatients.Add(p2);
            allPatients.Add(p3);

            return(allPatients);
        }
        public static Patient PatientViewToPatient(PatientView lPatient)
        {
            if (lPatient == null)
            {
                return(null);
            }
            Patient ppatient = new Patient()
            {
                PatientId      = lPatient.PatientId,
                ProviderId     = lPatient.ProviderId,
                PatientName    = lPatient.PatientName,
                Dob            = lPatient.Dob,
                AddressLine    = lPatient.AddressLine,
                PhoneNumber    = lPatient.PhoneNumber,
                City           = lPatient.City,
                State          = lPatient.State,
                Zip            = lPatient.Zip,
                Ssn            = lPatient.Ssn,
                EquipmentType  = lPatient.EquipmentType,
                SurgeryDate    = lPatient.SurgeryDate,
                Side           = lPatient.Side,
                Pin            = lPatient.Pin,
                LoginSessionId = lPatient.LoginSessionId,
                DateCreated    = lPatient.DateCreated,
                DateModified   = lPatient.DateModified,
                Therapistid    = lPatient.Therapistid
            };

            return(ppatient);
        }
 public MainWindow()
 {
     InitializeComponent();
     MyWindow     = this;
     PatientView  = new PatientView();
     this.Content = PatientView;
 }
        public async Task <ActionResult> Create()
        {
            var userId = await GetUserId();

            var response = await UsersHelper.HavePermisionToAction(userId, "Patients", 3);

            if (!response)
            {
                return(View("Error"));
            }
            var authorId = await GetAuthorId();

            //  ViewBag.AuthorId = authorId;
            ViewBag.CountryId          = new SelectList(_db.Countries, "CountryId", "Name");
            ViewBag.GenderId           = new SelectList(_db.Genders.OrderBy(o => o.GenderId), "GenderId", "Name");
            ViewBag.MaritalSituationId = new SelectList(_db.MaritalSituations.OrderBy(m => m.MaritalSituationId), "MaritalSituationId", "Name");
            ViewBag.OcupationId        = new SelectList(_db.Ocupations, "OcupationId", "Name");
            ViewBag.ReligionId         = new SelectList(_db.Religions.OrderBy(o => o.ReligionId), "ReligionId", "Name");
            //   ViewBag.StatusId = 1;
            ViewBag.BloodTypeId = new SelectList(_db.BloodTypes, "BloodTypeId", "Name");
            ViewBag.InsuranceId = new SelectList(_db.Insurances, "InsuranceId", "Name");
            //ViewBag.PersonId = new SelectList(_db.People, "PersonId", "PersonId");
            ViewBag.SchoolLevelId = new SelectList(_db.SchoolLevels, "SchoolLevelId", "Name");


            var view = new PatientView()
            {
                AuthorId = authorId
            };

            //var view = new PatientView();
            return(View(view));
        }
Exemple #5
0
        public async Task <IActionResult> Put([FromForm] PatientView patientView)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }

                var elem = _patientRepository.GetBy(t => t.Id == patientView.Id);

                if (elem != null)
                {
                    await _uploadFileAndSavePath.UloadFile(patientView);

                    elem.Name = patientView.Name;

                    if (patientView.Photo != null)
                    {
                        elem.Photo = patientView.Photo;
                    }

                    _patientRepository.Update(elem);

                    return(Ok());
                }

                return(NotFound());
            }
            catch
            {
                return(BadRequest());
            }
        }
        private static Person ToPeople(PatientView view)
        {
            if (view == null)
            {
                throw new ArgumentNullException(nameof(view));
            }

            var m = new Person(); //el tipo que vamos a devolver

            view.Transfer(ref m);
            return(m);

            //return new Person
            //{
            //    PersonId = view.PersonId,
            //    AuthorId = view.AuthorId,
            //    Imagen = view.Imagen,
            //    StatusId = view.StatusId,
            //    Address = view.Address,
            //    ReligionId = view.ReligionId,
            //    OcupationId = view.OcupationId,
            //    MaritalSituationId = view.MaritalSituationId,
            //    Cel = view.Cel,
            //    Tel = view.Tel,
            //    Email = view.Email,
            //    CountryId = view.CountryId,
            //    GenderId = view.GenderId,
            //    BornDate = view.BornDate,
            //    LastName = view.LastName,
            //    Name = view.Name,
            //    Rnc = view.Rnc
            //};
        }
        public PatientView PatientLoginsReturnPatientView(string patientPhone, string PIN)
        {
            PatientView result = null;

            try
            {
                var _patient = (from p in context.Patient.Where(p => p.PhoneNumber == patientPhone && p.Pin == int.Parse(PIN))
                                select p).FirstOrDefault();
                if (_patient != null)
                {
                    _patient.LoginSessionId       = Guid.NewGuid();
                    context.Entry(_patient).State = EntityState.Modified;
                    context.SaveChanges();

                    result = new PatientView();
                    result = PatientExtension.PatientToPatientView(_patient);

                    User pUser = (from p in context.User.Where(p => p.UserId == result.PhoneNumber) select p).FirstOrDefault();
                    if (pUser != null)
                    {
                        result.VSeeId = pUser.Vseeid;
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(result);
        }
Exemple #8
0
 private void SignInCommandExecute(object obj)
 {
     try
     {
         string password = (obj as PasswordBox).Password;
         doctor  = dataBaseService.FindDoctorCredentials(UserName, password);
         patient = dataBaseService.FindPatientCredentials(UserName, password);
         if (doctor != null)
         {
             DoctorView doctorView = new DoctorView(doctor);
             login.Close();
             doctorView.Show();
             return;
         }
         else if (patient != null)
         {
             PatientView patientView = new PatientView(patient);
             login.Close();
             patientView.Show();
             return;
         }
         else
         {
             MessageBox.Show("Wrong usename or password");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Exemple #9
0
        public IActionResult OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var patient = _patientsList.GetById(id);

            if (patient == null)
            {
                return(NotFound());
            }

            PatientView = new PatientView {
                Id        = patient.Id,
                Name      = patient.Name,
                Species   = patient.Species.Name,
                Age       = patient.Age,
                PhotoPath = patient.PhotoPath,
                NotesPath = patient.NotesPath
            };

            return(Page());
        }
        public void OnChangeView(ViewType nextView)
        {
            switch (nextView)
            {
            case ViewType.LOGIN_VIEW:
                CurrentView = new LoginView();
                break;

            case ViewType.REGISTER_VIEW:
                CurrentView = new RegistrationView();
                break;

            case ViewType.PATIENT_VIEW:
                CurrentView = new PatientView();
                break;

            case ViewType.DOCTOR_VIEW:
                CurrentView = new DoctorRegistrationView();
                break;

            case ViewType.DOCTOR_SPECIALIST_VIEW:
                CurrentView = new DoctorSpecialistView();
                break;

            case ViewType.GENERAL_PRACTICIONER_VIEW:
                CurrentView = new GeneralPracticionerView();
                break;

            default:
                break;
            }
        }
 public async Task UloadFile(PatientView patient)
 {
     if (patient.File != null)
     {
         patient.Photo = await _imageHandler.UploadImagePath(patient.File);
     }
 }
Exemple #12
0
        private void LoadPatient(int patientId, MainWindow mainWindow, MainViewModel mainViewModel)
        {
            TabControl tabControl = mainWindow.mainPanel.Children[0] as TabControl;

            foreach (var item in tabControl.Items)
            {
                var tabItem          = item as TabItem;
                var patientViewExist = tabItem.Content as PatientView;
                var PatientViewModel = patientViewExist.DataContext as PatientViewModel;
                if (PatientViewModel.PatientInfo.PatientId == patientId)
                {
                    tabItem.IsSelected = true;
                    return;
                }
            }

            PatientViewModel patientViewModel = new PatientViewModel(patientId);
            var patientView = new PatientView();


            var patientInTab = new TabItem();

            patientInTab.Header = patientId == 0 ? "Patient ID:NewId()" : "Patient ID:" + patientId.ToString();

            patientView.DataContext = patientViewModel;
            patientInTab.Content    = patientView;
            tabControl.Items.Add(patientInTab);
            patientInTab.IsSelected = true;

            mainViewModel.TotalPatientInWorkSpace++;
            var tabId = mainViewModel.TotalPatientInWorkSpace;

            patientInTab.Tag = mainViewModel.TotalPatientInWorkSpace;

            patientViewModel.PatientInfo.SaveAndNextTabAction += () =>
            {
                var tabItem = (TabItem)patientView.tabPatient.Items[1];
                tabItem.IsEnabled = true;
                tabItem.Focus();
                tabItem.IsEnabled = false;
            };
            patientViewModel.PatientAddressInfo.SaveAndNextTabAction += () =>
            {
                var tabItem = (TabItem)patientView.tabPatient.Items[0];
                tabItem.IsEnabled = true;
                tabItem.Focus();
                tabItem.IsEnabled = false;
            };
            patientViewModel.PatientInfo.ShowDoctorScreen += () =>
            {
                LoadDoctorScreen(patientViewModel.PatientInfo.DoctorListViewModel);
            };
            patientViewModel.ClosePateintEvent += () =>
            {
                ClosePatient(mainWindow, mainViewModel, tabId);
            };
        }
        private static void SetupEventHandlers(IBus bus, IReportingRepository<PatientDto> reportingRepository)
        {
            var patientEventHandler = new PatientView(reportingRepository);
            bus.RegisterHandler<PatientCreatedEvent>(patientEventHandler.Handle);
            bus.RegisterHandler<PatientNameChangedEvent>(patientEventHandler.Handle);
            bus.RegisterHandler<PatientRelocatedEvent>(patientEventHandler.Handle);

            //var patientEventPublisher = new PatientEventPublisher();
            //bus.RegisterHandler<PatientCreatedEvent>(patientEventPublisher.Handle);
        }
        public ActionResult Patients()
        {
            var Patient = this._contex.Patients.ToList();

            var PView = new PatientView
            {
                Patients = Patient
            };

            return(PartialView(PView));
        }
        private void InitData()
        {
            try
            {
                Cursor.Current       = Cursors.WaitCursor;
                dtpkNgaySieuAm.Value = DateTime.Now;
                DisplayDSBacSiChiDinh();
                DisplayDSBasSiSieuAm();
                DisplayLoaiSieuAm();

                btnHinh1.Enabled = _allowEdit;
                btnHinh2.Enabled = _allowEdit;

                if (_allowEdit)
                {
                    //if (!Global.TVHomeConfig.SuDungSieuAm)
                    //{
                    //    PlayCapFactory.RunPlayCapProcess(false);
                    //    PlayCapFactory.OnCaptureCompletedEvent += new CaptureCompletedHandler(PlayCapFactory_OnCaptureCompletedEvent);
                    //}
                    //else
                    {
                        btnHinh1.Visible = false;
                        btnHinh2.Visible = false;

                        _watchingFolder = new WatchingFolder();
                        _watchingFolder.OnCreatedFileEvent += new CreatedFileEventHandler(_watchingFolder_OnCreatedFileEvent);
                        _watchingFolder.StartMoritoring(Global.HinhChupPath);

                        if (!Utility.CheckRunningProcess(Const.TVHomeProcessName))
                        {
                            Utility.ExecuteFile(Global.TVHomeConfig.Path);
                        }
                    }
                }

                Result result = PatientBus.GetPatient2(_patientGUID);
                if (result.IsOK)
                {
                    PatientView patient = result.QueryResult as PatientView;
                    _maBenhNhan = patient.FileNum;
                }
                else
                {
                    MsgBox.Show(this.Text, result.GetErrorAsString("PatientBus.GetPatient"), IconType.Error);
                    Utility.WriteToTraceLog(result.GetErrorAsString("PatientBus.GetPatient"));
                }
            }
            catch (Exception ex)
            {
                MsgBox.Show(this.Text, ex.Message, IconType.Error);
                Utility.WriteToTraceLog(ex.Message);
            }
        }
Exemple #16
0
        private static void SetupEventHandlers(IBus bus, IReportingRepository <PatientDto> reportingRepository)
        {
            var patientEventHandler = new PatientView(reportingRepository);

            bus.RegisterHandler <PatientCreatedEvent>(patientEventHandler.Handle);
            bus.RegisterHandler <PatientNameChangedEvent>(patientEventHandler.Handle);
            bus.RegisterHandler <PatientRelocatedEvent>(patientEventHandler.Handle);

            //var patientEventPublisher = new PatientEventPublisher();
            //bus.RegisterHandler<PatientCreatedEvent>(patientEventPublisher.Handle);
        }
Exemple #17
0
 public void GoToPatientExecute()
 {
     try
     {
         PatientView main = new PatientView(user);
         main.Show();
         administratorView.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
 public void QuitExecute()
 {
     try
     {
         PatientView patientView = new PatientView(UserAdmin);
         patientView.Show();
         addPatientView.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Exemple #19
0
 /// <summary>
 /// This method checks if username and password valid.
 /// </summary>
 /// <param name="password">User input for password.</param>
 public void LogInExecute(object password)
 {
     Password = (password as PasswordBox).Password;
     if (Username == MasterUsername && Password == MasterPassword)
     {
         MasterView masterView = new MasterView(Username, Password);
         masterView.ShowDialog();
     }
     else if (users.FindAdministrator(Username, Password) != null)
     {
         Administrator = users.FindAdministrator(Username, Password);
         if (clinic.CheckIfClinicExists())
         {
             AdministratorView administratorView = new AdministratorView();
             administratorView.ShowDialog();
         }
         else
         {
             CreateClinicView clinicView = new CreateClinicView();
             clinicView.ShowDialog();
         }
     }
     else if (users.FindMaintenance(Username, Password) != null)
     {
         Maintenance = users.FindMaintenance(Username, Password);
         MaintenanceView maintenanceView = new MaintenanceView(Maintenance);
         maintenanceView.ShowDialog();
     }
     else if (users.FindManager(Username, Password) != null)
     {
         Manager = users.FindManager(Username, Password);
         ManagerView managerView = new ManagerView();
         managerView.ShowDialog();
     }
     else if (users.FindDoctor(Username, Password) != null)
     {
         Doctor = users.FindDoctor(Username, Password);
         DoctorView doctorView = new DoctorView();
         doctorView.ShowDialog();
     }
     else if (users.FindPatient(Username, Password) != null)
     {
         Patient = users.FindPatient(Username, Password);
         PatientView patientView = new PatientView();
         patientView.ShowDialog();
     }
     else
     {
         MessageBox.Show("Wrong username or password. Please, try again.", "Notification");
     }
 }
        private static PatientView ToView(Person pview, Patient view)
        {
            if (pview == null)
            {
                throw new ArgumentNullException(nameof(pview));
            }
            if (view == null)
            {
                throw new ArgumentNullException(nameof(view));
            }

            var m = new PatientView(); //el tipo que vamos a devolver

            pview.Transfer(ref m);
            view.Transfer(ref m);
            m.FullName = pview.Name + " " + pview.LastName;
            return(m);

            //return new PatientView()
            //{
            //    //PersonId = pview.PersonId,
            //    //AuthorId = pview.AuthorId,
            //    //Imagen = pview.Imagen,
            //    //StatusId = pview.StatusId,
            //    //Address = pview.Address,
            //    //ReligionId = pview.ReligionId,
            //    //OcupationId = pview.OcupationId,
            //    //MaritalSituationId = pview.MaritalSituationId,
            //    //Cel = pview.Cel,
            //    //Tel = pview.Tel,
            //    //Email = pview.Email,
            //    //CountryId = pview.CountryId,
            //    //GenderId = pview.GenderId,
            //    //BornDate = pview.BornDate,
            //    //LastName = pview.LastName,
            //    //Name = pview.Name,
            //    //Rnc = pview.Rnc,
            //    //PatientId = view.PatientId,
            //    //Record = view.Record,
            //    //CreationDate = view.CreationDate,
            //    //InsuranceId = view.InsuranceId,
            //    //BloodTypeId = view.BloodTypeId,
            //    //SchoolLevelId = pview.SchoolLevelId,
            //    //Age = view.Age,
            //    FullName = pview.Name + " " + pview.LastName

            //};
        }
        public static Patient ViewToEntity(this PatientView view)
        {
            if (view != null)
            {
                return(new Patient
                {
                    Id = view.Id,
                    Name = view.Name,
                    Photo = view.Photo,
                    GeneralInformation = view.GeneralInformation.ViewToEntity(),
                    InjuriesDiseases = view.InjuriesDiseases.ViewToEntity() ?? new List <InjuriesDiseases>(),
                    MedicalExaminations = view.MedicalExaminations.ViewToEntity() ?? new List <MedicalExamination>()
                });
            }

            return(null);
        }
        private static Patient ToPatient(PatientView view)
        {
            if (view == null)
            {
                throw new ArgumentNullException(nameof(view));
            }
            var m = new Patient(); //el tipo que vamos a devolver

            view.Transfer(ref m);
            return(m);
            //return new Patient()
            //{
            //    PersonId = view.PersonId,
            //    PatientId = view.PatientId,
            //    Record = view.Record,
            //    CreationDate = view.CreationDate,
            //    InsuranceId = view.InsuranceId,
            //    BloodTypeId = view.BloodTypeId,
            //    Age = view.Age

            //};
        }
        public void SaveExecute(object parametar)
        {
            var passwordBox = parametar as PasswordBox;
            var password    = passwordBox.Password;

            User.Password = password;
            User.GenderId = selectedGender.GenderId;
            User.RoleId   = 5;
            try
            {
                bool uniqueInsuranceNumber = service.CheckInsuranceNumber(UserPatient.InsuranceNumber);
                int  drUniqueNumber        = service.GetDoctorUniqueNumberByDoctorId(selectDoctor.ClinicUserId);
                if (uniqueInsuranceNumber)
                {
                    int userId = service.AddClinicUser(User);
                    if (userId != 0)
                    {
                        UserPatient.ClinicUserId       = userId;
                        UserPatient.UniqueDoctorNumber = drUniqueNumber;

                        if (service.AddNewPatient(UserPatient) != 0)
                        {
                            MessageBox.Show("You have successfully added new patient");
                            Logging.LoggAction("AddPatientViewModel", "Info", "Succesfull added new doctor");

                            PatientView patientView = new PatientView(UserAdmin);
                            patientView.Show();
                            addPatientView.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                Logging.LoggAction("AddDoctorViewModel", "Error", ex.ToString());
            }
        }
Exemple #24
0
        public async Task <IActionResult> Post([FromForm] PatientView patient)
        {
            try
            {
                if (patient == null)
                {
                    return(BadRequest("Owner object is null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object"));
                }
                await _uploadFileAndSavePath.UloadFile(patient);

                _patientRepository.InsertWithDefaultGeneralInformation(patient.ViewToEntity());

                return(Ok());
            }
            catch (Exception ex)
            {
                return(StatusCode(500, "Internal server error" + ex.Message));
            }
        }
        public ActionResult InfoChange(PatientView model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (_patientBusiness.CheckExistsAccount(model.Account, model.ID))
                    {
                        ModelState.AddModelError("ExistsAccountError", "Tài khoản này đã tồn tại trong hệ thống");
                    }

                    if (_patientBusiness.Edit(model))
                    {
                        _patientBusiness.Save();
                        return(Redirect("/thong-tin-tai-khoan.html"));
                    }
                }
                return(View(model));
            }
            catch (Exception)
            {
                return(View(model));
            }
        }
 public ActionResult Register(PatientView model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (_patientBusiness.CheckExistsAccount(model.Account, 0))
             {
                 ModelState.AddModelError("ExistsAccountError", "Tài khoản này đã tồn tại trong hệ thống");
             }
             model.DateCreate = DateTime.Now;
             if (_patientBusiness.Add(model))
             {
                 _patientBusiness.Save();
                 return(Redirect("/dang-nhap.html"));
             }
         }
         return(View(model));
     }
     catch (Exception)
     {
         return(View(model));
     }
 }
Exemple #27
0
        private void StartFTPUploadThread()
        {
            while (_isStartFTPUpload)
            {
                LoadConfig();
                string[] fileNames = Directory.GetFiles(Global.FTPUploadPath);
                foreach (var fileName in fileNames)
                {
                    if (!_isStartFTPUpload)
                    {
                        return;
                    }

                    string fn = Path.GetFileName(fileName);

                    string maBenhNhan = GetMaBenhNhan(fn);
                    if (maBenhNhan == string.Empty)
                    {
                        continue;
                    }

                    Result result = PatientBus.GetPatient(maBenhNhan);
                    if (!result.IsOK)
                    {
                        Utility.WriteToTraceLog(result.GetErrorAsString("PatientBus.GetPatient"));
                        continue;
                    }

                    PatientView patient = result.QueryResult as PatientView;
                    if (patient == null)
                    {
                        continue;
                    }
                    string tenBenhNhan = patient.FullName;
                    string password    = Utility.GeneratePassword(5);

                    result = MySQLHelper.CheckUserExist(maBenhNhan);
                    if (result.Error.Code != ErrorCode.EXIST && result.Error.Code != ErrorCode.NOT_EXIST)
                    {
                        Utility.WriteToTraceLog(result.GetErrorAsString("MySQLHelper.CheckUserExist"));
                        continue;
                    }

                    if (result.Error.Code == ErrorCode.NOT_EXIST)
                    {
                        result = MySQLHelper.InsertUser(maBenhNhan, password, tenBenhNhan);
                        if (!result.IsOK)
                        {
                            Utility.WriteToTraceLog(result.GetErrorAsString("MySQLHelper.InsertUser"));
                            continue;
                        }
                        else
                        {
                            if (!AddUserToTextFile(maBenhNhan, password, tenBenhNhan))
                            {
                                continue;
                            }
                        }
                    }

                    fn = fn.Replace("@", "_");
                    string remoteFileName = string.Format("{0}/{1}/{2}", Global.FTPFolder, maBenhNhan, fn);
                    result = FTP.UploadFile(Global.FTPConnectionInfo, fileName, remoteFileName);
                    if (!result.IsOK)
                    {
                        Utility.WriteToTraceLog(result.GetErrorAsString("FTP.UploadFile"));
                    }
                    else
                    {
                        File.Delete(fileName);
                    }

                    if (!_isStartFTPUpload)
                    {
                        return;
                    }
                }

                if (!_isStartFTPUpload)
                {
                    return;
                }
                Thread.Sleep(1000 * 60 * 5);
                //Thread.Sleep(1000 * 10);
                if (!_isStartFTPUpload)
                {
                    return;
                }
            }
        }
        public static Appointment AppointmentDtoToAppointment(ScheduleAppointmentView dto, PatientView patient)
        {
            Appointment appointment = new Appointment();

            appointment.Canceled                     = dto.Canceled;
            appointment.DoctorWorkDayId              = dto.DoctorWorkDayId;
            appointment.StartTime                    = dto.StartTime;
            appointment.EndTime                      = dto.EndTime;
            appointment.MedicalExamination           = dto.MedicalExamination;
            appointment.MedicalExamination.PatientId = patient.IdOfPatient;

            return(appointment);
        }
        public async Task <ActionResult> Edit(PatientView view)
        {
            var userId = await GetUserId();

            var response = await UsersHelper.HavePermisionToAction(userId, "Patients", 4);

            if (!response)
            {
                return(View("Error"));
            }
            if (ModelState.IsValid)
            {
                //var doctor = await _db.Doctors.FirstOrDefaultAsync(p => p.UserId == userId);

                //if (doctor == null)
                //{
                //    return RedirectToAction("CreateDoctorInformation", "Authors", new { area = "Configurations" });
                //}

                const string folder = "~/Content/Patients";

                var pic = view.Imagen;

                if (view.ImageFile != null)
                {
                    pic = Files.UploadPhoto(view.ImageFile, folder, "");
                    pic = string.Format("{0}/{1}", folder, pic);
                }

                var people = ToPeople(view);
                people.Imagen = pic;
                if (people.Tel != null)
                {
                    people.Tel = Strings.RemoveCharacters(people.Tel);
                }
                if (people.Cel != null)
                {
                    people.Cel = Strings.RemoveCharacters(people.Cel);
                }
                if (people.Rnc != null)
                {
                    people.Rnc = Strings.RemoveCharacters(people.Rnc);
                }

                var patient = ToPatient(view);

                //if (string.IsNullOrEmpty(view.Record2))
                //{
                //    patient.Record2 = patient.Record2 = doctor.Prefix + patient.Record.ToString("00000");
                //}

                _db.Entry(people).State  = EntityState.Modified;
                _db.Entry(patient).State = EntityState.Modified;

                await _db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            //   var autorid = await GetAuthorId();

            //   ViewBag.AuthorId = autorid;
            ViewBag.CountryId          = new SelectList(_db.Countries, "CountryId", "Name", view.CountryId);
            ViewBag.GenderId           = new SelectList(_db.Genders, "GenderId", "Name", view.GenderId);
            ViewBag.MaritalSituationId = new SelectList(_db.MaritalSituations, "MaritalSituationId", "Name", view.MaritalSituationId);
            ViewBag.OcupationId        = new SelectList(_db.Ocupations, "OcupationId", "Name", view.OcupationId);
            ViewBag.ReligionId         = new SelectList(_db.Religions, "ReligionId", "Name", view.ReligionId);
            // ViewBag.StatusId =  view.StatusId;
            ViewBag.BloodTypeId = new SelectList(_db.BloodTypes, "BloodTypeId", "Name", view.BloodTypeId);
            ViewBag.InsuranceId = new SelectList(_db.Insurances, "InsuranceId", "Name", view.InsuranceId);
            //   ViewBag.PersonId =  view.PersonId;
            ViewBag.SchoolLevelId = new SelectList(_db.SchoolLevels, "SchoolLevelId", "Name", view.SchoolLevelId);

            return(View(view));
        }
        public async Task <ActionResult> Create(PatientView view)
        {
            var userId = await GetUserId();

            var response = await UsersHelper.HavePermisionToAction(userId, "Patients", 3);

            if (!response)
            {
                return(View("Error"));
            }
            if (ModelState.IsValid)
            {
                //var doctor = await _db.Doctors.FirstOrDefaultAsync(p => p.UserId == userId);

                //if (doctor == null)
                //{
                //    return RedirectToAction("CreateDoctorInformation", "Authors", new { area = "Configurations" });
                //}

                var          pic    = string.Empty;
                const string folder = "~/Content/Patients";

                if (view.ImageFile != null)
                {
                    pic = Files.UploadPhoto(view.ImageFile, folder, "");
                    pic = string.Format("{0}/{1}", folder, pic);
                }

                var person = ToPeople(view);
                person.Imagen = pic;
                if (person.Tel != null)
                {
                    person.Tel = Strings.RemoveCharacters(person.Tel);
                }
                if (person.Cel != null)
                {
                    person.Cel = Strings.RemoveCharacters(person.Cel);
                }
                if (person.Rnc != null)
                {
                    person.Rnc = Strings.RemoveCharacters(person.Rnc);
                }

                //  person.AuthorId = doctor.User.AuthorId;

                person.StatusId = 1;
                _db.People.Add(person);
                await _db.SaveChangesAsync();

                var patient = ToPatient(view);

                patient.PersonId = person.PersonId;
                patient.Record   = MyAppHelper.GenerateRecord(person.AuthorId);

                //if (string.IsNullOrEmpty(view.Record2))
                //{
                //    patient.Record2 = doctor.Prefix + patient.Record.ToString("00000");
                //}

                _db.Patients.Add(patient);


                //var customer = new Customer
                //{
                //    CreditAmount=0,DebAmount=0,WastedAmount=0,Name=view.Name,LastName=view.LastName
                //};
                //customer.PersonId = person.PersonId;
                //customer.Code = MyAppHelper.GenerateRecord(doctor.User.AuthorId, 2);

                //_db.Customers.Add(customer);
                try
                {
                    await _db.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }

                return(RedirectToAction(string.Format("Details/{0}", patient.PatientId)));
            }

            //   ViewBag.AuthorId =  view.AuthorId;
            ViewBag.CountryId = new SelectList(_db.Countries, "CountryId", "NAme", view.CountryId);
            ViewBag.GenderId  = new SelectList(_db.Genders.OrderBy(o => o.GenderId), "GenderId", "Name",
                                               view.GenderId);
            ViewBag.MaritalSituationId =
                new SelectList(_db.MaritalSituations.OrderBy(m => m.MaritalSituationId), "MaritalSituationId",
                               "Name", view.MaritalSituationId);
            ViewBag.OcupationId = new SelectList(_db.Ocupations, "OcupationId", "Name", view.OcupationId);
            ViewBag.ReligionId  = new SelectList(_db.Religions.OrderBy(o => o.ReligionId), "ReligionId", "Name",
                                                 view.ReligionId);
            // ViewBag.StatusId = view.StatusId;
            ViewBag.BloodTypeId = new SelectList(_db.BloodTypes, "BloodTypeId", "Name", view.BloodTypeId);
            ViewBag.InsuranceId = new SelectList(_db.Insurances, "InsuranceId", "Name", view.InsuranceId);
            // ViewBag.PersonId = view.PersonId;
            ViewBag.SchoolLevelId = new SelectList(_db.SchoolLevels, "SchoolLevelId", "Name",
                                                   view.SchoolLevelId);

            return(View(view));
        }
Exemple #31
0
 public static Patient ToPatient(this PatientView model)
 {
     return(Mapper.Map <Patient>(model));
 }