View Javadoc
1   /*
2    * Copyright 2015 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.iti83;
18  
19  import org.hl7.fhir.dstu3.model.CapabilityStatement;
20  import org.hl7.fhir.dstu3.model.Identifier;
21  import org.hl7.fhir.dstu3.model.Parameters;
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  import org.openehealth.ipf.commons.ihe.fhir.iti83.Iti83Constants;
34  
35  
36  import javax.servlet.ServletException;
37  
38  import java.nio.charset.StandardCharsets;
39  import java.util.Base64;
40  
41  import static org.junit.Assert.assertEquals;
42  import static org.junit.Assert.assertFalse;
43  import static org.junit.Assert.assertTrue;
44  
45  /**
46   *
47   */
48  public class TestIti83Success extends AbstractTestIti83 {
49  
50      private static final String CONTEXT_DESCRIPTOR = "iti-83.xml";
51  
52      @BeforeClass
53      public static void setUpClass() throws ServletException {
54          startServer(CONTEXT_DESCRIPTOR);
55      }
56  
57      @Test
58      public void testGetConformance() {
59          CapabilityStatement conf = client.capabilities().ofType(CapabilityStatement.class).execute();
60  
61          assertEquals(1, conf.getRest().size());
62          CapabilityStatement.CapabilityStatementRestComponent component = conf.getRest().iterator().next();
63          CapabilityStatement.CapabilityStatementRestOperationComponent operation = component.getOperation().iterator().next();
64          assertEquals(Iti83Constants.PIXM_OPERATION_NAME.substring(1), operation.getName());
65  
66          // printAsXML(conf);
67      }
68  
69      @Test
70      public void testSendManualPixm() {
71  
72          Parameters result = sendManuallyOnType(validQueryParameters());
73  
74          // printAsXML(result);
75  
76          Parameters.ParametersParameterComponent parameter = result.getParameter().iterator().next();
77          assertEquals(ResponseCase.getRESULT_VALUE(), ((Identifier)parameter.getValue()).getValue());
78  
79          // Check ATNA Audit
80          AbstractMockedAuditMessageQueue sender = getAuditSender();
81          assertEquals(1, sender.getMessages().size());
82          AuditMessage event = sender.getMessages().get(0);
83  
84          assertEquals(
85                  EventOutcomeIndicator.Success,
86                  event.getEventIdentification().getEventOutcomeIndicator());
87          assertEquals(
88                  EventActionCode.Execute,
89                  event.getEventIdentification().getEventActionCode());
90  
91          assertEquals(EventIdCode.Query, event.getEventIdentification().getEventID());
92          assertEquals(FhirEventTypeCode.MobilePatientIdentifierCrossReferenceQuery, event.getEventIdentification().getEventTypeCode().get(0));
93  
94          // ActiveParticipant Source
95          ActiveParticipantType source = event.getActiveParticipants().get(0);
96          assertTrue(source.isUserIsRequestor());
97          assertEquals("127.0.0.1", source.getNetworkAccessPointID());
98          assertEquals(NetworkAccessPointTypeCode.IPAddress, source.getNetworkAccessPointTypeCode());
99  
100         // ActiveParticipant Destination
101         ActiveParticipantType destination = event.getActiveParticipants().get(1);
102         assertFalse(destination.isUserIsRequestor());
103         assertEquals("http://localhost:" + DEMO_APP_PORT + "/Patient/$ihe-pix", destination.getUserID());
104         assertEquals(AuditUtils.getLocalIPAddress(), destination.getNetworkAccessPointID());
105 
106         // Audit Source
107         AuditSourceIdentificationType sourceIdentificationType = event.getAuditSourceIdentification();
108         assertEquals("IPF", sourceIdentificationType.getAuditSourceID());
109         assertEquals("IPF", sourceIdentificationType.getAuditEnterpriseSiteID());
110 
111         // Patient (going in)
112         ParticipantObjectIdentificationType patientIn = event.getParticipantObjectIdentifications().get(0);
113         assertEquals(ParticipantObjectTypeCode.Person, patientIn.getParticipantObjectTypeCode());
114         assertEquals(ParticipantObjectTypeCodeRole.Patient, patientIn.getParticipantObjectTypeCodeRole());
115         assertEquals("urn:oid:1.2.3.4|0815", new String(patientIn.getParticipantObjectID()));
116 
117         // Query
118         ParticipantObjectIdentificationType patient = event.getParticipantObjectIdentifications().get(1);
119         assertEquals(ParticipantObjectTypeCode.System, patient.getParticipantObjectTypeCode());
120         assertEquals(ParticipantObjectTypeCodeRole.Query, patient.getParticipantObjectTypeCodeRole());
121         assertEquals("http://localhost:8999/Patient/$ihe-pix?sourceIdentifier=urn:oid:1.2.3.4|0815&targetSystem=urn:oid:1.2.3.4.6",
122                 new String(Base64.getDecoder().decode(patient.getParticipantObjectQuery()), StandardCharsets.UTF_8));
123 
124         assertEquals(FhirParticipantObjectIdTypeCode.MobilePatientIdentifierCrossReferenceQuery, patient.getParticipantObjectIDTypeCode());
125 
126     }
127 
128     @Test
129     public void testSendManualRead() {
130         Parameters result = sendManuallyOnInstance("0815", validTargetSystemParameters());
131         Parameters.ParametersParameterComponent parameter = result.getParameter().iterator().next();
132         assertEquals(ResponseCase.getRESULT_VALUE(), ((Identifier)parameter.getValue()).getValue());
133     }
134 
135     @Test
136     public void testSendEndpointPixm() {
137         Parameters result = getProducerTemplate().requestBody("direct:input", validQueryParameters(), Parameters.class);
138 
139         Parameters.ParametersParameterComponent parameter = result.getParameter().iterator().next();
140         assertEquals(ResponseCase.getRESULT_VALUE(), ((Identifier)parameter.getValue()).getValue());
141 
142         // Check ATNA Audit
143         AbstractMockedAuditMessageQueue sender = getAuditSender();
144         assertEquals(2, sender.getMessages().size());
145     }
146 
147     @Test
148     public void testSendEndpointPixmRead() {
149         Parameters result = getProducerTemplate().requestBody("direct:input", validReadParameters(), Parameters.class);
150 
151         Parameters.ParametersParameterComponent parameter = result.getParameter().iterator().next();
152         assertEquals(ResponseCase.getRESULT_VALUE(), ((Identifier)parameter.getValue()).getValue());
153 
154         // Check ATNA Audit
155         AbstractMockedAuditMessageQueue sender = getAuditSender();
156         assertEquals(2, sender.getMessages().size());
157     }
158 
159 }