The Easiest Way to Save and Share Code Snippets on the web

urHL7: Implementing a HL7MessageListener

java5 | by: devmorgan

posted: May, 2nd 2012 | jump to bottom

import org.urhl7.igor.*;
import org.urhl7.spark.*;
import java.util.*;
 
/**
 * A simple implementation of HL7MessageListener that will print the name 
 * and MRN of each patient in the message
 * @author dmorgan
 */
public class PrintPatientListener implements HL7MessageListener {
 
    public boolean messageReceived(HL7Structure struct) {
 
        String familyName = struct.helper().get("PID-5.1").getData();
        String givenName = struct.helper().get("PID-5.2").getData();
 
        List<DataField> patientMRNs = struct.helper().getAll("PID-3.1");
 
        System.out.println("Found Patient: " + givenName + " " + familyName);
        System.out.println("MRNs:");
        for(DataField df : patientMRNs) {
                System.out.println("\t" + df.getData());
        }
 
        return true;
    }
 
}
76 views