示例#1
0
        protected override IList <Staff> GetItemsForExport(IReadContext context, int firstRow, int maxRows)
        {
            StaffSearchCriteria where = new StaffSearchCriteria();
            where.Id.SortAsc(0);

            return(context.GetBroker <IStaffBroker>().Find(where, new SearchResultPage(firstRow, maxRows)));
        }
        public GetConversationEditorFormDataResponse GetConversationEditorFormData(
            GetConversationEditorFormDataRequest request)
        {
            var staffAssembler = new StaffAssembler();
            var groupAssembler = new StaffGroupAssembler();
            var response       = new GetConversationEditorFormDataResponse(
                CollectionUtils.Map(
                    this.CurrentUserStaff.ActiveGroups,                         // only active staff groups should be choices
                    (StaffGroup sg) => groupAssembler.CreateSummary(sg)));

            if (request.RecipientStaffIDs != null && request.RecipientStaffIDs.Count > 0)
            {
                var criteria = new StaffSearchCriteria();
                criteria.Id.In(request.RecipientStaffIDs);
                response.RecipientStaffs = CollectionUtils.Map(
                    PersistenceContext.GetBroker <IStaffBroker>().Find(criteria),
                    (Staff s) => staffAssembler.CreateStaffSummary(s, PersistenceContext));
            }

            if (request.RecipientStaffGroupNames != null && request.RecipientStaffGroupNames.Count > 0)
            {
                var criteria = new StaffGroupSearchCriteria();
                criteria.Name.In(request.RecipientStaffGroupNames);
                response.RecipientStaffGroups = CollectionUtils.Map(
                    PersistenceContext.GetBroker <IStaffGroupBroker>().Find(criteria),
                    (StaffGroup sg) => groupAssembler.CreateSummary(sg));
            }

            return(response);
        }
示例#3
0
        private Staff GetStaff(string id, IPersistenceContext context)
        {
            Staff staff = null;

            try
            {
                StaffSearchCriteria criteria = new StaffSearchCriteria();
                criteria.Id.EqualTo(id);

                IStaffBroker broker = context.GetBroker <IStaffBroker>();
                staff = broker.FindOne(criteria);
            }
            catch (EntityNotFoundException)
            {
                staff = new Staff();

                // need to populate required fields before we can lock (use dummy values)
                staff.Id = id;
                staff.Name.FamilyName = "";
                staff.Name.GivenName  = "";
                staff.Sex             = Sex.U;

                context.Lock(staff, DirtyState.New);
            }
            return(staff);
        }
示例#4
0
		// note: this operation is not protected with ClearCanvas.Ris.Application.Common.AuthorityTokens.StaffAdmin
		// because it is used in non-admin situations - perhaps we need to create a separate operation???
		public ListStaffResponse ListStaff(ListStaffRequest request)
		{

			var assembler = new StaffAssembler();

			var criteria = new StaffSearchCriteria();
			criteria.Name.FamilyName.SortAsc(0);

            if (!string.IsNullOrEmpty(request.StaffID))
				ApplyCondition(criteria.Id, request.StaffID, request.ExactMatch);

            if (!string.IsNullOrEmpty(request.GivenName))
				ApplyCondition(criteria.Name.GivenName, request.GivenName, request.ExactMatch); 

			if (!string.IsNullOrEmpty(request.FamilyName))
				ApplyCondition(criteria.Name.FamilyName, request.FamilyName, request.ExactMatch);

			if (!string.IsNullOrEmpty(request.UserName))
				criteria.UserName.EqualTo(request.UserName);

            if (!request.IncludeDeactivated)
				criteria.Deactivated.EqualTo(false);

			ApplyStaffTypesFilter(request.StaffTypesFilter, new [] { criteria });

			return new ListStaffResponse(
				CollectionUtils.Map<Staff, StaffSummary, List<StaffSummary>>(
					PersistenceContext.GetBroker<IStaffBroker>().Find(criteria, request.Page),
					s => assembler.CreateStaffSummary(s, PersistenceContext)));
		}
示例#5
0
        private static void ImportStaffFilter(WorklistStaffFilter filter, WorklistData.StaffFilterData staff, IUpdateContext context)
        {
            ImportFilter(filter, staff,
                         delegate(WorklistData.StaffSubscriberData s)
            {
                var criteria = new StaffSearchCriteria();
                criteria.Id.EqualTo(s.StaffId);

                var broker = context.GetBroker <IStaffBroker>();
                return(CollectionUtils.FirstElement(broker.Find(criteria)));
            });
            filter.IncludeCurrentStaff = staff.IncludeCurrentStaff;
        }
示例#6
0
        protected static Staff FindStaff(string id, IPersistenceContext context)
        {
            var searchCriteria = new StaffSearchCriteria();

            searchCriteria.Id.EqualTo(id);
            try
            {
                return(context.GetBroker <IStaffBroker>().FindOne(searchCriteria));
            }
            catch (EntityNotFoundException)
            {
                throw new Exception(id);
            }
        }
示例#7
0
        /// <summary>
        /// Applies this filter to the specified criteria object.
        /// </summary>
        /// <param name="criteria"></param>
        /// <param name="wqc"></param>
        public void Apply(StaffSearchCriteria criteria, IWorklistQueryContext wqc)
        {
            if (!this.IsEnabled)
            {
                return;
            }

            var values = new List <Staff>(this.Values);

            if (this.IncludeCurrentStaff)
            {
                values.Add(wqc.ExecutingStaff);
            }
            criteria.In(values);
        }
示例#8
0
        public TextQueryResponse <StaffSummary> TextQuery(StaffTextQueryRequest request)
        {
            var broker    = PersistenceContext.GetBroker <IStaffBroker>();
            var assembler = new StaffAssembler();

            var helper = new TextQueryHelper <Staff, StaffSearchCriteria, StaffSummary>(
                delegate
            {
                var rawQuery = request.TextQuery;

                // this will hold all criteria
                var criteria = new List <StaffSearchCriteria>();

                // build criteria against names
                var names = TextQueryHelper.ParsePersonNames(rawQuery);
                criteria.AddRange(CollectionUtils.Map(names,
                                                      (PersonName n) =>
                {
                    var sc = new StaffSearchCriteria();
                    sc.Name.FamilyName.StartsWith(n.FamilyName);
                    if (n.GivenName != null)
                    {
                        sc.Name.GivenName.StartsWith(n.GivenName);
                    }
                    return(sc);
                }));

                // build criteria against identifiers
                var ids = TextQueryHelper.ParseIdentifiers(rawQuery);
                criteria.AddRange(CollectionUtils.Map(ids,
                                                      (string word) =>
                {
                    var c = new StaffSearchCriteria();
                    c.Id.StartsWith(word);
                    return(c);
                }));


                ApplyStaffTypesFilter(request.StaffTypesFilter, criteria);

                return(criteria.ToArray());
            },
                staff => assembler.CreateStaffSummary(staff, PersistenceContext),
                (criteria, threshold) => broker.Count(criteria) <= threshold,
                broker.Find);

            return(helper.Query(request));
        }
示例#9
0
        private Staff GetStaff(string staffId, IList <Staff> importedStaff)
        {
            Staff staff = null;

            staff = CollectionUtils.SelectFirst <Staff>(importedStaff,
                                                        delegate(Staff s) { return(s.Id == staffId); });

            if (staff == null)
            {
                StaffSearchCriteria criteria = new StaffSearchCriteria();
                criteria.Id.EqualTo(staffId);

                IStaffBroker broker = _context.GetBroker <IStaffBroker>();
                staff = CollectionUtils.FirstElement(broker.Find(criteria));
            }

            return(staff);
        }
        private static Staff FindStaff(string staffId, IPersistenceContext context)
        {
            try
            {
                if (string.IsNullOrEmpty(staffId))
                {
                    return(null);
                }

                StaffSearchCriteria criteria = new StaffSearchCriteria();
                criteria.Id.EqualTo(staffId);

                IStaffBroker broker = context.GetBroker <IStaffBroker>();
                return(broker.FindOne(criteria));
            }
            catch (EntityNotFoundException)
            {
                return(null);
            }
        }
示例#11
0
        private void ValidateUserNameFree(string userName)
        {
            var staffBroker = PersistenceContext.GetBroker <IStaffBroker>();

            try
            {
                var where = new StaffSearchCriteria();
                where.UserName.EqualTo(userName);
                var existing = staffBroker.FindOne(where);
                if (existing != null)
                {
                    throw new RequestValidationException(
                              string.Format("Staff cannot be associated with user {0} because this user is already associated to staff {1}",
                                            userName, existing.Name));
                }
            }
            catch (EntityNotFoundException)
            {
                // no previously associated staff
            }
        }
示例#12
0
        private void ValidateUserNameFree(string userName)
        {
            var staffBroker = PersistenceContext.GetBroker <IStaffBroker>();

            try
            {
                var where = new StaffSearchCriteria();
                where.UserName.EqualTo(userName);
                var existing = staffBroker.FindOne(where);
                if (existing != null)
                {
                    throw new RequestValidationException(
                              string.Format(SR.InvalidRequest_UserAlreadyAssociatedWithStaff,
                                            userName, existing.Name));
                }
            }
            catch (EntityNotFoundException)
            {
                // no previously associated staff
            }
        }
示例#13
0
        // note: this operation is not protected with ClearCanvas.Ris.Application.Common.AuthorityTokens.StaffAdmin
        // because it is used in non-admin situations - perhaps we need to create a separate operation???
        public ListStaffResponse ListStaff(ListStaffRequest request)
        {
            var assembler = new StaffAssembler();

            var criteria = new StaffSearchCriteria();

            criteria.Name.FamilyName.SortAsc(0);

            if (!string.IsNullOrEmpty(request.StaffID))
            {
                ApplyCondition(criteria.Id, request.StaffID, request.ExactMatch);
            }

            if (!string.IsNullOrEmpty(request.GivenName))
            {
                ApplyCondition(criteria.Name.GivenName, request.GivenName, request.ExactMatch);
            }

            if (!string.IsNullOrEmpty(request.FamilyName))
            {
                ApplyCondition(criteria.Name.FamilyName, request.FamilyName, request.ExactMatch);
            }

            if (!string.IsNullOrEmpty(request.UserName))
            {
                criteria.UserName.EqualTo(request.UserName);
            }

            if (!request.IncludeDeactivated)
            {
                criteria.Deactivated.EqualTo(false);
            }

            ApplyStaffTypesFilter(request.StaffTypesFilter, new [] { criteria });

            return(new ListStaffResponse(
                       CollectionUtils.Map <Staff, StaffSummary, List <StaffSummary> >(
                           PersistenceContext.GetBroker <IStaffBroker>().Find(criteria, request.Page),
                           s => assembler.CreateStaffSummary(s, PersistenceContext))));
        }
示例#14
0
        protected override void Import(StaffGroupData data, IUpdateContext context)
        {
            StaffGroup group = LoadOrCreateGroup(data.Name, context);

            group.Deactivated = data.Deactivated;
            group.Description = data.Description;
            group.Elective    = data.Elective;

            if (data.Members != null)
            {
                foreach (StaffMemberData s in data.Members)
                {
                    StaffSearchCriteria where = new StaffSearchCriteria();
                    where.Id.EqualTo(s.Id);
                    Staff staff = CollectionUtils.FirstElement(context.GetBroker <IStaffBroker>().Find(where));
                    if (staff != null)
                    {
                        group.Members.Add(staff);
                    }
                }
            }
        }
示例#15
0
		public TextQueryResponse<StaffSummary> TextQuery(StaffTextQueryRequest request)
		{
			var broker = PersistenceContext.GetBroker<IStaffBroker>();
			var assembler = new StaffAssembler();

			var helper = new TextQueryHelper<Staff, StaffSearchCriteria, StaffSummary>(
                    delegate
					{
                        var rawQuery = request.TextQuery;

						// this will hold all criteria
						var criteria = new List<StaffSearchCriteria>();

						// build criteria against names
						var names = TextQueryHelper.ParsePersonNames(rawQuery);
						criteria.AddRange(CollectionUtils.Map(names,
							(PersonName n) =>
							{
								var sc = new StaffSearchCriteria();
								sc.Name.FamilyName.StartsWith(n.FamilyName);
								if (n.GivenName != null)
									sc.Name.GivenName.StartsWith(n.GivenName);
								return sc;
							}));

						// build criteria against identifiers
						var ids = TextQueryHelper.ParseIdentifiers(rawQuery);
						criteria.AddRange(CollectionUtils.Map(ids,
									 (string word) =>
									 {
										 var c = new StaffSearchCriteria();
										 c.Id.StartsWith(word);
										 return c;
									 }));


						ApplyStaffTypesFilter(request.StaffTypesFilter, criteria);

						return criteria.ToArray();
					},
                    staff => assembler.CreateStaffSummary(staff, PersistenceContext),
                    (criteria, threshold) => broker.Count(criteria) <= threshold,
					broker.Find);

			return helper.Query(request);
		}
示例#16
0
        private Staff GetStaff(string staffId, IList<Staff> importedStaff)
        {
            Staff staff = null;

            staff = CollectionUtils.SelectFirst<Staff>(importedStaff,
                delegate(Staff s) { return s.Id == staffId; });

            if (staff == null)
            {
                StaffSearchCriteria criteria = new StaffSearchCriteria();
                criteria.Id.EqualTo(staffId);

                IStaffBroker broker = _context.GetBroker<IStaffBroker>();
                staff = CollectionUtils.FirstElement(broker.Find(criteria));
            }

            return staff;
        }
示例#17
0
		private void ValidateUserNameFree(string userName)
		{
			var staffBroker = PersistenceContext.GetBroker<IStaffBroker>();
			try
			{
				var where = new StaffSearchCriteria();
				where.UserName.EqualTo(userName);
				var existing = staffBroker.FindOne(where);
				if (existing != null)
					throw new RequestValidationException(
						string.Format(SR.InvalidRequest_UserAlreadyAssociatedWithStaff,
							userName, existing.Name));
			}
			catch (EntityNotFoundException)
			{
				// no previously associated staff
			}
		}
示例#18
0
		private void ValidateUserNameFree(string userName)
		{
			var staffBroker = PersistenceContext.GetBroker<IStaffBroker>();
			try
			{
				var where = new StaffSearchCriteria();
				where.UserName.EqualTo(userName);
				var existing = staffBroker.FindOne(where);
				if (existing != null)
					throw new RequestValidationException(
						string.Format("Staff cannot be associated with user {0} because this user is already associated to staff {1}",
							userName, existing.Name));
			}
			catch (EntityNotFoundException)
			{
				// no previously associated staff
			}
		}
示例#19
0
        protected override void Import(WorklistData data, IUpdateContext context)
        {
            var worklist = LoadOrCreateWorklist(data.Name, data.Class, context);

            worklist.Description = data.Description;

            if (data.StaffSubscribers != null)
            {
                foreach (var s in data.StaffSubscribers)
                {
                    var criteria = new StaffSearchCriteria();
                    criteria.Id.EqualTo(s.StaffId);

                    var staff = context.GetBroker <IStaffBroker>().Find(criteria);
                    if (staff.Count == 1)
                    {
                        worklist.StaffSubscribers.Add(CollectionUtils.FirstElement(staff));
                    }
                }
            }

            if (data.GroupSubscribers != null)
            {
                foreach (var s in data.GroupSubscribers)
                {
                    var criteria = new StaffGroupSearchCriteria();
                    criteria.Name.EqualTo(s.StaffGroupName);

                    var groups = context.GetBroker <IStaffGroupBroker>().Find(criteria);
                    if (groups.Count == 1)
                    {
                        worklist.GroupSubscribers.Add(CollectionUtils.FirstElement(groups));
                    }
                }
            }

            // proc type filter
            ImportFilter(
                worklist.ProcedureTypeFilter,
                data.Filters.ProcedureTypes,
                delegate(WorklistData.ProcedureTypeData s)
            {
                var criteria = new ProcedureTypeSearchCriteria();
                criteria.Id.EqualTo(s.Id);

                var broker = context.GetBroker <IProcedureTypeBroker>();
                return(CollectionUtils.FirstElement(broker.Find(criteria)));
            });

            // proc type group filter
            ImportFilter(
                worklist.ProcedureTypeGroupFilter,
                data.Filters.ProcedureTypeGroups,
                delegate(WorklistData.ProcedureTypeGroupData s)
            {
                var criteria = new ProcedureTypeGroupSearchCriteria();
                criteria.Name.EqualTo(s.Name);

                var broker = context.GetBroker <IProcedureTypeGroupBroker>();
                return(CollectionUtils.FirstElement(broker.Find(criteria, ProcedureTypeGroup.GetSubClass(s.Class, context))));
            });

            //Bug #2284: don't forget to set the IncludeWorkingFacility property
            // facility filter
            worklist.FacilityFilter.IncludeWorkingFacility = data.Filters.Facilities.IncludeWorkingFacility;
            ImportFilter(
                worklist.FacilityFilter,
                data.Filters.Facilities,
                delegate(WorklistData.EnumValueData s)
            {
                var criteria = new FacilitySearchCriteria();
                criteria.Code.EqualTo(s.Code);

                var broker = context.GetBroker <IFacilityBroker>();
                return(CollectionUtils.FirstElement(broker.Find(criteria)));
            });

            // department filter
            ImportFilter(
                worklist.DepartmentFilter,
                data.Filters.Departments,
                delegate(WorklistData.DepartmentData s)
            {
                var criteria = new DepartmentSearchCriteria();
                criteria.Id.EqualTo(s.Id);

                var broker = context.GetBroker <IDepartmentBroker>();
                return(CollectionUtils.FirstElement(broker.Find(criteria)));
            });

            // priority filter
            ImportFilter(
                worklist.OrderPriorityFilter,
                data.Filters.OrderPriorities,
                delegate(WorklistData.EnumValueData s)
            {
                var broker = context.GetBroker <IEnumBroker>();
                return(broker.Find <OrderPriorityEnum>(s.Code));
            });

            // ordering prac filter
            ImportFilter(
                worklist.OrderingPractitionerFilter,
                data.Filters.OrderingPractitioners,
                delegate(WorklistData.PractitionerData s)
            {
                var criteria = new ExternalPractitionerSearchCriteria();
                criteria.Name.FamilyName.EqualTo(s.FamilyName);
                criteria.Name.GivenName.EqualTo(s.GivenName);

                // these criteria may not be provided (the data may not existed when exported),
                // but if available, they help to ensure the correct practitioner is being mapped
                if (!string.IsNullOrEmpty(s.BillingNumber))
                {
                    criteria.BillingNumber.EqualTo(s.BillingNumber);
                }
                if (!string.IsNullOrEmpty(s.LicenseNumber))
                {
                    criteria.LicenseNumber.EqualTo(s.LicenseNumber);
                }

                var broker = context.GetBroker <IExternalPractitionerBroker>();
                return(CollectionUtils.FirstElement(broker.Find(criteria)));
            });

            // patient class filter
            ImportFilter(
                worklist.PatientClassFilter,
                data.Filters.PatientClasses,
                delegate(WorklistData.EnumValueData s)
            {
                var broker = context.GetBroker <IEnumBroker>();
                return(broker.Find <PatientClassEnum>(s.Code));
            });

            // patient location filter
            ImportFilter(
                worklist.PatientLocationFilter,
                data.Filters.PatientLocations,
                delegate(WorklistData.LocationData s)
            {
                var criteria = new LocationSearchCriteria();
                criteria.Id.EqualTo(s.Id);

                var broker = context.GetBroker <ILocationBroker>();
                return(CollectionUtils.FirstElement(broker.Find(criteria)));
            });

            // portable filter
            worklist.PortableFilter.IsEnabled = data.Filters.Portable.Enabled;
            worklist.PortableFilter.Value     = data.Filters.Portable.Value;

            //Bug #2429: don't forget to include the time filter
            // time filter
            worklist.TimeFilter.IsEnabled = data.Filters.TimeWindow.Enabled;
            worklist.TimeFilter.Value     = data.Filters.TimeWindow == null || data.Filters.TimeWindow.Value == null
                                                                                        ? null
                                                                                        : data.Filters.TimeWindow.Value.CreateTimeRange();

            // reporting filters
            if (Worklist.GetSupportsReportingStaffRoleFilter(worklist.GetClass()))
            {
                ImportReportingWorklistFilters(data, worklist.As <ReportingWorklist>(), context);
            }
        }