source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Common/NhincDataTransformsLib/src/gov/hhs/fha/nhinc/transform/audit/FindAuditEventsTransforms.java@ 507

Last change on this file since 507 was 507, checked in by George Lilly, 15 years ago

NHIN gateway and adaptor for use on linux with VistA EHR and RPMS

File size: 6.0 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package gov.hhs.fha.nhinc.transform.audit;
7
8/**
9 *
10 * @author mflynn02
11 */
12
13import org.apache.commons.logging.Log;
14import org.apache.commons.logging.LogFactory;
15
16import java.io.ByteArrayOutputStream;
17import javax.xml.bind.Marshaller;
18import javax.xml.bind.JAXBContext;
19import javax.xml.bind.JAXBElement;
20
21import com.services.nhinc.schema.auditmessage.AuditMessageType;
22import com.services.nhinc.schema.auditmessage.AuditSourceIdentificationType;
23import com.services.nhinc.schema.auditmessage.CodedValueType;
24import com.services.nhinc.schema.auditmessage.ParticipantObjectIdentificationType;
25import gov.hhs.fha.nhinc.common.auditlog.LogEventRequestType;
26
27import gov.hhs.fha.nhinc.common.nhinccommon.UserType;
28import gov.hhs.fha.nhinc.common.auditlog.LogFindAuditEventsRequestType;
29
30public class FindAuditEventsTransforms {
31 private static Log log = LogFactory.getLog(FindAuditEventsTransforms.class);
32
33 public static LogEventRequestType transformFindAuditEventsReq2AuditMsg(LogFindAuditEventsRequestType message) {
34
35 AuditMessageType auditMsg = new AuditMessageType();
36 LogEventRequestType response = new LogEventRequestType();
37 response.setDirection(message.getDirection());
38 response.setInterface(message.getInterface());
39
40 if (message != null) {
41 log.info ("FAE message is NOT null");
42
43 // Extract UserInfo from Message.Assertion
44 UserType userInfo = new UserType();
45 if (message != null &&
46 message.getMessage() != null &&
47 message.getMessage().getAssertion() != null &&
48 message.getMessage().getAssertion().getUserInfo() != null) {
49 userInfo = message.getMessage().getAssertion().getUserInfo();
50 }
51
52 int eventOutcomeID = 0;
53 String userID = "";
54 CodedValueType eventID = AuditDataTransformHelper.createEventId("ADQ", "AuditQuery", "ADQ", "AuditQuery");
55
56 // EventIdentification
57 auditMsg.setEventIdentification(AuditDataTransformHelper.createEventIdentification(AuditDataTransformConstants.EVENT_ACTION_CODE_EXECUTE, eventOutcomeID, eventID));
58 log.info("set EventIdentification");
59
60 //ActiveParticipant
61 // NOTE: This is [1..*] in schema but only one item to map to from FindAuditEventsType
62
63 if (userInfo != null &&
64 userInfo.getUserName().length() > 0) {
65 userID = userInfo.getUserName();
66 log.info("userID " + userID);
67 }
68 String altUserID = "";
69 String userName = userInfo.getPersonName().getGivenName() + " " + userInfo.getPersonName().getFamilyName();
70 AuditMessageType.ActiveParticipant activeParticipant = AuditDataTransformHelper.createActiveParticipant(userID, altUserID, userName, true);
71
72 auditMsg.getActiveParticipant().add(activeParticipant);
73 log.info("set ActiveParticiapnt");
74
75 // AuditSourceIdentification
76 // NOTE: This is [1..*] in the schema but only one item to map to from FindAuditEventsType
77 String auditSourceID = "";
78 String enterpriseSiteID = "";
79 if (userInfo != null &&
80 userInfo.getOrg() != null) {
81 if (userInfo.getOrg().getName() != null &&
82 userInfo.getOrg().getName().length() > 0) {
83 enterpriseSiteID =userInfo.getOrg().getName();
84 }
85 if (userInfo.getOrg().getHomeCommunityId() != null &&
86 userInfo.getOrg().getHomeCommunityId().length() > 0) {
87
88 auditSourceID = userInfo.getOrg().getHomeCommunityId();
89 log.info("auditSourceID " + auditSourceID);
90 }
91 }
92 AuditSourceIdentificationType auditSource = AuditDataTransformHelper.createAuditSourceIdentification(auditSourceID, enterpriseSiteID);
93 auditMsg.getAuditSourceIdentification().add(auditSource);
94 log.info("set AuditSourceIdentification");
95
96 // ParticipationObjectIdentification
97 // NOTE: This is [0..*] in the schema but only one item to map to from FindAuditEventsType
98 String patientID = "";
99
100 if (message.getMessage().getFindAuditEvents().getPatientId() != null &&
101 message.getMessage().getFindAuditEvents().getPatientId().length() > 0) {
102 patientID = message.getMessage().getFindAuditEvents().getPatientId();
103 log.info("patientID " + patientID);
104 }
105 ParticipantObjectIdentificationType partObject = AuditDataTransformHelper.createParticipantObjectIdentification(patientID);
106
107 // Fill in the message field with the contents of the event message
108 try {
109 JAXBContext jc = JAXBContext.newInstance("com.services.nhinc.schema.auditmessage");
110 Marshaller marshaller = jc.createMarshaller();
111 ByteArrayOutputStream baOutStrm = new ByteArrayOutputStream();
112 baOutStrm.reset();
113
114 com.services.nhinc.schema.auditmessage.ObjectFactory factory = new com.services.nhinc.schema.auditmessage.ObjectFactory();
115 JAXBElement oJaxbElement = factory.createFindAuditEvents(message.getMessage().getFindAuditEvents());
116 baOutStrm.close();
117 marshaller.marshal(oJaxbElement, baOutStrm);
118
119 partObject.setParticipantObjectQuery(baOutStrm.toByteArray());
120 } catch (Exception e) {
121 e.printStackTrace();
122 throw new RuntimeException();
123 }
124
125 auditMsg.getParticipantObjectIdentification().add(partObject);
126 log.info("set ParticipantObjectIdentification");
127 }
128 response.setAuditMessage(auditMsg);
129 return response;
130 }
131}
Note: See TracBrowser for help on using the repository browser.