public ListWorklistClassesResponse ListWorklistClasses(ListWorklistClassesRequest request)
		{
			Platform.CheckForNullReference(request, "request");

			var worklistClasses =
				ListClassesHelper(request.ClassNames, request.Categories, request.IncludeStatic);

			var assembler = new WorklistAdminAssembler();
			return new ListWorklistClassesResponse(
				CollectionUtils.Map<Type, WorklistClassSummary>(worklistClasses,
					assembler.CreateClassSummary));
		}
		public ListWorklistsResponse ListWorklists(ListWorklistsRequest request)
		{
			Platform.CheckForNullReference(request, "request");
			var worklistClasses = ListClassesHelper(request.ClassNames, request.Categories, request.IncludeStatic);

			// grab the persistent worklists
			var broker = PersistenceContext.GetBroker<IWorklistBroker>();
			var persistentClassNames = CollectionUtils.Select(worklistClasses, t => !Worklist.GetIsStatic(t))
				.ConvertAll(Worklist.GetClassName);

			var worklists = broker.Find(request.WorklistName, request.IncludeUserDefinedWorklists, persistentClassNames, request.Page);

			// optionally include the static ones
			if (request.IncludeStatic)
			{
				foreach (var worklistClass in worklistClasses)
				{
					if (Worklist.GetIsStatic(worklistClass))
						worklists.Add(WorklistFactory.Instance.CreateWorklist(worklistClass));
				}
			}

			var adminAssembler = new WorklistAdminAssembler();
			return new ListWorklistsResponse(
				CollectionUtils.Map<Worklist, WorklistAdminSummary, List<WorklistAdminSummary>>(
				worklists,
				worklist => adminAssembler.CreateWorklistSummary(worklist, this.PersistenceContext)));
		}
		private void UpdateWorklistHelper(WorklistAdminDetail detail, Worklist worklist)
		{
			var adminAssembler = new WorklistAdminAssembler();
			adminAssembler.UpdateWorklist(
				worklist,
				detail,
				worklist.Owner.IsAdminOwner,	// only update subscribers iff the worklist is admin owned
				this.PersistenceContext);
		}
		private GetWorklistEditFormChoicesResponse GetWorklistEditFormChoices(GetWorklistEditFormChoicesRequest request)
		{
			var response = new GetWorklistEditFormChoicesResponse();

			var assembler = new WorklistAdminAssembler();
			response.WorklistClasses = CollectionUtils.Map<Type, WorklistClassSummary>(
				ListClassesHelper(null, null, false),
				assembler.CreateClassSummary);

			var staffAssembler = new StaffAssembler();
			response.StaffChoices = CollectionUtils.Map<Staff, StaffSummary>(
				this.PersistenceContext.GetBroker<IStaffBroker>().FindAll(false),
				item => staffAssembler.CreateStaffSummary(item, PersistenceContext));

			var staffGroupAssembler = new StaffGroupAssembler();
			response.GroupSubscriberChoices = CollectionUtils.Map<StaffGroup, StaffGroupSummary>(
				this.PersistenceContext.GetBroker<IStaffGroupBroker>().FindAll(false),
				staffGroupAssembler.CreateSummary);

			var facilityAssembler = new FacilityAssembler();
			response.FacilityChoices = CollectionUtils.Map<Facility, FacilitySummary>(
				this.PersistenceContext.GetBroker<IFacilityBroker>().FindAll(false),
				facilityAssembler.CreateFacilitySummary);

			var departmentAssembler = new DepartmentAssembler();
			response.DepartmentChoices = CollectionUtils.Map(
				this.PersistenceContext.GetBroker<IDepartmentBroker>().FindAll(false),
				(Department item) => departmentAssembler.CreateSummary(item, PersistenceContext));

			var locationAssembler = new LocationAssembler();
			response.PatientLocationChoices = CollectionUtils.Map<Location, LocationSummary>(
				this.PersistenceContext.GetBroker<ILocationBroker>().FindAll(false),
				locationAssembler.CreateLocationSummary);

			response.OrderPriorityChoices = EnumUtils.GetEnumValueList<OrderPriorityEnum>(PersistenceContext);
			response.PatientClassChoices = EnumUtils.GetEnumValueList<PatientClassEnum>(PersistenceContext);

			response.CurrentServerConfigurationRequiresTimeFilter = Worklist.CurrentServerConfigurationRequiresTimeFilter();
			response.CurrentServerConfigurationMaxSpanDays = Worklist.CurrentServerConfigurationMaxSpanDays();

			// add extra data iff editing a user-defined worklist (bug #4871)
			if (request.UserDefinedWorklist)
			{
				response.OwnerGroupChoices = CollectionUtils.Map<StaffGroup, StaffGroupSummary>(
					this.CurrentUserStaff.ActiveGroups, // only current user's active staff groups should be choosable
					staffGroupAssembler.CreateSummary);
			}

			var proceduerTypesAssembler = new ProcedureTypeAssembler();
			response.ProcedureTypeChoices = CollectionUtils.Map<ProcedureType, ProcedureTypeSummary>(
				this.PersistenceContext.GetBroker<IProcedureTypeBroker>().FindAll(false),
				proceduerTypesAssembler.CreateSummary);

			return response;
		}
		public UpdateWorklistResponse UpdateWorklist(UpdateWorklistRequest request)
		{
			var worklist = this.PersistenceContext.Load<Worklist>(request.EntityRef);

			// check if user can update
			CheckAccess(worklist.Owner);

			// update
			UpdateWorklistHelper(request.Detail, worklist);

			var adminAssembler = new WorklistAdminAssembler();
			return new UpdateWorklistResponse(adminAssembler.CreateWorklistSummary(worklist, this.PersistenceContext));
		}
		public AddWorklistResponse AddWorklist(AddWorklistRequest request)
		{
			if (string.IsNullOrEmpty(request.Detail.Name))
			{
				throw new RequestValidationException(SR.ExceptionWorklistNameRequired);
			}

			// create instance of worklist owner
			var owner = CreateOwner(request.Detail, request.IsUserWorklist);

			// ensure user has access to create this worklist
			CheckAccess(owner);

			CheckWorklistCountRestriction(owner);

			// create instance of appropriate class
			var worklist = WorklistFactory.Instance.CreateWorklist(request.Detail.WorklistClass.ClassName);

			// set owner
			worklist.Owner = owner;

			// update properties
			UpdateWorklistHelper(request.Detail, worklist);

			PersistenceContext.Lock(worklist, DirtyState.New);
			PersistenceContext.SynchState();

			var adminAssembler = new WorklistAdminAssembler();
			return new AddWorklistResponse(adminAssembler.CreateWorklistSummary(worklist, this.PersistenceContext));
		}
		public LoadWorklistForEditResponse LoadWorklistForEdit(LoadWorklistForEditRequest request)
		{
			var worklist = PersistenceContext.Load<Worklist>(request.EntityRef);

			var adminAssembler = new WorklistAdminAssembler();
			var adminDetail = adminAssembler.CreateWorklistDetail(worklist, this.PersistenceContext);
			return new LoadWorklistForEditResponse(worklist.GetRef(), adminDetail);
		}