Exemple #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="appointmentRepository"></param>
 /// <param name="appointmentEquipmentIsAvailableValidator"></param>
 /// <param name="appointmentPatientMustExistRuleValidator"></param>
 /// <param name="mediator"></param>
 public BookAppointmentCommandHandler(IAppointmentRepository appointmentRepository, IBaseRepository <Patient> repository, IEquipmentService equipmentService, IAppointmentEquipmentIsAvailableValidator appointmentEquipmentIsAvailableValidator, IAppointmentPatientMustExistRuleValidator appointmentPatientMustExistRuleValidator, IMediator mediator)
 {
     _appointmentRepository = appointmentRepository;
     _repository            = repository;
     _equipmentService      = equipmentService;
     _appointmentEquipmentIsAvailableValidator = appointmentEquipmentIsAvailableValidator;
     _appointmentPatientMustExistRuleValidator = appointmentPatientMustExistRuleValidator;
     _mediator = mediator;
 }
 /// <summary>
 ///  Appointment Patient Must Exist Rule
 /// </summary>
 /// <param name="appointmentBookingTimeSlotRule"></param>
 /// <param name="appointmentDate"></param>
 public AppointmentPatientMustExistRule(IAppointmentPatientMustExistRuleValidator appointmentPatientMustExistRuleValidator, int patientId)
 {
     _appointmentPatientMustExistRuleValidator = appointmentPatientMustExistRuleValidator;
     _patientId = patientId;
 }
        /// <summary>
        /// BookAppointment
        /// </summary>
        /// <param name="patientId"></param>
        /// <param name="equipmentId"></param>
        /// <param name="referenceCode"></param>
        /// <param name="appointmentDate"></param>
        /// <param name="patientMustExistRuleValidator"></param>
        /// <param name="timeSlotRuleValidator"></param>
        /// <param name="appointmentDateIsLessThanTwoWeeksInAdvanceRuleValidator"></param>
        /// <returns></returns>
        public static Appointment BookAppointment(int patientId, int equipmentId, string referenceCode, DateTime appointmentDate, TimeSpan startTime, TimeSpan endTime, IAppointmentEquipmentIsAvailableValidator appointmentEquipmentIsAvailableValidator, IAppointmentPatientMustExistRuleValidator patientMustExistRuleValidator)
        {
            // validate the business rules

            // Appointments can only be made for 2 weeks later at most.
            ValidateBusinessRule(new AppointmentIsLessThanTwoWeeksInAdvanceRule(appointmentDate));

            // Assumption that the patient has to registered for them to be able to book an appointment.
            ValidateBusinessRule(new AppointmentPatientMustExistRule(patientMustExistRuleValidator, patientId));

            // Appointments can be made between 08:00 and 16:00. An appointment takes 1 hour.
            ValidateBusinessRule(new AppointmentBookingTimeSlotRule(startTime, endTime));

            ValidateBusinessRule(new AppointmentEquipmentIsAvailableRule(appointmentEquipmentIsAvailableValidator, appointmentDate, startTime, endTime));

            return(new Appointment(patientId, equipmentId, referenceCode, appointmentDate, startTime, endTime));
        }