public async Task <IActionResult> Post([FromBody] AppointmentCreate appointmentDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var doctorExist = _context.Users.Any(x => x.Id == appointmentDto.DoctorId);

            if (!doctorExist)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }
            var duplicateHour = _context.Appointments
                                .Any(ap => ap.Hour == appointmentDto.Hour && ap.DoctorId == appointmentDto.DoctorId && ap.Date.Date == appointmentDto.Date.Date);

            if (duplicateHour)
            {
                return(BadRequest("Doctor is busy in this hour"));
            }

            var appointment = _mapper.Map <Appointment>(appointmentDto);

            appointment.StatusId  = (int)StatusEnum.Coming;
            appointment.Notify    = true;
            appointment.PatientId = int.Parse(User.FindFirst(user => user.Type == ClaimTypes.NameIdentifier).Value);

            await _context.Appointments.AddAsync(appointment);

            await _context.SaveChangesAsync();

            return(StatusCode(StatusCodes.Status201Created));
        }
        public bool CreateAppointment(AppointmentCreate model)
        {
            // if (model.AppointmentDate > DateTime.Now)
            //{
            var entity =
                new Appointment()
            {
                OwnerID           = _userId,
                AppointmentDate   = model.AppointmentDate,
                StartTime         = model.StartTime,
                EndTime           = model.EndTime,
                TypeOfAppointment = model.TypeOfAppointment,
                AppointmentReason = model.AppointmentReason,
                ClientId          = model.ClientId,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Appointments.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
            //}
            //else
            //{

            //    return false;
            //}
        }
Exemplo n.º 3
0
        public async Task Delete_Appointment_And_Return_Success()
        {
            const string expected_description = "This is description";
            var          dummy_entity_create  = new AppointmentCreate()
            {
                Description = expected_description
            };

            var entity = await this.PostAsync <Appointment, AppointmentCreate>(
                data : dummy_entity_create,
                expectedStatusCode : HttpStatusCode.Created
                );

            Assert.NotNull(entity);
            Assert.Equal(expected_description, entity.Result.Description);

            var id = entity.Result.Id;

            var entityDeleted = await this.DeleteAsync <Appointment, AppointmentCreate>(
                url : $"{this.Url}/{id}"
                );

            Assert.NotNull(entityDeleted);
            Assert.Equal(expected_description, entityDeleted.Result.Description);

            await this.GetAsync <Appointment>($"{this.Url}/{id}",
                                              successStatusCode : false,
                                              deserialize : true,
                                              expectedStatusCode : HttpStatusCode.NotFound
                                              );
        }
        //private readonly Guid _userID;

        //public AppointmentService(Guid userID)
        //{
        //    _userID = userID;
        //}

        public bool CreateAppointment(AppointmentCreate model)
        {
            var entity =
                new Appointment()
            {
                AppointmentDate = model.AppointmentDate,
                StartTime       = model.StartTime,
                EndTime         = model.EndTime,
                IsAvailable     = true,
                NumberOfAppointmentsAvailable = model.NumberOfAppointmentsAvailable,
            };

            _context.Appointments.Add(entity);

            //Trying to make multiple copies
            for (int i = 0; i < model.NumberOfAppointmentsAvailable - 1; i++)
            {
                var entityClone =
                    new Appointment()
                {
                    AppointmentDate = model.AppointmentDate,
                    StartTime       = model.StartTime,
                    EndTime         = model.EndTime,
                    IsAvailable     = true,
                };

                _context.Appointments.Add(entityClone);
                //_context.SaveChanges(); may need this
            }

            return(_context.SaveChanges() == model.NumberOfAppointmentsAvailable);
        }
Exemplo n.º 5
0
        public async Task Create_Appointment_And_Return_Created()
        {
            const string expected_description = "This is description";
            var          dummy_entity         = new AppointmentCreate()
            {
                Description = expected_description
            };

            var entityCreated = await this.PostAsync <Appointment, AppointmentCreate>(
                data : dummy_entity,
                url : $"{this.Url}",
                expectedStatusCode : HttpStatusCode.Created
                );

            Assert.NotNull(entityCreated);
            Assert.Equal(expected_description, entityCreated.Result.Description);

            var entity = await this.GetAsync <Appointment>($"{this.Url}/{entityCreated.Result.Id}",
                                                           successStatusCode : true,
                                                           deserialize : true
                                                           );

            Assert.NotNull(entity);
            Assert.Equal(expected_description, entity.Result.Description);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            AppointmentCreate appointmentcreate = db.AppointmentCreates.Find(id);

            db.AppointmentCreates.Remove(appointmentcreate);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 7
0
        public async Task Validate_Correct_Entity()
        {
            var expected_errors = 0;
            var dummy_entity    = new AppointmentCreate()
            {
                Description = "this is a description"
            };
            var validator = new AppointmentCreateValidator();
            var result    = await validator.ValidateAsync(dummy_entity);

            Assert.True(result.IsValid);
            Assert.Equal(expected_errors, result.Errors.Count);
        }
Exemplo n.º 8
0
        public async Task <IActionResult> CreateAppointment(AppointmentCreate model)
        {
            try
            {
                await _repository.AddAppointment(model);

                return(NoContent());
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 9
0
        public async Task Validate_Empty_Description_Return_Is_Invalid()
        {
            var expected_errors = 1;
            var dummy_entity    = new AppointmentCreate()
            {
                Description = String.Empty
            };
            var validator = new AppointmentCreateValidator();
            var result    = await validator.ValidateAsync(dummy_entity);

            Assert.False(result.IsValid);
            Assert.Equal(expected_errors, result.Errors.Count);
        }
Exemplo n.º 10
0
        public bool CreateAppointment(AppointmentCreate model)
        {
            var entity = new Appointment
            {
                PetId             = model.PetId,
                DateTime          = model.DateTime,
                ServiceProviderId = model.ServiceProviderId,
                ServiceType       = model.ServiceType
            };

            _dbContext.Appointments.Add(entity);
            return(_dbContext.SaveChanges() == 1);
        }
        // GET: /AppointmentCreate/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AppointmentCreate appointmentcreate = db.AppointmentCreates.Find(id);

            if (appointmentcreate == null)
            {
                return(HttpNotFound());
            }
            return(View(appointmentcreate));
        }
        public ActionResult Edit([Bind(Include = "AppointmentCreateId,TimeId,Date,Serial,PatientName,PhonNum,AppId,ProblemId")] AppointmentCreate appointmentcreate)
        {
            if (ModelState.IsValid)
            {
                db.Entry(appointmentcreate).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TimeId = new SelectList(db.Times, "TimeId", "Time1", db.Times);
            ViewBag.AppId  = new SelectList(db.AppTypes, "AppId", "AppType1", db.AppTypes);

            ViewBag.ProblemId = new SelectList(db.Problems, "ProblemId", "Problem1", db.Problems);
            return(View(appointmentcreate));
        }
Exemplo n.º 13
0
        public async Task Create_Appointment_And_Return_Argument_Exception()
        {
            var dummy_entity = new AppointmentCreate()
            {
                Description = string.Empty
            };

            await Assert.ThrowsAsync <ArgumentException>(async() =>
                                                         await this.PostAsync <AppointmentCreate, AppointmentCreate>(
                                                             data: dummy_entity,
                                                             url: $"{this.Url}",
                                                             expectedStatusCode: HttpStatusCode.NotFound
                                                             )
                                                         );
        }
        public ActionResult Create(AppointmentCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var service = CreateAppointmentService();

            if (service.CreateAppointment(model))
            {
                TempData["SaveResult"] = "New Appointment created.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Appointment could not be created.");
            return(View(model));
        }
        public ActionResult Post([FromBody] AppointmentCreate dto)
        {
            // If All Required Fields present
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            // Date should be future
            if (dto.Date < DateTime.Today)
            {
                ModelState.AddModelError("Date", "Min Date is Today");
                return(BadRequest(ModelState));
            }
            // Time Range
            if (dto.Date.Hour < 9 && dto.Date.Hour > 18)
            {
                ModelState.AddModelError("Time", "Time should be between 9AM and 6PM");
                return(BadRequest(ModelState));
            }
            // One appointment per day per doctor
            if (context.Appointments.Any(X => X.DoctorId == dto.DoctorId && X.Date.Date == dto.Date.Date))
            {
                ModelState.AddModelError("DoctorId", "Only One Appointment Per Doctor Per Day");
                return(BadRequest(ModelState));
            }
            // Limit Appointment Per Week
            var week = System.Globalization.ISOWeek.GetWeekOfYear(dto.Date);

            if (context.Appointments.Where(X => System.Globalization.ISOWeek.GetWeekOfYear(X.Date) == week).Count() > 5)
            {
                ModelState.AddModelError("Date", "Maximum Appointments Should be 5 per week");
                return(BadRequest(ModelState));
            }
            var entity = new Data.Entities.Appointment
            {
                Name     = dto.Name,
                Date     = dto.Date,
                Email    = dto.Email,
                Message  = dto.Message,
                DoctorId = dto.DoctorId
            };

            context.Appointments.Add(entity);
            context.SaveChanges();
            return(Ok());
        }
Exemplo n.º 16
0
        public bool CreateAppointmentService(AppointmentCreate model)
        {
            var entity =
                new Appointment()
            {
                AppointmentDate = model.AppointmentDate,
                AppointmentTime = model.AppointmentTime,
                Address         = model.Address,
                HairServiceID   = model.HairServiceID,
                UserID          = _userID
            };

            using (var apt = new ApplicationDbContext())
            {
                apt.Appointments.Add(entity);
                return(apt.SaveChanges() == 1);
            }
        }
Exemplo n.º 17
0
        public bool CreateAppointment(AppointmentCreate model)
        {
            var entity = new Appointment()
            {
                ScheduledStart = model.ScheduledStart,
                Length         = model.Length,
                PatientId      = model.PatientId,
                ProviderId     = model.ProviderId,
                Created        = DateTimeOffset.Now,
                CreatedBy      = _userId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Appointments.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 18
0
        public async Task Update_Appointment_And_Return_Argument_Exception()
        {
            var dummy_entity_update = new AppointmentCreate()
            {
                Description = string.Empty
            };

            var id = Guid.NewGuid();

            await Assert.ThrowsAsync <ArgumentException>(async() =>
                                                         await this.PutAsync <Appointment, AppointmentCreate>(
                                                             data: dummy_entity_update,
                                                             url: $"{this.Url}/{id}",
                                                             successStatusCode: false,
                                                             expectedStatusCode: HttpStatusCode.NotFound,
                                                             deserialize: false
                                                             )
                                                         );
        }
Exemplo n.º 19
0
        public async override Task <AppointmentView> Execute(CreateAppointmentCommand command, User?user)
        {
            var create = new AppointmentCreate(
                command.ServiceId,
                command.ClientId,
                command.Price,
                command.Notes
                );

            create.Blocks = command.Blocks.Select(b => new AppointmentBlockCreate(
                                                      b.Start,
                                                      b.End
                                                      )).ToList();

            var appointment = await service.Create(create, user !);

            throw new NotImplementedException();
            // return mapper.Map<Appointment, AppointmentView>(appointment);
        }
      public ActionResult Create(AppointmentCreate model)
      {
          if (!ModelState.IsValid)
          {
              return(View(model));
          }

          var service = CreateAppointmentService();

          if (service.CreateAppointment(model))
          {
              TempData["SaveResult"] = "Your appointment request has been submitted! One of our stylists will reach out to you shortly!";
              return(RedirectToAction("Index", "Inventory"));
          }
          ;

          ModelState.AddModelError("", "Appointment could not be submitted at this time.");

          return(View(model));
      }
Exemplo n.º 21
0
        public async Task Update_Appointment_And_Return_Not_Found()
        {
            const string expected_description_update = "This is description Updated";
            var          dummy_entity_update         = new AppointmentCreate()
            {
                Description = expected_description_update
            };

            var id = Guid.NewGuid();

            var entityUpdated = await this.PutAsync <Appointment, AppointmentCreate>(
                data : dummy_entity_update,
                url : $"{this.Url}/{id}",
                successStatusCode : false,
                expectedStatusCode : HttpStatusCode.NotFound,
                deserialize : false
                );

            Assert.Null(entityUpdated);
        }
        // GET: /AppointmentCreate/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AppointmentCreate appointmentcreate = db.AppointmentCreates.Find(id);

            if (appointmentcreate == null)
            {
                return(HttpNotFound());
            }


            ViewBag.TimeId = new SelectList(db.Times, "TimeId", "Time1", db.Times);
            ViewBag.AppId  = new SelectList(db.AppTypes, "AppId", "AppType1", db.AppTypes);

            ViewBag.ProblemId = new SelectList(db.Problems, "ProblemId", "Problem1", db.Problems);
            return(View(appointmentcreate));
        }
Exemplo n.º 23
0
        public bool CreateAppointment(AppointmentCreate model)
        {
            var entity =
                new Appointment()
            {
                CustomerID        = _userId,
                DateOfAppointment = model.DateOfAppointment,
                StylistID         = model.StylistID,
                Comment           = model.Comment,
                CustomerFirstName = model.CustomerFirstName,
                CustomerLastName  = model.CustomerLastName,
                TypeOfAppointment = model.TypeOfAppointment,
                EmailAddress      = model.EmailAddress,
                PhoneNumber       = model.PhoneNumber
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Appointments.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 24
0
        public async Task <IActionResult> UpdateAppointment(int apptId, AppointmentCreate model)
        {
            try
            {
                if (apptId != model.Id)
                {
                    return(BadRequest(new ErrorResponse {
                        ErrorMessage = "Id does not match"
                    }));
                }

                model.Date.AddHours(1);

                //(string, bool, bool) updated = await _repository.UpdateAppointment(model);
                var updated = await _repository.UpdateAppointment(model);

                //updateAppointmentResponse updateAppointmentResponse = new updateAppointmentResponse
                //{
                //    CheckinMessage = updated.Item1,
                //    IsCheckedIn = updated.Item2,
                //    IsUpdated = updated.Item3
                //};

                //if (!updated.Item3)
                //    return BadRequest(new ErrorResponse { ErrorMessage = "Record Not Found" });

                if (!updated.Item1)
                {
                    return(BadRequest(new ErrorResponse {
                        ErrorMessage = "Record Not Found"
                    }));
                }


                if (model.StatusId == 3 && updated.Item2 != null)
                {
                    var patient = await _patientRepo.GetPatientById(model.PatientNo, (int)model.AccountId);

                    var plantype = await _patientRepo.GetPatientPlantype(patient.Plantype);

                    if (plantype != null)
                    {
                        // checks if its a private patient
                        if (plantype.payerid == 1162 && plantype.plantypeid == 32)
                        {
                            // check if this private patient has ever been billed for registration
                            var regBill = await _billingRepository.CheckPrivatePatientBillForRegistration(model.PatientNo, (int)model.AccountId);

                            if (regBill == null)
                            {
                                // if there is no registration bill record for this private
                                // patient a reg bill is added for him or her
                                // add bill
                                BillingInvoice regBillingInvoice = new BillingInvoice()
                                {
                                    patientid   = model.PatientNo,
                                    ProviderID  = model.AccountId,
                                    locationid  = model.LocationId,
                                    encodedby   = int.Parse(model.Adjuster),
                                    encounterId = updated.Item2
                                };

                                var regBillResult = await _billingRepository.WritePatientRegistrationBill(regBillingInvoice);
                            }

                            // add bill
                            BillingInvoice billingInvoice = new BillingInvoice()
                            {
                                patientid   = model.PatientNo,
                                ProviderID  = model.AccountId,
                                locationid  = model.LocationId,
                                encodedby   = int.Parse(model.Adjuster),
                                encounterId = updated.Item2
                            };

                            var billResult = await _billingRepository.WritePatientConsultationBill(billingInvoice);
                        }
                    }
                }

                return(Ok(updated));
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }