1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
30
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 }