Override OnResponse method in bps . You can handle reponses in OnResponse() method.
First of all your source message is missing one segment , i corrected it. below code should work for you .
set target = ##class(EnsLib.HL7.Message).%New()
set target.DocType = source.DocType
write $System.Status.GetErrorText(source.BuildMap(1))
set tSC = $$$OK
try {
set segCount = source.SegCount
for segNo=1:1:segCount {
set oSegment = source.GetSegmentAt(segNo)
set segPath = source.GetSegmentPath(segNo)
set fieldCount = oSegment.GetValueAt("*")
for fieldNo=1:1:fieldCount {
set fieldValue = oSegment.GetValueAt(fieldNo)
set compCount = oSegment.GetValueAt(fieldNo_".*")
for compNo=1:1:compCount { // considering there is no repeat - if repeat then one more loop is required
set subCompCount = oSegment.GetValueAt(fieldNo_"."_compNo_".*")
for subCompNo=1:1:subCompCount {
set path = segPath_":"_fieldNo_"."_compNo_"."_subCompNo
set subCompValue = source.GetValueAt(path)
if (subCompValue '= "") && (subCompValue '= ($C(34)_$C(34))) {
//if (oSegment.Name = "PID")&&(fieldNo=2) break
if path="PIDgrp.PID:13.4.1" break
write path_"--->"_subCompValue,!
do target.SetValueAt(subCompValue,path)
}
}
}
//set componentCount = oSegment.GetValueAt(fieldNo
}
}
do target.OutputToFile("C:\Work\Report\target.hl7",1)
}
catch oEx {
}
![Open Sesame!](https://community.intersystems.com/sites/default/files/badges/303371180-6de11138-f4e7-4113-b5cc-836269f07693.png)
![1,000 Points](https://community.intersystems.com/sites/default/files/badges/290121674-53216c4b-fe0c-44e7-9d75-2f24390135ed.png)
![Challenge Starter](https://community.intersystems.com/sites/default/files/badges/295959213-b83dd91a-663f-4f07-8e0e-e3287b7c2309.png)
![DC Commenter](https://community.intersystems.com/sites/default/files/badges/dc_commenter_1.png)
![DC Problem Solver](https://community.intersystems.com/sites/default/files/badges/dc_problem_solver_1.png)
![InterSystems Researcher](https://community.intersystems.com/sites/default/files/badges/researcher.png)
You can use EnsLib.ITK.HL7.FormatXMLv2 . It was primarily designed for HL7 ITK version. You can extend this class and modify as you need.Then simply convert that into stream that you need and transfer wherever you want.
Alternatively you can download the xsd from HL7 site then map from HL7 to XML schema. It would be pretty lengthy method .