Ejemplo n.º 1
0
        public async Task <PatientDemographicContext> GetDemographicsAsync(DemographicCompilerContext context, CancellationToken token)
        {
            var exeContext = compiler.BuildDemographicSql(context, user.Anonymize());

            log.LogInformation("Compiled Demographic Execution Context. Context:{@Context}", exeContext);
            var demographic = await ExecuteDemographicsAsync(exeContext, token);

            return(demographic);
        }
Ejemplo n.º 2
0
 CompilerContextState GetContextState(DemographicCompilerContext context)
 {
     if (context.DemographicQuery == null || string.IsNullOrWhiteSpace(context.DemographicQuery.SqlStatement))
     {
         log.LogError("No demographic query configured in Leaf database.");
         return(CompilerContextState.DatasetNotFound);
     }
     if (!context.QueryContext.Found)
     {
         log.LogWarning("Incomplete demographic compiler context. Context:{@Context}", context);
         return(CompilerContextState.QueryNotFound);
     }
     return(CompilerContextState.Ok);
 }
Ejemplo n.º 3
0
        public DemographicExecutionContext BuildDemographicSql(DemographicCompilerContext context, bool restrictPhi)
        {
            executionContext = new DemographicExecutionContext(context.Shape, context.QueryContext);

            var cohort = CteCohortInternals(context.QueryContext);

            new SqlValidator(Dialect.ILLEGAL_COMMANDS).Validate(context.DemographicQuery);
            var dataset = CteDemographicInternals(context.DemographicQuery);

            var filter = CteFilterInternals(context, restrictPhi);
            var select = SelectFromCTE();

            executionContext.CompiledQuery = Compose(cohort, dataset, filter, select);

            return(executionContext);
        }
Ejemplo n.º 4
0
        string CteFilterInternals(DemographicCompilerContext context, bool restrictPhi)
        {
            var schema = ShapedDatasetContract.For(context.Shape);

            if (!restrictPhi)
            {
                executionContext.FieldSelectors = schema.Fields;
                return($"SELECT * FROM dataset");
            }

            bool include(SchemaFieldSelector field) => field.Required || !field.Phi || field.Mask;

            var restricted = schema.Fields.Where(include);

            executionContext.FieldSelectors = restricted;
            var fields = string.Join(", ", restricted.Select(f => f.Name));

            return($"SELECT {fields} FROM dataset");
        }