public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { var doctorId = _userService.GetUserAuthId(); var appointment = await _context.Appointments.FirstOrDefaultAsync( a => a.AppointmentId == request.AppointmentId && a.DoctorId.Equals(doctorId), cancellationToken); if (appointment is null) { return(new NotFoundResult()); } // the doctor should not be able to modify anything but the doctor notes; if (!request.DoctorId.Equals(appointment.DoctorId) || request.StartDateTime != appointment.StartDateTime || request.DurationMinutes != appointment.DurationMinutes) { return(new UnauthorizedResult()); } appointment.DoctorNotes = request.DoctorNotes; await _context.SaveChangesAsync(cancellationToken); return(new NoContentResult()); }
public async Task <BowelMovementEventDto> Handle(Command request, CancellationToken cancellationToken) { // convert to EFCore entity - BowelMovementEvent; var bme = new BowelMovementEvent { PatientId = request.PatientId, DateTime = request.DateTime, ContainedBlood = request.ContainedBlood, ContainedMucus = request.ContainedMucus }; // add to DB and save changes; await _context.BowelMovementEvents.AddAsync(bme, cancellationToken); await _context.SaveChangesAsync(cancellationToken); // convert to DTO to follow the best practice of not returning entire EFCore // entities in JSON body responses; // // ID is auto-generated by DB on addition and updated by EFCore so // that it exists on the bme object; return(new() { BowelMovementEventId = bme.BowelMovementEventId, PatientId = bme.PatientId, DateTime = bme.DateTime, ContainedBlood = bme.ContainedBlood, ContainedMucus = bme.ContainedMucus }); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { var currentUserId = _userService.GetUserAuthId(); // if already is registered return HTTP Bad Request result; if (await _userService.IsRegistered()) { return(new BadRequestResult()); } await _authService.RegisterDoctor(currentUserId); var doctor = new Doctor { DoctorId = _userService.GetUserAuthId(), Name = request.Name, Location = request.Location, OfficeHours = request.OfficeHours, IsApproved = false }; await _context.Doctors.AddAsync(doctor, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(new OkResult()); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { var patientId = _userService.GetUserAuthId(); var informationRequest = await _context.InformationRequests .FirstOrDefaultAsync(i => i.InformationRequestId == request.InformationRequestId && i.PatientId.Equals(patientId), cancellationToken); if (informationRequest is null) { return(new NotFoundResult()); } if (informationRequest.PatientId != patientId || informationRequest.DoctorId != request.DoctorId || informationRequest.RequestedDataFrom != request.RequestedDataFrom || informationRequest.RequestedDataTo != request.RequestedDataTo || informationRequest.RequestedPain != request.RequestedPain || informationRequest.RequestedBms != request.RequestedBms) { return(new UnauthorizedResult()); } informationRequest.IsActive = request.IsActive; await _context.SaveChangesAsync(cancellationToken); return(new NoContentResult()); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { var patientId = _userService.GetUserAuthId(); var bme = await _context.BowelMovementEvents.FirstOrDefaultAsync(b => b.BowelMovementEventId == request.BowelMovementEventId, cancellationToken); if (bme is null) { return(new NotFoundResult()); } // the patient should not be able to assign an BME to another patient; if (!patientId.Equals(bme.PatientId)) { return(new UnauthorizedResult()); } bme.DateTime = request.DateTime; bme.ContainedBlood = request.ContainedBlood; bme.ContainedMucus = request.ContainedMucus; await _context.SaveChangesAsync(cancellationToken); return(new NoContentResult()); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { // get the appointment that has been requested to be cancelled; var doctorId = _userService.GetUserAuthId(); var appointment = await _context.Appointments.FirstOrDefaultAsync( a => a.AppointmentId == request.AppointmentId && a.DoctorId.Equals(doctorId), cancellationToken); if (appointment is null) { return(new NotFoundResult()); } // remove the appointment from DB and save the changes; _context.Appointments.Remove(appointment); await _context.SaveChangesAsync(cancellationToken); // send confirmation email to the doctor in the background; // in the background so that the HTTP POST response does not have to wait for email to be sent; var doctorEmail = _userService.GetEmailOrDefault(); if (doctorEmail is not null) { BackgroundJob.Enqueue <IEmailService>(s => s.SendAppointmentCancellationConfirmationEmail(request.AppointmentId, doctorEmail)); } return(new NoContentResult()); }
public async Task <BowelMovementEventDto> Handle(Command request, CancellationToken cancellationToken) { // convert to EFCore entity; var patientId = _userService.GetUserAuthId(); var bme = new BowelMovementEvent { PatientId = patientId, DateTime = request.DateTime, ContainedBlood = request.ContainedBlood, ContainedMucus = request.ContainedMucus }; await _context.BowelMovementEvents.AddAsync(bme, cancellationToken); await _context.SaveChangesAsync(cancellationToken); // convert to DTO; return(new() { BowelMovementEventId = bme.BowelMovementEventId, PatientId = bme.PatientId, DateTime = bme.DateTime, ContainedBlood = bme.ContainedBlood, ContainedMucus = bme.ContainedMucus }); }
public async Task <PainEventDto> Handle(Command request, CancellationToken cancellationToken) { var patientId = _userService.GetUserAuthId(); // convert to EFCore entity; var pe = new PainEvent { PatientId = patientId, DateTime = request.DateTime ?? DateTime.UtcNow, MinutesDuration = request.MinutesDuration, PainScore = request.PainScore }; // add to db and save; await _context.PainEvents.AddAsync(pe, cancellationToken); await _context.SaveChangesAsync(cancellationToken); // convert to dto so can be returned with ActionResult; return(new PainEventDto { PainEventId = pe.PainEventId, PatientId = pe.PatientId, DateTime = pe.DateTime, MinutesDuration = pe.MinutesDuration, PainScore = pe.PainScore }); }
public async Task <InformationRequestDto> Handle(Command request, CancellationToken cancellationToken) { var ir = new InformationRequest { DoctorId = _userService.GetUserAuthId(), IsActive = request.IsActive, PatientId = request.PatientId, RequestedBms = request.RequestedBms, RequestedPain = request.RequestedPain, RequestedDataFrom = request.RequestedDataFrom, RequestedDataTo = request.RequestedDataTo }; await _context.InformationRequests.AddAsync(ir, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(new() { InformationRequestId = ir.InformationRequestId, DoctorId = ir.DoctorId, IsActive = ir.IsActive, PatientId = ir.PatientId, RequestedBms = ir.RequestedBms, RequestedPain = ir.RequestedPain, RequestedDataFrom = ir.RequestedDataFrom, RequestedDataTo = ir.RequestedDataTo }); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { var doctor = await _context.Doctors .FirstOrDefaultAsync(d => d.DoctorId.Equals(_userService.GetUserAuthId()), cancellationToken); if (doctor is null) { return(new BadRequestResult()); } doctor.OfficeHours = request.OfficeHours.ToList(); await _context.SaveChangesAsync(cancellationToken); return(new NoContentResult()); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { var res = await _context.GlobalNotifications .FirstOrDefaultAsync(n => n.GlobalNotificationId == request.Id, cancellationToken); if (res is null) { return(new NotFoundResult()); } _context.GlobalNotifications.Remove(res); await _context.SaveChangesAsync(cancellationToken); return(new NoContentResult()); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { // get the food item that has been requested to be deleted; var fi = await _context.FoodItems.FirstOrDefaultAsync(f => f.FoodItemId == request.Id, cancellationToken); if (fi is null) { return(new NotFoundResult()); } // remove the food item from DB and save the changes; _context.FoodItems.Remove(fi); await _context.SaveChangesAsync(cancellationToken); return(new NoContentResult()); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { var fi = await _context.FoodItems.FirstOrDefaultAsync(f => f.FoodItemId == request.FoodItemId, cancellationToken); if (fi is null) { return(new NotFoundResult()); } fi.Name = request.Name; fi.PictureUrl = request.PictureUrl; await _context.SaveChangesAsync(cancellationToken); return(new NoContentResult()); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { // get the BME that was requested to be deleted; var bme = await _context.BowelMovementEvents.FirstOrDefaultAsync( b => b.BowelMovementEventId == request.Id, cancellationToken); if (bme is null) { return(new NotFoundResult()); } // remove the BME and save the change; _context.BowelMovementEvents.Remove(bme); await _context.SaveChangesAsync(cancellationToken); return(new NoContentResult()); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { // get the appointment that has been requested to be deleted; var appointment = await _context.Appointments.FirstOrDefaultAsync(a => a.AppointmentId == request.Id, cancellationToken); if (appointment is null) { return(new NotFoundResult()); } // remove the appointment from DB and save the changes; _context.Appointments.Remove(appointment); await _context.SaveChangesAsync(cancellationToken); return(new NoContentResult()); }
public async Task <GlobalNotificationDto> Handle(Command request, CancellationToken cancellationToken) { // convert to EFCore entity; var notification = new GlobalNotification(request.Title, request.Message, request.Url); await _context.GlobalNotifications.AddAsync(notification, cancellationToken); await _context.SaveChangesAsync(cancellationToken); // convert result of the insertion to dto; return(new() { GlobalNotificationId = notification.GlobalNotificationId, Message = notification.Message, Title = notification.Title, Url = notification.Url }); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { var patientId = _userService.GetUserAuthId(); // get the appointment that has been requested to be deleted; var bme = await _context.BowelMovementEvents.FirstOrDefaultAsync( b => b.BowelMovementEventId == request.BowelMovementEventId && b.PatientId.Equals(patientId), cancellationToken); if (bme is null) { return(new NotFoundResult()); } _context.BowelMovementEvents.Remove(bme); await _context.SaveChangesAsync(cancellationToken); return(new NoContentResult()); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { var patientId = _userService.GetUserAuthId(); // get the settings that need to be modified; var settings = await _context.PatientApplicationSettings .FirstOrDefaultAsync(s => s.PatientId.Equals(patientId), cancellationToken); if (settings is null) { return(new NotFoundResult()); } settings.ShareDataForResearch = request.ShareDataForResearch; await _context.SaveChangesAsync(cancellationToken); return(new NoContentResult()); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { var notification = await _context.GlobalNotifications.FirstOrDefaultAsync( gn => gn.GlobalNotificationId == request.GlobalNotificationId, cancellationToken); if (notification is null) { return(new NotFoundResult()); } notification.Title = request.Title; notification.Message = request.Message; notification.TailwindColour = request.TailwindColour; notification.Url = request.Url; await _context.SaveChangesAsync(cancellationToken); return(new NoContentResult()); }
public async Task <MealDto> Handle(Command request, CancellationToken cancellationToken) { // convert to EFCore Meal entity; var patientId = _userService.GetUserAuthId(); var meal = new Meal { PatientId = patientId, Name = request.Name, }; foreach (var foodItemId in request.FoodItemIds) { var fi = await _context.FoodItems.FirstOrDefaultAsync(f => f.FoodItemId == foodItemId, cancellationToken); if (fi is null) { throw new KeyNotFoundException($"FoodItem with ID {foodItemId.ToString()} does not exist"); } meal.FoodItems.Add(fi); } // add to db and save; await _context.Meals.AddAsync(meal, cancellationToken); await _context.SaveChangesAsync(cancellationToken); // convert to dto so can be returned with ActionResult; return(new() { MealId = meal.MealId, Name = meal.Name, PatientId = meal.PatientId, FoodItems = meal.FoodItems.Select(fi => new FoodItemDto { FoodItemId = fi.FoodItemId, Name = fi.Name, PictureUrl = fi.PictureUrl }).ToList() }); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { // find the BME to modify; var bme = await _context.BowelMovementEvents .FirstOrDefaultAsync(b => b.BowelMovementEventId == request.BowelMovementEventId, cancellationToken); if (bme is null) { return(new NotFoundResult()); } bme.PatientId = request.PatientId; bme.DateTime = request.DateTime; bme.ContainedBlood = request.ContainedBlood; bme.ContainedMucus = request.ContainedMucus; await _context.SaveChangesAsync(cancellationToken); return(new NoContentResult()); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { var doctorToVerify = await _context.Doctors .FirstOrDefaultAsync(d => d.DoctorId.Equals(request.DoctorId), cancellationToken); if (doctorToVerify is null) { return(new NotFoundResult()); } if (doctorToVerify.IsApproved) { return(new BadRequestResult()); } doctorToVerify.IsApproved = true; await _context.SaveChangesAsync(cancellationToken); return(new NoContentResult()); }
public async Task <FoodItemDto> Handle(Command request, CancellationToken cancellationToken) { // convert to EFCore entity - FoodItem; var fi = new FoodItem(request.Name, request.PictureUrl); // add to DB and save changes; await _context.FoodItems.AddAsync(fi, cancellationToken); await _context.SaveChangesAsync(cancellationToken); // convert to DTO to follow the best practice of not returning entire EFCore // entities in JSON body responses; // // ID is auto-generated by DB on addition and updated by EFCore so // that it exists on the bme object; return(new() { FoodItemId = fi.FoodItemId, Name = fi.Name, PictureUrl = fi.PictureUrl }); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { var appointment = await _context.Appointments.FirstOrDefaultAsync(a => a.AppointmentId == request.AppointmentId, cancellationToken); if (appointment is null) { return(new NotFoundResult()); } appointment.PatientId = request.PatientId; appointment.DoctorId = request.DoctorId; appointment.StartDateTime = request.StartDateTime; appointment.DurationMinutes = request.DurationMinutes; appointment.DoctorNotes = request.DoctorNotes; appointment.PatientNotes = request.PatientNotes; await _context.SaveChangesAsync(cancellationToken); return(new NoContentResult()); }
public async Task <MealEventDto> Handle(Command request, CancellationToken cancellationToken) { var patientId = _userService.GetUserAuthId(); var mealEvent = new MealEvent { PatientId = patientId, MealId = request.MealId, DateTime = request.DateTime ?? DateTime.UtcNow }; await _context.MealEvents.AddAsync(mealEvent, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(new() { MealEventId = mealEvent.MealEventId, MealId = mealEvent.MealId, PatientId = mealEvent.PatientId, DateTime = mealEvent.DateTime }); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { var doctorId = _userService.GetUserAuthId(); var medication = await _context.Medications .FirstOrDefaultAsync(m => m.MedicationId == request.MedicationId, cancellationToken); if (medication is null) { return(new BadRequestResult()); } var patient = await _context.Patients .FirstOrDefaultAsync(p => p.DoctorId != null && p.PatientId.Equals(request.PatientId) && p.DoctorId.Equals(doctorId), cancellationToken); if (patient is null) { return(new UnauthorizedResult()); } var prescription = new Prescription { DoctorInstructions = request.DoctorInstructions, StartDateTime = request.StartDate, EndDateTime = request.EndDate, PatientId = request.PatientId, DoctorId = doctorId, MedicationId = request.MedicationId }; await _context.Prescriptions.AddAsync(prescription, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(new NoContentResult()); }
public async Task <ActionResult> Handle(Command request, CancellationToken cancellationToken) { var currentUserId = _userService.GetUserAuthId(); // if already is registered return HTTP Bad Request result; if (await _userService.IsRegistered()) { return(new BadRequestResult()); } await _auth0.RegisterPatient(currentUserId); var patient = new Patient(request.Name, request.IbdType, request.DateOfBirth, request.DateDiagnosed, request.DoctorId) { PatientId = currentUserId }; await _context.Patients.AddAsync(patient, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(new OkResult()); }
public async Task <AppointmentDto> Handle(Command request, CancellationToken cancellationToken) { var patientId = _userService.GetUserAuthId(); // convert to appointment; var appointment = new Appointment(patientId, request.DoctorId, request.StartDateTime, request.DurationMinutes, request.DoctorNotes, request.PatientNotes); // add to DB and save changes; await _context.Appointments.AddAsync(appointment, cancellationToken); await _context.SaveChangesAsync(cancellationToken); // send confirmation email to the patient in the background; // in the background so that the HTTP POST response does not have to wait for email to be sent; var patientEmail = _userService.GetEmailOrDefault(); if (patientEmail is not null) { BackgroundJob.Enqueue <IEmailService>(s => s.SendAppointmentBookingConfirmationEmail(appointment, patientEmail)); } // convert to DTO so that we don't return the entire EFCore entity with our JSON; return(new() { AppointmentId = appointment.AppointmentId, PatientId = appointment.PatientId, DoctorId = appointment.DoctorId, StartDateTime = appointment.StartDateTime, DurationMinutes = appointment.DurationMinutes, DoctorNotes = appointment.DoctorNotes, PatientNotes = appointment.PatientNotes }); }
public async Task <AppointmentDto> Handle(Command request, CancellationToken cancellationToken) { // convert to appointment; var appointment = new Appointment(request.PatientId, request.DoctorId, request.StartDateTime, request.DurationMinutes, request.DoctorNotes, request.PatientNotes); // add to DB and save changes; await _context.Appointments.AddAsync(appointment, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(new() { AppointmentId = appointment.AppointmentId, PatientId = appointment.PatientId, DoctorId = appointment.DoctorId, StartDateTime = appointment.StartDateTime, DurationMinutes = appointment.DurationMinutes, DoctorNotes = appointment.DoctorNotes, PatientNotes = appointment.PatientNotes }); }