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.Address;
22  import org.openehealth.ipf.commons.ihe.xds.core.metadata.PatientInfo;
23  
24  import java.util.ListIterator;
25  
26  /**
27   * Tests for patient address transformation in SourcePatientInfo.
28   * @author Jens Riemschneider
29   */
30  public class PatientAddressPIDTransformerTest {
31  
32      @Test
33      public void testToHL7() {
34          PatientInfo patientInfo = new PatientInfo();
35          Address address = new Address();
36          address.setStreetAddress("I live here 42");
37          address.setCountry("ECU");
38          patientInfo.getAddresses().add(address);
39          ListIterator<String> iterator = patientInfo.getHl7FieldIterator("PID-11");
40          assertEquals("I live here 42^^^^^ECU", iterator.next());
41          assertFalse(iterator.hasNext());
42      }
43  
44      @Test
45      public void testToHL7EmptyAddress() {
46          PatientInfo patientInfo = new PatientInfo();
47          Address address = new Address();
48          patientInfo.getAddresses().add(address);
49          ListIterator<String> iterator = patientInfo.getHl7FieldIterator("PID-11");
50          assertEquals("", iterator.next());
51          assertFalse(iterator.hasNext());
52      }
53  
54      @Test
55      public void testToHL7Null() {
56          PatientInfo patientInfo = new PatientInfo();
57          patientInfo.getAddresses().add(null);
58          ListIterator<String> iterator = patientInfo.getHl7FieldIterator("PID-11");
59          assertEquals("", iterator.next());
60          assertFalse(iterator.hasNext());
61      }
62  
63      @Test
64      public void testToHL7NoAddress() {
65          PatientInfo patientInfo = new PatientInfo();
66          assertFalse(patientInfo.getHl7FieldIterator("PID-11").hasNext());
67          assertFalse(patientInfo.getAddresses().hasNext());
68      }
69      
70      @Test
71      public void testFromHL7() {
72          PatientInfo patientInfo = new PatientInfo();
73          patientInfo.getHl7FieldIterator("PID-11").add("I live here 42^^^^^ECU");
74          ListIterator<Address> addresses = patientInfo.getAddresses();
75          Address address = addresses.next();
76          assertEquals("I live here 42", address.getStreetAddress());
77          assertEquals("ECU", address.getCountry());
78          assertFalse(addresses.hasNext());
79      }
80  
81      @Test
82      public void testFromHL7Empty() {
83          PatientInfo patientInfo = new PatientInfo();
84          patientInfo.getHl7FieldIterator("PID-11").add("");
85          ListIterator<Address> addresses = patientInfo.getAddresses();
86          assertNull(addresses.next());
87          assertFalse(addresses.hasNext());
88      }
89  
90      @Test
91      public void testFromHL7Null() {
92          PatientInfo patientInfo = new PatientInfo();
93          patientInfo.getHl7FieldIterator("PID-11").add(null);
94          ListIterator<Address> addresses = patientInfo.getAddresses();
95          assertNull(addresses.next());
96          assertFalse(addresses.hasNext());
97      }
98  }