1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 |
|
---|
6 | package gov.hhs.fha.nhinc.transform.audit;
|
---|
7 |
|
---|
8 | import com.services.nhinc.schema.auditmessage.AuditMessageType;
|
---|
9 | import com.services.nhinc.schema.auditmessage.AuditMessageType.ActiveParticipant;
|
---|
10 | import com.services.nhinc.schema.auditmessage.AuditSourceIdentificationType;
|
---|
11 | import com.services.nhinc.schema.auditmessage.CodedValueType;
|
---|
12 | import com.services.nhinc.schema.auditmessage.EventIdentificationType;
|
---|
13 | import com.services.nhinc.schema.auditmessage.ParticipantObjectIdentificationType;
|
---|
14 | import java.util.ArrayList;
|
---|
15 | import java.util.List;
|
---|
16 | import java.net.InetAddress;
|
---|
17 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.ExternalIdentifierType;
|
---|
18 | import org.junit.After;
|
---|
19 | import org.junit.AfterClass;
|
---|
20 | import org.junit.Before;
|
---|
21 | import org.junit.BeforeClass;
|
---|
22 | import org.junit.Test;
|
---|
23 | import static org.junit.Assert.*;
|
---|
24 | import gov.hhs.fha.nhinc.common.nhinccommon.UserType;
|
---|
25 | import gov.hhs.fha.nhinc.common.nhinccommon.PersonNameType;
|
---|
26 | import gov.hhs.fha.nhinc.common.nhinccommon.HomeCommunityType;
|
---|
27 |
|
---|
28 | import org.apache.commons.logging.Log;
|
---|
29 | import org.apache.commons.logging.LogFactory;
|
---|
30 |
|
---|
31 |
|
---|
32 | /**
|
---|
33 | *
|
---|
34 | * @author MFLYNN02
|
---|
35 | */
|
---|
36 | public class AuditDataTransformHelperTest {
|
---|
37 | private static Log log = LogFactory.getLog(AuditDataTransformHelperTest.class);
|
---|
38 |
|
---|
39 | public AuditDataTransformHelperTest() {
|
---|
40 | }
|
---|
41 |
|
---|
42 | @BeforeClass
|
---|
43 | public static void setUpClass() throws Exception {
|
---|
44 | }
|
---|
45 |
|
---|
46 | @AfterClass
|
---|
47 | public static void tearDownClass() throws Exception {
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Before
|
---|
51 | public void setUp() {
|
---|
52 | }
|
---|
53 |
|
---|
54 | @After
|
---|
55 | public void tearDown() {
|
---|
56 | }
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Test of createEventIdentification method, of class AuditDataTransformHelper.
|
---|
60 | */
|
---|
61 | @Test
|
---|
62 | public void testCreateEventIdentification() {
|
---|
63 | log.debug("Begin - testCreateEventIdentification");
|
---|
64 |
|
---|
65 | String actionCode = AuditDataTransformConstants.EVENT_ACTION_CODE_CREATE;
|
---|
66 | Integer eventOutcome = AuditDataTransformConstants.EVENT_OUTCOME_INDICATOR_SUCCESS;
|
---|
67 | CodedValueType eventId = new CodedValueType();
|
---|
68 | eventId.setCodeSystem(AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_ACK);
|
---|
69 | eventId.setDisplayName(AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_ENTITY_SD);
|
---|
70 |
|
---|
71 | EventIdentificationType expResult = new EventIdentificationType();
|
---|
72 | expResult.setEventID(eventId);
|
---|
73 | expResult.setEventActionCode(actionCode);
|
---|
74 |
|
---|
75 | EventIdentificationType result = AuditDataTransformHelper.createEventIdentification(actionCode, eventOutcome, eventId);
|
---|
76 |
|
---|
77 | assertSame(expResult.getEventID(), result.getEventID());
|
---|
78 | assertSame(expResult.getEventActionCode(), result.getEventActionCode());
|
---|
79 |
|
---|
80 | log.debug("End - testCreateEventIdentification");
|
---|
81 | }
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Test of createEventId method, of class AuditDataTransformHelper.
|
---|
85 | */
|
---|
86 | @Test
|
---|
87 | public void testCreateEventId() {
|
---|
88 | log.debug("Begin - testCreateEventId");
|
---|
89 |
|
---|
90 | String eventCode = AuditDataTransformConstants.EVENT_ACTION_CODE_DELETE;
|
---|
91 | String eventCodeSys = "";
|
---|
92 | String eventCodeSysName = AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_SDD;
|
---|
93 | String dispName = AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_SDREV;
|
---|
94 |
|
---|
95 | CodedValueType expResult = new CodedValueType();
|
---|
96 | expResult.setCodeSystemName(eventCodeSysName);
|
---|
97 | expResult.setDisplayName(dispName);
|
---|
98 | expResult.setCode(eventCode);
|
---|
99 |
|
---|
100 | CodedValueType result = AuditDataTransformHelper.createEventId(eventCode, eventCodeSys, eventCodeSysName, dispName);
|
---|
101 |
|
---|
102 | assertSame(expResult.getCodeSystemName(), result.getCodeSystemName());
|
---|
103 | assertSame(expResult.getDisplayName(), result.getDisplayName());
|
---|
104 | assertSame(expResult.getCode(), result.getCode());
|
---|
105 |
|
---|
106 | log.debug("End - testCreateEventId");
|
---|
107 | }
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Test of createActiveParticipantFromUser method, of class AuditDataTransformHelper.
|
---|
111 | */
|
---|
112 | @Test
|
---|
113 | public void testCreateActiveParticipantFromAssertion() {
|
---|
114 | log.debug("End - testCreateActiveParticipantFromAssertion");
|
---|
115 |
|
---|
116 | String ipAddr = null;
|
---|
117 |
|
---|
118 | try {
|
---|
119 | ipAddr = InetAddress.getLocalHost().getHostAddress();
|
---|
120 | }
|
---|
121 | catch (Exception ex) {
|
---|
122 | ex.printStackTrace();
|
---|
123 | throw new RuntimeException();
|
---|
124 | }
|
---|
125 |
|
---|
126 | PersonNameType personName = new PersonNameType();
|
---|
127 | personName.setFamilyName("Jones");
|
---|
128 | personName.setGivenName("John");
|
---|
129 | UserType userInfo = new UserType();
|
---|
130 | userInfo.setPersonName(personName);
|
---|
131 | userInfo.setUserName("tester");
|
---|
132 | Boolean userIsReq = true;
|
---|
133 |
|
---|
134 | ActiveParticipant expResult = new ActiveParticipant();
|
---|
135 | expResult.setNetworkAccessPointID(ipAddr);
|
---|
136 | expResult.setUserName("John Jones");
|
---|
137 | expResult.setUserID("tester");
|
---|
138 |
|
---|
139 | ActiveParticipant result = AuditDataTransformHelper.createActiveParticipantFromUser(userInfo, userIsReq);
|
---|
140 |
|
---|
141 | assertEquals(expResult.getNetworkAccessPointID(), result.getNetworkAccessPointID());
|
---|
142 | assertEquals(expResult.getUserID(), result.getUserID());
|
---|
143 | assertEquals (expResult.getUserName(), result.getUserName());
|
---|
144 |
|
---|
145 | log.debug("End - testCreateActiveParticipantFromAssertion");
|
---|
146 | }
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * Test of createActiveParticipant method, of class AuditDataTransformHelper.
|
---|
150 | */
|
---|
151 | @Test
|
---|
152 | public void testCreateActiveParticipant() {
|
---|
153 | log.debug("Begin - testCreateActiveParticipant");
|
---|
154 |
|
---|
155 | String userId = "test1";
|
---|
156 | String altUserId = "John";
|
---|
157 | String userName = "Thomas John Smith";
|
---|
158 | Boolean userIsReq = true;
|
---|
159 |
|
---|
160 | ActiveParticipant expResult = new ActiveParticipant();
|
---|
161 | expResult.setAlternativeUserID(altUserId);
|
---|
162 | expResult.setUserID(userId);
|
---|
163 | expResult.setUserName(userName);
|
---|
164 |
|
---|
165 | ActiveParticipant result = AuditDataTransformHelper.createActiveParticipant(userId, altUserId, userName, userIsReq);
|
---|
166 |
|
---|
167 | assertEquals(expResult.getAlternativeUserID(), result.getAlternativeUserID());
|
---|
168 | assertEquals(expResult.getUserID(), result.getUserID());
|
---|
169 | assertEquals(expResult.getUserName(), result.getUserName());
|
---|
170 |
|
---|
171 | log.debug("End - testCreateActiveParticipant");
|
---|
172 | }
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * Test of createAuditSourceIdentificationFromUser method, of class AuditDataTransformHelper.
|
---|
176 | */
|
---|
177 | @Test
|
---|
178 | public void testCreateAuditSourceIdentificationFromAssertion() {
|
---|
179 | log.debug("Begin - testCreateAuditSourceIdentificationFromAssertion");
|
---|
180 |
|
---|
181 | HomeCommunityType home = new HomeCommunityType();
|
---|
182 | home.setHomeCommunityId("2.16.840.1.113883.3.200");
|
---|
183 | home.setName("Federal - VA");
|
---|
184 | UserType userInfo = new UserType();
|
---|
185 | userInfo.setOrg(home);
|
---|
186 |
|
---|
187 | AuditSourceIdentificationType expResult = new AuditSourceIdentificationType();
|
---|
188 | expResult.setAuditSourceID(home.getHomeCommunityId());
|
---|
189 | expResult.setAuditEnterpriseSiteID(home.getName());
|
---|
190 |
|
---|
191 | AuditSourceIdentificationType result = AuditDataTransformHelper.createAuditSourceIdentificationFromUser(userInfo);
|
---|
192 |
|
---|
193 | assertEquals(expResult.getAuditEnterpriseSiteID(), result.getAuditEnterpriseSiteID());
|
---|
194 | assertEquals(expResult.getAuditSourceID(), result.getAuditSourceID());
|
---|
195 |
|
---|
196 | log.debug("End - testCreateAuditSourceIdentificationFromAssertion");
|
---|
197 | }
|
---|
198 |
|
---|
199 | /**
|
---|
200 | * Test of createAuditSourceIdentification method, of class AuditDataTransformHelper.
|
---|
201 | */
|
---|
202 | @Test
|
---|
203 | public void testCreateAuditSourceIdentification() {
|
---|
204 | log.debug("Begin - testCreateAuditSourceIdentification");
|
---|
205 |
|
---|
206 | String communityId = "2.16.840.1.113883.3.198";
|
---|
207 | String communityName = "Federal - DoD";
|
---|
208 |
|
---|
209 | AuditSourceIdentificationType expResult = new AuditSourceIdentificationType();
|
---|
210 | expResult.setAuditSourceID(communityId);
|
---|
211 | expResult.setAuditEnterpriseSiteID(communityName);
|
---|
212 |
|
---|
213 | AuditSourceIdentificationType result = AuditDataTransformHelper.createAuditSourceIdentification(communityId, communityName);
|
---|
214 |
|
---|
215 | assertEquals(expResult.getAuditEnterpriseSiteID(), result.getAuditEnterpriseSiteID());
|
---|
216 | assertEquals(expResult.getAuditSourceID(), result.getAuditSourceID());
|
---|
217 |
|
---|
218 | log.debug("End - testCreateAuditSourceIdentification");
|
---|
219 | }
|
---|
220 |
|
---|
221 | /**
|
---|
222 | * Test of createParticipantObjectIdentification method, of class AuditDataTransformHelper.
|
---|
223 | */
|
---|
224 | @Test
|
---|
225 | public void testCreateParticipantObjectIdentification() {
|
---|
226 | log.debug("Begin - testCreateParticipantObjectIdentification");
|
---|
227 |
|
---|
228 | String patientId = "44444";
|
---|
229 |
|
---|
230 | ParticipantObjectIdentificationType expResult = new ParticipantObjectIdentificationType();
|
---|
231 | expResult.setParticipantObjectID(patientId);
|
---|
232 |
|
---|
233 | ParticipantObjectIdentificationType result = AuditDataTransformHelper.createParticipantObjectIdentification(patientId);
|
---|
234 |
|
---|
235 | assertEquals(expResult.getParticipantObjectID(), result.getParticipantObjectID());
|
---|
236 |
|
---|
237 | log.debug("End - testCreateParticipantObjectIdentification");
|
---|
238 | }
|
---|
239 |
|
---|
240 | /**
|
---|
241 | * Test of logAuditMessage method, of class AuditDataTransformHelper.
|
---|
242 | */
|
---|
243 | @Test
|
---|
244 | public void testLogAuditMessage() {
|
---|
245 | log.debug("Begin - testLogAuditMessage");
|
---|
246 |
|
---|
247 | EventIdentificationType eventId = new EventIdentificationType();
|
---|
248 | CodedValueType code = new CodedValueType();
|
---|
249 | code.setCode(AuditDataTransformConstants.EVENT_ACTION_CODE_EXECUTE);
|
---|
250 | code.setCodeSystem(AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_SDN);
|
---|
251 | eventId.setEventActionCode(AuditDataTransformConstants.EVENT_ACTION_CODE_EXECUTE);
|
---|
252 | eventId.setEventID(code);
|
---|
253 |
|
---|
254 | ActiveParticipant participant = new ActiveParticipant();
|
---|
255 | participant.setUserID("tester");
|
---|
256 |
|
---|
257 | AuditSourceIdentificationType sourceId = new AuditSourceIdentificationType();
|
---|
258 | sourceId.setAuditSourceID("2.16.840.1.113883.3.198");
|
---|
259 | sourceId.setAuditEnterpriseSiteID("Federal - DoD");
|
---|
260 |
|
---|
261 | AuditMessageType message = new AuditMessageType();
|
---|
262 | message.setEventIdentification(eventId);
|
---|
263 | message.getActiveParticipant().add(participant);
|
---|
264 | message.getAuditSourceIdentification().add(sourceId);
|
---|
265 |
|
---|
266 | AuditDataTransformHelper.logAuditMessage(message);
|
---|
267 |
|
---|
268 | log.debug("End - testLogAuditMessage");
|
---|
269 | }
|
---|
270 |
|
---|
271 | /**
|
---|
272 | * Test of findSingleExternalIdentifier method, of class AuditDataTransformHelper.
|
---|
273 | */
|
---|
274 | @Test
|
---|
275 | public void testFindSingleExternalIdentifier() {
|
---|
276 | log.debug("Begin - testFindSingleExternalIdentifier");
|
---|
277 |
|
---|
278 | ExternalIdentifierType extId1 = new ExternalIdentifierType();
|
---|
279 | ExternalIdentifierType extId2 = new ExternalIdentifierType();
|
---|
280 | extId1.setIdentificationScheme("2.16.840.1.113883.3.198");
|
---|
281 | List<ExternalIdentifierType> olExtId = new ArrayList();
|
---|
282 | olExtId.add(extId1);
|
---|
283 | extId2.setIdentificationScheme("2.16.840.1.113883.3.200");
|
---|
284 | olExtId.add(extId2);
|
---|
285 |
|
---|
286 | String sIdentScheme = "2.16.840.1.113883.3.198";
|
---|
287 | ExternalIdentifierType expResult = new ExternalIdentifierType();
|
---|
288 | expResult = extId1;
|
---|
289 | ExternalIdentifierType result = AuditDataTransformHelper.findSingleExternalIdentifier(olExtId, sIdentScheme);
|
---|
290 | assertEquals(expResult.getIdentificationScheme(), result.getIdentificationScheme());
|
---|
291 |
|
---|
292 | log.debug("End - testFindSingleExternalIdentifier");
|
---|
293 | }
|
---|
294 |
|
---|
295 | /**
|
---|
296 | * Test of findSingleExternalIdentifierAndExtractValue method, of class AuditDataTransformHelper.
|
---|
297 | */
|
---|
298 | @Test
|
---|
299 | public void testFindSingleExternalIdentifierAndExtractValue() {
|
---|
300 | log.debug("Begin - testFindSingleExternalIdentifierAndExtractValue");
|
---|
301 |
|
---|
302 | ExternalIdentifierType extId1 = new ExternalIdentifierType();
|
---|
303 | extId1.setIdentificationScheme("2.16.840.1.113883.3.198");
|
---|
304 | extId1.setValue("198");
|
---|
305 |
|
---|
306 | ExternalIdentifierType extId2 = new ExternalIdentifierType();
|
---|
307 | extId2.setIdentificationScheme("2.16.840.1.113883.3.200");
|
---|
308 | extId2.setValue("200");
|
---|
309 |
|
---|
310 | List<ExternalIdentifierType> olExtId = new ArrayList();
|
---|
311 | olExtId.add(extId1);
|
---|
312 | olExtId.add(extId2);
|
---|
313 |
|
---|
314 | String sIdentScheme = "2.16.840.1.113883.3.198";
|
---|
315 | String expResult = extId1.getValue();
|
---|
316 |
|
---|
317 | String result = AuditDataTransformHelper.findSingleExternalIdentifierAndExtractValue(olExtId, sIdentScheme);
|
---|
318 |
|
---|
319 | assertEquals(expResult, result);
|
---|
320 |
|
---|
321 | log.debug("End - testFindSingleExternalIdentifierAndExtractValue");
|
---|
322 | }
|
---|
323 |
|
---|
324 | /**
|
---|
325 | * Test of createCompositePatientId method, of class AuditDataTransformHelper.
|
---|
326 | */
|
---|
327 | @Test
|
---|
328 | public void testCreateCompositePatientId() {
|
---|
329 | log.debug("Begin - testCreateCompositePatientId");
|
---|
330 |
|
---|
331 | String communityId = "2.16.840.1.113883.3.200";
|
---|
332 | String patientId = "12332";
|
---|
333 | String expResult = patientId +"^^^&" + communityId + "&ISO";
|
---|
334 |
|
---|
335 | String result = AuditDataTransformHelper.createCompositePatientId(communityId, patientId);
|
---|
336 |
|
---|
337 | assertEquals(expResult, result);
|
---|
338 |
|
---|
339 | log.debug("End - testCreateCompositePatientId");
|
---|
340 | }
|
---|
341 |
|
---|
342 | /**
|
---|
343 | * Test of createCompositePatientIdFromAssertion method, of class AuditDataTransformHelper.
|
---|
344 | */
|
---|
345 | @Test
|
---|
346 | public void testCreateCompositePatientIdFromAssertion() {
|
---|
347 | log.debug("Begin - testCreateCompositePatientIdFromAssertion");
|
---|
348 |
|
---|
349 | HomeCommunityType home = new HomeCommunityType();
|
---|
350 | home.setHomeCommunityId("2.16.840.1.113883.3.200");
|
---|
351 | home.setName("Federal - VA");
|
---|
352 | UserType userInfo = new UserType();
|
---|
353 | userInfo.setOrg(home);
|
---|
354 |
|
---|
355 | String uniquePatientId = "56765";
|
---|
356 |
|
---|
357 | String expResult = uniquePatientId +"^^^&" + userInfo.getOrg().getHomeCommunityId() + "&ISO";
|
---|
358 | String result = AuditDataTransformHelper.createCompositePatientIdFromAssertion(userInfo, uniquePatientId);
|
---|
359 | assertEquals(expResult, result);
|
---|
360 |
|
---|
361 | log.debug("End - testCreateCompositePatientIdFromAssertion");
|
---|
362 | }
|
---|
363 |
|
---|
364 | }
|
---|