Beispiel #1
0
        async Task <Dataset> ExecuteDatasetAsync(DatasetExecutionContext context, CancellationToken token)
        {
            var sql        = context.CompiledQuery;
            var parameters = context.SqlParameters();
            var pepper     = context.QueryContext.Pepper;

            using (var cn = new SqlConnection(opts.ConnectionString))
            {
                await cn.OpenAsync();

                using (var cmd = new SqlCommand(sql, cn))
                {
                    cmd.Parameters.AddRange(parameters);
                    using (var reader = await cmd.ExecuteReaderAsync(token))
                    {
                        var dbSchema     = GetShapedSchema(context, reader);
                        var marshaller   = DatasetMarshaller.For(context.Shape, dbSchema, pepper);
                        var data         = marshaller.Marshal(reader, user.Anonymize());
                        var resultSchema = ShapedDatasetSchema.From(dbSchema);

                        return(new Dataset
                        {
                            Schema = resultSchema,
                            Results = data.GroupBy(d => d.PersonId).ToDictionary(g => g.Key, g => g.Select(r => r))
                        });
                    }
                }
            }
        }
Beispiel #2
0
        public async Task <Dataset> ExecuteDatasetAsync(DatasetExecutionContext context, CancellationToken token)
        {
            var sql        = context.CompiledQuery;
            var parameters = context.SqlParameters();
            var pepper     = context.QueryContext.Pepper;
            var deidentify = deidentOpts.Patient.Enabled && user.Anonymize();

            using (var cn = new SqlConnection(dbOpts.ConnectionString))
            {
                await cn.OpenAsync();

                using (var cmd = new SqlCommand(sql, cn))
                {
                    cmd.Parameters.AddRange(parameters);
                    using (var reader = await cmd.ExecuteReaderAsync(token))
                    {
                        var dbSchema     = GetShapedSchema(context, reader);
                        var marshaller   = DatasetMarshaller.For(context, dbSchema, pepper);
                        var data         = marshaller.Marshal(reader, deidentify, deidentOpts);
                        var resultSchema = ShapedDatasetSchema.From(dbSchema, context);

                        return(new Dataset(resultSchema, data));
                    }
                }
            }
        }