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.ebxml;
17
18 import static org.junit.Assert.*;
19 import static org.openehealth.ipf.commons.ihe.xds.core.metadata.Vocabulary.*;
20 import static org.openehealth.ipf.commons.ihe.xds.core.transform.ebxml.EbrsTestUtils.*;
21
22 import java.util.List;
23
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLClassification;
27 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLExtrinsicObject;
28 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLFactory;
29 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLObjectLibrary;
30 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLSlot;
31 import org.openehealth.ipf.commons.ihe.xds.core.metadata.*;
32
33
34
35
36
37 public abstract class DocumentEntryTransformerTestBase implements FactoryCreator {
38 private DocumentEntryTransformer transformer;
39 private DocumentEntry documentEntry;
40 private EbXMLObjectLibrary objectLibrary;
41 private boolean homeAware = true;
42
43
44
45
46
47 protected void setHomeAware(boolean homeAware) {
48 this.homeAware = homeAware;
49 }
50
51 @Before
52 public final void baseSetUp() {
53 EbXMLFactory factory = createFactory();
54 transformer = new DocumentEntryTransformer(factory);
55 objectLibrary = factory.createObjectLibrary();
56
57 Author author1 = new Author();
58 author1.setAuthorPerson(createPerson(1));
59 author1.getAuthorInstitution().add(new Organization("inst1"));
60 author1.getAuthorInstitution().add(new Organization("inst2"));
61 author1.getAuthorRole().add(new Identifiable("role1", new AssigningAuthority("2.3.1", "ISO")));
62 author1.getAuthorRole().add(new Identifiable("role2", null));
63 author1.getAuthorSpecialty().add(new Identifiable("spec1", new AssigningAuthority("2.3.3", "ISO")));
64 author1.getAuthorSpecialty().add(new Identifiable("spec2", null));
65 author1.getAuthorTelecom().add(new Telecom(null, null, 7771L, null));
66 author1.getAuthorTelecom().add(new Telecom(null, null, 7772L, null));
67
68 Author author2 = new Author();
69 author2.setAuthorPerson(createPerson(30));
70 author2.getAuthorInstitution().add(new Organization("inst3"));
71 author2.getAuthorInstitution().add(new Organization("inst4"));
72 author2.getAuthorRole().add(new Identifiable("role3", null));
73 author2.getAuthorRole().add(new Identifiable("role4", new AssigningAuthority("2.3.6", "ISO")));
74 author2.getAuthorSpecialty().add(new Identifiable("spec3", null));
75 author2.getAuthorSpecialty().add(new Identifiable("spec4", new AssigningAuthority("2.3.8", "ISO")));
76 author2.getAuthorTelecom().add(new Telecom(null, null, 7773L, null));
77 author2.getAuthorTelecom().add(new Telecom(null, null, 7774L, null));
78
79 Address address = new Address();
80 address.setCity("city");
81 address.setCountry("country");
82 address.setCountyParishCode("countyParishCode");
83 address.setOtherDesignation("otherDesignation");
84 address.setStateOrProvince("stateOrProvince");
85 address.setStreetAddress("streetAddress");
86 address.setZipOrPostalCode("zipOrPostalCode");
87
88 PatientInfo sourcePatientInfo = new PatientInfo();
89 sourcePatientInfo.getAddresses().add(address);
90 sourcePatientInfo.setDateOfBirth("19800102");
91 sourcePatientInfo.setGender("F");
92 sourcePatientInfo.getNames().add(createName(3));
93 sourcePatientInfo.getIds().add(createIdentifiable(5));
94 sourcePatientInfo.getIds().add(createIdentifiable(6));
95
96 documentEntry = new DocumentEntry();
97 documentEntry.getAuthors().add(author1);
98 documentEntry.getAuthors().add(author2);
99 documentEntry.setAvailabilityStatus(AvailabilityStatus.APPROVED);
100 documentEntry.setClassCode(createCode(1));
101 documentEntry.setComments(createLocal(10));
102 documentEntry.setCreationTime("20150206");
103 documentEntry.setEntryUuid("uuid");
104 documentEntry.setFormatCode(createCode(2));
105 documentEntry.setHash("hash");
106 documentEntry.setHealthcareFacilityTypeCode(createCode(3));
107 documentEntry.setLanguageCode("languageCode");
108 documentEntry.setLegalAuthenticator(createPerson(2));
109 documentEntry.setMimeType("text/plain");
110 documentEntry.setPatientId(createIdentifiable(3));
111 documentEntry.setPracticeSettingCode(createCode(4));
112 documentEntry.setServiceStartTime("20150207");
113 documentEntry.setServiceStopTime("20150208");
114 documentEntry.setSize(174L);
115 documentEntry.setSourcePatientId(createIdentifiable(4));
116 documentEntry.setSourcePatientInfo(sourcePatientInfo);
117 documentEntry.setTitle(createLocal(11));
118 documentEntry.setTypeCode(createCode(5));
119 documentEntry.setUniqueId("uniqueId");
120 documentEntry.setUri("uri");
121 documentEntry.getConfidentialityCodes().add(createCode(6));
122 documentEntry.getConfidentialityCodes().add(createCode(7));
123 documentEntry.getEventCodeList().add(createCode(8));
124 documentEntry.getEventCodeList().add(createCode(9));
125 documentEntry.setRepositoryUniqueId("repo1");
126 documentEntry.setDocumentAvailability(DocumentAvailability.ONLINE);
127 documentEntry.setLimitedMetadata(true);
128
129 documentEntry.getReferenceIdList().add(new ReferenceId(
130 "ref-id-11", new CXiAssigningAuthority("ABCD", "1.1.2.3", "ISO"),
131 ReferenceId.ID_TYPE_CODE_ORDER));
132 documentEntry.getReferenceIdList().add(new ReferenceId(
133 "ref-id-12", new CXiAssigningAuthority("DEFG", "2.1.2.3", "ISO"),
134 ReferenceId.ID_TYPE_CODE_ACCESSION));
135
136 if (homeAware) {
137 documentEntry.setHomeCommunityId("123.456");
138 }
139 }
140
141 @Test
142 public void testToEbXML() {
143 EbXMLExtrinsicObject ebXML = transformer.toEbXML(documentEntry, objectLibrary);
144 assertNotNull(ebXML);
145
146 assertEquals(AvailabilityStatus.APPROVED, ebXML.getStatus());
147 assertEquals("text/plain", ebXML.getMimeType());
148 assertEquals("uuid", ebXML.getId());
149 assertEquals(DocumentEntryType.STABLE.getUuid(), ebXML.getObjectType());
150 if (homeAware) {
151 assertEquals("123.456", ebXML.getHome());
152 }
153
154 assertEquals(createLocal(10), ebXML.getDescription());
155 assertEquals(createLocal(11), ebXML.getName());
156
157 List<EbXMLSlot> slots = ebXML.getSlots();
158 assertSlot(SLOT_NAME_CREATION_TIME, slots, "20150206");
159 assertSlot(SLOT_NAME_HASH, slots, "hash");
160 assertSlot(SLOT_NAME_LANGUAGE_CODE, slots, "languageCode");
161 assertSlot(SLOT_NAME_SERVICE_START_TIME, slots, "20150207");
162 assertSlot(SLOT_NAME_SERVICE_STOP_TIME, slots, "20150208");
163 assertSlot(SLOT_NAME_SIZE, slots, "174");
164 assertSlot(SLOT_NAME_SOURCE_PATIENT_ID, slots, "id 4^^^&uni 4&uniType 4");
165 assertSlot(SLOT_NAME_URI, slots, "uri");
166 assertSlot(SLOT_NAME_LEGAL_AUTHENTICATOR, slots, "id 2^familyName 2^givenName 2^prefix 2^second 2^suffix 2^degree 2^^&uni 2&uniType 2");
167 assertSlot(SLOT_NAME_REPOSITORY_UNIQUE_ID, slots, "repo1");
168 assertSlot(SLOT_NAME_SOURCE_PATIENT_INFO, slots,
169 "PID-3|id 6^^^&uni 6&uniType 6~id 5^^^&uni 5&uniType 5",
170 "PID-5|familyName 3^givenName 3^prefix 3^second 3^suffix 3^degree 3",
171 "PID-7|19800102",
172 "PID-8|F",
173 "PID-11|streetAddress^otherDesignation^city^stateOrProvince^zipOrPostalCode^country^^^countyParishCode");
174
175 assertSlot(SLOT_NAME_REFERENCE_ID_LIST, slots,
176 "ref-id-11^^^ABCD&1.1.2.3&ISO^urn:ihe:iti:xds:2013:order",
177 "ref-id-12^^^DEFG&2.1.2.3&ISO^urn:ihe:iti:xds:2013:accession");
178 assertSlot(SLOT_NAME_DOCUMENT_AVAILABILITY, slots, "urn:ihe:iti:2010:DocumentAvailability:Online");
179
180 EbXMLClassification classification = assertClassification(DOC_ENTRY_AUTHOR_CLASS_SCHEME, ebXML, 0, "", -1);
181 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");
182 assertSlot(SLOT_NAME_AUTHOR_INSTITUTION, classification.getSlots(), "inst1", "inst2");
183 assertSlot(SLOT_NAME_AUTHOR_ROLE, classification.getSlots(), "role1^^^&2.3.1&ISO", "role2");
184 assertSlot(SLOT_NAME_AUTHOR_SPECIALTY, classification.getSlots(), "spec1^^^&2.3.3&ISO", "spec2");
185 assertSlot(SLOT_NAME_AUTHOR_TELECOM, classification.getSlots(), "^PRN^PH^^^^7771", "^PRN^PH^^^^7772");
186
187 classification = assertClassification(DOC_ENTRY_AUTHOR_CLASS_SCHEME, ebXML, 1, "", -1);
188 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");
189 assertSlot(SLOT_NAME_AUTHOR_INSTITUTION, classification.getSlots(), "inst3", "inst4");
190 assertSlot(SLOT_NAME_AUTHOR_ROLE, classification.getSlots(), "role3", "role4^^^&2.3.6&ISO");
191 assertSlot(SLOT_NAME_AUTHOR_SPECIALTY, classification.getSlots(), "spec3", "spec4^^^&2.3.8&ISO");
192 assertSlot(SLOT_NAME_AUTHOR_TELECOM, classification.getSlots(), "^PRN^PH^^^^7773", "^PRN^PH^^^^7774");
193
194 classification = assertClassification(DOC_ENTRY_CLASS_CODE_CLASS_SCHEME, ebXML, 0, "code 1", 1);
195 assertSlot(SLOT_NAME_CODING_SCHEME, classification.getSlots(), "scheme 1");
196
197 classification = assertClassification(DOC_ENTRY_CONFIDENTIALITY_CODE_CLASS_SCHEME, ebXML, 0, "code 6", 6);
198 assertSlot(SLOT_NAME_CODING_SCHEME, classification.getSlots(), "scheme 6");
199
200 classification = assertClassification(DOC_ENTRY_CONFIDENTIALITY_CODE_CLASS_SCHEME, ebXML, 1, "code 7", 7);
201 assertSlot(SLOT_NAME_CODING_SCHEME, classification.getSlots(), "scheme 7");
202
203 classification = assertClassification(DOC_ENTRY_EVENT_CODE_CLASS_SCHEME, ebXML, 0, "code 8", 8);
204 assertSlot(SLOT_NAME_CODING_SCHEME, classification.getSlots(), "scheme 8");
205
206 classification = assertClassification(DOC_ENTRY_EVENT_CODE_CLASS_SCHEME, ebXML, 1, "code 9", 9);
207 assertSlot(SLOT_NAME_CODING_SCHEME, classification.getSlots(), "scheme 9");
208
209 classification = assertClassification(DOC_ENTRY_FORMAT_CODE_CLASS_SCHEME, ebXML, 0, "code 2", 2);
210 assertSlot(SLOT_NAME_CODING_SCHEME, classification.getSlots(), "scheme 2");
211
212 classification = assertClassification(DOC_ENTRY_HEALTHCARE_FACILITY_TYPE_CODE_CLASS_SCHEME, ebXML, 0, "code 3", 3);
213 assertSlot(SLOT_NAME_CODING_SCHEME, classification.getSlots(), "scheme 3");
214
215 classification = assertClassification(DOC_ENTRY_PRACTICE_SETTING_CODE_CLASS_SCHEME, ebXML, 0, "code 4", 4);
216 assertSlot(SLOT_NAME_CODING_SCHEME, classification.getSlots(), "scheme 4");
217
218 classification = assertClassification(DOC_ENTRY_TYPE_CODE_CLASS_SCHEME, ebXML, 0, "code 5", 5);
219 assertSlot(SLOT_NAME_CODING_SCHEME, classification.getSlots(), "scheme 5");
220
221 assertExternalIdentifier(DOC_ENTRY_PATIENT_ID_EXTERNAL_ID, ebXML,
222 "id 3^^^&uni 3&uniType 3", DOC_ENTRY_LOCALIZED_STRING_PATIENT_ID);
223
224 assertExternalIdentifier(DOC_ENTRY_UNIQUE_ID_EXTERNAL_ID, ebXML,
225 "uniqueId", DOC_ENTRY_LOCALIZED_STRING_UNIQUE_ID);
226
227 assertClassification(DOC_ENTRY_LIMITED_METADATA_CLASS_SCHEME, ebXML, 0, null, 0);
228
229 assertEquals(12, ebXML.getClassifications().size());
230 assertEquals(13, ebXML.getSlots().size());
231 assertEquals(2, ebXML.getExternalIdentifiers().size());
232 }
233
234 @Test
235 public void testToEbXMLNull() {
236 assertNull(transformer.toEbXML(null, objectLibrary));
237 }
238
239 @Test
240 public void testToEbXMLEmpty() {
241 EbXMLExtrinsicObject ebXML = transformer.toEbXML(new DocumentEntry(), objectLibrary);
242 assertNotNull(ebXML);
243
244 assertNull(ebXML.getStatus());
245 assertEquals("application/octet-stream", ebXML.getMimeType());
246 assertNull(ebXML.getId());
247
248 assertNull(ebXML.getDescription());
249 assertNull(ebXML.getName());
250
251 assertEquals(0, ebXML.getSlots().size());
252 assertEquals(0, ebXML.getClassifications().size());
253 assertEquals(0, ebXML.getExternalIdentifiers().size());
254 }
255
256 @Test
257 public void testFromEbXML() {
258 EbXMLExtrinsicObject ebXML = transformer.toEbXML(documentEntry, objectLibrary);
259 DocumentEntry result = transformer.fromEbXML(ebXML);
260
261 assertNotNull(result);
262 assertEquals(documentEntry, result);
263 }
264
265 @Test
266 public void testFromEbXMLNull() {
267 assertNull(transformer.fromEbXML(null));
268 }
269
270 @Test
271 public void testFromEbXMLEmpty() {
272 EbXMLExtrinsicObject ebXML = transformer.toEbXML(new DocumentEntry(), objectLibrary);
273 DocumentEntry result = transformer.fromEbXML(ebXML);
274
275 DocumentEntry expected = new DocumentEntry();
276 expected.setMimeType("application/octet-stream");
277 assertEquals(expected, result);
278 }
279 }