source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Common/NhincDataTransformsLib/src/gov/hhs/fha/nhinc/transform/audit/DocumentRetrieveTransforms.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: 10.9 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
8import org.apache.commons.logging.Log;
9import org.apache.commons.logging.LogFactory;
10
11import javax.xml.bind.JAXBElement;
12import javax.xml.bind.JAXBContext;
13import java.io.ByteArrayOutputStream;
14import javax.xml.bind.Marshaller;
15
16import com.services.nhinc.schema.auditmessage.AuditMessageType;
17import com.services.nhinc.schema.auditmessage.AuditSourceIdentificationType;
18import com.services.nhinc.schema.auditmessage.CodedValueType;
19import com.services.nhinc.schema.auditmessage.EventIdentificationType;
20import com.services.nhinc.schema.auditmessage.ParticipantObjectIdentificationType;
21
22import gov.hhs.fha.nhinc.common.nhinccommon.UserType;
23import gov.hhs.fha.nhinc.common.auditlog.LogDocRetrieveRequestType;
24import gov.hhs.fha.nhinc.common.auditlog.LogDocRetrieveResultRequestType;
25import gov.hhs.fha.nhinc.common.auditlog.LogEventRequestType;
26
27import ihe.iti.xds_b._2007.RetrieveDocumentSetResponseType;
28/**
29 *
30 * @author MFLYNN02
31 */
32public class DocumentRetrieveTransforms {
33 private static Log log = LogFactory.getLog(DocumentRetrieveTransforms.class);
34
35 public static LogEventRequestType transformDocRetrieveReq2AuditMsg(LogDocRetrieveRequestType message) {
36 AuditMessageType auditMsg = new AuditMessageType();
37 LogEventRequestType response = new LogEventRequestType();
38 response.setDirection(message.getDirection());
39 response.setInterface(message.getInterface());
40
41 log.info("******************************************************************");
42 log.info("Entering transformDocRetrieveReq2AuditMsg() method.");
43 log.info("******************************************************************");
44
45 // Extract UserInfo from Message.Assertion
46 UserType userInfo = new UserType();
47 if (message != null &&
48 message.getMessage() != null &&
49 message.getMessage().getAssertion() != null &&
50 message.getMessage().getAssertion().getUserInfo() != null) {
51 userInfo = message.getMessage().getAssertion().getUserInfo();
52 }
53
54 // Create Event Identification Section
55 // TODO: Determine what to do with Event Code and Event Code System (either auto-generate or map in AdhocQueryRequest
56 CodedValueType eventId = AuditDataTransformHelper.createEventId(AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_DOC, AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_DOCRETRIEVE, AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_DOC, AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_DOCRETRIEVE);
57 EventIdentificationType eventIdentification = AuditDataTransformHelper.createEventIdentification(AuditDataTransformConstants.EVENT_ACTION_CODE_EXECUTE, AuditDataTransformConstants.EVENT_OUTCOME_INDICATOR_SUCCESS, eventId);
58 auditMsg.setEventIdentification(eventIdentification);
59
60 // Create Active Participant Section
61 if (userInfo != null) {
62 AuditMessageType.ActiveParticipant participant = AuditDataTransformHelper.createActiveParticipantFromUser(userInfo, true);
63 auditMsg.getActiveParticipant().add(participant);
64 }
65
66 // Create Audit Source Identification Section
67 String communityId = null;
68 if (message.getMessage() != null &&
69 message.getMessage().getRetrieveDocumentSetRequest() != null &&
70 message.getMessage().getRetrieveDocumentSetRequest().getDocumentRequest() != null &&
71 message.getMessage().getRetrieveDocumentSetRequest().getDocumentRequest().size() > 0) {
72 communityId = message.getMessage().getRetrieveDocumentSetRequest().getDocumentRequest().get(0).getHomeCommunityId();
73 AuditSourceIdentificationType auditSrcId = AuditDataTransformHelper.createAuditSourceIdentification(communityId, communityId);
74 auditMsg.getAuditSourceIdentification().add(auditSrcId);
75 }
76
77 /**
78 * TODO: Patient ID in Doc Retrieve -- Not sure where this is. Currently leaving null
79 */
80 String patientId = new String();
81
82 // Create Participation Object Identification Section
83 ParticipantObjectIdentificationType partObjId = new ParticipantObjectIdentificationType();
84 if (userInfo != null) {
85 partObjId = AuditDataTransformHelper.createParticipantObjectIdentification(patientId);
86 patientId = partObjId.getParticipantObjectID();
87 partObjId.setParticipantObjectID(AuditDataTransformHelper.createCompositePatientId(communityId, patientId));
88 }
89
90 // Fill in the message field with the contents of the event message
91 try {
92 JAXBContext jc = JAXBContext.newInstance("ihe.iti.xds_b._2007");
93 Marshaller marshaller = jc.createMarshaller();
94 ByteArrayOutputStream baOutStrm = new ByteArrayOutputStream();
95 baOutStrm.reset();
96 ihe.iti.xds_b._2007.ObjectFactory factory = new ihe.iti.xds_b._2007.ObjectFactory();
97 JAXBElement oJaxbElement = factory.createRetrieveDocumentSetRequest(message.getMessage().getRetrieveDocumentSetRequest());
98 baOutStrm.close();
99 marshaller.marshal(oJaxbElement, baOutStrm);
100
101 partObjId.setParticipantObjectQuery(baOutStrm.toByteArray());
102 } catch (Exception e) {
103 e.printStackTrace();
104 throw new RuntimeException();
105 }
106 auditMsg.getParticipantObjectIdentification().add(partObjId);
107
108 log.info("******************************************************************");
109 log.info("Exiting transformDocRetrieveReq2AuditMsg() method.");
110 log.info("******************************************************************");
111
112 response.setAuditMessage(auditMsg);
113 return response;
114 }
115
116 public static LogEventRequestType transformDocRetrieveResp2AuditMsg(LogDocRetrieveResultRequestType message) {
117 AuditMessageType auditMsg = new AuditMessageType();
118 LogEventRequestType response = new LogEventRequestType();
119 response.setDirection(message.getDirection());
120 response.setInterface(message.getInterface());
121
122 log.info("******************************************************************");
123 log.info("Entering transformDocRetrieveResp2AuditMsg() method.");
124 log.info("******************************************************************");
125
126 // Extract UserInfo from Message.Assertion
127 UserType userInfo = new UserType();
128 if (message != null &&
129 message.getMessage() != null &&
130 message.getMessage().getAssertion() != null &&
131 message.getMessage().getAssertion().getUserInfo() != null) {
132 userInfo = message.getMessage().getAssertion().getUserInfo();
133 }
134
135 // Create Event Identification Section
136 // TODO: Determine what to do with Event Code and Event Code System (either auto-generate or map in AdhocQueryRequest
137 CodedValueType eventId = AuditDataTransformHelper.createEventId(AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_DOC, AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_DOCRETRIEVE, AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_DOC, AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_DOCRETRIEVE);
138 EventIdentificationType eventIdentification = AuditDataTransformHelper.createEventIdentification(AuditDataTransformConstants.EVENT_ACTION_CODE_EXECUTE, AuditDataTransformConstants.EVENT_OUTCOME_INDICATOR_SUCCESS, eventId);
139 auditMsg.setEventIdentification(eventIdentification);
140
141 // Create Active Participant Section
142 if (userInfo != null) {
143 AuditMessageType.ActiveParticipant participant = AuditDataTransformHelper.createActiveParticipantFromUser(userInfo, true);
144 auditMsg.getActiveParticipant().add(participant);
145 }
146
147 // Create Audit Source Identification Section
148 String communityId = null;
149 if (message.getMessage() != null &&
150 message.getMessage().getRetrieveDocumentSetResponse() != null &&
151 message.getMessage().getRetrieveDocumentSetResponse().getDocumentResponse() != null &&
152 message.getMessage().getRetrieveDocumentSetResponse().getDocumentResponse().size() > 0) {
153 communityId = message.getMessage().getRetrieveDocumentSetResponse().getDocumentResponse().get(0).getHomeCommunityId();
154 }
155 AuditSourceIdentificationType auditSrcId = AuditDataTransformHelper.createAuditSourceIdentification(communityId, "");
156 auditMsg.getAuditSourceIdentification().add(auditSrcId);
157
158 /**
159 * TODO: Patient ID in Doc Retrieve -- Not sure where this is. Currently extracting
160 * from DocumentUniqueId
161 */
162 String patientId = new String();
163 if (message.getMessage() != null &&
164 message.getMessage().getRetrieveDocumentSetResponse() != null &&
165 message.getMessage().getRetrieveDocumentSetResponse().getRegistryResponse() != null &&
166 message.getMessage().getRetrieveDocumentSetResponse().getRegistryResponse().getRequestId() != null) {
167 patientId = message.getMessage().getRetrieveDocumentSetResponse().getRegistryResponse().getRequestId();
168 }
169 // Create Participation Object Identification Section
170 ParticipantObjectIdentificationType partObjId = new ParticipantObjectIdentificationType();
171 partObjId = AuditDataTransformHelper.createParticipantObjectIdentification(patientId);
172 if (patientId != null) {
173 patientId = partObjId.getParticipantObjectID();
174 partObjId.setParticipantObjectID(AuditDataTransformHelper.createCompositePatientId(communityId, patientId));
175 }
176
177 // Fill in the message field with the contents of the event message
178 try {
179 JAXBContext jc = JAXBContext.newInstance("ihe.iti.xds_b._2007");
180 Marshaller marshaller = jc.createMarshaller();
181 ByteArrayOutputStream baOutStrm = new ByteArrayOutputStream();
182 baOutStrm.reset();
183 ihe.iti.xds_b._2007.ObjectFactory factory = new ihe.iti.xds_b._2007.ObjectFactory();
184 JAXBElement oJaxbElement = factory.createRetrieveDocumentSetResponse(message.getMessage().getRetrieveDocumentSetResponse());
185 marshaller.marshal(oJaxbElement, baOutStrm);
186
187 partObjId.setParticipantObjectQuery(baOutStrm.toByteArray());
188 } catch (Exception e) {
189 e.printStackTrace();
190 throw new RuntimeException();
191 }
192 auditMsg.getParticipantObjectIdentification().add(partObjId);
193
194 log.info("******************************************************************");
195 log.info("Exiting transformDocRetrieveResp2AuditMsg() method.");
196 log.info("******************************************************************");
197
198 response.setAuditMessage(auditMsg);
199 return response;
200 }
201
202}
Note: See TracBrowser for help on using the repository browser.