示例#1
0
        public async Task <IActionResult> PutNurse(int id, Nurse nurse)
        {
            if (id != nurse.NurseId)
            {
                return(BadRequest());
            }

            _context.Entry(nurse).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NurseExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#2
0
        public async Task <IActionResult> DoctorRegistration(DoctorFormViewModel model)
        {
            Doctor doctorr = new Doctor()
            {
                Address     = model.doctor.Address,
                Phone       = model.doctor.Phone,
                Name        = model.doctor.Name,
                IsAvailable = true,
            };
            var iss = model.doctor.Id;

            _context.Doctors.Add(doctorr);


            await _context.SaveChangesAsync();

            var doctorId = doctorr.Id;

            foreach (var id in model.SelectedeSepcializationId)
            {
                _context.DoctorSpecializations.Add(new DoctorSpecialization
                {
                    SpecializationId = id,
                    DoctorId         = doctorId
                });
            }
            await _context.SaveChangesAsync();



            return(RedirectToAction("Index", "Home"));
        }
示例#3
0
        public async Task <IActionResult> PutPatient(int id, Patient patient)
        {
            if (id != patient.id)
            {
                return(BadRequest());
            }

            _context.Entry(patient).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PatientExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#4
0
        public async Task <IActionResult> PutCleaner(int id, Cleaner cleaner)
        {
            if (id != cleaner.CleanerId)
            {
                return(BadRequest());
            }

            _context.Entry(cleaner).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CleanerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#5
0
        public async Task <IActionResult> PutHospital(int id, Hospital hospital)
        {
            if (id != hospital.HospitalId)
            {
                return(BadRequest());
            }

            _context.Entry(hospital).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HospitalExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#6
0
        public async Task <IActionResult> Create([Bind("DiretorServicoID,Codigo,Nome,Contacto,Email,CC")] DiretorServico diretorServico)
        {
            var numero   = diretorServico.Codigo;
            var email    = diretorServico.Email;
            var nCC      = diretorServico.CC;
            var contacto = diretorServico.Contacto;

            //Validar Numero Mecanografico
            if (numMecIsInvalid(numero) == true)
            {
                //Mensagem de erro se o codigo for inválido
                ModelState.AddModelError("Codigo", "Este código já existe");
            }

            //Validar Email
            if (emailIsInvalid(email) == true)
            {
                //Mensagem de erro se o email for inválido
                ModelState.AddModelError("Email", "Este email já existe");
            }

            //Validar CC através do check digit
            if (!ValidateNumeroDocumentoCC(nCC))
            {
                //Mensagem de erro se o nº de CC é inválido
                ModelState.AddModelError("CC", "Nº de CC inválido");
            }

            //Validar CC
            if (ccIsInvalid(nCC))
            {
                //Mensagem de erro se o nº de CC já existe
                ModelState.AddModelError("CC", "Nº de CC já existente");
            }

            //Validar contacto
            if (contactoIsInvalid(contacto))
            {
                //Mensagem de erro se o contacto já existe
                ModelState.AddModelError("Contacto", "Contacto já existente");
            }


            if (ModelState.IsValid)
            {
                if (!contactoIsInvalid(contacto) || !numMecIsInvalid(numero) || !emailIsInvalid(email) || !ccIsInvalid(nCC) || ValidateNumeroDocumentoCC(nCC))
                {
                    diretorServico.Codigo = "D" + diretorServico.Codigo;
                    _context.Add(diretorServico);
                    await _context.SaveChangesAsync();

                    TempData["insertSuccess"] = "Registo inserido com sucesso!";
                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(diretorServico));
        }
示例#7
0
        public async Task <IActionResult> Create([Bind("TratamentoId,PatologiaId,PacienteId,GrauId,DataInicio,DataFim,DuracaoCiclo,RegimeId,EstadoId,MedicoId")] Tratamento tratamento)
        {
            /******************Validações**********************/


            DateTime dateNow          = DateTime.Now;
            DateTime inicioTratamento = tratamento.DataInicio;
            DateTime fimTratamento    = tratamento.DataFim;


            bool dataTratamentoIsInvalid = true;

            //Validar Data de inicio do tratamento
            DateTime dataInicio   = tratamento.DataInicio;
            DateTime dataFim      = tratamento.DataFim;
            TimeSpan duracaoCiclo = tratamento.DuracaoCiclo;
            Paciente idPaciente   = _context.Pacientes.SingleOrDefault(p => p.PacienteId == tratamento.PacienteId);
            int      idRegime     = tratamento.RegimeId;
            var      tipoRegime   = _context.Regime.SingleOrDefault(r => r.RegimeId == idRegime);
            string   regime       = tipoRegime.TipoRegime.ToString();

            string estado = EstadoTratamento(dateNow, dataInicio);

            Estado estadoTratamento = _context.Estado.SingleOrDefault(e => e.Nome == estado);

            tratamento.EstadoId = estadoTratamento.EstadoId;

            if (DataTratamentoIsInvalid(dataInicio, dataFim) == true)
            {
                dataTratamentoIsInvalid = true;
                ModelState.AddModelError("DataInicio", "Data Inválida, não pode ser inferior à data atual");
            }


            if (ModelState.IsValid)
            {
                if (!DataTratamentoIsInvalid(dataInicio, dataFim))
                {
                    _context.Add(tratamento);
                    await _context.SaveChangesAsync();

                    TempData["notice"] = "Tratamento inserido com sucesso!";
                    GenerateHorarioPaciente(_context, dataInicio, dataFim, duracaoCiclo, idPaciente, regime);
                    TempData["GeneratedSuccess"] = "Horário dos pacientes gerado com sucesso";
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GrauId"]      = new SelectList(_context.Grau, "GrauId", "TipoGrau", tratamento.GrauId);
            ViewData["MedicoId"]    = new SelectList(_context.Medicos, "MedicoId", "Nome", tratamento.MedicoId);
            ViewData["PacienteId"]  = new SelectList(_context.Pacientes, "PacienteId", "Nome", tratamento.PacienteId);
            ViewData["PatologiaId"] = new SelectList(_context.Patologia, "PatologiaId", "Nome", tratamento.PatologiaId);
            ViewData["RegimeId"]    = new SelectList(_context.Regime, "RegimeId", "TipoRegime", tratamento.RegimeId);
            ViewData["EstadoId"]    = new SelectList(_context.Estado, "EstadoId", "Nome", tratamento.EstadoId);
            return(View(tratamento));
        }
示例#8
0
        public async Task <IActionResult> Create([Bind("RegraId,RegrasEscalonamento,Numero")] Regra regra)
        {
            if (ModelState.IsValid)
            {
                _context.Add(regra);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(regra));
        }
示例#9
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,PatientID,Diseases,DateIn")] Appointment appointment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(appointment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(appointment));
        }
示例#10
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Post,Department")] Staff staff)
        {
            if (ModelState.IsValid)
            {
                _context.Add(staff);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(staff));
        }
示例#11
0
        public async Task <IActionResult> Create([Bind("GrauId,TipoGrau")] Grau grau)
        {
            if (ModelState.IsValid)
            {
                _context.Add(grau);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(grau));
        }
示例#12
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Diseases,DateIn,DateOut")] Patients patients)
        {
            if (ModelState.IsValid)
            {
                _context.Add(patients);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(patients));
        }
示例#13
0
        public async Task <IActionResult> Create([Bind("RegimeId,TipoRegime")] Regime regime)
        {
            if (ModelState.IsValid)
            {
                _context.Add(regime);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(regime));
        }
示例#14
0
        public async Task <IActionResult> Create([Bind("Id,Nombre,Apellido,FechaNacimiento,TipoDocumento,NumeroDocumento,EstadoCivil,Email,Direccion,Nacionalidad,Ciudad,CodigoPostal,Password")] Usuario usuario)
        {
            if (ModelState.IsValid)
            {
                _context.Add(usuario);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(usuario));
        }
示例#15
0
        public async Task <IActionResult> Create([Bind("EstadoId,Nome")] Estado estado)
        {
            if (ModelState.IsValid)
            {
                _context.Add(estado);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(estado));
        }
示例#16
0
        public async Task <IActionResult> Create([Bind("HorarioATrocarEnfermeiroId,HorarioEnfermeiroId")] HorarioATrocarEnfermeiro horarioATrocarEnfermeiro)
        {
            if (ModelState.IsValid)
            {
                _context.Add(horarioATrocarEnfermeiro);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["HorarioEnfermeiroId"] = new SelectList(_context.HorariosEnfermeiro, "HorarioEnfermeiroId", "HorarioEnfermeiroId", horarioATrocarEnfermeiro.HorarioEnfermeiroId);
            return(View(horarioATrocarEnfermeiro));
        }
        public async Task <IActionResult> Create([Bind("CleanerId,CleanerName,HospitalId")] Cleaner cleaner)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cleaner);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["HospitalId"] = new SelectList(_context.Hospitals, "HospitalId", "HospitalId", cleaner.HospitalId);
            return(View(cleaner));
        }
示例#18
0
        public async Task <IActionResult> Create([Bind("HorarioPacienteId,DataInicio,Duracao,DataFim,PacienteId")] HorarioPaciente horarioPaciente)
        {
            if (ModelState.IsValid)
            {
                _context.Add(horarioPaciente);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PacienteId"] = new SelectList(_context.Pacientes, "PacienteId", "CC", horarioPaciente.PacienteId);
            return(View(horarioPaciente));
        }
示例#19
0
        public async Task <IActionResult> Create([Bind("TurnoId,Nome,HoraInicio,HoraFim")] Turno turno)
        {
            if (ModelState.IsValid)
            {
                _context.Add(turno);
                await _context.SaveChangesAsync();

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

            return(View(turno));
        }
示例#20
0
        public async Task <IActionResult> Create([Bind("HorarioEnfermeiroId,DataInicioTurno,Duracao,DataFimTurno,TurnoId,EnfermeiroId")] HorarioEnfermeiro horarioEnfermeiro)
        {
            if (ModelState.IsValid)
            {
                _context.Add(horarioEnfermeiro);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EnfermeiroId"] = new SelectList(_context.Enfermeiros, "EnfermeiroId", "CC", horarioEnfermeiro.EnfermeiroId);
            ViewData["TurnoId"]      = new SelectList(_context.Turnos, "TurnoId", "TurnoId", horarioEnfermeiro.TurnoId);
            return(View(horarioEnfermeiro));
        }
        public async Task <IActionResult> EnrollDoctor(EnrollDoctorRequest request)
        {
            var doctor = _context.Doctors.Add(new Doctor()
            {
                FirstName = request.FirstName,
                LastName  = request.LastName,
                Email     = request.Email
            });

            await _context.SaveChangesAsync();

            return(new CreatedAtActionResult("Enroll Doctor", "DoctorsController", new { id = doctor.Entity.IdDoctor }, doctor));
        }
示例#22
0
        public async Task <IActionResult> Create([Bind("EspecialidadeEnfermeiroId,EnfermeiroId,Data_Registo")] EnfermeiroEspecialidade enfermeiroEspecialidade)
        {
            if (ModelState.IsValid)
            {
                _context.Add(enfermeiroEspecialidade);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EnfermeiroId"] = new SelectList(_context.Enfermeiros, "EnfermeiroId", "Nome", enfermeiroEspecialidade.EnfermeiroId);
            ViewData["EspecialidadeEnfermeiroId"] = new SelectList(_context.Set <EspecialidadeEnfermeiro>(), "EspecialidadeEnfermeiroId", "Especialidade", enfermeiroEspecialidade.EspecialidadeEnfermeiroId);
            return(View(enfermeiroEspecialidade));
        }
示例#23
0
        public async Task <IActionResult> Create([Bind("PatologiaId,Nome")] Patologia patologia)
        {
            if (ModelState.IsValid)
            {
                _context.Add(patologia);
                await _context.SaveChangesAsync();

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


            return(View(patologia));
        }
示例#24
0
        public async Task <IActionResult> Create([Bind("MedicoId, NomeEspecialidade, Data_Registo")] MedicoEspecialidade medicoEspecialidade)
        {
            if (ModelState.IsValid)
            {
                _context.Add(medicoEspecialidade);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EspecialidadeMedicoId"] = new SelectList(_context.EspecialidadeMedicos, "EspecialidadeMedicoId", "NomeEspecialidade", medicoEspecialidade.EspecialidadeMedicoId);
            ViewData["MedicoId"] = new SelectList(_context.Medicos, "MedicoId", "Nome", medicoEspecialidade.MedicoId);
            return(View(medicoEspecialidade));
        }
        public async Task <IActionResult> Create([Bind("PatientId,PatientName,DOB,DoctorId,NurseId,HospitalId")] Patient patient)
        {
            if (ModelState.IsValid)
            {
                _context.Add(patient);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DoctorId"]   = new SelectList(_context.Doctors, "DoctorId", "DoctorId", patient.DoctorId);
            ViewData["HospitalId"] = new SelectList(_context.Hospitals, "HospitalId", "HospitalId", patient.HospitalId);
            ViewData["NurseId"]    = new SelectList(_context.Nurses, "NurseId", "NurseId", patient.NurseId);
            return(View(patient));
        }
示例#26
0
        /// <summary>
        /// method to add info in DataBase
        /// "UTF-8" - doesn't work. Work only Encoding.GetEncoding(1251)
        /// Adding list of drugs to database
        /// Export medicines to database from *.txt file
        /// </summary>
        /// <param name="medDrug">List of drugs which need to be saved</param>
        /// <param name="name">short name of file we read</param>
        private async void AddDrugToDb(List <Drugs> medDrug, string name)
        {
            using (var context = new HospitalDbContext())
            {
                foreach (var item in medDrug)
                {
                    context.Medicines.Add(new Medicine()
                    {
                        Name         = item.Name,
                        Manufacturer = new Manufacturer()
                        {
                            FactoryName = item.Manufacturers.FactoryName,
                            Country     = item.Manufacturers.Country,
                        },
                        MedicineType = new MedicineType()
                        {
                            Name = item.Type.Name
                        }
                    });
                }
                await context.SaveChangesAsync();
            }

            MessageBox.Show(@"File " + name + @" imported!", @"Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
示例#27
0
        private async void btnSignUp_Click(object sender, EventArgs e)
        {
            using (var context = new HospitalDbContext())
            {
                var myData = Convert.ToDateTime(lvSchedule.FocusedItem.SubItems[chTime.Index].Text);

                var data = dtpSignPatientDate.Value;
                data = data.AddHours(myData.Hour);
                data = data.AddMinutes(myData.Minute);

                var worker    = context.Users.Include(x => x.Adress).Include(x => x.Position.WorkerPositionType).FirstOrDefault(x => x.Id == _docId);
                var patientId = int.Parse(lvPatients.FocusedItem.SubItems[chId.Index].Text);

                var patient = context.Users.Include(x => x.Adress).Include(x => x.Position.WorkerPositionType).FirstOrDefault(x => x.Id == patientId);
                if (worker != null)
                {
                    context.WorkSchedules.Add(new WorkSchedules()
                    {
                        Data     = data,
                        Patient  = patient,
                        Worker   = worker,
                        WorkRoom = worker.Position.WorkerPositionType.Room
                    });
                }
                await context.SaveChangesAsync();
            }
            Close();
        }
        public async Task <IActionResult> Create(Patient createModel)
        {
            Doctor foundDoctor = await hospitalDb.Doctors.FirstAsync(x => x.Id == createModel.DoctorId);

            if (foundDoctor == null)
            {
                return(RedirectToAction("Create", "Doctor"));
            }
            if (ModelState.IsValid)
            {
                Patient patient = new Patient
                {
                    Name     = createModel.Name,
                    Egn      = createModel.Egn,
                    Lechenie = createModel.Lechenie,
                    Result   = createModel.Result,
                    Price    = createModel.Price,
                    DoctorId = foundDoctor.Id,
                    Doctor   = foundDoctor
                };

                hospitalDb.Add(patient);
                await hospitalDb.SaveChangesAsync();

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

            return(View(createModel));
        }
        public async Task <CreateHospitalResponse> CreateAsync(CreateHospitalRequest request)
        {
            if (_dbContext.Hospitals.GetByName(request.Name) != null)
            {
                return(new CreateHospitalResponse {
                    Result = CreateHospitalResult.AlreadyExists
                });
            }

            //Todo: use AutoMapper
            //Note: relying on NServiceBus to handle exceptions and do exception logging
            var hospital = _dbContext.Hospitals.Add(new Hospital
            {
                Id        = Guid.NewGuid(),
                Name      = request.Name,
                Address   = request.Address,
                CreatedAt = DateTime.UtcNow
            });
            await _dbContext.SaveChangesAsync();

            return(new CreateHospitalResponse
            {
                Result = CreateHospitalResult.Success,
                Entity = hospital
            });
        }
示例#30
0
 public async Task <bool> SaveChangesAsync()
 {
     if (await ctx.SaveChangesAsync() > 0)
     {
         return(true);
     }
     return(false);
 }