Author: Vivek Hariganesan
About HL7
Health Level Seven International (HL7) is a not-for-profit, ANSI-accredited standards-developing organization dedicated to providing a comprehensive framework and related standards for the exchange, integration, sharing, and retrieval of electronic health information that supports clinical practice and the management, delivery, and evaluation of health services. The HL7 standards use schemas to define message structures. The integration platform generates schemas based on data provided by HL7.Â
We can custom-build schema subsets for specific Electronic Data Interchange (EDI), Trading Partner, and TransType scenarios. The schemas provide the following:
- File structures
- Metadata support
- Parsing capabilities
- Validation support
More information on creating custom schemas is explained in the following link: https://docs.mulesoft.com/hl7-connector/4.2/hl7-connector-config-topics
Introduction:
The purpose of this article is to show how to customize the HL7 Schemas files that use a YAML format called ESL in order to allow the Mule Apps to accept Z segments or customized HL7 segments that do not follow the HL7 standard. This is a common requirement involving HL7 integrations.
Scope:
HL7 Connector and HL7 Message
Prerequisites:
- Anypoint Connectors
- Mule runtime engine (Mule)
- Elements and global elements in a Mule flow
- Creating a Mule app using Anypoint Studio (Studio)
- HL7 EDI Connector
- To use HL7 EDI Connector, you must have purchased a MuleSoft license for HL7. Contact your Account Representative about purchasing a license.
- Anypoint Studio 7.0 or later.
How to parse and extract Z* segments in HL7 Connector:
In this blog, we can focus on how to parse and extract the Z* Segments which are not present as part of the schema configuration.
Sample HL7 Message with Z Segments:
MSH|^~\&|LAB|MYFAC|LAB||201411130917||ORU^R01|3216598|D|2.3|||AL|NE|
PID|1|ABC123DF|AND234DA_PID3|PID_4_ALTID|Patlast^Patfirst^Mid||19670202|F|||4505 21 st^^LAKE COUNTRY^BC^V4V 2S7||222-555-8484|||||MF0050356/15|
PV1|1|O|MYFACSOMPL||||^Xavarie^Sonna^^^^^XAVS|||||||||||REF||SELF|||||||||||||||||||MYFAC||REG|||201411071440||||||||23390^PV1_52Surname^PV1_52Given^H^^Dr^^PV1_52Mnemonic|
ORC|RE|PT103933301.0100|||CM|N|||201411130917|^Kyle^Andra^J.^^^^KYLA||^Xavarie^Sonna^^^^^XAVS|MYFAC|
OBR|1|PT1311:H00001R301.0100|PT1311:H00001R|301.0100^Complete Blood Count (CBC)^00065227^57021-8^CBC \T\ Auto Differential^pCLOCD|R||201411130914|||KYLA||||201411130914||^Xavarie^Sonna^^^^^XAVS||00065227||||201411130915||LAB|F||^^^^^R|^Xavarie^Sonna^^^^^XAVS|
OBX|1|NM|301.0500^White Blood Count (WBC)^00065227^6690-2^Leukocytes^pCLOCD|1|10.1|10\S\9/L|3.1-9.7|H||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|2|NM|301.0600^Red Blood Count (RBC)^00065227^789-8^Erythrocytes^pCLOCD|1|3.2|10\S\12/L|3.7-5.0|L||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|3|NM|301.0700^Hemoglobin (HGB)^00065227^718-7^Hemoglobin^pCLOCD|1|140|g/L|118-151|N||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|4|NM|301.0900^Hematocrit (HCT)^00065227^4544-3^Hematocrit^pCLOCD|1|0.34|L/L|0.33-0.45|N||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|5|NM|301.1100^MCV^00065227^787-2^Mean Corpuscular Volume^pCLOCD|1|98.0|fL|84.0-98.0|N||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|6|NM|301.1300^MCH^00065227^785-6^Mean Corpuscular Hemoglobin^pCLOCD|1|27.0|pg|28.3-33.5|L||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|7|NM|301.1500^MCHC^00065227^786-4^Mean Corpuscular Hemoglobin Concentration^pCLOCD|1|330|g/L|329-352|N||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|8|NM|301.1700^RDW^00065227^788-0^Erythrocyte Distribution Width^pCLOCD|1|12.0|%|12.0-15.0|N||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|9|NM|301.1900^Platelets^00065227^777-3^Platelets^pCLOCD|1|125|10\S\9/L|147-375|L||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|10|NM|301.2100^Neutrophils^00065227^751-8^Neutrophils^pCLOCD|1|8.0|10\S\9/L|1.2-6.0|H||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|11|NM|301.2300^Lymphocytes^00065227^731-0^Lymphocytes^pCLOCD|1|1.0|10\S\9/L|0.6-3.1|N||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|12|NM|301.2500^Monocytes^00065227^742-7^Monocytes^pCLOCD|1|1.0|10\S\9/L|0.1-0.9|H||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|13|NM|301.2700^Eosinophils^00065227^711-2^Eosinophils^pCLOCD|1|0.0|10\S\9/L|0.0-0.5|N||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
OBX|14|NM|301.2900^Basophils^00065227^704-7^Basophils^pCLOCD|1|0.0|10\S\9/L|0.0-0.2|N||A~S|F|||201411130916|MYFAC^MyFake Hospital^L|
ZDR||^^^^^^F^^^^^FTM^^U|
By default, the HL7 connector will not parse Z segments. To parse these segments, the option “genericExtensionPattern” must be configured in the HL7 parser.
For the demo purpose, I have skipped configuring the flow and you can use the below image as a reference to the flow.

In the HL7 read Connector, I’m using the read operation to read the inbound HL7 message so that the HL7 connector converts the payload received from the source.
Now to parse the above segment we need the below configuration to be configured.

You can add the Generic Extension Pattern in the xml file or configure it from the HL7 connector as below:


Once the parsing is complete, we will receive the parsed segments under Extension Segs in json format.

Using this way we can parse the Z segments from the HL7 message.