Esempio n. 1
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));
        }
Esempio n. 2
0
        public TextQueryResponse <ExternalPractitionerSummary> TextQuery(TextQueryRequest request)
        {
            var broker    = PersistenceContext.GetBroker <IExternalPractitionerBroker>();
            var assembler = new ExternalPractitionerAssembler();

            var helper = new TextQueryHelper <ExternalPractitioner, ExternalPractitionerSearchCriteria, ExternalPractitionerSummary>(
                delegate
            {
                var rawQuery = request.TextQuery;

                var criteria = new List <ExternalPractitionerSearchCriteria>();

                // build criteria against names
                var names = TextQueryHelper.ParsePersonNames(rawQuery);
                criteria.AddRange(CollectionUtils.Map(names,
                                                      delegate(PersonName n)
                {
                    var sc = new ExternalPractitionerSearchCriteria();
                    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,
                                                      delegate(string word)
                {
                    var c = new ExternalPractitionerSearchCriteria();
                    c.LicenseNumber.StartsWith(word);
                    return(c);
                }));

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

            return(helper.Query(request));
        }