Question
Bukhtiar Ahmad · Oct 6, 2020

business rule function to get list of segments used in the HL7 message

Hi

I need to get list of segments from a message ,  so that i can validate if EMR sending all valid segment against a msg structure. calling this function should return me below string

,MSH,EVN,PID,PD1,NK1,PV1,PV2,DB1,OBX,OBX,AL1,DG1,DRG,PR1,ROL,GT1,IN1,IN2,IN3,ACC,UB1,UB2,

Below is my HL7 msg

MSH|^~\&|REGADT|MCM|IFENG||199601061253||ADT^A01|000001|P|2.3.1|1||
EVN|A01|199601061000|199601101400|1
PID|||999473857^^^GENHOSP|253763|MASSIE^JAMES^A||19560129|M|||87 MAIN ST^^CAMBRIDGE^MA^02142^||(900)485-5344|(900)485-5344|ENGLISH|S|C|10199925|371-66-9256
PD1|||||||||
NK1||||||
PV1||O|||||0148^ADDISON^JAMES|0148^ADDISON^JAMES|0148^ADDISON^JAMES|AMB|||||||0148^ADDISON^JAMES|S|1400|A|||||||||||||||||GENHOSP
PV2||||||||199601101400|199601101400
DB1|||||||||||
OBX||ST|1010.1^BODY WEIGHT||62|kg
OBX||ST|1010.1^HEIGHT||190|cm
AL1|||||||||||
DG1|||||||||||
DRG|||||||||||
PR1|||||||||||
ROL|||||||||||
GT1|||||||||||
IN1|||||||||||
IN2|||||||||||
IN3|||||||||||
ACC|||||||||||
UB1|||||||||||
UB2|||||||||||

00
0 2 57 4

Replies

HI Bukhtiar,

Iris has built in validation against a schema see: HL7 Schemas and Available Tools

But, is simple to iterate over all segments of a HL7 message  or any Virtual Document like this example:

#Dim hl7Msg   As EnsLib.HL7.Message = ##Class(EnsLib.HL7.Message).%OpenId(<changByAId>)
#Dim segIndex As %Integer           = 0
For segIndex = 1 : 1 : hl7Msg.SegCount
{
    #Dim segment As EnsLib.HL7.Segment = hl7Msg.getSegmentByIndex(segIndex)
    //
    Write segment.Name, !
}

For more details se then documentation:

EnsLib.HL7.Message

EnsLib.HL7.Segment

Hi Bukhtiar,

You can validate against a defined HL7 Schema without any code changes. Each HL7 Business Service has a property Message Schema Category. It's a drop-down menu and you can pick any schema to validate against. For example, your message is 2.3.1 so you can pick "2.3.1" to validate against that schema. If message contains segments that are not part of the schema, or if segments are in wrong order you will messages displayed in Ensemble with captions such as "Unrecognized segment found in ...". It will display all "good" segments that it validated in blue and all "unrecognized" segments in black. If you know you will have segments that are not part of standard schemas, you can create custom schemas based on the standard ones.

Your custom validation code is probably going to live on a Business Process. I would create a business rule that would define your custom business process as a target so you can send your messages for validation there. You can also combine this with the Validation property on the RoutingEngine class... there is a whole list of options that are available to also validate the message on the Router.