Пример #1
0
        /// <summary>
        /// Расчитывает ключ для указанных параметров
        /// </summary>
        /// <param name="searchKeyTypeXml">
        /// </param>
        /// <param name="insuredPersonDataXml">
        /// </param>
        /// <param name="documentXml">
        /// </param>
        /// <param name="address1Xml">
        /// </param>
        /// <param name="address2Xml">
        /// </param>
        /// <param name="medicalInsuranceXml">
        /// </param>
        /// <param name="okato">
        /// </param>
        /// <returns>
        /// The <see cref="byte[]"/>.
        /// </returns>
        public byte[] CalculateUserSearchKey(
            string searchKeyTypeXml,
            string insuredPersonDataXml,
            string documentXml,
            string address1Xml,
            string address2Xml,
            string medicalInsuranceXml,
            string okato)
        {
            // Парсинг
            ModelAdapter model = null;

            try
            {
                model = new ModelAdapter
                {
                    SearchKeyType    = SearchKeyType.FromXML(searchKeyTypeXml),
                    PersonData       = InsuredPersonDatum.FromXML(insuredPersonDataXml),
                    Document         = Document.FromXML(documentXml),
                    Address1         = address.FromXML(address1Xml),
                    Address2         = address.FromXML(address2Xml),
                    MedicalInsurance = MedicalInsurance.FromXML(medicalInsuranceXml),
                    Okato            = okato
                };
            }
            catch (Exception ex)
            {
                throw new Exception("Ошибка парсинга xml", ex);
            }

            return(CalculateUserSearchKey(model));
        }
Пример #2
0
        /// <summary>
        /// The check object.
        /// </summary>
        /// <param name="statement">
        /// The statement.
        /// </param>
        public override void CheckObject(Statement statement)
        {
            InsuredPersonDatum d = null;
            var insuredPersonId  = statement.InsuredPerson != null ? statement.InsuredPerson.Id : Guid.Empty;
            var snils            = statement.InsuredPersonData.Snils;

            var session = ObjectFactory.GetInstance <ISessionFactory>().GetCurrentSession();

            if (string.IsNullOrEmpty(snils))
            {
                return;
            }

            if (!statement.InsuredPersonData.NotCheckExistsSnils)
            {
                var count =
                    session.QueryOver <Statement>()
                    .JoinAlias(x => x.InsuredPersonData, () => d)
                    .Where(x => d.Snils == snils)
                    .And(x => x.InsuredPerson.Id != insuredPersonId)
                    .And(x => x.Id != statement.Id)
                    .And(x => x.Status.Id != StatusStatement.Cancelled)
                    .And(x => x.Status.Id != StatusStatement.Declined)
                    .RowCount();

                if (count > 0)
                {
                    throw new FaultSnilsExistsException();
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Расчитывает ключ для указанных параметров
        /// </summary>
        /// <param name="searchKeyTypeXml">
        /// </param>
        /// <param name="exchangeXml">
        /// The exchange Xml.
        /// </param>
        /// <param name="documentXml">
        /// The document Xml.
        /// </param>
        /// <param name="addressXml">
        /// The address Xml.
        /// </param>
        /// <returns>
        /// The <see cref="byte[]"/>.
        /// </returns>
        public byte[] CalculateUserSearchKeyExchange(
            string searchKeyTypeXml,
            string exchangeXml,
            string documentXml,
            string addressXml)
        {
            // Парсинг
            ModelAdapter model = null;

            try
            {
                model = new ModelAdapter
                {
                    SearchKeyType = SearchKeyType.FromXML(searchKeyTypeXml),
                    PersonData    = InsuredPersonDatum.FromXML(exchangeXml),
                    Document      = Document.FromXML(documentXml),
                    Address1      = address.FromXML(addressXml)
                };
            }
            catch (Exception ex)
            {
                throw new Exception("Ошибка парсинга xml", ex);
            }

            // создание внешнего hash алгоритма
            var hashAlgorithm = new HashAlgorithm();

            byte[] hash = null;
            using (var stream = new MemoryStream())
            {
                using (var currentWriter = new BinaryWriter(stream, Encoding.Unicode))
                {
                    // Персональные данные
                    WriteField(model, x => x.PersonData.LastName, currentWriter);
                    WriteField(model, x => x.PersonData.FirstName, currentWriter);
                    WriteField(model, x => x.PersonData.MiddleName, currentWriter);
                    WriteField(model, x => x.PersonData.Birthday, currentWriter);
                    WriteField(model, x => x.PersonData.Birthplace, currentWriter);
                    WriteField(model, x => x.PersonData.Snils, currentWriter);

                    // Документ УДЛ
                    WriteField(model, x => x.Document.DocumentTypeId, currentWriter);
                    WriteField(model, x => x.Document.Series, currentWriter);
                    WriteField(model, x => x.Document.Number, currentWriter);

                    // расчет ключа с помощью внешнего алгоритма
                    stream.Flush();
                    stream.Position = 0;
                    hash            = hashAlgorithm.ComputeHash(stream);
                }
            }

            return(hash);
        }
Пример #4
0
        /// <summary>
        /// Расчитывает ключ для указанных параметров
        /// </summary>
        /// <param name="keyType">
        /// </param>
        /// <param name="personData">
        /// </param>
        /// <param name="document">
        /// </param>
        /// <param name="address1">
        /// </param>
        /// <param name="address2">
        /// </param>
        /// <param name="medicalInsurance">
        /// </param>
        /// <param name="okato">
        /// </param>
        /// <returns>
        /// The <see cref="byte[]"/>.
        /// </returns>
        public byte[] CalculateUserSearchKey(
            SearchKeyType keyType,
            InsuredPersonDatum personData,
            Document document,
            address address1,
            address address2,
            MedicalInsurance medicalInsurance,
            string okato)
        {
            var model = new ModelAdapter
            {
                SearchKeyType    = keyType,
                PersonData       = personData,
                Document         = document,
                Address1         = address1,
                Address2         = address2,
                MedicalInsurance = medicalInsurance,
                Okato            = okato
            };

            return(CalculateUserSearchKey(model));
        }
Пример #5
0
        /// <summary>
        /// The procesing bad data.
        /// </summary>
        /// <param name="statement">
        /// The statement.
        /// </param>
        private void ProcesingBadData(Statement statement)
        {
            if (statement == null)
            {
                throw new ArgumentNullException("statement");
            }

            var session = ObjectFactory.GetInstance <ISessionFactory>().GetCurrentSession();

            // Обрабатываем испорченный паспорт
            if (statement.DocumentUdl != null && statement.DocumentUdl.ExistDocument)
            {
                Statement st = null;
                var       insuredPersonId = statement.InsuredPerson != null ? statement.InsuredPerson.Id : Guid.Empty;
                var       docTypeId       = statement.DocumentUdl.DocumentType.Id;
                var       series          = statement.DocumentUdl.Series;
                var       number          = statement.DocumentUdl.Number;

                var query =
                    session.QueryOver <Document>()
                    .JoinAlias(x => x.Statements1, () => st)
                    .Where(x => x.DocumentType.Id == docTypeId)
                    .And(x => x.Series == series)
                    .And(x => x.Number == number)
                    .And(x => st.Id != statement.Id)
                    .And(x => st.Status.Id != StatusStatement.Cancelled)
                    .And(x => st.Status.Id != StatusStatement.Declined);
                if (insuredPersonId != Guid.Empty)
                {
                    query.Where(x => st.InsuredPerson.Id != insuredPersonId);
                }

                // Получаем список испорченных документов в БД
                foreach (var document in query.List())
                {
                    document.IsBad = true;
                    session.Update(document);
                }

                session.Flush();
            }

            // Обработка плохого СНИЛСа
            if (statement.InsuredPersonData != null && statement.InsuredPersonData.NotCheckExistsSnils)
            {
                InsuredPersonDatum d = null;
                var query            =
                    session.QueryOver <Statement>()
                    .JoinAlias(x => x.InsuredPersonData, () => d)
                    .Where(x => d.Snils == statement.InsuredPersonData.Snils)
                    .And(x => x.InsuredPerson.Id != statement.InsuredPerson.Id)
                    .And(x => x.Id != statement.Id)
                    .And(x => x.Status.Id != StatusStatement.Cancelled)
                    .And(x => x.Status.Id != StatusStatement.Declined)
                    .List();

                foreach (var s in query)
                {
                    s.InsuredPersonData.IsBadSnils = true;
                    session.Update(s.InsuredPersonData);
                }

                session.Flush();
            }
        }
Пример #6
0
        /// <summary>
        /// The search.
        /// </summary>
        /// <param name="criteria">
        /// The criteria.
        /// </param>
        /// <param name="addCriteriaDelegate">
        /// The add criteria delegate.
        /// </param>
        /// <returns>
        /// The
        ///   <see>
        ///     <cref>SearchResult</cref>
        ///   </see>
        ///   .
        /// </returns>
        private SearchResult <SearchStatementResult> Search(
            SearchStatementCriteria criteria,
            Action <SearchStatementCriteria, QueryOver <Statement, Statement>, InsuredPersonDatum, Document, MedicalInsurance, bool> addCriteriaDelegate)
        {
            var session     = ObjectFactory.GetInstance <ISessionFactory>().GetCurrentSession();
            var currentUser = ObjectFactory.GetInstance <ISecurityProvider>().GetCurrentUser();
            var currentSmo  = currentUser.GetSmo();

            InsuredPersonDatum dpersonDatum      = null;
            InsuredPerson      dperson           = null;
            Document           ddocument         = null;
            MedicalInsurance   dmedicalInsurance = null;
            var deatachQuery =
                QueryOver.Of <Statement>()
                .JoinAlias(x => x.InsuredPersonData, () => dpersonDatum)
                .JoinAlias(x => x.InsuredPerson, () => dperson)
                .JoinAlias(x => x.DocumentUdl, () => ddocument)
                .JoinAlias(x => x.MedicalInsurances, () => dmedicalInsurance, JoinType.LeftOuterJoin)
                .Select(x => dperson.Id);

            Statement          statement    = null;
            InsuredPersonDatum personDatum  = null;
            InsuredPerson      person       = null;
            CauseReinsurance   cause        = null;
            Organisation       tfom         = null;
            Organisation       smo          = null;
            Organisation       point        = null;
            Concept            gender       = null;
            Concept            citizenship  = null;
            Document           document     = null;
            Concept            documentType = null;
            Concept            status       = null;
            var query =
                session.QueryOver(() => statement)
                .Left.JoinAlias(x => x.Status, () => status)
                .Left.JoinAlias(x => x.InsuredPersonData, () => personDatum)
                .Left.JoinAlias(x => x.InsuredPerson, () => person)
                .Left.JoinAlias(x => x.CauseFiling, () => cause)
                .Left.JoinAlias(x => x.PointDistributionPolicy, () => point)
                .Left.JoinAlias(() => point.Parent, () => smo)
                .Left.JoinAlias(() => smo.Parent, () => tfom)
                .Left.JoinAlias(() => personDatum.Gender, () => gender)
                .Left.JoinAlias(() => personDatum.Citizenship, () => citizenship)
                .Left.JoinAlias(x => x.DocumentUdl, () => document)
                .Left.JoinAlias(() => document.DocumentType, () => documentType)
                .WithSubquery.WhereProperty(x => x.InsuredPerson.Id)
                .In(deatachQuery);

            var emptyCriteria = true;

            // Статус заявления
            if (criteria.StatementStatus > 0)
            {
                switch (criteria.StatementStatus)
                {
                case 9000:
                    query.Where(x => document.IsBad);
                    query.Where(x => point.Parent.Id == currentSmo.Id);
                    break;

                case 9001:
                    query.Where(x => personDatum.IsBadSnils);
                    query.Where(x => point.Parent.Id == currentSmo.Id);
                    break;

                default:
                    query.Where(x => x.Status.Id == criteria.StatementStatus);
                    break;
                }

                emptyCriteria = false;
            }

            // Тип заявления
            if (criteria.StatementType > 0)
            {
                emptyCriteria = false;
                query.WhereRestrictionOn(x => x.CauseFiling.Id).IsInG(Statement.GetCauseFillingByType(criteria.StatementType));
            }

            // Поиск по дате подачи заявления
            if (criteria.UseDateFiling && criteria.DateFilingFrom != null && criteria.DateFilingTo != null)
            {
                if (criteria.DateFilingFrom > criteria.DateFilingTo)
                {
                    throw new SearchException("Дата начала периода больше, чем дата его окончания.");
                }

                criteria.DateFilingTo = criteria.DateFilingTo.Value.Date.AddHours(23).AddMinutes(59).AddSeconds(59);

                emptyCriteria = false;
                query.WhereRestrictionOn(x => x.DateFiling).IsBetween(criteria.DateFilingFrom).And(criteria.DateFilingTo);
            }

            // Выводить только последние значения
            if (criteria.ReturnLastStatement)
            {
                query.Where(x => x.IsActive);
            }

            addCriteriaDelegate(criteria, deatachQuery, dpersonDatum, ddocument, dmedicalInsurance, emptyCriteria);

            var count        = query.RowCount();
            var searchResult = new SearchResult <SearchStatementResult> {
                Skip = criteria.Skip, Total = count
            };

            query = AddOrder(criteria, statement, cause, smo, personDatum, gender, citizenship, documentType, document, query);

            query.Skip(criteria.Skip).Take(criteria.Take);

            SearchStatementResult result = null;
            var res =
                query.SelectList(
                    y =>
                    y.Select(x => x.Id)
                    .WithAlias(() => result.Id)
                    .Select(x => x.DateFiling)
                    .WithAlias(() => result.DateFiling)
                    .Select(x => x.IsActive)
                    .WithAlias(() => result.IsActive)
                    .Select(x => cause.Name)
                    .WithAlias(() => result.CauseFiling)
                    .Select(x => x.CauseFiling.Id)
                    .WithAlias(() => result.CauseFilingId)
                    .Select(x => smo.Id)
                    .WithAlias(() => result.SmoId)
                    .Select(x => smo.ShortName)
                    .WithAlias(() => result.Smo)
                    .Select(x => smo.Ogrn)
                    .WithAlias(() => result.SmoOGRN)
                    .Select(x => tfom.Okato)
                    .WithAlias(() => result.TfomOKATO)
                    .Select(x => personDatum.FirstName)
                    .WithAlias(() => result.FirstName)
                    .Select(x => personDatum.LastName)
                    .WithAlias(() => result.LastName)
                    .Select(x => personDatum.MiddleName)
                    .WithAlias(() => result.MiddleName)
                    .Select(x => gender.Name)
                    .WithAlias(() => result.Gender)
                    .Select(x => personDatum.Birthday)
                    .WithAlias(() => result.Birthday)
                    .Select(x => personDatum.Birthplace)
                    .WithAlias(() => result.Birthplace)
                    .Select(x => x.Address2)
                    .WithAlias(() => result.AddressLive)
                    .Select(x => x.Address)
                    .WithAlias(() => result.AddressRegistration)
                    .Select(x => x.NumberPolicy)
                    .WithAlias(() => result.PolicyNumber)
                    .Select(x => citizenship.Name)
                    .WithAlias(() => result.Citizenship)
                    .Select(x => documentType.Name)
                    .WithAlias(() => result.DocumentType)
                    .Select(x => document.Series)
                    .WithAlias(() => result.DocumentSeria)
                    .Select(x => document.Number)
                    .WithAlias(() => result.DocumentNumber)
                    .Select(x => personDatum.Snils)
                    .WithAlias(() => result.Snils)
                    .Select(x => status.Name)
                    .WithAlias(() => result.StatusStatement)
                    .Select(x => status.Id)
                    .WithAlias(() => result.Status)
                    .Select(x => person.Status.Id)
                    .WithAlias(() => result.PersonStatus)
                    .Select(x => x.IsExportPolis)
                    .WithAlias(() => result.IsSinhronized))
                .TransformUsing(Transformers.AliasToBean <SearchStatementResult>())
                .List <SearchStatementResult>();

            var errorManager        = ObjectFactory.GetInstance <IErrorManager>();
            var conceptCacheManager = ObjectFactory.GetInstance <IConceptCacheManager>();

            // получение текущего пользователя и текущей страховой
            foreach (var statementResult in res)
            {
                if (statementResult.IsActive)
                {
                    statementResult.StatusStatement += " (Активное";
                    if (statementResult.PersonStatus == StatusPerson.Dead)
                    {
                        statementResult.StatusStatement += " , Умерший";
                    }

                    statementResult.StatusStatement += ")";
                }

                statementResult.Errors =
                    errorManager.GetBy(x => x.Statement.Id == statementResult.Id)
                    .Select(
                        x =>
                        string.IsNullOrEmpty(x.Repl) ? x.Message1 : string.Format("{0} ({1})", x.Message1, x.Repl))
                    .ToList();
                statementResult.TypeStatement =
                    conceptCacheManager.GetById(Statement.GetTypeStatementId(statementResult.CauseFilingId)).Name;
                statementResult.FromCurrentSmo   = currentSmo.Id == statementResult.SmoId;
                statementResult.DateInsuranceEnd = new DateTime(2030, 1, 1); // TODO: логика для даты окончания

                var temp =
                    ObjectFactory.GetInstance <IMedicalInsuranceManager>()
                    .GetBy(x => x.Statement.Id == statementResult.Id && x.IsActive && x.PolisType.Id == PolisType.В)
                    .FirstOrDefault();
                if (temp != null)
                {
                    statementResult.NumberTemporaryCertificate = temp.PolisNumber;
                }

                var polis =
                    ObjectFactory.GetInstance <IMedicalInsuranceManager>()
                    .GetBy(x => x.Statement.Id == statementResult.Id && x.IsActive && x.PolisType.Id != PolisType.В)
                    .FirstOrDefault();
                if (polis != null)
                {
                    statementResult.PolicyNumber = polis.Enp;
                }
            }

            searchResult.Rows = res;
            return(searchResult);
        }
Пример #7
0
        /// <summary>
        /// The add order.
        /// </summary>
        /// <param name="criteria">
        /// The criteria.
        /// </param>
        /// <param name="statement">
        /// The statement.
        /// </param>
        /// <param name="cause">
        /// The cause.
        /// </param>
        /// <param name="smo">
        /// The smo.
        /// </param>
        /// <param name="personDatum">
        /// The person datum.
        /// </param>
        /// <param name="gender">
        /// The gender.
        /// </param>
        /// <param name="citizenship">
        /// The citizenship.
        /// </param>
        /// <param name="documentType">
        /// The document type.
        /// </param>
        /// <param name="document">
        /// The document.
        /// </param>
        /// <param name="query">
        /// The query.
        /// </param>
        /// <returns>
        /// The <see cref="IQueryOver"/>.
        /// </returns>
        private IQueryOver <Statement, Statement> AddOrder(
            SearchStatementCriteria criteria,
            Statement statement,
            Concept cause,
            Organisation smo,
            InsuredPersonDatum personDatum,
            Concept gender,
            Concept citizenship,
            Concept documentType,
            Document document,
            IQueryOver <Statement, Statement> query)
        {
            // Сортировка
            if (!string.IsNullOrEmpty(criteria.SortExpression))
            {
                Expression <Func <object> > expression = () => statement.DateFiling;
                switch (criteria.SortExpression)
                {
                case "DateFiling":
                    expression = () => statement.DateFiling;
                    break;

                case "CauseFilling":
                    expression = () => cause.Name;
                    break;

                case "SMO":
                    expression = () => smo.FullName;
                    break;

                case "FirstName":
                    expression = () => personDatum.FirstName;
                    break;

                case "LastName":
                    expression = () => personDatum.LastName;
                    break;

                case "MiddleName":
                    expression = () => personDatum.MiddleName;
                    break;

                case "Gender":
                    expression = () => gender.Name;
                    break;

                case "Birthday":
                    expression = () => personDatum.Birthday;
                    break;

                case "Citizenship":
                    expression = () => citizenship.Name;
                    break;

                case "DocumentType":
                    expression = () => documentType.Name;
                    break;

                case "DocumentId":
                    expression = () => document.Number;
                    break;

                case "SNILS":
                    expression = () => personDatum.Snils;
                    break;

                    ////case "NumberTemporaryCertificate":
                    ////  expression = () => statement.NumberTemporaryCertificate;
                    ////  break;
                }

                query = criteria.SortDirection == SortDirection.Ascending
                  ? query.OrderBy(expression).Asc
                  : query.OrderBy(expression).Desc;
            }

            query = query.OrderBy(x => x.Id).Asc;
            return(query);
        }
Пример #8
0
        /// <summary>
        /// The add criteria keys.
        /// </summary>
        /// <param name="criteria">
        /// The criteria.
        /// </param>
        /// <param name="deatachQuery">
        /// The deatach query.
        /// </param>
        /// <param name="dpersonDatum">
        /// The dperson datum.
        /// </param>
        /// <param name="ddocument">
        /// The ddocument.
        /// </param>
        /// <param name="dmedicalInsurance">
        /// The dmedical Insurance.
        /// </param>
        /// <param name="emptyCriteria">
        /// The empty Criteria.
        /// </param>
        private void AddCriteriaKeys(
            SearchStatementCriteria criteria,
            QueryOver <Statement, Statement> deatachQuery,
            InsuredPersonDatum dpersonDatum,
            Document ddocument,
            MedicalInsurance dmedicalInsurance,
            bool emptyCriteria)
        {
            ////// Статус заявления
            ////if (criteria.StatementStatus > 0)
            ////{
            ////  deatachQuery.Where(x => x.Status.Id == criteria.StatementStatus);
            ////}

            ////// Тип заявления
            ////if (criteria.StatementType > 0)
            ////{
            ////  deatachQuery.WhereRestrictionOn(x => x.CauseFiling.Id)
            ////    .IsInG(Statement.GetCauseFillingByType(criteria.StatementType));
            ////}

            ////// Поиск по дате подачи заявления
            ////if (criteria.UseDateFiling && criteria.DateFilingFrom != null && criteria.DateFilingTo != null)
            ////{
            ////  if (criteria.DateFilingFrom > criteria.DateFilingTo)
            ////  {
            ////    throw new SearchException("Дата начала периода больше, чем дата его окончания.");
            ////  }

            ////  deatachQuery.WhereRestrictionOn(x => x.DateFiling).IsBetween(criteria.DateFilingFrom).And(criteria.DateFilingTo);
            ////}
            var statement = new Statement
            {
                InsuredPersonData =
                    new InsuredPersonDatum
                {
                    Birthday      = criteria.BirthDate,
                    Birthplace    = criteria.BirthPlace,
                    FirstName     = criteria.FirstName,
                    LastName      = criteria.LastName,
                    MiddleName    = criteria.MiddleName,
                    Snils         = criteria.SNILS,
                    NotCheckSnils = criteria.NotCheckSnils
                },
                DocumentUdl =
                    new Document
                {
                    Series       = criteria.DocumentSeries,
                    Number       = criteria.DocumentNumber,
                    DocumentType =
                        ObjectFactory.GetInstance <IConceptCacheManager>()
                        .GetById(criteria.DocumentTypeId)
                },
            };

            var searchKeyManager = ObjectFactory.GetInstance <ISearchKeyManager>();

            var keys = searchKeyManager.CalculateStandardKeys(statement);

            var queryKeys =
                QueryOver.Of <SearchKey>()
                .WhereRestrictionOn(x => x.KeyValue)
                .IsIn(keys.Select(y => y.KeyValue).ToList())
                .Select(x => x.InsuredPerson.Id);

            deatachQuery.WithSubquery.WhereProperty(x => x.InsuredPerson.Id).In(queryKeys);
        }
Пример #9
0
        /// <summary>
        /// The add criteria data.
        /// </summary>
        /// <param name="criteria">
        /// The criteria.
        /// </param>
        /// <param name="deatachQuery">
        /// The deatach query.
        /// </param>
        /// <param name="dpersonDatum">
        /// The dperson datum.
        /// </param>
        /// <param name="ddocument">
        /// The ddocument.
        /// </param>
        /// <param name="dmedicalInsurance">
        /// The dmedical Insurance.
        /// </param>
        /// <param name="emptyCriteria">
        /// The empty Criteria.
        /// </param>
        private void AddCriteriaData(
            SearchStatementCriteria criteria,
            QueryOver <Statement, Statement> deatachQuery,
            InsuredPersonDatum dpersonDatum,
            Document ddocument,
            MedicalInsurance dmedicalInsurance,
            bool emptyCriteria)
        {
            // Номер ВС
            if (!string.IsNullOrEmpty(criteria.CertificateNumber))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => dmedicalInsurance.PolisNumber == criteria.CertificateNumber)
                .And(x => dmedicalInsurance.PolisType.Id == PolisType.В);
            }

            // Имя
            if (!string.IsNullOrEmpty(criteria.FirstName))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => dpersonDatum.FirstName == criteria.FirstName.Trim());
            }

            // Фамилия
            if (!string.IsNullOrEmpty(criteria.LastName))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => dpersonDatum.LastName == criteria.LastName.Trim());
            }

            // Отчество
            if (!string.IsNullOrEmpty(criteria.MiddleName))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => dpersonDatum.MiddleName == criteria.MiddleName.Trim());
            }

            // СНИЛС
            if (!string.IsNullOrEmpty(criteria.SNILS))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => dpersonDatum.Snils == SnilsChecker.SsToShort(criteria.SNILS));
            }

            // Тип документа
            if (criteria.DocumentTypeId > 0 &&
                (!string.IsNullOrEmpty(criteria.DocumentSeries) || !string.IsNullOrEmpty(criteria.DocumentNumber)))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => ddocument.DocumentType.Id == criteria.DocumentTypeId);
            }

            // Серия документа
            if (!string.IsNullOrEmpty(criteria.DocumentSeries))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => ddocument.Series == criteria.DocumentSeries);
            }

            // Номер документа
            if (!string.IsNullOrEmpty(criteria.DocumentNumber))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => ddocument.Number == criteria.DocumentNumber);
            }

            // Номер документа
            if (!string.IsNullOrEmpty(criteria.BirthPlace))
            {
                emptyCriteria = false;
                deatachQuery.Where(x => dpersonDatum.Birthplace == criteria.BirthPlace.Trim());
            }

            // Номер полиса
            if (!string.IsNullOrEmpty(criteria.PolicyNumber))
            {
                emptyCriteria = false;

                // deatachQuery.Where(x => x.NumberPolicy == criteria.PolicyNumber.Trim());
                deatachQuery.Where(x => dmedicalInsurance.Enp == criteria.PolicyNumber.Trim())
                .And(x => dmedicalInsurance.PolisType.Id != PolisType.В);
            }

            // Дата рождения
            if (criteria.BirthDate.HasValue)
            {
                emptyCriteria = false;
                deatachQuery.Where(x => dpersonDatum.Birthday == criteria.BirthDate.Value);
            }

            if (!string.IsNullOrEmpty(criteria.Error))
            {
                emptyCriteria = false;
                Error error = null;
                deatachQuery.JoinAlias(x => x.Errors, () => error).Where(x => error.Message1 == criteria.Error);
            }

            // если не сработал ни один критерий то осталяем выборку пустой
            if (emptyCriteria)
            {
                throw new SetParameterSearchException();
            }
        }
Пример #10
0
        /// <summary>
        /// Расчитывает и сохраняет пользовательские ключи для заявления
        /// </summary>
        /// <param name="keyTypeList">
        /// The key Type List.
        /// </param>
        /// <param name="pd">
        /// The pd.
        /// </param>
        /// <param name="doc">
        /// The doc.
        /// </param>
        /// <param name="addr1">
        /// The addr 1.
        /// </param>
        /// <param name="addr2">
        /// The addr 2.
        /// </param>
        /// <param name="medicalInsurances">
        /// The medical Insurances.
        /// </param>
        /// <param name="okato">
        /// The okato.
        /// </param>
        /// <returns>
        /// The <see cref="IList{SearchKey}"/>.
        /// </returns>
        public IList <SearchKey> CalculateUserKeys(
            IList <SearchKeyType> keyTypeList,
            InsuredPersonDatum pd,
            Document doc,
            address addr1,
            address addr2,
            IList <MedicalInsurance> medicalInsurances,
            string okato)
        {
            var result = new List <SearchKey>();

            foreach (var kt in keyTypeList)
            {
                // Перекодирование типа ключа
                var keyType = new database.business.model.SearchKeyType
                {
                    RowId                = kt.Id,
                    FirstName            = kt.FirstName,
                    LastName             = kt.LastName,
                    MiddleName           = kt.MiddleName,
                    Birthday             = kt.Birthday,
                    Birthplace           = kt.Birthplace,
                    Snils                = kt.Snils,
                    DocumentType         = kt.DocumentType,
                    DocumentSeries       = kt.DocumentSeries,
                    DocumentNumber       = kt.DocumentNumber,
                    Okato                = kt.Okato,
                    PolisType            = kt.PolisType,
                    PolisSeria           = kt.PolisSeria,
                    PolisNumber          = kt.PolisNumber,
                    FirstNameLength      = kt.FirstNameLength,
                    LastNameLength       = kt.LastNameLength,
                    MiddleNameLength     = kt.MiddleNameLength,
                    BirthdayLength       = kt.BirthdayLength,
                    AddressStreet        = kt.AddressStreet,
                    AddressStreetLength  = kt.AddressStreetLength,
                    AddressHouse         = kt.AddressHouse,
                    AddressRoom          = kt.AddressRoom,
                    AddressStreet2       = kt.AddressStreet2,
                    AddressStreetLength2 = kt.AddressStreetLength2,
                    AddressHouse2        = kt.AddressHouse2,
                    AddressRoom2         = kt.AddressRoom2,
                    IdenticalLetters     = kt.IdenticalLetters
                };

                // Перекодировка персональных данных
                var personData = new database.business.model.InsuredPersonDatum
                {
                    RowId      = pd.Id,
                    LastName   = pd.LastName,
                    FirstName  = pd.FirstName,
                    MiddleName = pd.MiddleName,
                    Birthday   = pd.Birthday,
                    Birthplace = pd.Birthplace,
                    Snils      = pd.Snils,
                };

                // Перекодировка документа
                database.business.model.Document document = null;
                if (doc != null && doc.DocumentType != null)
                {
                    document = new database.business.model.Document
                    {
                        RowId          = doc.Id,
                        DocumentTypeId = doc.DocumentType.Id,
                        Series         = doc.Series,
                        Number         = doc.Number,
                    };
                }

                // Перекодировка адреса регистрации
                var address1 = new database.business.model.address
                {
                    RowId  = addr1.Id,
                    Street = addr1.Street,
                    House  = addr1.House,
                    Room   = addr1.Room,
                    Okato  = addr1.Okato,
                };

                // Перекодировка адреса проживания
                database.business.model.address address2 = null;
                if (addr2 != null)
                {
                    address2 = new database.business.model.address
                    {
                        RowId  = addr2.Id,
                        Street = addr2.Street,
                        House  = addr2.House,
                        Room   = addr2.Room,
                        Okato  = addr2.Okato,
                    };
                }

                // Перекодировка страховок
                foreach (var medicalInsurance in medicalInsurances)
                {
                    var insurance = new database.business.model.MedicalInsurance
                    {
                        RowId       = medicalInsurance.Id,
                        PolisTypeId = medicalInsurance.PolisType.Id,
                        PolisSeria  = medicalInsurance.PolisSeria,
                        PolisNumber = medicalInsurance.PolisNumber,
                    };

                    // Расчет ключа
                    var keyValue = database.business.ObjectFactory.GetPseudonymizationManager()
                                   .CalculateUserSearchKey(
                        keyType,
                        personData,
                        document,
                        address1,
                        address2,
                        insurance,
                        okato);

                    var conceptCacheManager = ObjectFactory.GetInstance <IConceptCacheManager>();
                    var searchKey           = new SearchKey
                    {
                        KeyValue        = keyValue,
                        KeyType         = kt,
                        DocumentUdlType =
                            doc != null && doc.DocumentType != null
                                ? conceptCacheManager.GetById(doc.DocumentType.Id)
                                : null
                    };

                    result.Add(searchKey);
                }
            }

            return(result);
        }