示例#1
0
        public AppointmentCollection Find(DataTypes.AppointmentSearchCriteria criteria)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException("criteria");
            }

            BMS.AppointmentSearchCriteria businessCriteria = AppointmentTranslator.TranslateSearchCriteria(criteria);

            List <BMS.Appointment> businessAppointments = new List <BMS.Appointment>(Helper.GetApplication().Find(businessCriteria));

            return(new AppointmentCollection(businessAppointments.ConvertAll <DataTypes.Appointment>(
                                                 new Converter <BMS.Appointment, DataTypes.Appointment> (AppointmentTranslator.TranslateBusinessToService)
                                                 )));
        }
示例#2
0
        public DataTypes.Appointment Save(DataTypes.Appointment appointment)
        {
            if (appointment == null)
            {
                throw new ArgumentNullException("appointment");
            }

            SetupWorkflowEnvironment();

            BMS.Appointment[] businessAppointments = Helper.GetApplication().Find(new AppointmentSearchCriteria(appointment.Ubrn));

            BMS.Appointment businessAppointment;
            if (businessAppointments.Length > 0)
            {
                // Existing Appointment
                // No need to use the workflow as no state change happening.
                businessAppointment = businessAppointments[0];
                businessAppointment = AppointmentTranslator.TranslateServiceToBusiness(appointment, businessAppointment);
                businessAppointment.Save();
            }
            else
            {
                // New Appointment
                if (appointment.Patient == null || appointment.Provider == null || appointment.ClinicType == null)
                {
                    throw new ArgumentNullException("appointment");
                }

                Guid workflowInstanceId = Guid.NewGuid();

                WorkflowInstance workflowInstance =
                    _workflowRuntime.CreateWorkflow(typeof(AppointmentWorkflow), null, workflowInstanceId);
                workflowInstance.Start();

                _appointmentLocalService.RaiseAppointmentCreateEvent
                    (workflowInstanceId, appointment.Patient.Id, appointment.Provider.Id, appointment.ClinicType.Id);

                RunWorkFlow(workflowInstanceId);

                AppointmentSearchCriteria criteria = new AppointmentSearchCriteria(null);
                criteria.WorkflowId = workflowInstanceId;
                businessAppointment = Helper.GetApplication().Find(criteria)[0];
            }

            return(AppointmentTranslator.TranslateBusinessToService(businessAppointment));
        }