1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 | package gov.hhs.fha.nhinc.transform.subdisc;
|
---|
6 |
|
---|
7 | import gov.hhs.fha.nhinc.nhinclib.NullChecker;
|
---|
8 | import java.io.Serializable;
|
---|
9 | import java.util.TimeZone;
|
---|
10 | import java.util.GregorianCalendar;
|
---|
11 | import java.util.Iterator;
|
---|
12 | import java.util.List;
|
---|
13 | import javax.xml.bind.JAXBElement;
|
---|
14 | import org.apache.commons.logging.Log;
|
---|
15 | import org.apache.commons.logging.LogFactory;
|
---|
16 | import org.hl7.v3.*;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | *
|
---|
20 | * @author Jon Hoppesch
|
---|
21 | */
|
---|
22 | public class HL7DataTransformHelper {
|
---|
23 |
|
---|
24 | private static Log log = LogFactory.getLog(HL7DataTransformHelper.class);
|
---|
25 |
|
---|
26 | public static II IIFactory(String root) {
|
---|
27 | return IIFactory(root, null, null);
|
---|
28 | }
|
---|
29 |
|
---|
30 | public static II IIFactory(String root, String extension) {
|
---|
31 | return IIFactory(root, extension, null);
|
---|
32 | }
|
---|
33 |
|
---|
34 | public static II IIFactory(String root, String extension, String assigningAuthorityName) {
|
---|
35 | II ii = new II();
|
---|
36 | if (NullChecker.isNotNullish(root)) {
|
---|
37 | log.debug("Setting root attribute of II to " + root);
|
---|
38 | ii.setRoot(root);
|
---|
39 | }
|
---|
40 | if (NullChecker.isNotNullish(extension)) {
|
---|
41 | log.debug("Setting extension attribute of II to " + extension);
|
---|
42 | ii.setExtension(extension);
|
---|
43 | }
|
---|
44 | if (NullChecker.isNotNullish(assigningAuthorityName)) {
|
---|
45 | log.debug("Setting assigning authority attribute of II to " + assigningAuthorityName);
|
---|
46 | ii.setAssigningAuthorityName(assigningAuthorityName);
|
---|
47 | }
|
---|
48 | return ii;
|
---|
49 | }
|
---|
50 | public static II IIFactoryCreateNull() {
|
---|
51 | II ii = new II();
|
---|
52 | ii.getNullFlavor().add(HL7Constants.NULL_FLAVOR);
|
---|
53 | return ii;
|
---|
54 | }
|
---|
55 |
|
---|
56 | public static CS CSFactory(String code) {
|
---|
57 | CS cs = new CS();
|
---|
58 |
|
---|
59 | if (NullChecker.isNotNullish(code)) {
|
---|
60 | log.debug("Setting the code attribute of CS " + code);
|
---|
61 | cs.setCode(code);
|
---|
62 | }
|
---|
63 |
|
---|
64 | return cs;
|
---|
65 | }
|
---|
66 |
|
---|
67 | public static CE CEFactory(String code) {
|
---|
68 | CE ce = new CE();
|
---|
69 |
|
---|
70 | if (NullChecker.isNotNullish(code)) {
|
---|
71 | log.debug("Setting the code attribute of CE " + code);
|
---|
72 | ce.setCode(code);
|
---|
73 | }
|
---|
74 |
|
---|
75 | return ce;
|
---|
76 | }
|
---|
77 |
|
---|
78 | public static CD CDFactory(String code) {
|
---|
79 | return CDFactory(code, null);
|
---|
80 | }
|
---|
81 |
|
---|
82 | public static CD CDFactory(String code, String codeSystem) {
|
---|
83 | CD cd = new CD();
|
---|
84 |
|
---|
85 | if (NullChecker.isNotNullish(code)) {
|
---|
86 | log.debug("Setting the code attribute of CD " + code);
|
---|
87 | cd.setCode(code);
|
---|
88 | }
|
---|
89 |
|
---|
90 | if (NullChecker.isNotNullish(codeSystem)) {
|
---|
91 | log.debug("Setting the code system attribute of CD: " + codeSystem);
|
---|
92 | cd.setCodeSystem(codeSystem);
|
---|
93 | }
|
---|
94 |
|
---|
95 | return cd;
|
---|
96 | }
|
---|
97 |
|
---|
98 | public static TSExplicit TSExplicitFactory (String value) {
|
---|
99 | TSExplicit ts = new TSExplicit();
|
---|
100 |
|
---|
101 | ts.setValue(value);
|
---|
102 |
|
---|
103 | return ts;
|
---|
104 | }
|
---|
105 |
|
---|
106 | public static TSExplicit CreationTimeFactory() {
|
---|
107 | String timestamp = "";
|
---|
108 | TSExplicit creationTime = new TSExplicit();
|
---|
109 |
|
---|
110 | try {
|
---|
111 | GregorianCalendar today = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
|
---|
112 |
|
---|
113 | timestamp = String.valueOf(today.get(GregorianCalendar.YEAR)) +
|
---|
114 | String.valueOf(today.get(GregorianCalendar.MONTH) + 1) +
|
---|
115 | String.valueOf(today.get(GregorianCalendar.DAY_OF_MONTH)) +
|
---|
116 | String.valueOf(today.get(GregorianCalendar.HOUR_OF_DAY)) +
|
---|
117 | String.valueOf(today.get(GregorianCalendar.MINUTE)) +
|
---|
118 | String.valueOf(today.get(GregorianCalendar.SECOND));
|
---|
119 | } catch (Exception e) {
|
---|
120 | log.error("Exception when creating XMLGregorian Date");
|
---|
121 | log.error(" message: " + e.getMessage());
|
---|
122 | }
|
---|
123 |
|
---|
124 | if (NullChecker.isNotNullish(timestamp)) {
|
---|
125 | log.debug("Setting the creation timestamp to " + timestamp);
|
---|
126 | creationTime.setValue(timestamp);
|
---|
127 | }
|
---|
128 |
|
---|
129 | return creationTime;
|
---|
130 | }
|
---|
131 |
|
---|
132 | public static ENExplicit ConvertPNToEN(PNExplicit pnName) {
|
---|
133 | org.hl7.v3.ObjectFactory factory = new org.hl7.v3.ObjectFactory();
|
---|
134 | ENExplicit enName = (ENExplicit) (factory.createENExplicit());
|
---|
135 | List enNamelist = enName.getContent();
|
---|
136 | EnExplicitFamily familyName = new EnExplicitFamily();
|
---|
137 | EnExplicitGiven givenName = new EnExplicitGiven();
|
---|
138 |
|
---|
139 | List<Serializable> choice = pnName.getContent();
|
---|
140 | Iterator<Serializable> iterSerialObjects = choice.iterator();
|
---|
141 |
|
---|
142 | while (iterSerialObjects.hasNext()) {
|
---|
143 | Serializable contentItem = iterSerialObjects.next();
|
---|
144 |
|
---|
145 | if (contentItem instanceof JAXBElement) {
|
---|
146 | JAXBElement oJAXBElement = (JAXBElement) contentItem;
|
---|
147 |
|
---|
148 | if (oJAXBElement.getValue() instanceof EnExplicitFamily) {
|
---|
149 | familyName = (EnExplicitFamily) oJAXBElement.getValue();
|
---|
150 | enNamelist.add(factory.createENExplicitFamily(familyName));
|
---|
151 | }
|
---|
152 | else if(oJAXBElement.getValue() instanceof EnExplicitGiven) {
|
---|
153 | givenName = (EnExplicitGiven) oJAXBElement.getValue();
|
---|
154 | enNamelist.add(factory.createENExplicitGiven(givenName));
|
---|
155 | }
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 | return enName;
|
---|
160 | }
|
---|
161 |
|
---|
162 | public static PNExplicit CreatePNExplicit (String firstName, String lastName) {
|
---|
163 | org.hl7.v3.ObjectFactory factory = new org.hl7.v3.ObjectFactory();
|
---|
164 | PNExplicit name = (PNExplicit) (factory.createPNExplicit());
|
---|
165 | List namelist = name.getContent();
|
---|
166 |
|
---|
167 | if (NullChecker.isNotNullish(lastName)) {
|
---|
168 | EnExplicitFamily familyName = new EnExplicitFamily();
|
---|
169 | familyName.setPartType("FAM");
|
---|
170 | familyName.setContent(lastName);
|
---|
171 | log.info("Setting Patient Lastname: " + lastName);
|
---|
172 | namelist.add(factory.createPNExplicitFamily(familyName));
|
---|
173 | }
|
---|
174 |
|
---|
175 | if (NullChecker.isNotNullish(firstName)) {
|
---|
176 | EnExplicitGiven givenName = new EnExplicitGiven();
|
---|
177 | givenName.setPartType("GIV");
|
---|
178 | givenName.setContent(firstName);
|
---|
179 | log.info("Setting Patient Firstname: " + firstName);
|
---|
180 | namelist.add(factory.createPNExplicitGiven(givenName));
|
---|
181 | }
|
---|
182 |
|
---|
183 | return name;
|
---|
184 | }
|
---|
185 | }
|
---|