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.joda.time.DateTime;
21  import org.joda.time.DateTimeZone;
22  import org.junit.Test;
23  import org.openehealth.ipf.commons.ihe.xds.core.metadata.PatientInfo;
24  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Timestamp;
25  
26  import java.util.ListIterator;
27  
28  /**
29   * Tests for date of birth transformation in SourcePatientInfo.
30   * @author Jens Riemschneider
31   */
32  public class DateOfBirthPIDTransformerTest {
33      @Test
34      public void testToHL7() {
35          PatientInfo patientInfo = new PatientInfo();
36          patientInfo.setDateOfBirth("19800102030405+0100");
37          ListIterator<String> iterator = patientInfo.getHl7FieldIterator("PID-7");
38          assertEquals("19800102030405+0100", iterator.next());
39          assertFalse(iterator.hasNext());
40      }
41      
42      @Test
43      public void testToHL7WithNoDate() {
44          PatientInfo patientInfo = new PatientInfo();
45          ListIterator<String> iterator = patientInfo.getHl7FieldIterator("PID-7");
46          assertFalse(iterator.hasNext());
47          assertNull(patientInfo.getDateOfBirth());
48      }
49  
50      @Test
51      public void testFromHL7() {
52          PatientInfo patientInfo = new PatientInfo();
53          patientInfo.getHl7FieldIterator("PID-7").add("19800102030405-0100^sdf");
54          DateTime expected = new DateTime(1980, 1, 2, 3, 4, 5, DateTimeZone.forOffsetHoursMinutes(-1, 0));
55          assertEquals(
56                  new Timestamp(expected, Timestamp.Precision.SECOND),
57                  patientInfo.getDateOfBirth());
58      }
59  
60      @Test
61      public void testFromHL7Null() {
62          PatientInfo patientInfo = new PatientInfo();
63          patientInfo.getHl7FieldIterator("PID-7").add(null);
64          assertNull(patientInfo.getDateOfBirth());
65      }
66  
67      @Test
68      public void testFromHL7Empty() {
69          PatientInfo patientInfo = new PatientInfo();
70          patientInfo.getHl7FieldIterator("PID-7").add("");
71          assertNull(patientInfo.getDateOfBirth());
72      }
73  }