/// <summary> /// Build an ExtractionErrorMessage that conveys the issues reported in this exception. /// </summary> public ExtractionErrorMessage CreateExtractionErrorMessage() { var message = new ExtractionErrorMessage(sourceMessage); message.Issues.Add(new Issue(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Exception, this.Message)); return(message); }
/// <summary> /// Construct the appropriate subclass of BaseMessage based on a FHIR Bundle. /// Clients can use the typeof operator to determine the type of message object returned. /// </summary> /// <param name="bundle">A FHIR Bundle</param> /// <returns>The message object of the appropriate message type</returns> public static BaseMessage Parse(Bundle bundle) { BaseMessage message = new BaseMessage(bundle, true, false); switch (message.MessageType) { case "http://nchs.cdc.gov/vrdr_submission": message = new DeathRecordSubmission(bundle, message); break; case "http://nchs.cdc.gov/vrdr_submission_update": message = new DeathRecordUpdate(bundle, message); break; case "http://nchs.cdc.gov/vrdr_acknowledgement": message = new AckMessage(bundle); break; case "http://nchs.cdc.gov/vrdr_submission_void": message = new VoidMessage(bundle); break; case "http://nchs.cdc.gov/vrdr_coding": message = new CodingResponseMessage(bundle); break; case "http://nchs.cdc.gov/vrdr_coding_update": message = new CodingUpdateMessage(bundle); break; case "http://nchs.cdc.gov/vrdr_extraction_error": message = new ExtractionErrorMessage(bundle, message); break; default: string errorText; if (message.Header == null) { errorText = "Failed to find a Bundle Entry containing a Resource of type MessageHeader"; } else if (message.MessageType == null) { errorText = "Message type was missing from MessageHeader"; } else { errorText = $"Unsupported message type: {message.MessageType}"; } throw new MessageParseException(errorText, message); } return(message); }
/// <summary> /// Parse an XML or JSON serialization of a FHIR Bundle and construct the appropriate subclass of /// BaseMessage. Clients can use the typeof operator to determine the type of message object returned. /// </summary> /// <param name="source">the XML or JSON serialization of a FHIR Bundle</param> /// <param name="permissive">if the parser should be permissive when parsing the given string</param> /// <returns>The deserialized message object</returns> public static BaseMessage Parse(string source, bool permissive = false) { Bundle bundle = null; if (!String.IsNullOrEmpty(source) && source.TrimStart().StartsWith("<")) { bundle = ParseXML(source, permissive); } else if (!String.IsNullOrEmpty(source) && source.TrimStart().StartsWith("{")) { bundle = ParseJSON(source, permissive); } else { throw new System.ArgumentException("The given input does not appear to be a valid XML or JSON FHIR message."); } BaseMessage message = new BaseMessage(bundle, true, false); switch (message.MessageType) { case "http://nchs.cdc.gov/vrdr_submission": message = new DeathRecordSubmission(bundle, message); break; case "http://nchs.cdc.gov/vrdr_submission_update": message = new DeathRecordUpdate(bundle, message); break; case "http://nchs.cdc.gov/vrdr_acknowledgement": message = new AckMessage(bundle); break; case "http://nchs.cdc.gov/vrdr_submission_void": message = new VoidMessage(bundle); break; case "http://nchs.cdc.gov/vrdr_coding": message = new CodingResponseMessage(bundle); break; case "http://nchs.cdc.gov/vrdr_coding_update": message = new CodingUpdateMessage(bundle); break; case "http://nchs.cdc.gov/vrdr_extraction_error": message = new ExtractionErrorMessage(bundle, message); break; default: string errorText; if (message.Header == null) { errorText = "Failed to find a Bundle Entry containing a Resource of type MessageHeader"; } else if (message.MessageType == null) { errorText = "Message type was missing from MessageHeader"; } else { errorText = $"Unsupported message type: {message.MessageType}"; } throw new MessageParseException(errorText, message); } return(message); }