public Task <bool> Handle(RegisterConsultationCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { NotifyValidationErrors(request); return(Task.FromResult(false)); } var consultation = new Consultation(Guid.NewGuid(), request.DoctorId, request.PatientId, request.TreatmentRoomId, request.RegistrationDate, request.ConsultationDate); var treatmentRoom = _treatmentRoomRepository.GetById(request.TreatmentRoomId); if (_doctorRepository.IsDoctorReservedByHour(request.DoctorId, request.ConsultationDate)) { _mediator.RaiseEvent(new DomainNotification(request.MessageType, "Doctor's timetable is already taken.")); return(Task.FromResult(false)); } if (_patientRepository.isPatientCovid19(request.PatientId)) { if (!_doctorRepository.IsDoctorPulmonologist(request.DoctorId)) { _mediator.RaiseEvent(new DomainNotification(request.MessageType, "Doctor must be a Pulmologist.")); return(Task.FromResult(false)); } if (!_treatmentRoomRepository.isTreatmentRoomEquipped(request.TreatmentRoomId)) { _mediator.RaiseEvent(new DomainNotification(request.MessageType, "Treatment room must not be empty.")); return(Task.FromResult(false)); } } else { if (!_doctorRepository.IsDoctorGeneralPractitioner(request.DoctorId)) { _mediator.RaiseEvent(new DomainNotification(request.MessageType, "Doctor must be a General practitioner.")); return(Task.FromResult(false)); } } _consultationRepository.Add(consultation); if (!Commit()) { return(Task.FromResult(true)); } _mediator.SendCommand(new ReserveDoctorCommand(consultation.DoctorId, consultation.ConsultationDate, consultation.Id)); _mediator.SendCommand(new ReserveTreatmentRoomCommand(consultation.TreatmentRoomId, consultation.ConsultationDate, treatmentRoom.TreatmentMachineId)); return(Task.FromResult(true)); }
public Task <bool> Handle(EquipTreatmentRoomWithMachineCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { NotifyValidationErrors(request); return(Task.FromResult(false)); } var existingTreatmentRoom = _treatmentRoomRepository.GetById(request.Id); var treatmentRoom = new TreatmentRoom(existingTreatmentRoom.Id, request.TreatmentMachineId, existingTreatmentRoom.Name); _treatmentRoomRepository.Update(treatmentRoom); if (Commit()) { _mediator.RaiseEvent(new TreatmentRoomEquippedWithMachineEvent(existingTreatmentRoom.Id, existingTreatmentRoom.TreatmentMachineId)); } return(Task.FromResult(true)); }
public TreatmentRoomViewModel GetById(Guid id) { return(_mapper.Map <TreatmentRoomViewModel>(_treatmentRoomRepository.GetById(id))); }