0

I can't get my BizTalk map to work with messages after envelope debatching. The map seems to require a namespace prefix but the debatched message doesn't have a prefix. If I add a prefix to the root, like this <ns0:Encounter xmlns:ns0="http://hl7.org/fhir/Encounters"> then the map works correctly when I use test map in visual studio. Without the prefix I still get an output from the map but only constants are mapped into the destination schema, nothing is mapped from the source schema.

I get the following error message for every mapped element

"error btm1044: Input validation error: The 'value' attribute is not declared."

I have tried changing the value of elementFormDefault from unqualified to qualified as suggested on a separate post but still no luck.

After envelope debatching I end up with the following XML. Note that there is no namespace prefix. If I stop the Send Port and look at the debatched messages the MessageType is http://hl7.org/fhir/Encounters#Encounter .

  <?xml version="1.0" encoding="utf-8"?>
<Encounter xmlns="http://hl7.org/fhir/Encounters">
    <id value="ac34e2c2-6080-4c46-9ec5-d7340a7c4177" />
    <extension url="https://api-foo.org/documents/fhir/extensions/encounter-facility">
        <valueString value="foo" />
    </extension>
    <extension url="https://api-foo.org/documents/fhir/extensions/encounter-service">
        <valueString value="fooo" />.......

My schema looks like this

  <?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://hl7.org/fhir/Encounters" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://hl7.org/fhir/Encounters" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Encounter">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="id">
          <xs:complexType>
            <xs:attribute name="value" type="xs:string" use="required" />
          </xs:complexType>
        </xs:element>
        <xs:element maxOccurs="unbounded" name="extension">
          <xs:complexType>
            <xs:sequence>
              <xs:element minOccurs="0" name="valueInteger">
                <xs:complexType>
                  <xs:attribute name="value" type="xs:unsignedByte" use="required" />
                </xs:complexType>
              </xs:element>
              <xs:element minOccurs="0" name="valueString">
                <xs:complexType>
                  <xs:attribute name="value" type="xs:string" use="required" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="url" type="xs:string" use="required" />
          </xs:complexType>
        </xs:element> ............

Is there a way to get the map/schema to work with the message as is, or a way to get the debatched message to have the prefix.

I also have a custom pipeline component to change the namespace of the incoming message before debatching. I'm not sure if this could be causing the issue the code is below.

public IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
    {
        if (Enabled)
        {
            try
            {
                IBaseMessagePart bodyPart = inmsg.BodyPart;

                if (bodyPart != null)
                {
                    string json;

                    using (Stream originalDataStream = bodyPart.GetOriginalDataStream())
                    {
                        if (originalDataStream != null)
                        {
                            //Read the json message
                            using (TextReader tr = new StreamReader(originalDataStream))
                            {
                                json = tr.ReadToEnd();
                            }

                            //Use FHIR-NET-API to create a FHIR resource from the json
                            Hl7.Fhir.Serialization.ResourceReader resourceReader = new Hl7.Fhir.Serialization.ResourceReader(FhirJsonParser.CreateFhirReader(json), ParserSettings.Default);

                            //switch the namespace
                            var doc = XElement.Parse(Hl7.Fhir.Serialization.FhirSerializer.SerializeToXml(resourceReader.Deserialize()));

                            XNamespace toNs = Namespace;
                            doc.DescendantsAndSelf().Attributes().Where(a => a.IsNamespaceDeclaration).Remove();
                            var ele = doc.DescendantsAndSelf();
                            foreach (var el in ele)
                                el.Name = toNs + el.Name.LocalName;

                            //Create the new BizTalk message
                            var memoryStream = new MemoryStream();
                            doc.Save(memoryStream);
                            //  memoryStream.Write(resourceXmlBytes, 0, resourceXmlBytes.Length);
                            memoryStream.Position = 0;
                            inmsg.BodyPart.Data = memoryStream;
                        }
                    }
                }

                return inmsg;
            }
            catch (Exception e)
            {
                GenericEventLogger.LogEvent(
                ExceptionSource,
                String.Format("An exception [{0}] occured in [{1}( )]. \n\nMessage: \n{2} \n\nStack Trace: \n{3}",
                                e.GetType().Name,
                                System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName,
                                e.Message,
                                e.StackTrace),
                EventLogEntryType.Error,
                999);
                throw;
            }
        }

        return inmsg;
    }

Here is the Envelope Schema

    <?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://hl7.org/fhir/Encounters" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://hl7.org/fhir/Encounters" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:annotation>
    <xs:appinfo>
      <b:schemaInfo is_envelope="yes" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" />
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="Bundle">
    <xs:annotation>
      <xs:appinfo>
        <b:recordInfo body_xpath="/*[local-name()='Bundle' and namespace-uri()='http://hl7.org/fhir/Encounters']/*[local-name()='entry' and namespace-uri()='http://hl7.org/fhir/Encounters']/*[local-name()='resource' and namespace-uri()='http://hl7.org/fhir/Encounters']" />
      </xs:appinfo>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="total">
          <xs:complexType>
            <xs:attribute name="value" type="xs:unsignedByte" use="required" />
          </xs:complexType>
        </xs:element>
        <xs:element maxOccurs="unbounded" name="entry">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="resource">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="Encounter">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:any />
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
David
  • 139
  • 1
  • 13
  • In what part of the receive pipeline is your namespace pipeline component? What method are you using the debatch the message? With an Envelope schema? (if so, show the schema for that) If you take the map off the port, what Message Type is in the context of the message? Do you also have a XML validator in the Pipeline? (As that error looks to be from that and not a map, or is that the error you get from Visual Studio when testing the map?) – Dijkgraaf Jun 30 '17 at 02:08
  • Are you using the BizTalk HL7 disassembler? – Johns-305 Jun 30 '17 at 14:53
  • In the pipeline component I am using a HL7 FHIR library to convert the incoming json to XML and then change the namespace in the Execute method . The pipeline component sits in the Decode part of the pipeline. The standard XML disassembler component is in the Disassemble part of the pipeline. No other components are used. I will update the main the post with the envelope schema and other requested information. – David Jun 30 '17 at 17:08
  • Made several updates to post to include information requested by @Dijkgraaf – David Jun 30 '17 at 18:01

1 Answers1

2

Since you're using the JSON representations of FHIR, the first question should be do you even need to use Xml Namespaces.

When working with native JSON content in BizTalk, my recommendation is to use the Empty Namespace in all Xml processing.

You can refer to this Wiki Article for more details: BizTalk: Simplify BizTalk Dev by Using the Empty Namespace

Johns-305
  • 10,908
  • 12
  • 21
  • Thanks @Johns-305 I'm going to have a look at this and your response to my other thread and make the design changes needed to do this correctly. – David Jun 30 '17 at 21:01
  • For anyone else reading there is more on this same issue on this thread [link](https://stackoverflow.com/questions/44837027/add-namespace-and-alias-to-existing-xml). Where @Johns-305 supplies additional links to solutions. – David Jun 30 '17 at 21:04
  • I switched to using empty namespaces on my envelope and msg schema and specifying the schemas in the XmlDisassembler as described in link above and my application is now functioning as expected. Thanks again for the help. @Johns-305 - The article mentions that "The Visual Studio Solution for the Community Namespace Remove" is coming soon". Is this VS solution available for download? – David Jul 04 '17 at 20:52
  • @David Sorry, that a mistake, corrected. Only the compiled Assembly is available in the sample project. – Johns-305 Jul 05 '17 at 16:32