1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package ca.uhn.hl7v2.examples;
29
30 import ca.uhn.hl7v2.DefaultHapiContext;
31 import ca.uhn.hl7v2.HL7Exception;
32 import ca.uhn.hl7v2.HapiContext;
33 import ca.uhn.hl7v2.model.Message;
34 import ca.uhn.hl7v2.model.v25.message.ORU_R01;
35 import ca.uhn.hl7v2.parser.EncodingNotSupportedException;
36 import ca.uhn.hl7v2.parser.Parser;
37 import ca.uhn.hl7v2.util.Terser;
38
39
40
41
42
43
44
45 public class ExampleUseTerser
46 {
47
48
49
50
51
52
53
54 public static void main(String[] args) throws Exception {
55 String msg = "MSH|^~\\&|HIS|RIH|EKG|EKG|199904140038||ADT^A01||P|2.2\r"
56 + "PID|0001|00009874|00001122|A00977|SMITH^JOHN^M|MOM|19581119|F|NOTREAL^LINDA^M|C|564 SPRING ST^^NEEDHAM^MA^02494^US|0002|(818)565-1551|(425)828-3344|E|S|C|0000444444|252-00-4414||||SA|||SA||||NONE|V1|0001|I|D.ER^50A^M110^01|ER|P00055|11B^M011^02|070615^BATMAN^GEORGE^L|555888^NOTREAL^BOB^K^DR^MD|777889^NOTREAL^SAM^T^DR^MD^PHD|ER|D.WT^1A^M010^01|||ER|AMB|02|070615^NOTREAL^BILL^L|ER|000001916994|D||||||||||||||||GDD|WA|NORM|02|O|02|E.IN^02D^M090^01|E.IN^01D^M080^01|199904072124|199904101200|199904101200||||5555112333|||666097^NOTREAL^MANNY^P\r"
57 + "NK1|0222555|NOTREAL^JAMES^R|FA|STREET^OTHER STREET^CITY^ST^55566|(222)111-3333|(888)999-0000|||||||ORGANIZATION\r"
58 + "PV1|0001|I|D.ER^1F^M950^01|ER|P000998|11B^M011^02|070615^BATMAN^GEORGE^L|555888^OKNEL^BOB^K^DR^MD|777889^NOTREAL^SAM^T^DR^MD^PHD|ER|D.WT^1A^M010^01|||ER|AMB|02|070615^VOICE^BILL^L|ER|000001916994|D||||||||||||||||GDD|WA|NORM|02|O|02|E.IN^02D^M090^01|E.IN^01D^M080^01|199904072124|199904101200|||||5555112333|||666097^DNOTREAL^MANNY^P\r"
59 + "PV2|||0112^TESTING|55555^PATIENT IS NORMAL|NONE|||19990225|19990226|1|1|TESTING|555888^NOTREAL^BOB^K^DR^MD||||||||||PROD^003^099|02|ER||NONE|19990225|19990223|19990316|NONE\r"
60 + "AL1||SEV|001^POLLEN\r"
61 + "AL1||SEV|003^DUST\r"
62 + "GT1||0222PL|NOTREAL^BOB^B||STREET^OTHER STREET^CITY^ST^77787|(444)999-3333|(222)777-5555||||MO|111-33-5555||||NOTREAL GILL N|STREET^OTHER STREET^CITY^ST^99999|(111)222-3333\r"
63 + "IN1||022254P|4558PD|BLUE CROSS|STREET^OTHER STREET^CITY^ST^00990||(333)333-6666||221K|LENIX|||19980515|19990515|||PATIENT01 TEST D||||||||||||||||||02LL|022LP554";
64
65 HapiContext context = new DefaultHapiContext();
66 Parser p = context.getGenericParser();
67 Message hapiMsg = p.parse(msg);
68
69
70
71
72
73
74 Terserl#Terser">Terser terser = new Terser(hapiMsg);
75
76
77
78
79
80 String sendingApplication = terser.get("/.MSH-3-1");
81 System.out.println(sendingApplication);
82
83
84
85
86
87 String secondAllergyType = terser.get("/AL1(1)-3-2");
88 System.out.println(secondAllergyType);
89
90
91
92 terser.set("/.MSH-3-1", "new_sending_app");
93
94
95 ORU_R01sage/ORU_R01.html#ORU_R01">ORU_R01 oru = new ORU_R01();
96 oru.initQuickstart("ORU", "R01", "P");
97
98 terser = new Terser(oru);
99 for (int i = 0; i < 5; i++) {
100 terser.set("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(" + i + ")/OBX-1", "" + (i + 1));
101 terser.set("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(" + i + ")/OBX-3", "ST");
102 terser.set("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(" + i + ")/OBX-5", "This is the value for rep " + i);
103 }
104
105 System.out.println(p.encode(oru));
106
107
108
109
110
111
112
113
114
115 }
116
117 }