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.iti78;
18  
19  import org.hl7.fhir.dstu3.model.Bundle;
20  import org.hl7.fhir.dstu3.model.ResourceType;
21  import org.junit.BeforeClass;
22  import org.junit.Test;
23  import org.openehealth.ipf.commons.audit.codes.*;
24  import org.openehealth.ipf.commons.audit.model.ActiveParticipantType;
25  import org.openehealth.ipf.commons.audit.model.AuditMessage;
26  import org.openehealth.ipf.commons.audit.model.AuditSourceIdentificationType;
27  import org.openehealth.ipf.commons.audit.model.ParticipantObjectIdentificationType;
28  import org.openehealth.ipf.commons.audit.utils.AuditUtils;
29  import org.openehealth.ipf.commons.audit.queue.AbstractMockedAuditMessageQueue;
30  import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode;
31  import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirParticipantObjectIdTypeCode;
32  import org.openehealth.ipf.commons.ihe.fhir.iti78.PdqPatient;
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 TestIti78Success extends AbstractTestIti78 {
44  
45      private static final String CONTEXT_DESCRIPTOR = "iti-78.xml";
46  
47      @BeforeClass
48      public static void setUpClass() throws ServletException {
49          startServer(CONTEXT_DESCRIPTOR, false);
50          startClient();
51      }
52  
53      @Test
54      public void testGetConformance() {
55          assertConformance("Patient");
56      }
57  
58      @Test
59      public void testSendManualPdqm() {
60  
61          Bundle result = sendManually(familyParameters());
62  
63          // printAsXML(result);
64  
65          assertEquals(Bundle.BundleType.SEARCHSET, result.getType());
66          assertEquals(ResourceType.Bundle, result.getResourceType());
67          assertTrue(result.hasEntry());
68  
69  
70          PdqPatient p = (PdqPatient)result.getEntry().get(0).getResource();
71          assertEquals("Test", p.getName().get(0).getFamily());
72          assertEquals("http://localhost:8999/Patient/4711", p.getId());
73  
74  
75          // Check ATNA Audit
76  
77          AbstractMockedAuditMessageQueue sender = getAuditSender();
78          assertEquals(1, sender.getMessages().size());
79          AuditMessage event = sender.getMessages().get(0);
80  
81          // Event
82          assertEquals(
83                  EventOutcomeIndicator.Success,
84                  event.getEventIdentification().getEventOutcomeIndicator());
85          assertEquals(
86                  EventActionCode.Execute,
87                  event.getEventIdentification().getEventActionCode());
88          assertEquals(EventIdCode.Query, event.getEventIdentification().getEventID());
89          assertEquals(FhirEventTypeCode.MobilePatientDemographicsQuery, event.getEventIdentification().getEventTypeCode().get(0));
90  
91          // ActiveParticipant Source
92          ActiveParticipantType source = event.getActiveParticipants().get(0);
93          assertTrue(source.isUserIsRequestor());
94          assertEquals("127.0.0.1", source.getNetworkAccessPointID());
95          assertEquals(NetworkAccessPointTypeCode.IPAddress, source.getNetworkAccessPointTypeCode());
96  
97          // ActiveParticipant Destination
98          ActiveParticipantType destination = event.getActiveParticipants().get(1);
99          assertFalse(destination.isUserIsRequestor());
100         assertEquals("http://localhost:" + DEMO_APP_PORT + "/Patient", destination.getUserID());
101         assertEquals(AuditUtils.getLocalIPAddress(), destination.getNetworkAccessPointID());
102 
103         // Audit Source
104         AuditSourceIdentificationType sourceIdentificationType = event.getAuditSourceIdentification();
105         assertEquals("IPF", sourceIdentificationType.getAuditSourceID());
106         assertEquals("IPF", sourceIdentificationType.getAuditEnterpriseSiteID());
107 
108         // Query
109         ParticipantObjectIdentificationType patient = event.getParticipantObjectIdentifications().get(0);
110         assertEquals(ParticipantObjectTypeCode.System, patient.getParticipantObjectTypeCode());
111         assertEquals(ParticipantObjectTypeCodeRole.Query, patient.getParticipantObjectTypeCodeRole());
112         assertEquals("http://localhost:8999/Patient?family=Test",
113                 new String(Base64.getDecoder().decode(patient.getParticipantObjectQuery()), StandardCharsets.UTF_8));
114 
115         assertEquals(FhirParticipantObjectIdTypeCode.MobilePatientDemographicsQuery, patient.getParticipantObjectIDTypeCode());
116 
117     }
118 
119     @Test
120     public void testGetResource() {
121         PdqPatient p = client.read()
122                 .resource(PdqPatient.class)
123                 .withId("4711")
124                 .execute();
125         assertEquals("Test", p.getName().get(0).getFamily());
126         assertEquals(String.format("http://localhost:%d/Patient/4711", DEMO_APP_PORT), p.getId());
127         AbstractMockedAuditMessageQueue sender = getAuditSender();
128         assertEquals(1, sender.getMessages().size());
129         AuditMessage event = sender.getMessages().get(0);
130 
131         // Patient
132         ParticipantObjectIdentificationType patient = event.getParticipantObjectIdentifications().get(0);
133         assertEquals(ParticipantObjectTypeCode.Person, patient.getParticipantObjectTypeCode());
134         assertEquals(ParticipantObjectTypeCodeRole.Patient, patient.getParticipantObjectTypeCodeRole());
135         assertEquals("Patient/4711", patient.getParticipantObjectID());
136     }
137 
138 
139     @Test
140     public void testSendEndpointPdqmCriterion() {
141         Bundle result = getProducerTemplate().requestBody("direct:input", familyParameters(), Bundle.class);
142         // printAsXML(result);
143 
144         // Check ATNA Audit
145         AbstractMockedAuditMessageQueue sender = getAuditSender();
146         assertEquals(2, sender.getMessages().size());
147         // FIXME client-side audit message needs ip addresses, target URL and queryString
148     }
149 
150     @Test
151     public void testSendEndpointPdqmString() {
152         Bundle result = getProducerTemplate().requestBody("direct:input", "Patient?family=Test", Bundle.class);
153         // printAsXML(result);
154 
155         // Check ATNA Audit
156         AbstractMockedAuditMessageQueue sender = getAuditSender();
157         assertEquals(2, sender.getMessages().size());
158         // FIXME client-side audit message needs ip addresses, target URL and queryString
159     }
160 
161 
162 
163 }