1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 | package gov.hhs.fha.nhinc.transform.audit;
|
---|
6 |
|
---|
7 | import com.services.nhinc.schema.auditmessage.AuditMessageType;
|
---|
8 | import com.services.nhinc.schema.auditmessage.AuditSourceIdentificationType;
|
---|
9 | import com.services.nhinc.schema.auditmessage.CodedValueType;
|
---|
10 | import com.services.nhinc.schema.auditmessage.ParticipantObjectIdentificationType;
|
---|
11 | import gov.hhs.fha.nhinc.common.auditlog.LogEventRequestType;
|
---|
12 | import gov.hhs.fha.nhinc.common.hiemauditlog.LogEntityNotifyResponseType;
|
---|
13 | import gov.hhs.fha.nhinc.common.hiemauditlog.LogNhinNotifyRequestType;
|
---|
14 | import gov.hhs.fha.nhinc.common.nhinccommon.UserType;
|
---|
15 | import gov.hhs.fha.nhinc.nhinclib.NullChecker;
|
---|
16 | import java.io.ByteArrayOutputStream;
|
---|
17 | import javax.xml.bind.JAXBContext;
|
---|
18 | import javax.xml.bind.JAXBElement;
|
---|
19 | import javax.xml.bind.Marshaller;
|
---|
20 | import org.apache.commons.logging.Log;
|
---|
21 | import org.apache.commons.logging.LogFactory;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | *
|
---|
25 | * @author jhoppesc
|
---|
26 | */
|
---|
27 | public class NotifyTransforms {
|
---|
28 |
|
---|
29 | private static Log log = LogFactory.getLog(NotifyTransforms.class);
|
---|
30 |
|
---|
31 | public static LogEventRequestType transformNhinNotifyRequestToAuditMessage(LogNhinNotifyRequestType message) {
|
---|
32 | LogEventRequestType response = new LogEventRequestType();
|
---|
33 | AuditMessageType auditMsg = new AuditMessageType();
|
---|
34 | response.setDirection(message.getDirection());
|
---|
35 | response.setInterface(message.getInterface());
|
---|
36 |
|
---|
37 | log.info("******************************************************************");
|
---|
38 | log.info("Entering transformNhinNotifyRequestToAuditMessage() method.");
|
---|
39 | log.info("******************************************************************");
|
---|
40 |
|
---|
41 | // Extract UserInfo from Message.Assertion
|
---|
42 | UserType userInfo = new UserType();
|
---|
43 | if (message != null &&
|
---|
44 | message.getMessage() != null &&
|
---|
45 | message.getMessage().getAssertion() != null &&
|
---|
46 | message.getMessage().getAssertion().getUserInfo() != null) {
|
---|
47 | userInfo = message.getMessage().getAssertion().getUserInfo();
|
---|
48 | }
|
---|
49 |
|
---|
50 | // Create EventIdentification
|
---|
51 | CodedValueType eventID = new CodedValueType();
|
---|
52 | eventID = AuditDataTransformHelper.createEventId(AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_NOT, AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_NOTIFY, AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_NOT, AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_NOTIFY);
|
---|
53 | auditMsg.setEventIdentification(AuditDataTransformHelper.createEventIdentification(AuditDataTransformConstants.EVENT_ACTION_CODE_CREATE, AuditDataTransformConstants.EVENT_OUTCOME_INDICATOR_SUCCESS, eventID));
|
---|
54 |
|
---|
55 | // Create Active Participant Section
|
---|
56 | if (userInfo != null) {
|
---|
57 | AuditMessageType.ActiveParticipant participant = AuditDataTransformHelper.createActiveParticipantFromUser(userInfo, true);
|
---|
58 | auditMsg.getActiveParticipant().add(participant);
|
---|
59 | }
|
---|
60 |
|
---|
61 | /* Assign AuditSourceIdentification */
|
---|
62 |
|
---|
63 | String patientId = "";
|
---|
64 | if (NullChecker.isNotNullish(message.getMessage().getAssertion().getUniquePatientId()) &&
|
---|
65 | NullChecker.isNotNullish(message.getMessage().getAssertion().getUniquePatientId().get(0))) {
|
---|
66 | patientId = message.getMessage().getAssertion().getUniquePatientId().get(0);
|
---|
67 | }
|
---|
68 |
|
---|
69 | String communityId = "";
|
---|
70 | String communityName = "";
|
---|
71 | if (userInfo != null &&
|
---|
72 | userInfo.getOrg() != null) {
|
---|
73 |
|
---|
74 | if (userInfo.getOrg().getHomeCommunityId() != null) {
|
---|
75 | communityId = userInfo.getOrg().getHomeCommunityId();
|
---|
76 | }
|
---|
77 | if (userInfo.getOrg().getName() != null) {
|
---|
78 | communityName = userInfo.getOrg().getName();
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | AuditSourceIdentificationType auditSource = AuditDataTransformHelper.createAuditSourceIdentification(communityId, communityName);
|
---|
83 | auditMsg.getAuditSourceIdentification().add(auditSource);
|
---|
84 |
|
---|
85 | /* Assign ParticipationObjectIdentification */
|
---|
86 | ParticipantObjectIdentificationType participantObject = AuditDataTransformHelper.createParticipantObjectIdentification(patientId);
|
---|
87 |
|
---|
88 | // Fill in the message field with the contents of the event message
|
---|
89 | try {
|
---|
90 | JAXBContext jc = JAXBContext.newInstance(org.oasis_open.docs.wsn.b_2.ObjectFactory.class, ihe.iti.xds_b._2007.ObjectFactory.class);
|
---|
91 | Marshaller marshaller = jc.createMarshaller();
|
---|
92 | ByteArrayOutputStream baOutStrm = new ByteArrayOutputStream();
|
---|
93 | baOutStrm.reset();
|
---|
94 | marshaller.marshal(message.getMessage().getNotify(), baOutStrm);
|
---|
95 | participantObject.setParticipantObjectQuery(baOutStrm.toByteArray());
|
---|
96 |
|
---|
97 | } catch (Exception e) {
|
---|
98 | e.printStackTrace();
|
---|
99 | log.error("EXCEPTION when marshalling Nhin Notify Request : " + e);
|
---|
100 | throw new RuntimeException();
|
---|
101 | }
|
---|
102 | auditMsg.getParticipantObjectIdentification().add(participantObject);
|
---|
103 |
|
---|
104 | response.setAuditMessage(auditMsg);
|
---|
105 |
|
---|
106 | log.info("******************************************************************");
|
---|
107 | log.info("Exiting transformNhinNotifyRequestToAuditMessage() method.");
|
---|
108 | log.info("******************************************************************");
|
---|
109 |
|
---|
110 | return response;
|
---|
111 | }
|
---|
112 |
|
---|
113 | public static LogEventRequestType transformEntityNotifyResponseToGenericAudit(LogEntityNotifyResponseType message) {
|
---|
114 | LogEventRequestType response = new LogEventRequestType();
|
---|
115 | AuditMessageType auditMsg = new AuditMessageType();
|
---|
116 | response.setDirection(message.getDirection());
|
---|
117 | response.setInterface(message.getInterface());
|
---|
118 |
|
---|
119 | log.info("******************************************************************");
|
---|
120 | log.info("Entering transformEntityNotifyResponseToGenericAudit() method.");
|
---|
121 | log.info("******************************************************************");
|
---|
122 |
|
---|
123 | // Extract UserInfo from Message.Assertion
|
---|
124 | UserType userInfo = new UserType();
|
---|
125 | if (message != null &&
|
---|
126 | message.getMessage() != null &&
|
---|
127 | message.getMessage().getAssertion() != null &&
|
---|
128 | message.getMessage().getAssertion().getUserInfo() != null) {
|
---|
129 | userInfo = message.getMessage().getAssertion().getUserInfo();
|
---|
130 | }
|
---|
131 |
|
---|
132 | // Create EventIdentification
|
---|
133 | CodedValueType eventID = new CodedValueType();
|
---|
134 | eventID = AuditDataTransformHelper.createEventId(AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_NOT, AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_NOTIFY, AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_NOT, AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_NOTIFY);
|
---|
135 | auditMsg.setEventIdentification(AuditDataTransformHelper.createEventIdentification(AuditDataTransformConstants.EVENT_ACTION_CODE_CREATE, AuditDataTransformConstants.EVENT_OUTCOME_INDICATOR_SUCCESS, eventID));
|
---|
136 |
|
---|
137 | // Create Active Participant Section
|
---|
138 | if (userInfo != null) {
|
---|
139 | AuditMessageType.ActiveParticipant participant = AuditDataTransformHelper.createActiveParticipantFromUser(userInfo, true);
|
---|
140 | auditMsg.getActiveParticipant().add(participant);
|
---|
141 | }
|
---|
142 |
|
---|
143 | /* Assign AuditSourceIdentification */
|
---|
144 |
|
---|
145 | String patientId = "";
|
---|
146 | if (NullChecker.isNotNullish(message.getMessage().getAssertion().getUniquePatientId()) &&
|
---|
147 | NullChecker.isNotNullish(message.getMessage().getAssertion().getUniquePatientId().get(0))) {
|
---|
148 | patientId = message.getMessage().getAssertion().getUniquePatientId().get(0);
|
---|
149 | }
|
---|
150 |
|
---|
151 | String communityId = "";
|
---|
152 | String communityName = "";
|
---|
153 | if (userInfo != null &&
|
---|
154 | userInfo.getOrg() != null) {
|
---|
155 |
|
---|
156 | if (userInfo.getOrg().getHomeCommunityId() != null) {
|
---|
157 | communityId = userInfo.getOrg().getHomeCommunityId();
|
---|
158 | }
|
---|
159 | if (userInfo.getOrg().getName() != null) {
|
---|
160 | communityName = userInfo.getOrg().getName();
|
---|
161 | }
|
---|
162 | }
|
---|
163 |
|
---|
164 | AuditSourceIdentificationType auditSource = AuditDataTransformHelper.createAuditSourceIdentification(communityId, communityName);
|
---|
165 | auditMsg.getAuditSourceIdentification().add(auditSource);
|
---|
166 |
|
---|
167 | /* Assign ParticipationObjectIdentification */
|
---|
168 | ParticipantObjectIdentificationType participantObject = AuditDataTransformHelper.createParticipantObjectIdentification(patientId);
|
---|
169 |
|
---|
170 | // Fill in the message field with the contents of the event message
|
---|
171 | // try {
|
---|
172 | // JAXBContext jc = JAXBContext.newInstance("gov.hhs.fha.nhinc.common.nhinccommon");
|
---|
173 | // Marshaller marshaller = jc.createMarshaller();
|
---|
174 | // ByteArrayOutputStream baOutStrm = new ByteArrayOutputStream();
|
---|
175 | // baOutStrm.reset();
|
---|
176 | //
|
---|
177 | // gov.hhs.fha.nhinc.common.nhinccommon.ObjectFactory factory = new gov.hhs.fha.nhinc.common.nhinccommon.ObjectFactory();
|
---|
178 | // JAXBElement oJaxbElement = factory.createAcknowledgement(message.getMessage().getAck());
|
---|
179 | // baOutStrm.close();
|
---|
180 | // marshaller.marshal(oJaxbElement, baOutStrm);
|
---|
181 | //
|
---|
182 | // participantObject.setParticipantObjectQuery(baOutStrm.toByteArray());
|
---|
183 | //
|
---|
184 | // } catch (Exception e) {
|
---|
185 | // e.printStackTrace();
|
---|
186 | // log.error("EXCEPTION when marshalling Nhin Notify Request : " + e);
|
---|
187 | // throw new RuntimeException();
|
---|
188 | // }
|
---|
189 | auditMsg.getParticipantObjectIdentification().add(participantObject);
|
---|
190 |
|
---|
191 | response.setAuditMessage(auditMsg);
|
---|
192 |
|
---|
193 | log.info("******************************************************************");
|
---|
194 | log.info("Exiting transformEntityNotifyResponseToGenericAudit() method.");
|
---|
195 | log.info("******************************************************************");
|
---|
196 | return response;
|
---|
197 | }
|
---|
198 | }
|
---|