Exemplo n.º 1
0
        public static JObject LoadErrorsDetected(string source, FHIRResponse response, string name, ILogger log)
        {
            log.LogInformation($"ImportFHIRBundles:Checking for load errors file {name}");
            JObject retVal = new JObject();

            retVal["id"]        = name;
            retVal["errors"]    = new JArray();
            retVal["throttled"] = new JArray();
            try
            {
                JObject so = JObject.Parse(source);
                JObject o  = JObject.Parse(response.Content);
                int     ec = 0;
                if (o["entry"] != null && so["entry"] != null)
                {
                    JArray oentries = (JArray)so["entry"];
                    JArray entries  = (JArray)o["entry"];
                    if (oentries.Count != entries.Count)
                    {
                        log.LogWarning($"ImportFHIRBundles: Original resource count and response counts do not agree for file {name}");
                    }
                    foreach (JToken tok in entries)
                    {
                        if (tok["response"] != null && tok["response"]["status"] != null)
                        {
                            string s  = (string)tok["response"]["status"];
                            int    rc = 200;
                            if (int.TryParse(s, out rc))
                            {
                                if (rc < 200 || rc > 299)
                                {
                                    if (rc == 429)
                                    {
                                        JArray ja = (JArray)retVal["throttled"];
                                        ja.Add(oentries[ec]);
                                    }
                                    else
                                    {
                                        JObject errcontainer = new JObject();
                                        errcontainer["resource"] = oentries[ec];
                                        errcontainer["response"] = tok["response"];
                                        JArray ja = (JArray)retVal["errors"];
                                        ja.Add(errcontainer);
                                    }
                                }
                            }
                        }
                        ec++;
                    }
                    JArray jac = (JArray)retVal["throttled"];
                    if (jac.Count > 0)
                    {
                        log.LogError($"ImportFHIRBundles: {jac.Count} resources were throttled by server for {name}");
                    }
                    jac = (JArray)retVal["errors"];
                    if (jac.Count > 0)
                    {
                        log.LogError($"ImportFHIRBundles: {jac.Count} errors detected in response entries for {name}");
                    }
                }
                else
                {
                    log.LogWarning($"ImportFHIRBundles: Cannot detect resource entries in source/response for {name}");
                }
                return(retVal);
            }
            catch (Exception e)
            {
                log.LogError($"ImportFHIRBundles: Unable to parse server response to check for errors file {name}:{e.Message}");
                return(retVal);
            }
        }