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.commons.ihe.hl7v2.audit.it8;
18  
19  import org.junit.Test;
20  import org.openehealth.ipf.commons.audit.codes.EventActionCode;
21  import org.openehealth.ipf.commons.audit.codes.EventIdCode;
22  import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator;
23  import org.openehealth.ipf.commons.audit.model.AuditMessage;
24  import org.openehealth.ipf.commons.ihe.hl7v2.audit.FeedAuditDataset;
25  import org.openehealth.ipf.commons.ihe.hl7v2.audit.Hl7v2AuditorTestBase;
26  import org.openehealth.ipf.commons.ihe.hl7v2.audit.iti8.Iti8AuditStrategy;
27  
28  import static org.junit.Assert.assertNotNull;
29  
30  /**
31   * @author Christian Ohr
32   */
33  public class Iti8AuditStrategyTest extends Hl7v2AuditorTestBase {
34  
35      @Test
36      public void testCreateServerSide() {
37          testRequest(true, EventActionCode.Create);
38      }
39  
40      @Test
41      public void testCreateClientSide() {
42          testRequest(false, EventActionCode.Create);
43      }
44  
45      @Test
46      public void testUpdateServerSide() {
47          testRequest(true, EventActionCode.Update);
48      }
49  
50      @Test
51      public void testUpdateClientSide() {
52          testRequest(false, EventActionCode.Update);
53      }
54  
55  
56      private void testRequest(boolean serverSide, EventActionCode eventActionCode) {
57          Iti8AuditStrategy strategy = new Iti8AuditStrategy(serverSide);
58          FeedAuditDataset auditDataset = getHl7v2AuditDataset(strategy, eventActionCode);
59          AuditMessage auditMessage = makeAuditMessage(strategy, auditContext, auditDataset);
60  
61          assertNotNull(auditMessage);
62          auditMessage.validate();
63          assertCommonV2AuditAttributes(auditMessage,
64                  EventOutcomeIndicator.Success,
65                  EventIdCode.PatientRecord,
66                  eventActionCode,
67                  serverSide,
68                  true);
69      }
70  
71      private FeedAuditDataset getHl7v2AuditDataset(Iti8AuditStrategy strategy, EventActionCode eventActionCode) {
72          FeedAuditDataset auditDataset = strategy.createAuditDataset();
73          auditDataset.setEventOutcomeIndicator(EventOutcomeIndicator.Success);
74          // auditDataset.setLocalAddress(SERVER_URI);
75          auditDataset.setRemoteAddress(CLIENT_IP_ADDRESS);
76          auditDataset.setMessageControlId(MESSAGE_ID);
77          auditDataset.setPatientId(PATIENT_IDS[0]);
78          switch (eventActionCode) {
79              case Create: auditDataset.setMessageType("A01"); break;
80              case Update: auditDataset.setMessageType("A08"); break;
81          }
82  
83          auditDataset.setSendingFacility(SENDING_FACILITY);
84          auditDataset.setSendingApplication(SENDING_APPLICATION);
85          auditDataset.setReceivingFacility(RECEIVING_FACILITY);
86          auditDataset.setReceivingApplication(RECEIVING_APPLICATION);
87          return auditDataset;
88      }
89  }