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.iti65;
18  
19  import ca.uhn.fhir.rest.api.MethodOutcome;
20  import org.hl7.fhir.dstu3.model.Bundle;
21  import org.hl7.fhir.dstu3.model.CapabilityStatement;
22  import org.junit.BeforeClass;
23  import org.junit.Ignore;
24  import org.junit.Test;
25  import org.openehealth.ipf.commons.audit.codes.*;
26  import org.openehealth.ipf.commons.audit.model.ActiveParticipantType;
27  import org.openehealth.ipf.commons.audit.model.AuditMessage;
28  import org.openehealth.ipf.commons.audit.model.ParticipantObjectIdentificationType;
29  import org.openehealth.ipf.commons.audit.queue.AbstractMockedAuditMessageQueue;
30  import org.openehealth.ipf.commons.audit.types.ParticipantObjectIdType;
31  import org.openehealth.ipf.commons.audit.utils.AuditUtils;
32  import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode;
33  
34  import javax.servlet.ServletException;
35  
36  import static org.junit.Assert.*;
37  
38  /**
39   *
40   */
41  public class TestIti65Success extends AbstractTestIti65 {
42  
43      private static final String CONTEXT_DESCRIPTOR = "iti-65.xml";
44  
45      @BeforeClass
46      public static void setUpClass() throws ServletException {
47          startServer(CONTEXT_DESCRIPTOR);
48      }
49  
50      @Test
51      public void testGetConformance() {
52          CapabilityStatement conf = client.capabilities().ofType(CapabilityStatement.class).execute();
53          CapabilityStatement.CapabilityStatementRestComponent component = conf.getRest().iterator().next();
54          assertEquals(CapabilityStatement.SystemRestfulInteraction.TRANSACTION, component.getInteraction().get(0).getCode());
55      }
56  
57      @Test
58      public void testSendManualMhd() throws Exception {
59  
60          Bundle result = sendManually(provideAndRegister());
61          // printAsXML(result);
62  
63          // Check ATNA Audit
64          AbstractMockedAuditMessageQueue sender = getAuditSender();
65          assertEquals(1, sender.getMessages().size());
66          AuditMessage event = sender.getMessages().get(0);
67  
68          // Event
69          assertEquals(
70                  EventOutcomeIndicator.Success,
71                  event.getEventIdentification().getEventOutcomeIndicator());
72          assertEquals(
73                  EventActionCode.Create,
74                  event.getEventIdentification().getEventActionCode());
75  
76          assertEquals(EventIdCode.Import, event.getEventIdentification().getEventID());
77          assertEquals(FhirEventTypeCode.ProvideDocumentBundle, event.getEventIdentification().getEventTypeCode().get(0));
78  
79          // ActiveParticipant Source
80          ActiveParticipantType source = event.getActiveParticipants().get(0);
81          assertTrue(source.isUserIsRequestor());
82          assertEquals("127.0.0.1", source.getNetworkAccessPointID());
83          assertEquals(NetworkAccessPointTypeCode.IPAddress, source.getNetworkAccessPointTypeCode());
84  
85          // ActiveParticipant Destination
86          ActiveParticipantType destination = event.getActiveParticipants().get(1);
87          assertFalse(destination.isUserIsRequestor());
88          assertEquals("http://localhost:" + DEMO_APP_PORT + "/", destination.getUserID());
89          assertEquals(AuditUtils.getLocalIPAddress(), destination.getNetworkAccessPointID());
90  
91          // Patient
92          ParticipantObjectIdentificationType patient = event.getParticipantObjectIdentifications().get(0);
93          assertEquals(ParticipantObjectTypeCode.Person, patient.getParticipantObjectTypeCode());
94          assertEquals(ParticipantObjectTypeCodeRole.Patient, patient.getParticipantObjectTypeCodeRole());
95          assertEquals(ParticipantObjectIdTypeCode.PatientNumber, patient.getParticipantObjectIDTypeCode());
96          assertEquals("Patient/a2", patient.getParticipantObjectID());
97  
98          // SubmissionSet
99          ParticipantObjectIdentificationType poit = event.getParticipantObjectIdentifications().get(1);
100         assertEquals(ParticipantObjectTypeCode.System, poit.getParticipantObjectTypeCode());
101         assertEquals(ParticipantObjectTypeCodeRole.Job, poit.getParticipantObjectTypeCodeRole());
102 
103         // No real instructions how this should look like, so fpr now we take the XDS stuff
104         ParticipantObjectIdType poitTypeCode = poit.getParticipantObjectIDTypeCode();
105         assertEquals("urn:uuid:a54d6aa5-d40d-43f9-88c5-b4633d873bdd", poitTypeCode.getCode());
106         assertEquals("IHE XDS Metadata", poitTypeCode.getCodeSystemName());
107     }
108 
109     @Ignore
110     public void testSendEndpointMhd() throws Exception {
111         MethodOutcome result = getProducerTemplate().requestBody("direct:input", provideAndRegister(), MethodOutcome.class);
112         // printAsXML(result);
113 
114         // Check ATNA Audit
115         AbstractMockedAuditMessageQueue sender = getAuditSender();
116         assertEquals(2, sender.getMessages().size());
117     }
118 
119 
120 }