All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ca.uhn.hl7v2.protocol.impl.MetadataExtractor Maven / Gradle / Ivy

/*
 * Created on 19-Apr-2004
 */
package ca.uhn.hl7v2.protocol.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.util.Terser;

/**
 * A utility for getting a list of fields from a Message, 
 * e.g. for inclusion in a Transportable. 
 *  
 * @author Bryan Tripp
 * @version $Revision: 1.1 $ updated on $Date: 2007-02-19 02:24:26 $ by $Author: jamesagnew $
 */
public class MetadataExtractor {

    /**
     * @param theMessage a message from which to extract fields
     * @param theTerserPaths a list of paths to desired fields, in the 
     *      form required by Terser.  
     * @return a Map from Terser paths to field values 
     */
    public static Map getFields(Message theMessage, List theTerserPaths) throws HL7Exception {
        Map fields = new HashMap();
        Terser terser = new Terser(theMessage);
        for (int i = 0; i < theTerserPaths.size(); i++) {
            String path = theTerserPaths.get(i);
            String fieldValue = terser.get(path);
            fields.put(path, fieldValue);
        }
        return fields;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy