View Javadoc
1   /*
2    * Copyright 2016 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  
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          // Check ATNA Audit
71  
72          AbstractMockedAuditMessageQueue sender = getAuditSender();
73          assertEquals(1, sender.getMessages().size());
74          AuditMessage event = sender.getMessages().get(0);
75  
76          // Event
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          // ActiveParticipant Source
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          // ActiveParticipant Destination
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          // Audit Source
100         AuditSourceIdentificationType sourceIdentificationType = event.getAuditSourceIdentification();
101         assertEquals("IPF", sourceIdentificationType.getAuditSourceID());
102         assertEquals("IPF", sourceIdentificationType.getAuditEnterpriseSiteID());
103 
104         // Patient
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         // Query Parameters
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 }