Exemplo n.º 1
0
        public async Task <SearchResult> GetSearchResult(IVonkContext context)
        {
            Log.Information("Handling Csv");
            _ = await Task.FromResult(true);

            var(_, args, _) = context.Parts();

            foreach (var arg in args)
            {
                if (arg.ArgumentValue.Contains("/$csv"))
                {
                    arg.ArgumentValue = arg.ArgumentValue.Remove
                                            (arg.ArgumentValue.Length - 5);
                }
            }


            // FIXME: double check this

            //        if (!response.Success()) throw new ArgumentException("Server returned 404. Please check query");

            var searchResult = await _searchRepository.Search(context.Arguments,
                                                              SearchOptions.Latest(context.ServerBase, context.Request.Interaction, context.InformationModel));

            return(searchResult);
        }
Exemplo n.º 2
0
 private void CancelEverythingOperation(IVonkContext vonkContext, int statusCode, VonkIssue failedReference = null)
 {
     vonkContext.Response.HttpResult = statusCode;
     if (failedReference != null)
     {
         vonkContext.Response.Outcome.AddIssue(failedReference);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Handle GET [base]/Patient/id/$everything
        /// </summary>
        /// <param name="vonkContext">IVonkContext for details of the request and providing the response</param>
        /// <returns></returns>
        public async Task PatientInstanceGET(IVonkContext vonkContext)
        {
            var patientID = vonkContext.Arguments.ResourceIdArgument().ArgumentValue;

            _logger.LogInformation($"Attempting to find all patient-related resources for patientId: {patientID}");
            await FindPatientReferencedResources(vonkContext, patientID);

            //await EverythingBundle(vonkContext, patientID);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create a new FHIR Search bundle: add the Patient resource as a match, as $everything is a search operation.
        /// Additionally, include all resources found through references in the Patient resource.
        /// Only a single Patient resource is currently considered (the resource upon which $everything is called).
        /// </summary>
        /// <param name="vonkContext"></param>
        /// <returns></returns>
        public async Task EverythingBundle(IVonkContext vonkContext, string patientID)
        {
            // Build empty everything result bundle
            var everythingBundle = CreateEmptyBundle();

            vonkContext.Arguments.Handled(); // Signal to Vonk -> Mark arguments as "done"

            // Get Patient resource
            (var patientResolved, var resolvedResource, var error) = await ResolveResource(patientID, "Patient");

            if (patientResolved)
            {
                if (resolvedResource.InformationModel != vonkContext.InformationModel)
                {
                    CancelEverythingOperation(vonkContext, StatusCodes.Status415UnsupportedMediaType, WrongInformationModel(vonkContext.InformationModel, resolvedResource));
                    return;
                }

                // Include Patient resource in search results
                everythingBundle = everythingBundle.AddEntry(resolvedResource, "Patient/" + patientID);

                // Recursively resolve and include all references in the search bundle, overwrite everythingBundle as GenericBundle is immutable
                (_, everythingBundle, error) = await IncludeReferencesInBundle(resolvedResource, everythingBundle);
            }

            // Handle responses
            if (!(error is null))
            {
                if (!patientResolved) // Patient resource, on which the operation is called, does not exist
                {
                    _logger.LogTrace("$everythingt called on non-existing Patient/{id}", patientID);
                    CancelEverythingOperation(vonkContext, StatusCodes.Status404NotFound);
                }
                else if (error.Equals(VonkIssue.PROCESSING_ERROR))
                {
                    _logger.LogTrace("$everything failed to include resource in correct information model", patientID);
                    CancelEverythingOperation(vonkContext, StatusCodes.Status415UnsupportedMediaType, error);
                }
                else // Local or external reference reference could not be found
                {
                    CancelEverythingOperation(vonkContext, StatusCodes.Status500InternalServerError, error);
                }
                return;
            }

            // Check if we need to persist the bundle
            var persistArgument            = vonkContext.Arguments.GetArgument("persist");
            var userRequestedPersistOption = persistArgument == null ? String.Empty : persistArgument.ArgumentValue;

            if (userRequestedPersistOption.Equals("true"))
            {
                await _changeRepository.Create(everythingBundle.ToIResource(vonkContext.InformationModel));
            }

            SendCreatedBundle(vonkContext, everythingBundle); // Return newly created bundle
        }
        /// <summary>
        /// Handle GET [base]/<Resource>/id/$test and POST [base]/<Resource>/$test
        /// </summary>
        /// <param name="vonkContext">IVonkContext for details of the request and providing the response</param>
        /// <returns></returns>
        public async Task Test(IVonkContext vonkContext)
        {
            var(_, _, response) = vonkContext.Parts();
            vonkContext.Arguments.Handled();
            response.HttpResult = 200;

            _ = await Task.FromResult(true); // Replace with own complex operation

            vonkContext.Response.Outcome.AddIssue(IssueSeverity.Information, IssueType.Informational, diagnostics: "$test operation was executed successfully");

            _logger.LogDebug("VonkPluginService - Executed $test"); // Adjust log level in logsettings.instance.json to see the message
        }
Exemplo n.º 6
0
        public async Task DocumentTypePOST(IVonkContext context)
        {
            var(request, _, response) = context.Parts();
            if (request.GetRequiredPayload(response, out var payload))
            {
                var parameters    = payload.ToTypedElement(_schemaProvider);
                var nameParameter = parameters.Select("children().where($this.name = 'id')").FirstOrDefault();

                var compositionID = nameParameter?.ChildString("value");
                if (string.IsNullOrEmpty(compositionID))
                {
                    response.HttpResult = StatusCodes.Status400BadRequest;
                    response.Outcome.AddIssue(VonkIssue.INVALID_REQUEST, "Parameter 'id' is missing.");
                    return;
                }
                if (!Uri.TryCreate(compositionID, UriKind.Relative, out var uri))
                {
                    response.HttpResult = StatusCodes.Status501NotImplemented;
                    response.Outcome.AddIssue(VonkIssue.NOT_IMPLEMENTED, "Parameter 'id' is an absolute url, which is not supported.");
                    return;
                }
                await Document(context, compositionID);
            }
        }
Exemplo n.º 7
0
 private void SendCreatedBundle(IVonkContext vonkContext, GenericBundle searchBundle)
 {
     vonkContext.Response.Payload    = searchBundle.ToIResource(vonkContext.InformationModel);
     vonkContext.Response.HttpResult = 200;
     vonkContext.Response.Headers.Add(VonkResultHeader.Location, "Bundle/" + vonkContext.Response.Payload.Id);
 }
Exemplo n.º 8
0
        private async Task <(bool found, IEnumerable <IResource> resolvedResources)> ResourceHasPatientReference(IVonkContext vonkContext, string resourceType, string propertyName, string patientId)
        {
            var searchArgs = new ArgumentCollection(
                new Argument(ArgumentSource.Internal, ArgumentNames.resourceType, resourceType)
            {
                MustHandle = true
            },
                new Argument(ArgumentSource.Internal, propertyName, $"Patient/{patientId}")
            {
                MustHandle = true
            }
                );

            var options = SearchOptions.Latest(vonkContext.ServerBase, vonkContext.Request.Interaction, vonkContext.InformationModel);

            var searchResult = await _searchRepository.Search(searchArgs, options);

            if (searchResult == null || searchResult.TotalCount == 0)
            {
                return(false, null);
            }

            return(searchResult.TotalCount > 0, searchResult);
        }
Exemplo n.º 9
0
        private async Task FindPatientReferencedResources(IVonkContext vonkContext, string patientID)
        {
            // Build empty everything result bundle
            var everythingBundle = CreateEmptyBundle();

            vonkContext.Arguments.Handled(); // Signal to Vonk -> Mark arguments as "done"

            // Get Patient resource
            (var patientResolved, var resolvedResource, var error) = await ResolveResource(patientID, "Patient");

            if (patientResolved)
            {
                if (resolvedResource.InformationModel != vonkContext.InformationModel)
                {
                    CancelEverythingOperation(vonkContext, StatusCodes.Status415UnsupportedMediaType, WrongInformationModel(vonkContext.InformationModel, resolvedResource));
                    return;
                }

                // Include Patient resource in search results
                everythingBundle = everythingBundle.AddEntry(resolvedResource, $"Patient/{patientID}");

                IEnumerable <IResource> resources = new List <IResource>();

                foreach (var token in _patientSearchList)
                {
                    bool found = false;

                    var resourceName = token["code"].Value <string>();
                    var param        = token["param"].Values <string>();

                    foreach (string propName in param)
                    {
                        (found, resources) = await ResourceHasPatientReference(vonkContext, resourceName, propName, patientID);

                        if (found)
                        {
                            _logger.LogInformation($"Found: {found}, Count: {resources.Count()} resources for [Resource: {resourceName}, PropertyName: {propName}");

                            foreach (var resource in resources)
                            {
                                // add resources to bundle
                                everythingBundle = everythingBundle.AddEntry(resource, $"{resourceName}/{resource.Id}");
                            }
                        }
                    }
                }
            }

            // Handle responses
            if (!(error is null))
            {
                if (!patientResolved) // Patient resource, on which the operation is called, does not exist
                {
                    _logger.LogTrace("$everythingt called on non-existing Patient/{id}", patientID);
                    CancelEverythingOperation(vonkContext, StatusCodes.Status404NotFound);
                }
                else if (error.Equals(VonkIssue.PROCESSING_ERROR))
                {
                    _logger.LogTrace("$everything failed to include resource in correct information model", patientID);
                    CancelEverythingOperation(vonkContext, StatusCodes.Status415UnsupportedMediaType, error);
                }
                else // Local or external reference reference could not be found
                {
                    CancelEverythingOperation(vonkContext, StatusCodes.Status500InternalServerError, error);
                }
                return;
            }

            // Check if we need to persist the bundle
            var persistArgument            = vonkContext.Arguments.GetArgument("persist");
            var userRequestedPersistOption = persistArgument == null ? String.Empty : persistArgument.ArgumentValue;

            if (userRequestedPersistOption.Equals("true"))
            {
                await _changeRepository.Create(everythingBundle.ToIResource(vonkContext.InformationModel));
            }

            SendCreatedBundle(vonkContext, everythingBundle); // Return newly created bundle
        }
Exemplo n.º 10
0
        /// <summary>
        /// Handle GET [base]/Composition/id/$document
        /// </summary>
        /// <param name="vonkContext">IVonkContext for details of the request and providing the response</param>
        /// <returns></returns>
        public async Task DocumentInstanceGET(IVonkContext vonkContext)
        {
            var compositionID = vonkContext.Arguments.ResourceIdArgument().ArgumentValue;

            await Document(vonkContext, compositionID);
        }
 public async Task PostHandlerTest(IVonkContext vonkContext)
 {
     _logger.LogDebug("VonkPluginService - PostHandler $test");
     _ = await Task.FromResult(true);
 }
 public async Task PrepareTest(IVonkContext vonkContext)
 {
     _logger.LogDebug("VonkPluginService - About to execute $test");
     _ = await Task.FromResult(true);
 }