When attempting to use ca.uhn.hl7v2.util.Terser to set empty fields on a given specific subclass of ca.uhn.hl7v2.model.Message (in this case ca.uhn.hl7v2.model.v251.message.ORU_R01), I receive no error messages during the .each{} closure and afterwards the message object has no fields populated.
hl7Map is populated on class instantiation, with values like: def hl7Map= [ "HL7MessageFields":['PID-3-1':"internal order map key", 'PID-3-4':"internal order map key",etc.]]
Code below:
def buildHL7Message(order){
def date = new Date()
def format = new SimpleDateFormat(hl7Map["dateFormat"]).format(date)
//Set date on the Message Header Object
hl7Map["MSH"]["-7"]= format
def message = (context.getModelClassFactory().getMessageClass(hl7Map["MessageInstantiationMap"]["messageType"],
hl7Map["MessageInstantiationMap"]["version"],
true) as Class).newInstance()
Terser terser = new Terser(message)
hl7Map["HL7MessageFields"].each{
terser.set(it.key, order[it.value])
}
println message
return message
}
The end of method results in no output and error logged about encoding, MSH-1 is a required field, pipe delminator but is empty. If the code above uses message.initQuickstart("ORU", "R01", "T"), only the default initQuickstart fields are populated.
If hl7Map["HL7MessageFields"] contains a 'it.key' that is not a valid Group/Segment field, an error is logged by terser that it failed to find the value, the above code with a properly formatted map does not cause an error.
Can anyone help explain why I am not receiving errors yet my message is empty, and help me to populate the message with the appropriate terser.set(params)?