Ejemplo n.º 1
0
        public HttpResponseMessage Update(string type, string id, ResourceEntry entry)
        {
            entry.Tags = Request.GetFhirTags(); // todo: move to model binder?

            // ballot: Update is a mix between name from CRUD (only update no create) and functionality from Rest PUT (Create or update)
            ResourceEntry newEntry = service.Update(type, id, entry, null);

            if (newEntry != null)
            {
                return(Request.StatusResponse(newEntry, HttpStatusCode.OK));
            }
            else
            {
                newEntry = service.Create(type, entry, id);
                return(Request.StatusResponse(newEntry, HttpStatusCode.Created));
            }
        }
Ejemplo n.º 2
0
        public void LoadData()
        {
            var messages = new StringBuilder();

            messages.AppendLine("Import completed!");
            try
            {
                //cleans store and index
                Progress("Clearing the database...", 0);
                fhirStoreAdministration.Clean();
                fhirIndex.Clean();

                Progress("Loading examples data...", 5);
                this.resources = GetExampleData();

                var resarray = resources.ToArray();
                ResourceCount = resarray.Count();

                for (int x = 0; x <= ResourceCount - 1; x++)
                {
                    var res = resarray[x];
                    // Sending message:
                    var msg = Message("Importing " + res.ResourceType.ToString() + " " + res.Id + "...", x);
                    Clients.Caller.sendMessage(msg);

                    try
                    {
                        //Thread.Sleep(1000);
                        Key key = res.ExtractKey();

                        if (res.Id != null && res.Id != "")
                        {
                            fhirService.Put(key, res);
                        }
                        else
                        {
                            fhirService.Create(key, res);
                        }
                    }
                    catch (Exception e)
                    {
                        // Sending message:
                        var msgError = Message("ERROR Importing " + res.ResourceType.ToString() + " " + res.Id + "... ", x);
                        Clients.Caller.sendMessage(msg);
                        messages.AppendLine(msgError.Message + ": " + e.Message);
                    }
                }

                Progress(messages.ToString(), 100);
            }
            catch (Exception e)
            {
                Progress("Error: " + e.Message);
            }
        }
Ejemplo n.º 3
0
        public async void LoadExamplesToStore()
        {
            var messages = new StringBuilder();
            var notifier = new HubContextProgressNotifier(_hubContext, _logger);

            try
            {
                await notifier.SendProgressUpdate("Loading examples data...", 1);

                _resources = GetExampleData();

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

                for (int x = 0; x <= _resourceCount - 1; x++)
                {
                    var res = resarray[x];
                    // Sending message:
                    var msg = Message("Importing " + res.ResourceType.ToString() + " " + res.Id + "...", x);
                    await notifier.SendProgressUpdate(msg.Message, msg.Progress);

                    try
                    {
                        Key key = res.ExtractKey();

                        if (res.Id != null && res.Id != "")
                        {
                            _fhirService.Put(key, res);
                        }
                        else
                        {
                            _fhirService.Create(key, res);
                        }
                    }
                    catch (Exception e)
                    {
                        // Sending message:
                        var msgError = Message("ERROR Importing " + res.ResourceType.ToString() + " " + res.Id + "... ", x);
                        await Clients.All.SendAsync("Error", msg);

                        messages.AppendLine(msgError.Message + ": " + e.Message);
                    }
                }

                await notifier.SendProgressUpdate(messages.ToString(), 100);
            }
            catch (Exception e)
            {
                await notifier.Progress("Error: " + e.Message);
            }
        }
Ejemplo n.º 4
0
        public HttpResponseMessage ResourceCreate(string type, Resource resource, IFhirService service)
        {
            if (service != null && !string.IsNullOrEmpty(type) && resource != null)
            {
                var key    = Key.Create(type);
                var result = service.Create(key, resource);
                if (result != null)
                {
                    return(result);
                }
            }

            return(new HttpResponseMessage(HttpStatusCode.Ambiguous));
        }
Ejemplo n.º 5
0
        public FhirResponse Create(string type, Resource resource)
        {
            Key key = Key.Create(type, resource?.Id);

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

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

            return(_fhirService.Create(key, resource));
        }
Ejemplo n.º 6
0
        public ServerFhirResponse Create(string type, Resource resource)
        {
            Key key = Key.Create(type, resource?.Id);

            if (HttpHeaderUtil.Exists(Request.Headers, FhirHttpHeaders.IfNoneExist))
            {
                NameValueCollection searchQueryString =
                    HttpUtility.ParseQueryString(
                        Request.Headers.First(h => h.Key == FhirHttpHeaders.IfNoneExist).Value.Single());

                IEnumerable <Tuple <string, string> > searchValues =
                    searchQueryString.Keys.Cast <string>()
                    .Select(k => new Tuple <string, string>(k, searchQueryString[k]));


                return(fhirService.ConditionalCreate(key, resource, SearchParams.FromUriParamList(searchValues)));
            }

            return(fhirService.Create(key, resource));
        }
Ejemplo n.º 7
0
        public FhirResponse Create(string type, Resource resource)
        {
            Key key = Key.Create(type, resource?.Id);

            if (Request.Headers.Exists(FhirHttpHeaders.IfNoneExist))
            {
                NameValueCollection searchQueryString =
                    HttpUtility.ParseQueryString(
                        Request.Headers.First(h => h.Key == FhirHttpHeaders.IfNoneExist).Value.Single());
                IEnumerable <Tuple <string, string> > searchValues =
                    searchQueryString.Keys.Cast <string>()
                    .Select(k => new Tuple <string, string>(k, searchQueryString[k]));


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

            //entry.Tags = Request.GetFhirTags(); // todo: move to model binder?

            return(_fhirService.Create(key, resource));
        }