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.iti64;
18  
19  import org.junit.Test;
20  import org.openehealth.ipf.commons.audit.codes.*;
21  import org.openehealth.ipf.commons.audit.model.AuditMessage;
22  import org.openehealth.ipf.commons.ihe.hl7v2.audit.Hl7v2AuditorTestBase;
23  
24  import static org.junit.Assert.assertEquals;
25  import static org.junit.Assert.assertNotNull;
26  
27  /**
28   * @author Christian Ohr
29   */
30  public class Iti64AuditStrategyTest extends Hl7v2AuditorTestBase {
31  
32      @Test
33      public void testServerSide() {
34          testRequest(true);
35      }
36  
37      @Test
38      public void testClientSide() {
39          testRequest(false);
40      }
41  
42      private void testRequest(boolean serverSide) {
43          Iti64AuditStrategy strategy = new Iti64AuditStrategy(serverSide);
44          Iti64AuditDataset auditDataset = getHl7v2AuditDataset(strategy);
45          AuditMessage auditMessage = makeAuditMessage(strategy, auditContext, auditDataset);
46  
47          assertNotNull(auditMessage);
48          auditMessage.validate();
49          assertCommonV2AuditAttributes(auditMessage,
50                  EventOutcomeIndicator.Success,
51                  EventIdCode.PatientRecord,
52                  EventActionCode.Update,
53                  serverSide,
54                  true);
55  
56          assertEquals(2, auditMessage.findParticipantObjectIdentifications(
57                  poit -> poit.getParticipantObjectDataLifeCycle() == ParticipantObjectDataLifeCycle.Origination).size());
58          assertEquals(2, auditMessage.findParticipantObjectIdentifications(
59                  poit -> poit.getParticipantObjectDataLifeCycle() == ParticipantObjectDataLifeCycle.LogicalDeletion).size());
60          assertEquals(1, auditMessage.findParticipantObjectIdentifications(
61                  poit -> poit.getParticipantObjectTypeCode() == ParticipantObjectTypeCode.System).size());
62  
63          // System.out.println(printAuditMessage(auditMessage));
64      }
65  
66      private Iti64AuditDataset getHl7v2AuditDataset(Iti64AuditStrategy strategy) {
67          Iti64AuditDataset auditDataset = strategy.createAuditDataset();
68          auditDataset.setEventOutcomeIndicator(EventOutcomeIndicator.Success);
69          // auditDataset.setLocalAddress(SERVER_URI);
70          auditDataset.setRemoteAddress(CLIENT_IP_ADDRESS);
71          auditDataset.setMessageControlId(MESSAGE_ID);
72          auditDataset.setNewPatientId(PATIENT_IDS[0]);
73          auditDataset.setPreviousPatientId(PATIENT_IDS[1]);
74          auditDataset.setLocalPatientId(PATIENT_IDS[0]);
75          auditDataset.setSubsumedLocalPatientId(PATIENT_IDS[1]);
76          auditDataset.setSendingFacility(SENDING_FACILITY);
77          auditDataset.setSendingApplication(SENDING_APPLICATION);
78          auditDataset.setReceivingFacility(RECEIVING_FACILITY);
79          auditDataset.setReceivingApplication(RECEIVING_APPLICATION);
80          auditDataset.setSubmissionSetUuid(SUBMISSION_SET_UUID);
81          return auditDataset;
82      }
83  }