Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MetadataExtractor |
|
| 2.0;2 |
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 | 0 | 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 | 5 | Map<String, String> fields = new HashMap<String, String>(); |
31 | 5 | Terser terser = new Terser(theMessage); |
32 | 20 | for (int i = 0; i < theTerserPaths.size(); i++) { |
33 | 15 | String path = theTerserPaths.get(i); |
34 | 15 | String fieldValue = terser.get(path); |
35 | 15 | fields.put(path, fieldValue); |
36 | } | |
37 | 5 | return fields; |
38 | } | |
39 | ||
40 | } |