View Javadoc
1   /*
2    * Copyright 2009 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *     
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.commons.ihe.xds.core.transform.hl7.pid;
17  
18  import static org.junit.Assert.*;
19  
20  import org.junit.Test;
21  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Name;
22  import org.openehealth.ipf.commons.ihe.xds.core.metadata.PatientInfo;
23  import org.openehealth.ipf.commons.ihe.xds.core.metadata.XcnName;
24  import org.openehealth.ipf.commons.ihe.xds.core.metadata.XpnName;
25  
26  import java.util.ListIterator;
27  
28  /**
29   * Tests for patient name transformation in SourcePatientInfo.
30   * @author Jens Riemschneider
31   */
32  public class SourcePatientNamePIDTransformerTest {
33  
34      @Test
35      public void testToHL7() {
36          PatientInfo patientInfo = new PatientInfo();
37          Name name = new XpnName();
38          name.setFamilyName("Jo|man");
39          name.setGivenName("Jo|chen");
40          name.setSecondAndFurtherGivenNames("Jo|achim");
41          name.setSuffix("von Jo|del");
42          name.setPrefix("Jo|dler");
43          patientInfo.getNames().add(name);
44  
45          ListIterator<String> iterator = patientInfo.getHl7FieldIterator("PID-5");
46          assertEquals("Jo\\F\\man^Jo\\F\\chen^Jo\\F\\achim^von Jo\\F\\del^Jo\\F\\dler", iterator.next());
47          assertFalse(iterator.hasNext());
48      }
49      
50      @Test
51      public void testToHL7EmptyName() {
52          PatientInfo patientInfo = new PatientInfo();
53          patientInfo.getNames().add(new XcnName());
54          ListIterator<String> iterator = patientInfo.getHl7FieldIterator("PID-5");
55          assertEquals("", iterator.next());
56          assertFalse(iterator.hasNext());
57      }
58      
59      @Test
60      public void testToHL7NoName() {
61          PatientInfo patientInfo = new PatientInfo();
62          assertFalse(patientInfo.getHl7FieldIterator("PID-5").hasNext());
63      }
64  
65      
66      @Test
67      public void testFromHL7() {
68          PatientInfo patientInfo = new PatientInfo();
69          patientInfo.getHl7FieldIterator("PID-5").add("Jo\\F\\man^Jo\\F\\chen^Jo\\F\\achim^von Jo\\F\\del^Jo\\F\\dler");
70  
71          ListIterator<Name> names = patientInfo.getNames();
72          Name name = names.next();
73          assertNotNull(name);
74          assertEquals("Jo|man", name.getFamilyName());
75          assertEquals("Jo|chen", name.getGivenName());
76          assertEquals("Jo|achim", name.getSecondAndFurtherGivenNames());
77          assertEquals("von Jo|del", name.getSuffix());
78          assertEquals("Jo|dler", name.getPrefix());
79  
80          assertFalse(names.hasNext());
81      }
82  
83      @Test
84      public void testFromHL7Empty() {
85          PatientInfo patientInfo = new PatientInfo();
86          patientInfo.getHl7FieldIterator("PID-5").add("^^");
87          ListIterator<Name> names = patientInfo.getNames();
88          assertNull(names.next());
89          assertFalse(names.hasNext());
90      }
91  
92      @Test
93      public void testFromHL7Null() {
94          PatientInfo patientInfo = new PatientInfo();
95          patientInfo.getHl7FieldIterator("PID-5").add(null);
96          ListIterator<Name> names = patientInfo.getNames();
97          assertNull(names.next());
98          assertFalse(names.hasNext());
99      }
100 }