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.iti67;
18  
19  import org.hl7.fhir.dstu3.model.Bundle;
20  import org.hl7.fhir.dstu3.model.DocumentReference;
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  import javax.servlet.ServletException;
35  import java.nio.charset.StandardCharsets;
36  import java.util.Base64;
37  
38  import static org.junit.Assert.*;
39  
40  /**
41   *
42   */
43  public class TestIti67Success extends AbstractTestIti67 {
44  
45      private static final String CONTEXT_DESCRIPTOR = "iti-67.xml";
46  
47      @BeforeClass
48      public static void setUpClass() throws ServletException {
49          startServer(CONTEXT_DESCRIPTOR);
50      }
51  
52      @Test
53      public void testGetConformance() {
54          assertConformance("DocumentReference");
55      }
56  
57      @Test
58      public void testSendManualIti67() {
59  
60          Bundle result = sendManually(referencePatientIdentifierParameter());
61  
62          assertEquals(Bundle.BundleType.SEARCHSET, result.getType());
63          assertEquals(ResourceType.Bundle, result.getResourceType());
64          assertEquals(1, result.getTotal());
65  
66          DocumentReference p = (DocumentReference) result.getEntry().get(0).getResource();
67          assertEquals("63ab1c29-4225-11e6-9b33-0050569b0094", p.getIdElement().getIdPart());
68  
69          // Check ATNA Audit
70  
71          AbstractMockedAuditMessageQueue sender = getAuditSender();
72          assertEquals(1, sender.getMessages().size());
73          AuditMessage event = sender.getMessages().get(0);
74  
75          // Event
76          assertEquals(
77                  EventOutcomeIndicator.Success,
78                  event.getEventIdentification().getEventOutcomeIndicator());
79          assertEquals(
80                  EventActionCode.Execute,
81                  event.getEventIdentification().getEventActionCode());
82          assertEquals(EventIdCode.Query, event.getEventIdentification().getEventID());
83          assertEquals(FhirEventTypeCode.MobileDocumentReferenceQuery, event.getEventIdentification().getEventTypeCode().get(0));
84  
85  
86          // ActiveParticipant Source
87          ActiveParticipantType source = event.getActiveParticipants().get(0);
88          assertTrue(source.isUserIsRequestor());
89          assertEquals("127.0.0.1", source.getNetworkAccessPointID());
90          assertEquals(NetworkAccessPointTypeCode.IPAddress, source.getNetworkAccessPointTypeCode());
91  
92          // ActiveParticipant Destination
93          ActiveParticipantType destination = event.getActiveParticipants().get(1);
94          assertFalse(destination.isUserIsRequestor());
95          assertEquals("http://localhost:" + DEMO_APP_PORT + "/DocumentReference", destination.getUserID());
96          assertEquals(AuditUtils.getLocalIPAddress(), destination.getNetworkAccessPointID());
97  
98          // Audit Source
99          AuditSourceIdentificationType sourceIdentificationType = event.getAuditSourceIdentification();
100         assertEquals("IPF", sourceIdentificationType.getAuditSourceID());
101         assertEquals("IPF", sourceIdentificationType.getAuditEnterpriseSiteID());
102 
103         // Patient
104         ParticipantObjectIdentificationType patient = event.getParticipantObjectIdentifications().get(0);
105         assertEquals(ParticipantObjectTypeCode.Person, patient.getParticipantObjectTypeCode());
106         assertEquals(ParticipantObjectTypeCodeRole.Patient, patient.getParticipantObjectTypeCodeRole());
107         assertEquals("urn:oid:2.16.840.1.113883.3.37.4.1.1.2.1.1|1", patient.getParticipantObjectID());
108 
109         // Query Parameters
110         ParticipantObjectIdentificationType query = event.getParticipantObjectIdentifications().get(1);
111         assertEquals(ParticipantObjectTypeCode.System, query.getParticipantObjectTypeCode());
112         assertEquals(ParticipantObjectTypeCodeRole.Query, query.getParticipantObjectTypeCodeRole());
113         assertEquals("http://localhost:8999/DocumentReference?patient.identifier=urn:oid:2.16.840.1.113883.3.37.4.1.1.2.1.1|1",
114                 new String(Base64.getDecoder().decode(query.getParticipantObjectQuery()), StandardCharsets.UTF_8));
115 
116         assertEquals(FhirParticipantObjectIdTypeCode.MobileDocumentReferenceQuery, query.getParticipantObjectIDTypeCode());
117 
118     }
119 
120     @Test
121     public void testSendIti67WithPatientReference() {
122         Bundle result = sendManually(referencePatientReferenceParameter());
123         assertEquals(Bundle.BundleType.SEARCHSET, result.getType());
124         assertEquals(ResourceType.Bundle, result.getResourceType());
125         assertEquals(1, result.getTotal());
126 
127         DocumentReference p = (DocumentReference) result.getEntry().get(0).getResource();
128         assertEquals("63ab1c29-4225-11e6-9b33-0050569b0094", p.getIdElement().getIdPart());
129     }
130 
131     @Test
132     public void testGetResource() {
133         DocumentReference p = client.read()
134                 .resource(DocumentReference.class)
135                 .withId("63ab1c29-4225-11e6-9b33-0050569b0094")
136                 .execute();
137         assertEquals(String.format("http://localhost:%d/DocumentReference/63ab1c29-4225-11e6-9b33-0050569b0094", DEMO_APP_PORT), p.getId());
138     }
139 
140 
141 }