[507] | 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 java.io.Serializable;
|
---|
| 8 | import java.util.Iterator;
|
---|
| 9 | import java.util.List;
|
---|
| 10 | import javax.xml.bind.JAXBElement;
|
---|
| 11 | import org.hl7.v3.*;
|
---|
| 12 | import org.junit.After;
|
---|
| 13 | import org.junit.AfterClass;
|
---|
| 14 | import org.junit.Before;
|
---|
| 15 | import org.junit.BeforeClass;
|
---|
| 16 | import org.junit.Test;
|
---|
| 17 | import static org.junit.Assert.*;
|
---|
| 18 | import org.apache.commons.logging.Log;
|
---|
| 19 | import org.apache.commons.logging.LogFactory;
|
---|
| 20 |
|
---|
| 21 | /**
|
---|
| 22 | *
|
---|
| 23 | * @author Jon Hoppesch
|
---|
| 24 | */
|
---|
| 25 | public class HL7DataTransformHelperTest {
|
---|
| 26 |
|
---|
| 27 | private static Log log = LogFactory.getLog(HL7DataTransformHelperTest.class);
|
---|
| 28 |
|
---|
| 29 | public HL7DataTransformHelperTest() {
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | @BeforeClass
|
---|
| 33 | public static void setUpClass() throws Exception {
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | @AfterClass
|
---|
| 37 | public static void tearDownClass() throws Exception {
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | @Before
|
---|
| 41 | public void setUp() {
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | @After
|
---|
| 45 | public void tearDown() {
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | /**
|
---|
| 49 | * Test of IIFactory method, of class HL7DataTransformHelper.
|
---|
| 50 | * root only
|
---|
| 51 | */
|
---|
| 52 | @Test
|
---|
| 53 | public void testIIFactory_1arg() {
|
---|
| 54 | log.info("testIIFactory_1arg");
|
---|
| 55 |
|
---|
| 56 | String root = "2.16.840.1.113883.3.200";
|
---|
| 57 | II result = HL7DataTransformHelper.IIFactory(root);
|
---|
| 58 | assertEquals(result.getRoot(), "2.16.840.1.113883.3.200");
|
---|
| 59 | assertNull(result.getExtension());
|
---|
| 60 | assertNull(result.getAssigningAuthorityName());
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | /**
|
---|
| 64 | * Test of IIFactory method, of class HL7DataTransformHelper.
|
---|
| 65 | * 1 arg, no input
|
---|
| 66 | */
|
---|
| 67 | @Test
|
---|
| 68 | public void testIIFactory_1arg_NoInput() {
|
---|
| 69 | log.info("testIIFactory_1arg_NoInput");
|
---|
| 70 |
|
---|
| 71 | II result = HL7DataTransformHelper.IIFactory(null);
|
---|
| 72 | assertNull(result.getRoot());
|
---|
| 73 | assertNull(result.getExtension());
|
---|
| 74 | assertNull(result.getAssigningAuthorityName());
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | /**
|
---|
| 78 | * Test of IIFactory method, of class HL7DataTransformHelper.
|
---|
| 79 | * root and extension
|
---|
| 80 | */
|
---|
| 81 | @Test
|
---|
| 82 | public void testIIFactory_2args() {
|
---|
| 83 | log.info("testIIFactory_2args");
|
---|
| 84 |
|
---|
| 85 | String root = "2.16.840.1.113883.3.200";
|
---|
| 86 | String extension = "1234567890";
|
---|
| 87 |
|
---|
| 88 | II result = HL7DataTransformHelper.IIFactory(root, extension);
|
---|
| 89 | assertEquals(result.getRoot(), "2.16.840.1.113883.3.200");
|
---|
| 90 | assertEquals(result.getExtension(), "1234567890");
|
---|
| 91 | assertNull(result.getAssigningAuthorityName());
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | /**
|
---|
| 95 | * Test of IIFactory method, of class HL7DataTransformHelper.
|
---|
| 96 | * 2 args, no input
|
---|
| 97 | */
|
---|
| 98 | @Test
|
---|
| 99 | public void testIIFactory_2args_NoInput() {
|
---|
| 100 | log.info("testIIFactory_2args_NoInput");
|
---|
| 101 |
|
---|
| 102 | II result = HL7DataTransformHelper.IIFactory(null, null);
|
---|
| 103 | assertNull(result.getRoot());
|
---|
| 104 | assertNull(result.getExtension());
|
---|
| 105 | assertNull(result.getAssigningAuthorityName());
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | /**
|
---|
| 109 | * Test of IIFactory method, of class HL7DataTransformHelper.
|
---|
| 110 | * root, extension, and assigning authority name
|
---|
| 111 | */
|
---|
| 112 | @Test
|
---|
| 113 | public void testIIFactory_3args() {
|
---|
| 114 | log.info("testIIFactory_3args");
|
---|
| 115 | String root = "2.16.840.1.113883.3.200";
|
---|
| 116 | String extension = "1234567890";
|
---|
| 117 | String assigningAuthorityName = "Social Security Administration";
|
---|
| 118 |
|
---|
| 119 | II result = HL7DataTransformHelper.IIFactory(root, extension, assigningAuthorityName);
|
---|
| 120 | assertEquals(result.getRoot(), "2.16.840.1.113883.3.200");
|
---|
| 121 | assertEquals(result.getExtension(), "1234567890");
|
---|
| 122 | assertEquals(result.getAssigningAuthorityName(), "Social Security Administration");
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | /**
|
---|
| 126 | * Test of IIFactory method, of class HL7DataTransformHelper.
|
---|
| 127 | * root, extension, and assigning authority name, no inputs
|
---|
| 128 | */
|
---|
| 129 | @Test
|
---|
| 130 | public void testIIFactory_3args_NoInput() {
|
---|
| 131 | log.info("testIIFactory_3args_NoInput");
|
---|
| 132 |
|
---|
| 133 | II result = HL7DataTransformHelper.IIFactory(null, null, null);
|
---|
| 134 | assertNull(result.getRoot());
|
---|
| 135 | assertNull(result.getExtension());
|
---|
| 136 | assertNull(result.getAssigningAuthorityName());
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | /**
|
---|
| 140 | * Test of CSFactory method, of class HL7DataTransformHelper.
|
---|
| 141 | */
|
---|
| 142 | @Test
|
---|
| 143 | public void testCSFactory() {
|
---|
| 144 | log.info("testCSFactory");
|
---|
| 145 |
|
---|
| 146 | String code = "R";
|
---|
| 147 | CS result = HL7DataTransformHelper.CSFactory(code);
|
---|
| 148 | assertEquals(result.getCode(), "R");
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | /**
|
---|
| 152 | * Test of CSFactory method, of class HL7DataTransformHelper.
|
---|
| 153 | * with no input
|
---|
| 154 | */
|
---|
| 155 | @Test
|
---|
| 156 | public void testCSFactory_NoInput() {
|
---|
| 157 | log.info("testCSFactory_NoInput");
|
---|
| 158 |
|
---|
| 159 | CS result = HL7DataTransformHelper.CSFactory(null);
|
---|
| 160 | assertNull(result.getCode());
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | /**
|
---|
| 164 | * Test of CEFactory method, of class HL7DataTransformHelper.
|
---|
| 165 | */
|
---|
| 166 | @Test
|
---|
| 167 | public void testCEFactory() {
|
---|
| 168 | log.info("testCEFactory");
|
---|
| 169 |
|
---|
| 170 | String code = "T";
|
---|
| 171 | CE result = HL7DataTransformHelper.CEFactory(code);
|
---|
| 172 | assertEquals(result.getCode(), "T");
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | /**
|
---|
| 176 | * Test of CEFactory method, of class HL7DataTransformHelper.
|
---|
| 177 | * with no input
|
---|
| 178 | */
|
---|
| 179 | @Test
|
---|
| 180 | public void testCEFactory_NoInput() {
|
---|
| 181 | log.info("testCEFactory_NoInput");
|
---|
| 182 |
|
---|
| 183 | CE result = HL7DataTransformHelper.CEFactory(null);
|
---|
| 184 | assertNull(result.getCode());
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | /**
|
---|
| 188 | * Test of CDFactory method, of class HL7DataTransformHelper.
|
---|
| 189 | */
|
---|
| 190 | @Test
|
---|
| 191 | public void testCDFactory_1arg() {
|
---|
| 192 | log.info("testCDFactory_1arg");
|
---|
| 193 |
|
---|
| 194 | String code = "R";
|
---|
| 195 | CD result = HL7DataTransformHelper.CDFactory(code);
|
---|
| 196 | assertEquals(result.getCode(), "R");
|
---|
| 197 | assertNull(result.getCodeSystem());
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | /**
|
---|
| 201 | * Test of CDFactory method, of class HL7DataTransformHelper.
|
---|
| 202 | * with no input
|
---|
| 203 | */
|
---|
| 204 | @Test
|
---|
| 205 | public void testCDFactory_1arg_NoInput() {
|
---|
| 206 | log.info("testCDFactory_1arg_NoInput");
|
---|
| 207 |
|
---|
| 208 | CD result = HL7DataTransformHelper.CDFactory(null);
|
---|
| 209 | assertNull(result.getCode());
|
---|
| 210 | assertNull(result.getCodeSystem());
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | /**
|
---|
| 214 | * Test of CDFactory method, of class HL7DataTransformHelper.
|
---|
| 215 | */
|
---|
| 216 | @Test
|
---|
| 217 | public void testCDFactory_2args() {
|
---|
| 218 | log.info("testCDFactory_2args");
|
---|
| 219 |
|
---|
| 220 | String code = "R";
|
---|
| 221 | String codeSystem = "1.1.333";
|
---|
| 222 | CD result = HL7DataTransformHelper.CDFactory(code, codeSystem);
|
---|
| 223 | assertEquals(result.getCode(), "R");
|
---|
| 224 | assertEquals(result.getCodeSystem(), "1.1.333");
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | /**
|
---|
| 228 | * Test of CDFactory method, of class HL7DataTransformHelper.
|
---|
| 229 | * with no input
|
---|
| 230 | */
|
---|
| 231 | @Test
|
---|
| 232 | public void testCDFactory_2args_NoInput() {
|
---|
| 233 | log.info("testCDFactory_2args_NoInput");
|
---|
| 234 |
|
---|
| 235 | CD result = HL7DataTransformHelper.CDFactory(null, null);
|
---|
| 236 | assertNull(result.getCode());
|
---|
| 237 | assertNull(result.getCodeSystem());
|
---|
| 238 | }
|
---|
| 239 |
|
---|
| 240 | /**
|
---|
| 241 | * Test of testTSExplicitFactory method, of class HL7DataTransformHelper.
|
---|
| 242 | */
|
---|
| 243 | @Test
|
---|
| 244 | public void testTSExplicitFactory () {
|
---|
| 245 | log.info("testTSExplicitFactory");
|
---|
| 246 |
|
---|
| 247 | TSExplicit result = HL7DataTransformHelper.TSExplicitFactory("M");
|
---|
| 248 |
|
---|
| 249 | assertEquals ("M", result.getValue());
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 | /**
|
---|
| 253 | * Test of testTSExplicitFactory method, of class HL7DataTransformHelper.
|
---|
| 254 | * no input
|
---|
| 255 | */
|
---|
| 256 | @Test
|
---|
| 257 | public void testTSExplicitFactory_NoInput () {
|
---|
| 258 | log.info("testTSExplicitFactory_NoInput");
|
---|
| 259 |
|
---|
| 260 | TSExplicit result = HL7DataTransformHelper.TSExplicitFactory(null);
|
---|
| 261 |
|
---|
| 262 | assertNull (result.getValue());
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | /**
|
---|
| 266 | * Test of CreationTimeFactory method, of class HL7DataTransformHelper.
|
---|
| 267 | */
|
---|
| 268 | @Test
|
---|
| 269 | public void testCreationTimeFactory() {
|
---|
| 270 | log.info("CreationTimeFactory");
|
---|
| 271 | TSExplicit result = HL7DataTransformHelper.CreationTimeFactory();
|
---|
| 272 | assertNotNull(result);
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | /**
|
---|
| 276 | * Test of ConvertPNToEN method, of class HL7DataTransformHelper.
|
---|
| 277 | */
|
---|
| 278 | @Test
|
---|
| 279 | public void testConvertPNToEN() {
|
---|
| 280 | log.info("testConvertPNToEN");
|
---|
| 281 |
|
---|
| 282 | org.hl7.v3.ObjectFactory factory = new org.hl7.v3.ObjectFactory();
|
---|
| 283 | PNExplicit pnName = (PNExplicit) (factory.createPNExplicit());
|
---|
| 284 | List pnNamelist = pnName.getContent();
|
---|
| 285 |
|
---|
| 286 | // Setup input
|
---|
| 287 | EnExplicitFamily familyName = new EnExplicitFamily();
|
---|
| 288 | familyName.setPartType("FAM");
|
---|
| 289 | familyName.setContent("Smith");
|
---|
| 290 | pnNamelist.add(factory.createENExplicitFamily(familyName));
|
---|
| 291 | EnExplicitGiven givenName = new EnExplicitGiven();
|
---|
| 292 | givenName.setPartType("GIV");
|
---|
| 293 | givenName.setContent("Hugo");
|
---|
| 294 | pnNamelist.add(factory.createENExplicitGiven(givenName));
|
---|
| 295 |
|
---|
| 296 | ENExplicit enName = HL7DataTransformHelper.ConvertPNToEN(pnName);
|
---|
| 297 |
|
---|
| 298 | // Parse out output
|
---|
| 299 | List<Serializable> choice = enName.getContent();
|
---|
| 300 | Iterator<Serializable> iterSerialObjects = choice.iterator();
|
---|
| 301 |
|
---|
| 302 | TestHelper.assertNameEquals(iterSerialObjects, familyName, givenName);
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | /**
|
---|
| 306 | * Test of ConvertPNToEN method, of class HL7DataTransformHelper.
|
---|
| 307 | * Only the family name is specified.
|
---|
| 308 | */
|
---|
| 309 | @Test
|
---|
| 310 | public void testConvertPNToEN_OnlyFamily() {
|
---|
| 311 | log.info("testConvertPNToEN_OnlyFamily");
|
---|
| 312 |
|
---|
| 313 | org.hl7.v3.ObjectFactory factory = new org.hl7.v3.ObjectFactory();
|
---|
| 314 | PNExplicit pnName = (PNExplicit) (factory.createPNExplicit());
|
---|
| 315 | List pnNamelist = pnName.getContent();
|
---|
| 316 |
|
---|
| 317 | // Setup input
|
---|
| 318 | EnExplicitFamily familyName = new EnExplicitFamily();
|
---|
| 319 | familyName.setPartType("FAM");
|
---|
| 320 | familyName.setContent("Smith");
|
---|
| 321 | pnNamelist.add(factory.createENExplicitFamily(familyName));
|
---|
| 322 |
|
---|
| 323 | ENExplicit enName = HL7DataTransformHelper.ConvertPNToEN(pnName);
|
---|
| 324 |
|
---|
| 325 | // Parse out output
|
---|
| 326 | List<Serializable> choice = enName.getContent();
|
---|
| 327 | Iterator<Serializable> iterSerialObjects = choice.iterator();
|
---|
| 328 |
|
---|
| 329 | TestHelper.assertNameEquals(iterSerialObjects, familyName, null);
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | /**
|
---|
| 333 | * Test of ConvertPNToEN method, of class HL7DataTransformHelper.
|
---|
| 334 | * Only the given name is specified.
|
---|
| 335 | */
|
---|
| 336 | @Test
|
---|
| 337 | public void testConvertPNToEN_OnlyGiven() {
|
---|
| 338 | log.info("testConvertPNToEN_OnlyGiven");
|
---|
| 339 |
|
---|
| 340 | org.hl7.v3.ObjectFactory factory = new org.hl7.v3.ObjectFactory();
|
---|
| 341 | PNExplicit pnName = (PNExplicit) (factory.createPNExplicit());
|
---|
| 342 | List pnNamelist = pnName.getContent();
|
---|
| 343 |
|
---|
| 344 | // Setup input
|
---|
| 345 | EnExplicitGiven givenName = new EnExplicitGiven();
|
---|
| 346 | givenName.setPartType("GIV");
|
---|
| 347 | givenName.setContent("Hugo");
|
---|
| 348 | pnNamelist.add(factory.createENExplicitGiven(givenName));
|
---|
| 349 |
|
---|
| 350 | ENExplicit enName = HL7DataTransformHelper.ConvertPNToEN(pnName);
|
---|
| 351 |
|
---|
| 352 | // Parse out output
|
---|
| 353 | List<Serializable> choice = enName.getContent();
|
---|
| 354 | Iterator<Serializable> iterSerialObjects = choice.iterator();
|
---|
| 355 |
|
---|
| 356 | TestHelper.assertNameEquals(iterSerialObjects, null, givenName);
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 | /**
|
---|
| 360 | * Test of createPNExplicit method, of class HL7DataTransformHelper.
|
---|
| 361 | */
|
---|
| 362 | @Test
|
---|
| 363 | public void testCreatePNExplicit () {
|
---|
| 364 | log.info("testCreatePNExplicit");
|
---|
| 365 |
|
---|
| 366 | String lastName = "Johnson";
|
---|
| 367 | String firstName = "Frank";
|
---|
| 368 |
|
---|
| 369 | PNExplicit result = HL7DataTransformHelper.CreatePNExplicit(firstName, lastName);
|
---|
| 370 |
|
---|
| 371 | TestHelper.assertPNNameEquals (result, lastName, firstName);
|
---|
| 372 | }
|
---|
| 373 |
|
---|
| 374 | /**
|
---|
| 375 | * Test of createPNExplicit method, of class HL7DataTransformHelper.
|
---|
| 376 | * only family name
|
---|
| 377 | */
|
---|
| 378 | @Test
|
---|
| 379 | public void testCreatePNExplicit_OnlyFamily () {
|
---|
| 380 | log.info("testCreatePNExplicit_OnlyFamily");
|
---|
| 381 |
|
---|
| 382 | String lastName = "Johnson";
|
---|
| 383 |
|
---|
| 384 | PNExplicit result = HL7DataTransformHelper.CreatePNExplicit(null, lastName);
|
---|
| 385 |
|
---|
| 386 | TestHelper.assertPNNameEquals (result, lastName, null);
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 | /**
|
---|
| 390 | * Test of CreatePNExplicit method, of class HL7DataTransformHelper.
|
---|
| 391 | * only given name
|
---|
| 392 | */
|
---|
| 393 | @Test
|
---|
| 394 | public void testCreatePNExplicit_OnlyGiven () {
|
---|
| 395 | log.info("testCreatePNExplicit_OnlyGiven");
|
---|
| 396 |
|
---|
| 397 | String firstName = "Frank";
|
---|
| 398 |
|
---|
| 399 | PNExplicit result = HL7DataTransformHelper.CreatePNExplicit(firstName, null);
|
---|
| 400 |
|
---|
| 401 | TestHelper.assertPNNameEquals (result, null, firstName);
|
---|
| 402 | }
|
---|
| 403 | }
|
---|