1 /*
2 * Created on 19-Apr-2004
3 */
4 package ca.uhn.hl7v2.protocol.impl;
5
6 import java.util.HashMap;
7 import java.util.List;
8 import java.util.Map;
9
10 import ca.uhn.hl7v2.HL7Exception;
11 import ca.uhn.hl7v2.model.Message;
12 import ca.uhn.hl7v2.util.Terser;
13
14 /**
15 * A utility for getting a list of fields from a <code>Message</code>,
16 * e.g. for inclusion in a <code>Transportable</code>.
17 *
18 * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
19 * @version $Revision: 1.1 $ updated on $Date: 2007-02-19 02:24:26 $ by $Author: jamesagnew $
20 */
21 public class MetadataExtractor {
22
23 /**
24 * @param theMessage a message from which to extract fields
25 * @param theTerserPaths a list of paths to desired fields, in the
26 * form required by <code>Terser</code>.
27 * @return a Map from Terser paths to field values
28 */
29 public static Map<String, String> getFields(Message theMessage, List<String> theTerserPaths) throws HL7Exception {
30 Map<String, String> fields = new HashMap<>();
31 Terserhtml#Terser">Terser terser = new Terser(theMessage);
32 for (String path : theTerserPaths) {
33 String fieldValue = terser.get(path);
34 fields.put(path, fieldValue);
35 }
36 return fields;
37 }
38
39 }