View Javadoc
1   /*
2    * Copyright 2018 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.pcc44;
18  
19  import org.hl7.fhir.dstu3.model.Bundle;
20  import org.hl7.fhir.dstu3.model.Observation;
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.queue.AbstractMockedAuditMessageQueue;
30  import org.openehealth.ipf.commons.audit.utils.AuditUtils;
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 TestPcc44Success extends AbstractTestPcc44 {
44  
45      private static final String CONTEXT_DESCRIPTOR = "pcc-44.xml";
46  
47      @BeforeClass
48      public static void setUpClass() {
49          startServer(CONTEXT_DESCRIPTOR);
50      }
51  
52      @Test
53      public void testGetConformance() {
54          assertConformance("Observation");
55      }
56  
57      @Test
58      public void testSendManualPcc44() {
59  
60          Bundle result = sendManually(observationPatientReferenceParameter());
61  
62          assertEquals(Bundle.BundleType.SEARCHSET, result.getType());
63          assertEquals(ResourceType.Bundle, result.getResourceType());
64          assertEquals(1, result.getTotal());
65  
66          Observation p = (Observation) result.getEntry().get(0).getResource();
67          assertEquals("heart-rate", 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.MobileQueryExistingData, 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 + "/Observation", 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("Patient/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/Observation?patient=http://fhirserver.org/Patient/1",
114                 new String(Base64.getDecoder().decode(query.getParticipantObjectQuery()), StandardCharsets.UTF_8));
115 
116         assertEquals(FhirParticipantObjectIdTypeCode.MobileQueryExistingData, query.getParticipantObjectIDTypeCode());
117 
118     }
119 
120     @Test
121     public void testSendPcc44WithPatientReference() {
122         Bundle result = sendManually(observationPatientReferenceParameter());
123         assertEquals(Bundle.BundleType.SEARCHSET, result.getType());
124         assertEquals(ResourceType.Bundle, result.getResourceType());
125         assertEquals(1, result.getTotal());
126 
127         Observation p = (Observation) result.getEntry().get(0).getResource();
128         assertEquals("heart-rate", p.getIdElement().getIdPart());
129     }
130 
131     @Test
132     public void testGetResource() {
133         Observation p = client.read()
134                 .resource(Observation.class)
135                 .withId("heart-rate")
136                 .execute();
137         assertEquals(String.format("http://localhost:%d/Observation/heart-rate", DEMO_APP_PORT), p.getId());
138     }
139 
140 
141 }