Example #1
0
        public async Task <FhirResponse> Create(string type, Resource resource)
        {
            var key = Key.Create(type, resource?.Id);

            if (Request.Headers.ContainsKey(FhirHttpHeaders.IfNoneExist))
            {
                var searchQueryString = HttpUtility.ParseQueryString(Request.GetTypedHeaders().IfNoneExist());
                var searchValues      = searchQueryString.Keys.Cast <string>()
                                        .Select(k => new Tuple <string, string>(k, searchQueryString[k]));

                return(await _fhirService.ConditionalCreate(key, resource, SearchParams.FromUriParamList(searchValues))
                       .ConfigureAwait(false));
            }

            return(await _fhirService.Create(key, resource).ConfigureAwait(false));
        }
Example #2
0
        public async void LoadExamplesToStore()
        {
            try
            {
                await _hubContext.Clients.All.SendAsync("UpdateProgress", "Loading examples").ConfigureAwait(false);

                _resources = GetExampleData();

                var resarray = _resources.ToArray();
                _resourceCount = resarray.Length;

                for (int x = 0; x <= _resourceCount - 1; x++)
                {
                    var res = resarray[x];
                    var msg = $"Importing {res.TypeName}, id {res.Id} ...";
                    await _hubContext.Clients.All.SendAsync("UpdateProgress", msg).ConfigureAwait(false);

                    try
                    {
                        Key key = res.ExtractKey();

                        if (!string.IsNullOrEmpty(res.Id))
                        {
                            await _fhirService.Put(key, res).ConfigureAwait(false);
                        }
                        else
                        {
                            await _fhirService.Create(key, res).ConfigureAwait(false);
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e, "Failed when loading example.");
                        var msgError = $"ERROR Importing {res.TypeName}, id {res.Id}...";
                        await _hubContext.Clients.All.SendAsync("UpdateProgress", msgError).ConfigureAwait(false);
                    }
                }

                await _hubContext.Clients.All.SendAsync("UpdateProgress", "Finished loading examples").ConfigureAwait(false);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Failed to load examples.");
                await _hubContext.Clients.All.SendAsync("UpdateProgress", "Error: " + e.Message).ConfigureAwait(false);
            }
        }