Exemplo n.º 1
0
 public CohortCounter(IPanelConverter converter,
                      IPanelValidator validator,
                      IPatientCohortService counter,
                      ICohortCacheService cohortCache,
                      IUserContext user,
                      ILogger <CohortCounter> log)
 {
     this.converter   = converter;
     this.validator   = validator;
     this.counter     = counter;
     this.cohortCache = cohortCache;
     this.user        = user;
     this.log         = log;
 }
Exemplo n.º 2
0
        public async Task <ActionResult <QuerySaveResponseDTO> > Save(
            string id,
            [FromBody] QuerySaveDTO querySave,
            [FromServices] IPanelConverterService panelConverter,
            [FromServices] IPanelValidator panelValidator,
            CancellationToken cancelToken
            )
        {
            try
            {
                // federated user submitting an initial save request
                if (!user.IsInstutional && QueryUrn.From(querySave.UniversalId) == null)
                {
                    return(BadRequest("Initial save requests must be made to home node."));
                }

                var ctx = await panelConverter.GetPanelsAsync(querySave, cancelToken);

                if (!ctx.PreflightPassed)
                {
                    return(BadRequest(new QuerySaveResponseDTO {
                        Preflight = new PreflightCheckDTO(ctx.PreflightCheck)
                    }));
                }
                var query = panelValidator.Validate(ctx);

                cancelToken.ThrowIfCancellationRequested();

                if (!user.IsInstutional)
                {
                    panelConverter.LocalizeDefinition(querySave, query);
                }


                var toSave = new QuerySave
                {
                    QueryId     = new Guid(id),
                    UniversalId = ctx.UniversalId,
                    Name        = querySave.Name,
                    Category    = querySave.Category,
                    Definition  = QueryDefinitionDTO.JSON(querySave),
                    Resources   = query.Panels.GetResources()
                };
                if (querySave.Ver.HasValue)
                {
                    toSave.Ver = querySave.Ver.Value;
                }

                var saved = await queryService.Save(toSave);

                if (saved == null)
                {
                    return(NotFound());
                }

                var response = new QuerySaveResponseDTO
                {
                    Preflight = new PreflightCheckDTO(ctx.PreflightCheck),
                    Query     = new QuerySaveResultDTO(saved)
                };

                return(Ok(response));
            }
            catch (InvalidOperationException ie)
            {
                log.LogError("Unrecoverable validation error in query. Error:{Error}", ie.Message);
                return(BadRequest());
            }
            catch (FormatException fe)
            {
                log.LogError("Malformed query identifier. Id:{Id} UniversalId:{UniversalId} Error:{Error}", id, querySave.UniversalId, fe.Message);
                return(BadRequest());
            }
            catch (OperationCanceledException)
            {
                log.LogInformation("Request cancelled.");
                return(NoContent());
            }
            catch (LeafDbException lde)
            {
                return(StatusCode(lde.StatusCode));
            }
            catch (Exception e)
            {
                log.LogError("Could not save query. QueryId:{QueryId} Query:{@Query} Error:{Error}", id, querySave, e.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }