Builds a JSON Abstract Syntax Tree that describes the HL7 Segment notation
PEG grammar rules
- Segments are listed from left to right and always starts with MSH
- Optional segments are enclosed in
[]
square bracketsMSH PID NK1 PV1 [PV2]
In this example, PV2 can be optionally included in the message.
MSH|^~\&|... PID|....|... NK1|....|... PV1|....|... PV2|....|...
- Repeating segments are enclosed in
{}
curly brackets.MSH PID {NK1} PV1 [PV2]
In this example, one or more NK1 segements can be included prior to PV1
MSH|^~\&|... PID|....|... NK1|....|... NK1|....|... PV1|....|... PV2|....|...
- Segments that are both optional and repeating are enclosed in both curly and square brackets
[{}]
or{[]}
MSH PID [{NK1}] PV1 [PV2]
In this example, optional and repeating NK1 groups are optionally included.
MSH|^~\&|... NK1|....|... NK1|....|... PV1|....|...
- Optional or repeating segment groups contain multiple segment names inside of square or curly brackets
MSH PID [{OBR {OBX}}]
In this example, multple sets of OBR, followed by OBX result groups can be optionally included.
MSH|^~\&|... PID|....|... OBR|....|... OBX|....|... OBR|....|... OBX|....|... OBX|....|...
npm install
$ npm run compile
$ npm run start
$ npm run dev "MSH"
$ npm run start "MSH PID [{ IN1 [ IN2 ] [{ OBX }] }]"
Output
[{
type: 'segment',
name: 'MSH',
required: true,
repeating: false
},
{
type: 'segment',
name: 'PID',
required: true,
repeating: false
},
{
type: 'optional-repeating-segment',
segments: [{
type: 'segment',
name: 'IN1',
required: true,
repeating: false
},
{
type: 'optional-segment',
name: 'IN2',
required: false,
repeating: false
},
{
type: 'optional-repeating-segment',
segments: [{
type: 'segment',
name: 'OBX',
required: true,
repeating: false
}],
required: false,
repeating: true
}
],
required: false,
repeating: true
}
]