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.ebxml;
17  
18  import org.junit.Before;
19  import org.junit.Test;
20  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLClassification;
21  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLFactory;
22  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLObjectLibrary;
23  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRegistryPackage;
24  import org.openehealth.ipf.commons.ihe.xds.core.metadata.*;
25  
26  import static org.junit.Assert.*;
27  import static org.openehealth.ipf.commons.ihe.xds.core.metadata.Vocabulary.*;
28  import static org.openehealth.ipf.commons.ihe.xds.core.transform.ebxml.EbrsTestUtils.*;
29  
30  /**
31   * Tests for {@link SubmissionSetTransformer}.
32   * @author Jens Riemschneider
33   */
34  public abstract class SubmissionSetTransformerTestBase implements FactoryCreator {
35      private SubmissionSetTransformer transformer;
36      private SubmissionSet set;
37      private EbXMLObjectLibrary objectLibrary;
38      private boolean homeAware = true;
39  
40      /**
41       * @param homeAware
42       *          <code>true</code> to enable comparison of the homeCommunityId.
43       */
44      protected void setHomeAware(boolean homeAware) {
45          this.homeAware = homeAware;
46      }
47      
48      @Before
49      public final void baseSetUp() {
50          EbXMLFactory factory = createFactory();
51          transformer = new SubmissionSetTransformer(factory);
52          objectLibrary = factory.createObjectLibrary();
53          
54          Author author1 = new Author();
55          author1.setAuthorPerson(createPerson(1));
56          author1.getAuthorInstitution().add(new Organization("inst1"));
57          author1.getAuthorInstitution().add(new Organization("inst2"));
58          author1.getAuthorRole().add(new Identifiable("role1", new AssigningAuthority("2.3.1", "ISO")));
59          author1.getAuthorRole().add(new Identifiable("role2", null));
60          author1.getAuthorSpecialty().add(new Identifiable("spec1", new AssigningAuthority("2.3.3", "ISO")));
61          author1.getAuthorSpecialty().add(new Identifiable("spec2", null));
62          author1.getAuthorTelecom().add(new Telecom(41L, 76L, 73901L, 0L));
63          author1.getAuthorTelecom().add(new Telecom(41L, 76L, 73901L, 1L));
64  
65          Author author2 = new Author();
66          author2.setAuthorPerson(createPerson(30));
67          author2.getAuthorInstitution().add(new Organization("inst3"));
68          author2.getAuthorInstitution().add(new Organization("inst4"));
69          author2.getAuthorRole().add(new Identifiable("role3", new AssigningAuthority("2.3.5", "ISO")));
70          author2.getAuthorRole().add(new Identifiable("role4", null));
71          author2.getAuthorSpecialty().add(new Identifiable("spec3", new AssigningAuthority("2.3.7", "ISO")));
72          author2.getAuthorSpecialty().add(new Identifiable("spec4", null));
73          author2.getAuthorTelecom().add(new Telecom(41L, 76L, 73901L, 2L));
74          author2.getAuthorTelecom().add(new Telecom(41L, 76L, 73901L, 3L));
75  
76          Address address = new Address();
77          address.setCity("city");
78          address.setCountry("country");
79          address.setCountyParishCode("countyParishCode");
80          address.setOtherDesignation("otherDesignation");
81          address.setStateOrProvince("stateOrProvince");
82          address.setStreetAddress("streetAddress");
83          address.setZipOrPostalCode("zipOrPostalCode");
84          
85          PatientInfo sourcePatientInfo = new PatientInfo();
86          sourcePatientInfo.getAddresses().add(address);
87          sourcePatientInfo.setDateOfBirth("1980");
88          sourcePatientInfo.setGender("F");
89          sourcePatientInfo.getNames().add(createName(3));
90          sourcePatientInfo.getIds().add(createIdentifiable(5));
91          sourcePatientInfo.getIds().add(createIdentifiable(6));
92  
93          set = new SubmissionSet();
94          set.getAuthors().add(author1);
95          set.getAuthors().add(author2);
96          set.setAvailabilityStatus(AvailabilityStatus.APPROVED);
97          set.setComments(createLocal(10));
98          set.setSubmissionTime("20150102030405");
99          set.setEntryUuid("uuid");
100         set.setPatientId(createIdentifiable(3));
101         set.setTitle(createLocal(11));
102         set.setUniqueId("uniqueId");
103         set.setContentTypeCode(createCode(6));
104         set.setSourceId("sourceId");
105         set.setLimitedMetadata(true);
106         set.getIntendedRecipients().add(new Recipient(createOrganization(20), createPerson(22), null));
107         set.getIntendedRecipients().add(new Recipient(createOrganization(21), null, null));
108         set.getIntendedRecipients().add(new Recipient(null, createPerson(23), null));
109 
110         if (homeAware) {
111             set.setHomeCommunityId("123.456");
112         }
113     }
114 
115     @Test
116     public void testToEbXML() {
117         EbXMLRegistryPackage ebXML = transformer.toEbXML(set, objectLibrary);        
118         assertNotNull(ebXML);
119         
120         assertEquals(AvailabilityStatus.APPROVED, ebXML.getStatus());
121         assertEquals("uuid", ebXML.getId());
122         assertNull(ebXML.getObjectType());
123         if (homeAware) {
124             assertEquals("123.456", ebXML.getHome());
125         }
126 
127         assertEquals(createLocal(10), ebXML.getDescription());        
128         assertEquals(createLocal(11), ebXML.getName());
129         
130         assertSlot(SLOT_NAME_SUBMISSION_TIME, ebXML.getSlots(), "20150102030405");
131         
132         assertSlot(SLOT_NAME_INTENDED_RECIPIENT, ebXML.getSlots(),
133                 "orgName 20^^^^^&uni 20&uniType 20^^^^id 20|id 22^familyName 22^givenName 22^prefix 22^second 22^suffix 22^degree 22^^&uni 22&uniType 22",
134                 "orgName 21^^^^^&uni 21&uniType 21^^^^id 21",
135                 "|id 23^familyName 23^givenName 23^prefix 23^second 23^suffix 23^degree 23^^&uni 23&uniType 23");
136 
137 
138         EbXMLClassification classification = assertClassification(SUBMISSION_SET_AUTHOR_CLASS_SCHEME, ebXML, 0, "", -1);
139         assertSlot(SLOT_NAME_AUTHOR_PERSON, classification.getSlots(), "id 1^familyName 1^givenName 1^prefix 1^second 1^suffix 1^degree 1^^&uni 1&uniType 1");
140         assertSlot(SLOT_NAME_AUTHOR_INSTITUTION, classification.getSlots(), "inst1", "inst2");
141         assertSlot(SLOT_NAME_AUTHOR_ROLE, classification.getSlots(), "role1^^^&2.3.1&ISO", "role2");
142         assertSlot(SLOT_NAME_AUTHOR_SPECIALTY, classification.getSlots(), "spec1^^^&2.3.3&ISO", "spec2");
143         assertSlot(SLOT_NAME_AUTHOR_TELECOM, classification.getSlots(), "^PRN^PH^^41^76^73901^0", "^PRN^PH^^41^76^73901^1");
144 
145         classification = assertClassification(SUBMISSION_SET_AUTHOR_CLASS_SCHEME, ebXML, 1, "", -1);
146         assertSlot(SLOT_NAME_AUTHOR_PERSON, classification.getSlots(), "id 30^familyName 30^givenName 30^prefix 30^second 30^suffix 30^degree 30^^&uni 30&uniType 30");
147         assertSlot(SLOT_NAME_AUTHOR_INSTITUTION, classification.getSlots(), "inst3", "inst4");
148         assertSlot(SLOT_NAME_AUTHOR_ROLE, classification.getSlots(), "role3^^^&2.3.5&ISO", "role4");
149         assertSlot(SLOT_NAME_AUTHOR_SPECIALTY, classification.getSlots(), "spec3^^^&2.3.7&ISO", "spec4");
150         assertSlot(SLOT_NAME_AUTHOR_TELECOM, classification.getSlots(), "^PRN^PH^^41^76^73901^2", "^PRN^PH^^41^76^73901^3");
151 
152         classification = assertClassification(SUBMISSION_SET_CONTENT_TYPE_CODE_CLASS_SCHEME, ebXML, 0, "code 6", 6);
153         assertSlot(SLOT_NAME_CODING_SCHEME, classification.getSlots(), "scheme 6");
154         
155         assertExternalIdentifier(SUBMISSION_SET_PATIENT_ID_EXTERNAL_ID, ebXML,
156                 "id 3^^^&uni 3&uniType 3", SUBMISSION_SET_LOCALIZED_STRING_PATIENT_ID);
157 
158         assertExternalIdentifier(SUBMISSION_SET_UNIQUE_ID_EXTERNAL_ID, ebXML,
159                 "uniqueId", SUBMISSION_SET_LOCALIZED_STRING_UNIQUE_ID);
160 
161         assertExternalIdentifier(SUBMISSION_SET_SOURCE_ID_EXTERNAL_ID, ebXML,
162                 "sourceId", SUBMISSION_SET_LOCALIZED_STRING_SOURCE_ID);
163 
164         assertClassification(SUBMISSION_SET_LIMITED_METADATA_CLASS_SCHEME, ebXML, 0, null, 0);
165 
166         assertEquals(4, ebXML.getClassifications().size());
167         assertEquals(2, ebXML.getSlots().size());
168         assertEquals(3, ebXML.getExternalIdentifiers().size());
169     }
170 
171     @Test
172     public void testToEbXMLNull() {
173         assertNull(transformer.toEbXML(null, objectLibrary));
174     }
175    
176     @Test
177     public void testToEbXMLEmpty() {
178         EbXMLRegistryPackage ebXML = transformer.toEbXML(new SubmissionSet(), objectLibrary);        
179         assertNotNull(ebXML);
180         
181         assertNull(ebXML.getStatus());
182         assertNull(ebXML.getId());
183         
184         assertNull(ebXML.getDescription());        
185         assertNull(ebXML.getName());
186         
187         assertEquals(0, ebXML.getSlots().size());
188         assertEquals(0, ebXML.getClassifications().size());
189         assertEquals(0, ebXML.getExternalIdentifiers().size());
190     }
191     
192     
193     
194     @Test
195     public void testFromEbXML() {
196         EbXMLRegistryPackage ebXML = transformer.toEbXML(set, objectLibrary);
197         SubmissionSet result = transformer.fromEbXML(ebXML);
198         
199         assertNotNull(result);
200         assertEquals(set, result);
201     }
202     
203     @Test
204     public void testFromEbXMLNull() {
205         assertNull(transformer.fromEbXML(null));
206     }
207     
208     @Test
209     public void testFromEbXMLEmpty() {
210         EbXMLRegistryPackage ebXML = transformer.toEbXML(new SubmissionSet(), objectLibrary);
211         SubmissionSet result = transformer.fromEbXML(ebXML);
212         assertEquals(new SubmissionSet(), result);
213     }
214 }