1
2
3
4
5
6 package ca.uhn.hl7v2.examples;
7
8 import ca.uhn.hl7v2.DefaultHapiContext;
9 import ca.uhn.hl7v2.HL7Exception;
10 import ca.uhn.hl7v2.HapiContext;
11 import ca.uhn.hl7v2.examples.custommodel.v25.message.ZDT_A01;
12 import ca.uhn.hl7v2.examples.custommodel.v25.segment.ZPI;
13 import ca.uhn.hl7v2.model.Segment;
14 import ca.uhn.hl7v2.model.v25.message.ADT_A01;
15 import ca.uhn.hl7v2.parser.CustomModelClassFactory;
16 import ca.uhn.hl7v2.parser.ModelClassFactory;
17 import ca.uhn.hl7v2.parser.Parser;
18
19
20
21
22
23 public class CustomModelClasses {
24
25 public static void main(String[] args) throws HL7Exception {
26
27
28
29
30
31
32
33
34
35
36
37
38 String messageText = "MSH|^~\\&|IRIS|SANTER|AMB_R|SANTER|200803051508||ADT^A01|263206|P|2.5\r"
39 + "EVN||200803051509||||200803031508\r"
40 + "PID|||5520255^^^PK^PK~ZZZZZZ83M64Z148R^^^CF^CF~ZZZZZZ83M64Z148R^^^SSN^SSN^^20070103^99991231~^^^^TEAM||ZZZ^ZZZ||19830824|F||||||||||||||||||||||N\r"
41 + "ZPI|Fido~Fred|13\r"
42 + "PV1||I|6402DH^^^^^^^^MED. 1 - ONCOLOGIA^^OSPEDALE MAGGIORE DI LODI&LODI|||^^^^^^^^^^OSPEDALE MAGGIORE DI LODI&LODI|13936^TEST^TEST||||||||||5068^TEST2^TEST2||2008003369||||||||||||||||||||||||||200803031508\r"
43 + "PR1|1||1111^Mastoplastica|Protesi|20090224|02|";
44
45
46 HapiContext context = new DefaultHapiContext();
47 Parser parser = context.getPipeParser();
48 ADT_A01/../../../ca/uhn/hl7v2/model/v25/message/ADT_A01.html#ADT_A01">ADT_A01 message = (ADT_A01) parser.parse(messageText);
49
50
51 Segmentca/uhn/hl7v2/model/Segment.html#Segment">Segment zpiGenericSegment = (Segment) message.get("ZPI");
52
53 String firstPetName = zpiGenericSegment.getField(1, 0).encode();
54 String secondPetName = zpiGenericSegment.getField(1, 1).encode();
55 System.out.println(firstPetName);
56 System.out.println(secondPetName);
57
58 String shoeSize = zpiGenericSegment.getField(2, 0).encode();
59 System.out.println(shoeSize);
60
61
62
63
64
65
66
67 ZPI zpi;
68
69
70 ZDT_A01 zdtA01;
71
72
73
74 ModelClassFactory cmf = new CustomModelClassFactory("ca.uhn.hl7v2.examples.custommodel");
75 context.setModelClassFactory(cmf);
76
77
78 messageText = "MSH|^~\\&|IRIS|SANTER|AMB_R|SANTER|200803051508||ZDT^A01|263206|P|2.5\r"
79 + "EVN||200803051509||||200803031508\r"
80 + "PID|||5520255^^^PK^PK~ZZZZZZ83M64Z148R^^^CF^CF~ZZZZZZ83M64Z148R^^^SSN^SSN^^20070103^99991231~^^^^TEAM||ZZZ^ZZZ||19830824|F||||||||||||||||||||||N\r"
81 + "ZPI|Fido~Fred|13\r"
82 + "PV1||I|6402DH^^^^^^^^MED. 1 - ONCOLOGIA^^OSPEDALE MAGGIORE DI LODI&LODI|||^^^^^^^^^^OSPEDALE MAGGIORE DI LODI&LODI|13936^TEST^TEST||||||||||5068^TEST2^TEST2||2008003369||||||||||||||||||||||||||200803031508\r"
83 + "PR1|1||1111^Mastoplastica|Protesi|20090224|02|";
84 zdtA01 = (ZDT_A01) parser.parse(messageText);
85
86
87 zpi = zdtA01.getZPI();
88
89 System.out.println(zpi.getPetName()[0].encode());
90 System.out.println(zpi.getPetName()[1].encode());
91 System.out.println(zpi.getShoeSize().encode());
92
93 }
94
95 }