Your source node could be a SQL query or a CSV list of patient IDs. You would want to change the 677 in this query below to a variable based on the source node values.
message = qie.createHL7Message('UTF-8');
var queryResult = qie.doQuery('Database Name',
"SELECT lastname, firstname FROM person\n" +
" WHERE patientid = '677'"
);
message.setNode('PID-5.1', queryResult.getNode('lastname'));
message.setNode('PID-5.2', queryResult.getNode('firstname'));