Example #1
0
        /// <summary>
        /// Setting Global Patient object _patientInfo
        /// </summary>
        public void InitialisePatient(string id)
        {
            try
            {
                isExceptionEncountered = false;

                Patient pt = _fc.Read <Patient>(ResourceIdentity.Build("Patient", id));

                Generalinformation = new PDInformation(pt);

                setPatientDetectedIssues();

                getPatientAllergies();

                getPatientCurrentConditions();
            }
            catch (FhirOperationException foe)
            {
                isExceptionEncountered = true;
                ExceptionIssues        = foe.Outcome.Issue;
            }
            catch (Exception ex)
            {
                isExceptionEncountered = true;
                OperationOutcome.IssueComponent ic = new OperationOutcome.IssueComponent();
                ic.Diagnostics = ex.Message;
                ExceptionIssues.Add(ic);
            }
        }
        /// <summary>
        /// Deserialize JSON into a FHIR OperationOutcome#Issue
        /// </summary>
        public static void DeserializeJson(this OperationOutcome.IssueComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options)
        {
            string propertyName;

            while (reader.Read())
            {
                if (reader.TokenType == JsonTokenType.EndObject)
                {
                    return;
                }

                if (reader.TokenType == JsonTokenType.PropertyName)
                {
                    propertyName = reader.GetString();
                    if (Hl7.Fhir.Serialization.FhirSerializerOptions.Debug)
                    {
                        Console.WriteLine($"OperationOutcome.IssueComponent >>> OperationOutcome#Issue.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    reader.Read();
                    current.DeserializeJsonProperty(ref reader, options, propertyName);
                }
            }

            throw new JsonException($"OperationOutcome.IssueComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
Example #3
0
        private static void AddError(this OperationOutcome outcome, Exception exception)
        {
            string message;

            if (exception is SparkException)
            {
                message = exception.Message;
            }
            else
            {
                message = $"{exception.GetType().Name}: {exception.Message}";
            }

            outcome.AddError(message);

            // Don't add a stacktrace if this is an acceptable logical-level error
            if (!(exception is SparkException))
            {
                var stackTrace = new OperationOutcome.IssueComponent
                {
                    Severity    = OperationOutcome.IssueSeverity.Information,
                    Diagnostics = exception.StackTrace
                };
                outcome.Issue.Add(stackTrace);
            }
        }
Example #4
0
        public static OperationOutcome Error(this OperationOutcome outcome, Exception exception)
        {
            string message;

            if (exception is FhirServerException)
            {
                message = exception.Message;
            }
            else
            {
                message = string.Format("{0}: {1}", exception.GetType().Name, exception.Message);
            }

            var baseResult = outcome.Error(message);

            // Don't add a stack trace if this is an acceptable logical-level error
            if (!(exception is FhirServerException))
            {
                var stackTrace = new OperationOutcome.IssueComponent();
                stackTrace.Severity = OperationOutcome.IssueSeverity.Information;
                stackTrace.Details  = new CodeableConcept(null, null, exception.StackTrace);
                baseResult.Issue.Add(stackTrace);
            }

            return(baseResult);
        }
 public static OperationOutcome Append(OperationOutcome.IssueSeverity IssueSeverity, OperationOutcome.IssueType?IssueType, string Message, ICollection <string> Location, OperationOutcome Exsisting = null)
 {
     //Todo: if I need to escape the messages then use this function below!!
     //XhtmlSupport.EncodeToString(Issue.Details.Text);
     if (Exsisting == null)
     {
         return(Create(IssueSeverity, IssueType, Message));
     }
     else
     {
         var oIssueComponent = new OperationOutcome.IssueComponent();
         oIssueComponent.Severity = IssueSeverity;
         if (IssueType.HasValue)
         {
             oIssueComponent.Code = IssueType.Value;
         }
         oIssueComponent.Location     = Location;
         oIssueComponent.Details      = new CodeableConcept();
         oIssueComponent.Details.Text = Message;
         if (Exsisting.Issue == null)
         {
             Exsisting.Issue = new List <OperationOutcome.IssueComponent>();
         }
         Exsisting.Issue.Add(oIssueComponent);
         return(Exsisting);
     }
 }
Example #6
0
        public OperationOutcome.IssueComponent ToIssueComponent(string message, string path = null)
        {
            // https://www.hl7.org/fhir/operationoutcome-definitions.html#OperationOutcome.issue.details
            // Comments: "A human readable description of the error issue SHOULD be placed in details.text."

            // var ic = new OperationOutcome.IssueComponent() { Severity = this.Severity, Code = this.Type, Diagnostics = message };
            var ic = new OperationOutcome.IssueComponent()
            {
                Severity = this.Severity, Code = this.Type
            };

            ic.Details = ToCodeableConcept(message);

            if (path != null)
            {
                ic.Location = new List <string> {
                    path
                }
            }
            ;
            if (message != null)
            {
                ic.Details = ToCodeableConcept(message);
            }

            return(ic);
        }
        private static OperationOutcome.IssueComponent CheckForHttpResponseException(Exception exception)
        {
            OperationOutcome.IssueComponent responseIssue = null;
            if (exception.GetType().ToString().Contains(nameof(HttpResponseException)))
            {
                var responseException = (HttpResponseException)exception;

                if (responseException.Response != null)
                {
                    responseIssue = new OperationOutcome.IssueComponent
                    {
                        Severity = OperationOutcome.IssueSeverity.Fatal,
                        Code     = OperationOutcome.IssueType.Exception,
                        Details  =
                            new CodeableConcept("Response", exception.GetType().ToString(),
                                                responseException.Response.ReasonPhrase)
                    };
                    if (ShowStackTraceInOperationOutcome())
                    {
                        responseIssue.Diagnostics = exception.StackTrace;
                    }
                }
            }
            return(responseIssue);
        }
        public static OperationOutcome AddError(this OperationOutcome outcome, Exception exception)
        {
            string message;

            if (exception is SparkException)
            {
                message = exception.Message;
            }
            else
            {
                message = string.Format("{0}: {1}", exception.GetType().Name, exception.Message);
            }

            outcome.AddError(message);

            // Don't add a stacktrace if this is an acceptable logical-level error
            if (Debugger.IsAttached && !(exception is SparkException))
            {
                var stackTrace = new OperationOutcome.IssueComponent
                {
                    Severity    = OperationOutcome.IssueSeverity.Information,
                    Diagnostics = exception.StackTrace
                };
                outcome.Issue.Add(stackTrace);
            }

            return(outcome);
        }
Example #9
0
        private async Task <Resource> ProcessSingleResource(Resource p, string resourceType, string matchversionid = null)
        {
            //Version conflict detection
            if (!String.IsNullOrEmpty(matchversionid))
            {
                var cv = await storage.LoadFHIRResource(p.Id, resourceType);

                if (cv == null || !matchversionid.Equals(cv.Meta.VersionId))
                {
                    OperationOutcome oo = new OperationOutcome();
                    oo.Issue = new System.Collections.Generic.List <OperationOutcome.IssueComponent>();
                    OperationOutcome.IssueComponent ic = new OperationOutcome.IssueComponent();
                    ic.Severity    = OperationOutcome.IssueSeverity.Error;
                    ic.Code        = OperationOutcome.IssueType.Exception;
                    ic.Diagnostics = "Version conflict current resource version of " + resourceType + "/" + p.Id + " is " + cv.Meta.VersionId;
                    oo.Issue.Add(ic);
                    return(oo);
                }
            }
            //Prepare for Insert/update and Version
            if (String.IsNullOrEmpty(p.Id))
            {
                p.Id = Guid.NewGuid().ToString();
            }
            p.Meta             = new Meta();
            p.Meta.VersionId   = Guid.NewGuid().ToString();
            p.Meta.LastUpdated = DateTimeOffset.UtcNow;
            var rslt = await storage.UpsertFHIRResource(p);

            return(p);
        }
Example #10
0
        public Base Read(SearchParams searchParams)
        {
            var parameters = searchParams.Parameters;

            foreach (var parameter in parameters)
            {
                if (parameter.Item1.ToLower().Contains("log") && parameter.Item2.ToLower().Contains("normal"))
                {
                    throw new ArgumentException("Using " + nameof(SearchParams) +
                                                " in Read(SearchParams searchParams) should throw an exception which is put into an OperationOutcomes issues");
                }
                if (parameter.Item1.Contains("log") && parameter.Item2.Contains("operationoutcome"))
                {
                    var operationOutcome = new OperationOutcome {
                        Issue = new List <OperationOutcome.IssueComponent>()
                    };
                    var issue = new OperationOutcome.IssueComponent
                    {
                        Severity = OperationOutcome.IssueSeverity.Information,
                        Code     = OperationOutcome.IssueType.Incomplete,
                        Details  = new CodeableConcept("SomeExampleException", typeof(FhirOperationException).ToString(),
                                                       "Something expected happened and needs to be handled with more detail.")
                    };
                    operationOutcome.Issue.Add(issue);
                    //var errorMessage = fh
                    var serialized = FhirSerializer.SerializeResourceToXml(operationOutcome);
                    throw new ArgumentException(serialized);
                }
            }
            throw new ArgumentException("Generic error");
        }
Example #11
0
        public static void ConfigureExceptionHandler(this IApplicationBuilder app, ILogger <IFhirService> logger)
        {
            app.UseExceptionHandler(appError =>
            {
                appError.Run(async context =>
                {
                    context.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
                    context.Response.ContentType = "application/json";

                    var contextFeature = context.Features.Get <IExceptionHandlerFeature>();
                    if (contextFeature != null)
                    {
                        logger.LogError($"The request {context.Request.Path} failed: {contextFeature.Error}");
                        var issue = new OperationOutcome.IssueComponent
                        {
                            Details = new CodeableConcept(nameof(HttpError), nameof(HttpError),
                                                          contextFeature.Error.Message),
                            Diagnostics = contextFeature.Error.StackTrace
                        };
                        var outcome = new OperationOutcome();
                        outcome.Issue.Add(issue);
                        var fhirJsonSerializer = new FhirJsonSerializer();
                        var outcomeStr         = fhirJsonSerializer.SerializeToString(outcome);
                        await context.Response.WriteAsync(outcomeStr);
                    }
                });
            });
        }
        protected override Resource GetOperationOutCome(Exception exception)
        {
            LogError(exception);

            var operationOutCome = new OperationOutcome {
                Issue = new List <OperationOutcome.IssueComponent>()
            };
            var issue = new OperationOutcome.IssueComponent
            {
                Severity = OperationOutcome.IssueSeverity.Fatal,
                Code     = OperationOutcome.IssueType.NotFound,
                Details  = new CodeableConcept("StandardException", exception.GetType().ToString(), exception.Message),
            };

            if (exception.InnerException != null)
            {
                issue.Diagnostics = exception.InnerException.Message;
            }

            var responseIssue = CheckForHttpResponseException(exception);

            if (responseIssue != null)
            {
                operationOutCome.Issue.Add(responseIssue);
            }

            operationOutCome.Issue.Add(issue);
            return(operationOutCome);
        }
        public static Resource GetOperationOutCome(Exception exception, bool ShowStackTrace)
        {
            var operationOutCome = new OperationOutcome {
                Issue = new List <OperationOutcome.IssueComponent>()
            };
            var issue = new OperationOutcome.IssueComponent
            {
                Severity = OperationOutcome.IssueSeverity.Fatal,
                Code     = OperationOutcome.IssueType.NotFound,
                Details  = new CodeableConcept("StandardException", exception.GetType().ToString(), exception.Message),
            };

            if (ShowStackTrace)
            {
                issue.Diagnostics = exception.StackTrace;
            }

            var responseIssue = CheckForHttpResponseException(exception, ShowStackTrace);

            if (responseIssue != null)
            {
                operationOutCome.Issue.Add(responseIssue);
            }

            operationOutCome.Issue.Add(issue);
            return(operationOutCome);
        }
        public static bool IsAt(this OperationOutcome.IssueComponent issue, string path)
        {
            if (issue.Location != null)
            {
                return(issue.Location.Contains(path));
            }

            return(false);
        }
Example #15
0
        public void AddIssue(string errorMessage, OperationOutcome.IssueSeverity severity = OperationOutcome.IssueSeverity.Error)
        {
            var newIssue = new OperationOutcome.IssueComponent()
            {
                Diagnostics = errorMessage, Severity = severity
            };

            outcome.Issue.Add(newIssue);
        }
Example #16
0
        public HttpResponseMessage GetHistoryComplete(string resource, string id)
        {
            try
            {
                string respval               = "";
                string validResource         = FhirHelper.ValidateResourceType(resource);
                IEnumerable <string> history = storage.HistoryStore.GetResourceHistory(validResource, id);
                //Create Return Bundle
                Bundle results = new Bundle();
                results.Id    = Guid.NewGuid().ToString();
                results.Type  = Bundle.BundleType.History;
                results.Total = history.Count();
                results.Link  = new System.Collections.Generic.List <Bundle.LinkComponent>();
                results.Link.Add(new Bundle.LinkComponent()
                {
                    Url = Request.RequestUri.GetLeftPart(UriPartial.Authority), Relation = "self"
                });
                results.Entry = new System.Collections.Generic.List <Bundle.EntryComponent>();
                //Add History Items to Bundle
                foreach (string h in history)
                {
                    //todo
                    var r = (Resource)jsonparser.Parse(h, FhirHelper.ResourceTypeFromString(validResource));
                    results.Entry.Add(new Bundle.EntryComponent()
                    {
                        Resource = r, FullUrl = FhirHelper.GetFullURL(Request, r)
                    });
                }


                //Serialize and Return Bundle
                respval = SerializeResponse(results);
                var response = this.Request.CreateResponse(HttpStatusCode.OK);
                response.Headers.TryAddWithoutValidation("Accept", CurrentAcceptType);

                response.Content = new StringContent(respval, Encoding.UTF8);
                response.Content.Headers.TryAddWithoutValidation("Content-Type", IsAccceptTypeJSON ? FHIRCONTENTTYPEJSON : FHIRCONTENTTYPEXML);
                return(response);
            }
            catch (Exception e)
            {
                OperationOutcome oo = new OperationOutcome();
                oo.Issue = new System.Collections.Generic.List <OperationOutcome.IssueComponent>();
                OperationOutcome.IssueComponent ic = new OperationOutcome.IssueComponent();
                ic.Severity    = OperationOutcome.IssueSeverity.Error;
                ic.Code        = OperationOutcome.IssueType.Exception;
                ic.Diagnostics = e.Message;
                oo.Issue.Add(ic);
                var response = this.Request.CreateResponse(HttpStatusCode.BadRequest);
                response.Headers.TryAddWithoutValidation("Accept", CurrentAcceptType);
                response.Content = new StringContent(SerializeResponse(oo), Encoding.UTF8);
                response.Content.Headers.TryAddWithoutValidation("Content-Type", IsAccceptTypeJSON ? FHIRCONTENTTYPEJSON : FHIRCONTENTTYPEXML);
                response.Content.Headers.LastModified = DateTimeOffset.Now;
                return(response);
            }
        }
        public static OperationOutcome.IssueComponent CreateIssue(OperationOutcome.IssueSeverity IssueSeverity, OperationOutcome.IssueType?IssueType, string Message)
        {
            var Issue = new OperationOutcome.IssueComponent();

            Issue.Severity     = IssueSeverity;
            Issue.Code         = IssueType;
            Issue.Details      = new CodeableConcept();
            Issue.Details.Text = Message;
            return(Issue);
        }
Example #18
0
        public async SystemTask.Task Invoke(HttpContext context)
        {
            context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;

            var ex = context.Features.Get <IExceptionHandlerFeature>()?.Error;

            if (ex == null)
            {
                return;
            }

            var ooException = new HttpFhirException();

            OperationOutcome.IssueComponent fhirIssue = null;
            var issue = new Issue
            {
                Message = "An unkown error has occured."
            };

            if (ex.GetType() == typeof(HttpFhirException))
            {
                ooException = ex as HttpFhirException;
                fhirIssue   = ooException.OperationOutcome?.Issue.FirstOrDefault();
            }

            if (fhirIssue != null)
            {
                issue.Message  = fhirIssue?.Code.ToString();
                issue.Severity = EnumHelpers.GetEnum <IssueSeverity>(fhirIssue.Severity.ToString());
                issue.Details  = fhirIssue.Details;
            }

            if (_env.IsDevelopment())
            {
                issue.Diagnostics = $"Message: {ex.Message}. StackTrace: {ex.StackTrace}.";

                if (ex.InnerException != null)
                {
                    issue.Diagnostics = $"{issue.Diagnostics}. Inner Exception Stack Trace: {ex.InnerException.StackTrace}";
                }

                if (fhirIssue != null)
                {
                    issue.Diagnostics = fhirIssue?.Diagnostics;
                }
            }

            context.Response.ContentType = "application/json";

            using (var writer = new StreamWriter(context.Response.Body))
            {
                new JsonSerializer().Serialize(writer, issue);
                await writer.FlushAsync().ConfigureAwait(false);
            }
        }
Example #19
0
        public async Task <HttpResponseMessage> Get(string resource, string id)
        {
            try
            {
                if (Request.Method == HttpMethod.Post)
                {
                    return(await Upsert(resource));
                }
                if (Request.Method == HttpMethod.Put)
                {
                    return(await Upsert(resource));
                }

                HttpResponseMessage response = null;
                string respval       = "";
                string validResource = FhirHelper.ValidateResourceType(resource);
                var    retVal        = await storage.LoadFHIRResource(id, validResource);

                if (retVal != null)
                {
                    respval  = SerializeResponse(retVal);
                    response = this.Request.CreateResponse(HttpStatusCode.OK);
                    response.Headers.TryAddWithoutValidation("Accept", CurrentAcceptType);
                    response.Content = new StringContent(respval, Encoding.UTF8);
                    response.Content.Headers.LastModified = retVal.Meta.LastUpdated;
                    response.Headers.Add("ETag", "W/\"" + retVal.Meta.VersionId + "\"");
                }
                else
                {
                    response         = this.Request.CreateResponse(HttpStatusCode.NotFound);
                    response.Content = new StringContent("", Encoding.UTF8);
                }
                response.Content.Headers.TryAddWithoutValidation("Content-Type", IsAccceptTypeJSON ? FHIRCONTENTTYPEJSON : FHIRCONTENTTYPEXML);
                return(response);
            } catch (Exception e)
            {
                OperationOutcome oo = new OperationOutcome();
                oo.Issue = new System.Collections.Generic.List <OperationOutcome.IssueComponent>();
                OperationOutcome.IssueComponent ic = new OperationOutcome.IssueComponent();
                ic.Severity    = OperationOutcome.IssueSeverity.Error;
                ic.Code        = OperationOutcome.IssueType.Exception;
                ic.Diagnostics = e.Message;
                oo.Issue.Add(ic);
                var response = this.Request.CreateResponse(HttpStatusCode.BadRequest);
                response.Headers.TryAddWithoutValidation("Accept", CurrentAcceptType);
                response.Content = new StringContent(SerializeResponse(oo), Encoding.UTF8);
                response.Content.Headers.TryAddWithoutValidation("Content-Type", IsAccceptTypeJSON? FHIRCONTENTTYPEJSON : FHIRCONTENTTYPEXML);
                response.Content.Headers.LastModified = DateTimeOffset.Now;
                return(response);
            }
        }
Example #20
0
        private static OperationOutcome AddIssue(this OperationOutcome outcome, OperationOutcome.IssueSeverity severity, string message)
        {
            if (outcome.Issue == null)
            {
                outcome.Init();
            }

            var item = new OperationOutcome.IssueComponent();

            item.Severity    = severity;
            item.Diagnostics = message;
            outcome.Issue.Add(item);
            return(outcome);
        }
Example #21
0
        private static OperationOutcome AddIssue(this OperationOutcome outcome, OperationOutcome.IssueSeverity severity, string message)
        {
            if (outcome.Issue == null)
            {
                outcome.Init();
            }

            var item = new OperationOutcome.IssueComponent();

            item.Severity = severity;
            item.Details  = new CodeableConcept(null, null, message);
            outcome.Issue.Add(item);
            return(outcome);
        }
Example #22
0
        /// <summary>
        /// To get patient Allergies with the help of global Patient object
        /// </summary>
        public void setPatientDetectedIssues()
        {
            try
            {
                SearchParams searchParams = new SearchParams();

                searchParams.Add("patient", Generalinformation.Id);

                searchParams.Add("_count", "20");

                Bundle bd = _fc.Search <DetectedIssue>(searchParams);

                bool isCountOver = false;

                List <DetectedIssue> lstDI = new List <DetectedIssue>();

                while (!isCountOver)
                {
                    if (bd.NextLink == null)
                    {
                        isCountOver = true;
                    }

                    foreach (Bundle.EntryComponent et in bd.Entry)
                    {
                        if (et.Resource.ResourceType == ResourceType.DetectedIssue)
                        {
                            lstDI.Add((DetectedIssue)et.Resource);
                        }
                    }

                    bd = _fc.Continue(bd);
                }

                DetectedIssues.AddRange(lstDI);
            }
            catch (FhirOperationException foe)
            {
                isExceptionEncountered = true;
                ExceptionIssues        = foe.Outcome.Issue;
            }
            catch (Exception ex)
            {
                isExceptionEncountered = true;
                OperationOutcome.IssueComponent ic = new OperationOutcome.IssueComponent();
                ic.Diagnostics = ex.Message;
                ExceptionIssues.Add(ic);
            }
        }
Example #23
0
 OperationOutcome.IssueComponent addIssue(OperationOutcome.IssueComponent component, string profileUrl = null)
 {
     if (component == null)
     {
         throw Error.ArgumentNull(nameof(component));
     }
     if (_outcome == null)
     {
         _outcome = new OperationOutcome();
     }
     // Return current profile url in Diagnostics field
     component.Diagnostics = profileUrl ?? CurrentProfileUri;
     _outcome.AddIssue(component);
     return(component);
 }
        public void GivenAMessage_WhenInitialized_ThenCorrectOperationOutcomeShouldBeAdded()
        {
            string message = "message";

            var exception = new InvalidSearchOperationException(message);

            Assert.NotNull(exception.Issues);
            Assert.Equal(1, exception.Issues.Count);

            OperationOutcome.IssueComponent issue = exception.Issues.First();

            Assert.Equal(OperationOutcome.IssueSeverity.Error, issue.Severity);
            Assert.Equal(OperationOutcome.IssueType.Forbidden, issue.Code);
            Assert.Equal(message, issue.Diagnostics);
        }
Example #25
0
        private static OperationOutcome AddIssue(this OperationOutcome outcome, OperationOutcome.IssueSeverity severity, string message, OperationOutcome.IssueType issueType = OperationOutcome.IssueType.Unknown, CodeableConcept codeableConcept = null)
        {
            if (outcome.Issue == null)
            {
                outcome.Init();
            }

            var item = new OperationOutcome.IssueComponent();

            item.Severity    = severity;
            item.Diagnostics = message;
            item.Code        = issueType;
            item.Details     = codeableConcept;
            outcome.Issue.Add(item);
            return(outcome);
        }
        private void CheckOperationOutcomeIssue(
            OperationNotImplementedException exception,
            OperationOutcome.IssueSeverity expectedSeverity,
            OperationOutcome.IssueType expectedCode,
            string expectedMessage)
        {
            IEnumerator <OperationOutcomeIssue> enumerator = exception.Issues.GetEnumerator();

            enumerator.MoveNext();
            OperationOutcome.IssueComponent issue = enumerator.Current.ToPoco();

            // Check expected outcome
            Assert.Equal(expectedSeverity, issue.Severity);
            Assert.Equal(expectedCode, issue.Code);
            Assert.Equal(expectedMessage, issue.Diagnostics);
        }
Example #27
0
        public string Serialize(long index, string errorMessage)
        {
            EnsureArg.IsNotNullOrEmpty(errorMessage, nameof(errorMessage));

            var issue = new OperationOutcome.IssueComponent();

            issue.Severity     = OperationOutcome.IssueSeverity.Error;
            issue.Diagnostics  = string.Format("Failed to process resource at line: {0}", index);
            issue.Details      = new CodeableConcept();
            issue.Details.Text = errorMessage;
            OperationOutcome operationOutcome = new OperationOutcome();

            operationOutcome.Issue.Add(issue);

            return(_fhirJsonSerializer.SerializeToString(operationOutcome));
        }
Example #28
0
        /// <summary>
        /// Save method.
        /// </summary>
        public void Save()
        {
            try
            {
                IPyroDbContext.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                var outputLines = new StringBuilder();
                foreach (var eve in e.EntityValidationErrors)
                {
                    outputLines.AppendLine(string.Format(
                                               "{0}: Entity of type \"{1}\" in state \"{2}\" has the following validation errors:", DateTime.Now,
                                               eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        outputLines.AppendLine(string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage));
                    }
                }
                //System.IO.File.AppendAllLines(@"C:\errors.txt", outputLines);

                var OpOutCome = new OperationOutcome();
                OpOutCome.Issue = new List <OperationOutcome.IssueComponent>();
                var OpOutComeIssueComp = new OperationOutcome.IssueComponent();
                OpOutComeIssueComp.Severity    = OperationOutcome.IssueSeverity.Fatal;
                OpOutComeIssueComp.Code        = OperationOutcome.IssueType.Exception;
                OpOutComeIssueComp.Diagnostics = outputLines.ToString();
                OpOutCome.Issue.Add(OpOutComeIssueComp);
                throw new PyroException(System.Net.HttpStatusCode.InternalServerError, OpOutCome, outputLines.ToString(), e);
            }
            catch (DbUpdateException Exec)
            {
                if (Exec.InnerException != null && Exec.InnerException.InnerException != null &&
                    Exec.InnerException.InnerException is System.Data.SqlClient.SqlException)
                {
                    throw Exec.InnerException.InnerException;
                }
                var OpOutCome = new OperationOutcome();
                OpOutCome.Issue = new List <OperationOutcome.IssueComponent>();
                var OpOutComeIssueComp = new OperationOutcome.IssueComponent();
                OpOutComeIssueComp.Severity    = OperationOutcome.IssueSeverity.Fatal;
                OpOutComeIssueComp.Code        = OperationOutcome.IssueType.Exception;
                OpOutComeIssueComp.Diagnostics = Exec.InnerException.InnerException.ToString();
                OpOutCome.Issue.Add(OpOutComeIssueComp);
                throw new PyroException(System.Net.HttpStatusCode.InternalServerError, OpOutCome, Exec.InnerException.InnerException.Message, Exec);
            }
        }
Example #29
0
        public virtual OperationOutcome Validate(Validator validator, IElementNavigator errorLocation)
        {
            var outcome = new OperationOutcome();

            if (!Cardinality.InRange(Members.Count))
            {
                OperationOutcome.IssueComponent issue = validator.Trace(outcome, $"Instance count for '{Name}' is {Members.Count}, which is not within the specified cardinality of {Cardinality.ToString()}",
                                                                        Issue.CONTENT_INCORRECT_OCCURRENCE, errorLocation);
                if (issue != null)
                {
                    // the location in the structure definition (this will match to the discriminator when checking slicing)
                    // issue.LocationElement.Add(new FhirString(Path));
                    issue.SetAnnotation(new SlicePathAnnotation(Path));
                }
            }
            return(outcome);
        }
Example #30
0
        /// <summary>
        /// To get patient history (procedures performed on or with patient ) with the help of global Patient object
        /// </summary>
        public void getPatientCurrentConditions()
        {
            try
            {
                SearchParams searchParams = new SearchParams();

                searchParams.Add("patient", Generalinformation.Id);

                searchParams.Add("_count", "20");

                Bundle bd = _fc.Search <Condition>(searchParams);

                bool isCountOver = false;

                while (!isCountOver)
                {
                    if (bd.NextLink == null)
                    {
                        isCountOver = true;
                    }

                    foreach (Bundle.EntryComponent et in bd.Entry)
                    {
                        if (et.Resource.ResourceType == ResourceType.Condition)
                        {
                            Conditions.Add((Condition)et.Resource);
                        }
                    }

                    bd = _fc.Continue(bd);
                }
            }
            catch (FhirOperationException foe)
            {
                isExceptionEncountered = true;
                ExceptionIssues        = foe.Outcome.Issue;
            }
            catch (Exception ex)
            {
                isExceptionEncountered = true;
                OperationOutcome.IssueComponent ic = new OperationOutcome.IssueComponent();
                ic.Diagnostics = ex.Message;
                ExceptionIssues.Add(ic);
            }
        }