1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.openehealth.ipf.platform.camel.ihe.fhir.iti66;
18
19 import org.hl7.fhir.dstu3.model.Bundle;
20 import org.hl7.fhir.dstu3.model.DocumentManifest;
21 import org.hl7.fhir.dstu3.model.ResourceType;
22 import org.junit.BeforeClass;
23 import org.junit.Test;
24 import org.openehealth.ipf.commons.audit.codes.*;
25 import org.openehealth.ipf.commons.audit.model.ActiveParticipantType;
26 import org.openehealth.ipf.commons.audit.model.AuditMessage;
27 import org.openehealth.ipf.commons.audit.model.AuditSourceIdentificationType;
28 import org.openehealth.ipf.commons.audit.model.ParticipantObjectIdentificationType;
29 import org.openehealth.ipf.commons.audit.utils.AuditUtils;
30 import org.openehealth.ipf.commons.audit.queue.AbstractMockedAuditMessageQueue;
31 import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode;
32 import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirParticipantObjectIdTypeCode;
33
34
35 import javax.servlet.ServletException;
36
37 import java.nio.charset.StandardCharsets;
38 import java.util.Base64;
39
40 import static org.junit.Assert.*;
41
42
43
44
45 public class TestIti66Success extends AbstractTestIti66 {
46
47 private static final String CONTEXT_DESCRIPTOR = "iti-66.xml";
48
49 @BeforeClass
50 public static void setUpClass() throws ServletException {
51 startServer(CONTEXT_DESCRIPTOR);
52 }
53
54 @Test
55 public void testGetConformance() {
56 assertConformance("DocumentManifest");
57 }
58
59 @Test
60 public void testSendManualIti66() {
61 Bundle result = sendManually(manifestPatientIdentifierParameter());
62
63 assertEquals(Bundle.BundleType.SEARCHSET, result.getType());
64 assertEquals(ResourceType.Bundle, result.getResourceType());
65 assertEquals(1, result.getTotal());
66
67 DocumentManifest p = (DocumentManifest) result.getEntry().get(0).getResource();
68 assertEquals("9bc72458-49b0-11e6-8a1c-3c1620524153", p.getIdElement().getIdPart());
69
70
71
72 AbstractMockedAuditMessageQueue sender = getAuditSender();
73 assertEquals(1, sender.getMessages().size());
74 AuditMessage event = sender.getMessages().get(0);
75
76
77 assertEquals(
78 EventOutcomeIndicator.Success,
79 event.getEventIdentification().getEventOutcomeIndicator());
80 assertEquals(
81 EventActionCode.Execute,
82 event.getEventIdentification().getEventActionCode());
83
84 assertEquals(EventIdCode.Query, event.getEventIdentification().getEventID());
85 assertEquals(FhirEventTypeCode.MobileDocumentManifestQuery, event.getEventIdentification().getEventTypeCode().get(0));
86
87
88 ActiveParticipantType source = event.getActiveParticipants().get(0);
89 assertTrue(source.isUserIsRequestor());
90 assertEquals("127.0.0.1", source.getNetworkAccessPointID());
91 assertEquals(NetworkAccessPointTypeCode.IPAddress, source.getNetworkAccessPointTypeCode());
92
93
94 ActiveParticipantType destination = event.getActiveParticipants().get(1);
95 assertFalse(destination.isUserIsRequestor());
96 assertEquals("http://localhost:" + DEMO_APP_PORT + "/DocumentManifest", destination.getUserID());
97 assertEquals(AuditUtils.getLocalIPAddress(), destination.getNetworkAccessPointID());
98
99
100 AuditSourceIdentificationType sourceIdentificationType = event.getAuditSourceIdentification();
101 assertEquals("IPF", sourceIdentificationType.getAuditSourceID());
102 assertEquals("IPF", sourceIdentificationType.getAuditEnterpriseSiteID());
103
104
105 ParticipantObjectIdentificationType patient = event.getParticipantObjectIdentifications().get(0);
106 assertEquals(ParticipantObjectTypeCode.Person, patient.getParticipantObjectTypeCode());
107 assertEquals(ParticipantObjectTypeCodeRole.Patient, patient.getParticipantObjectTypeCodeRole());
108 assertEquals("urn:oid:2.16.840.1.113883.3.37.4.1.1.2.1.1|1", patient.getParticipantObjectID());
109
110
111 ParticipantObjectIdentificationType query = event.getParticipantObjectIdentifications().get(1);
112 assertEquals(ParticipantObjectTypeCode.System, query.getParticipantObjectTypeCode());
113 assertEquals(ParticipantObjectTypeCodeRole.Query, query.getParticipantObjectTypeCodeRole());
114 assertEquals("http://localhost:8999/DocumentManifest?patient.identifier=urn:oid:2.16.840.1.113883.3.37.4.1.1.2.1.1|1",
115 new String(Base64.getDecoder().decode(query.getParticipantObjectQuery()), StandardCharsets.UTF_8));
116
117 assertEquals(FhirParticipantObjectIdTypeCode.MobileDocumentManifestQuery, query.getParticipantObjectIDTypeCode());
118 }
119 @Test
120 public void testSendIti66WithPatientReference() {
121 Bundle result = sendManually(manifestPatientReferenceParameter());
122 assertEquals(Bundle.BundleType.SEARCHSET, result.getType());
123 assertEquals(ResourceType.Bundle, result.getResourceType());
124 assertEquals(1, result.getTotal());
125
126 DocumentManifest p = (DocumentManifest) result.getEntry().get(0).getResource();
127 assertEquals("9bc72458-49b0-11e6-8a1c-3c1620524153", p.getIdElement().getIdPart());
128 }
129
130 @Test
131 public void testGetResource() {
132 DocumentManifest p = client.read()
133 .resource(DocumentManifest.class)
134 .withId("9bc72458-49b0-11e6-8a1c-3c1620524153")
135 .execute();
136 assertEquals(String.format("http://localhost:%d/DocumentManifest/9bc72458-49b0-11e6-8a1c-3c1620524153", DEMO_APP_PORT), p.getId());
137 }
138
139
140 }