Here is an excellent explanation of how an HL7 message is generated and what the various elements of the message are. This is taken from the website for interfaceware a vendor of software products to enable the creation of HL7 interfaces and message creation.
There are other good interface engines, notably Mirth, which is a free and open source (FOSS) product that is built with several other open source products that are part of the Apache Software Foundation.
Please note that this section is still being developed. More shortly.