added a comment -
10/Oct/08 6:30 PM According to the HL7 v2.5 specification for A17, the segment grammar should be:
MSH
{[SFT]}
EVN
PID
[PD1]
PV1
[PV2]
{[DB1]}
{[OBX]}
PID
[PD1]
PV1
[PV2]
{[DB1]}
{[OBX]}
Hapi is a strict hl7 parser that requires you to follow this grammar. Your test message has a third PID and PV1 segment. This is not allowed so the strict parser fails on it, giving the erroneous output.