1 | package gov.hhs.fha.nhinc.transform.audit;
|
---|
2 |
|
---|
3 | import com.services.nhinc.schema.auditmessage.AuditMessageType;
|
---|
4 | import com.services.nhinc.schema.auditmessage.AuditSourceIdentificationType;
|
---|
5 | import com.services.nhinc.schema.auditmessage.CodedValueType;
|
---|
6 | import com.services.nhinc.schema.auditmessage.ParticipantObjectIdentificationType;
|
---|
7 | import gov.hhs.fha.nhinc.common.auditlog.LogEventRequestType;
|
---|
8 | import gov.hhs.fha.nhinc.common.hiemauditlog.LogNhinSubscribeRequestType;
|
---|
9 | import gov.hhs.fha.nhinc.common.hiemauditlog.LogSubscribeResponseType;
|
---|
10 | import org.oasis_open.docs.wsn.b_2.Subscribe;
|
---|
11 |
|
---|
12 | import gov.hhs.fha.nhinc.common.nhinccommon.UserType;
|
---|
13 | import gov.hhs.fha.nhinc.nhinclib.NullChecker;
|
---|
14 | import gov.hhs.fha.nhinc.transform.audit.AuditDataTransformConstants;
|
---|
15 | import gov.hhs.fha.nhinc.transform.audit.AuditDataTransformHelper;
|
---|
16 | import gov.hhs.fha.nhinc.util.format.PatientIdFormatUtil;
|
---|
17 | import java.io.ByteArrayOutputStream;
|
---|
18 | import java.util.List;
|
---|
19 | import javax.xml.bind.JAXBContext;
|
---|
20 | import javax.xml.bind.JAXBElement;
|
---|
21 | import javax.xml.bind.Marshaller;
|
---|
22 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType;
|
---|
23 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotType1;
|
---|
24 | import org.apache.commons.logging.Log;
|
---|
25 | import org.apache.commons.logging.LogFactory;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Transforms for subscribe messages.
|
---|
29 | *
|
---|
30 | * @author webbn
|
---|
31 | */
|
---|
32 | public class SubscribeTransforms {
|
---|
33 | private static Log log = LogFactory.getLog(SubscribeTransforms.class);
|
---|
34 | private static final String SLOT_NAME_PATIENT_ID = "$XDSDocumentEntryPatientId";
|
---|
35 |
|
---|
36 | public LogEventRequestType transformNhinSubscribeRequestToAuditMessage(LogNhinSubscribeRequestType message)
|
---|
37 | {
|
---|
38 | LogEventRequestType response = new LogEventRequestType();
|
---|
39 | AuditMessageType auditMsg = new AuditMessageType();
|
---|
40 | response.setDirection(message.getDirection());
|
---|
41 | response.setInterface(message.getInterface());
|
---|
42 |
|
---|
43 | log.info("******************************************************************");
|
---|
44 | log.info("Entering transformNhinSubscribeRequestToAuditMessage() method.");
|
---|
45 | log.info("******************************************************************");
|
---|
46 |
|
---|
47 | // Extract UserInfo from Message.Assertion
|
---|
48 | UserType userInfo = new UserType();
|
---|
49 | if (message != null &&
|
---|
50 | message.getMessage() != null &&
|
---|
51 | message.getMessage().getAssertion() != null &&
|
---|
52 | message.getMessage().getAssertion().getUserInfo() != null)
|
---|
53 | {
|
---|
54 | userInfo = message.getMessage().getAssertion().getUserInfo();
|
---|
55 | }
|
---|
56 |
|
---|
57 | // Create EventIdentification
|
---|
58 | CodedValueType eventID = new CodedValueType();
|
---|
59 | eventID = AuditDataTransformHelper.createEventId(AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_SUB, AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_SUBSCRIBE, AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_SUB, AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_SUBSCRIBE);
|
---|
60 | auditMsg.setEventIdentification(AuditDataTransformHelper.createEventIdentification(AuditDataTransformConstants.EVENT_ACTION_CODE_CREATE, AuditDataTransformConstants.EVENT_OUTCOME_INDICATOR_SUCCESS, eventID));
|
---|
61 |
|
---|
62 | // Create Active Participant Section
|
---|
63 | if (userInfo != null)
|
---|
64 | {
|
---|
65 | AuditMessageType.ActiveParticipant participant = AuditDataTransformHelper.createActiveParticipantFromUser(userInfo, true);
|
---|
66 | auditMsg.getActiveParticipant().add(participant);
|
---|
67 | }
|
---|
68 |
|
---|
69 | /* Assign AuditSourceIdentification */
|
---|
70 | String communityId = "";
|
---|
71 | String communityName = "";
|
---|
72 | String patientId = "";
|
---|
73 |
|
---|
74 |
|
---|
75 | if ((message != null) &&
|
---|
76 | (message.getMessage() != null) &&
|
---|
77 | (message.getMessage().getSubscribe() != null))
|
---|
78 | {
|
---|
79 | PatientInfo patientInfo = extractPatientInfo(message.getMessage().getSubscribe());
|
---|
80 |
|
---|
81 | if (patientInfo != null)
|
---|
82 | {
|
---|
83 | communityId = patientInfo.getCommunityId();
|
---|
84 | communityName = patientInfo.getCommunityName();
|
---|
85 | patientId = patientInfo.getPatientId();
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | if (userInfo != null &&
|
---|
90 | userInfo.getOrg() != null)
|
---|
91 | {
|
---|
92 | if (userInfo.getOrg().getHomeCommunityId() != null)
|
---|
93 | {
|
---|
94 | communityId = userInfo.getOrg().getHomeCommunityId();
|
---|
95 | }
|
---|
96 | if (userInfo.getOrg().getName() != null)
|
---|
97 | {
|
---|
98 | communityName = userInfo.getOrg().getName();
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | AuditSourceIdentificationType auditSource = AuditDataTransformHelper.createAuditSourceIdentification(communityId, communityName);
|
---|
103 | auditMsg.getAuditSourceIdentification().add(auditSource);
|
---|
104 |
|
---|
105 | /* Assign ParticipationObjectIdentification */
|
---|
106 | ParticipantObjectIdentificationType participantObject = AuditDataTransformHelper.createParticipantObjectIdentification(patientId);
|
---|
107 |
|
---|
108 | // Fill in the message field with the contents of the event message
|
---|
109 | try
|
---|
110 | {
|
---|
111 | JAXBContext jc = JAXBContext.newInstance(org.oasis_open.docs.wsn.b_2.ObjectFactory.class, oasis.names.tc.ebxml_regrep.xsd.rim._3.ObjectFactory.class);
|
---|
112 | Marshaller marshaller = jc.createMarshaller();
|
---|
113 | ByteArrayOutputStream baOutStrm = new ByteArrayOutputStream();
|
---|
114 | baOutStrm.reset();
|
---|
115 | marshaller.marshal(message.getMessage().getSubscribe(), baOutStrm);
|
---|
116 | participantObject.setParticipantObjectQuery(baOutStrm.toByteArray());
|
---|
117 |
|
---|
118 | } catch (Exception e)
|
---|
119 | {
|
---|
120 | e.printStackTrace();
|
---|
121 | log.error("EXCEPTION when marshalling subscribe request: " + e);
|
---|
122 | throw new RuntimeException();
|
---|
123 | }
|
---|
124 | auditMsg.getParticipantObjectIdentification().add(participantObject);
|
---|
125 |
|
---|
126 |
|
---|
127 |
|
---|
128 | response.setAuditMessage(auditMsg);
|
---|
129 |
|
---|
130 | log.info("******************************************************************");
|
---|
131 | log.info("Exiting transformNhinSubscribeRequestToAuditMessage() method.");
|
---|
132 | log.info("******************************************************************");
|
---|
133 |
|
---|
134 | return response;
|
---|
135 | }
|
---|
136 |
|
---|
137 | public LogEventRequestType transformSubscribeResponseToAuditMessage(LogSubscribeResponseType message)
|
---|
138 | {
|
---|
139 | LogEventRequestType response = new LogEventRequestType();
|
---|
140 | AuditMessageType auditMsg = new AuditMessageType();
|
---|
141 | response.setDirection(message.getDirection());
|
---|
142 | response.setInterface(message.getInterface());
|
---|
143 |
|
---|
144 | log.info("******************************************************************");
|
---|
145 | log.info("Entering transformSubscribeResponseToAuditMessage() method.");
|
---|
146 | log.info("******************************************************************");
|
---|
147 |
|
---|
148 | // Extract UserInfo from Message.Assertion
|
---|
149 | UserType userInfo = new UserType();
|
---|
150 | if (message != null &&
|
---|
151 | message.getMessage() != null &&
|
---|
152 | message.getMessage().getAssertion() != null &&
|
---|
153 | message.getMessage().getAssertion().getUserInfo() != null)
|
---|
154 | {
|
---|
155 | userInfo = message.getMessage().getAssertion().getUserInfo();
|
---|
156 | }
|
---|
157 |
|
---|
158 | // Create EventIdentification
|
---|
159 | CodedValueType eventID = new CodedValueType();
|
---|
160 | eventID = AuditDataTransformHelper.createEventId(AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_SUB, AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_SUBSCRIBE, AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_SUB, AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_SUBSCRIBE);
|
---|
161 | auditMsg.setEventIdentification(AuditDataTransformHelper.createEventIdentification(AuditDataTransformConstants.EVENT_ACTION_CODE_CREATE, AuditDataTransformConstants.EVENT_OUTCOME_INDICATOR_SUCCESS, eventID));
|
---|
162 |
|
---|
163 | // Create Active Participant Section
|
---|
164 | if (userInfo != null)
|
---|
165 | {
|
---|
166 | AuditMessageType.ActiveParticipant participant = AuditDataTransformHelper.createActiveParticipantFromUser(userInfo, true);
|
---|
167 | auditMsg.getActiveParticipant().add(participant);
|
---|
168 | }
|
---|
169 |
|
---|
170 | String communityId = "";
|
---|
171 | String communityName = "";
|
---|
172 | if (userInfo != null &&
|
---|
173 | userInfo.getOrg() != null)
|
---|
174 | {
|
---|
175 | if (userInfo.getOrg().getHomeCommunityId() != null)
|
---|
176 | {
|
---|
177 | communityId = userInfo.getOrg().getHomeCommunityId();
|
---|
178 | }
|
---|
179 | if (userInfo.getOrg().getName() != null)
|
---|
180 | {
|
---|
181 | communityName = userInfo.getOrg().getName();
|
---|
182 | }
|
---|
183 | }
|
---|
184 |
|
---|
185 | AuditSourceIdentificationType auditSource = AuditDataTransformHelper.createAuditSourceIdentification(communityId, communityName);
|
---|
186 | auditMsg.getAuditSourceIdentification().add(auditSource);
|
---|
187 |
|
---|
188 | String patientId = "unknown";
|
---|
189 | /* Assign ParticipationObjectIdentification */
|
---|
190 | ParticipantObjectIdentificationType participantObject = AuditDataTransformHelper.createParticipantObjectIdentification(patientId);
|
---|
191 |
|
---|
192 | // Fill in the message field with the contents of the event message
|
---|
193 | try
|
---|
194 | {
|
---|
195 | JAXBContext jc = JAXBContext.newInstance("org.oasis_open.docs.wsn.b_2");
|
---|
196 | Marshaller marshaller = jc.createMarshaller();
|
---|
197 | ByteArrayOutputStream baOutStrm = new ByteArrayOutputStream();
|
---|
198 | baOutStrm.reset();
|
---|
199 | marshaller.marshal(message.getMessage().getSubscribeResponse(), baOutStrm);
|
---|
200 |
|
---|
201 | participantObject.setParticipantObjectQuery(baOutStrm.toByteArray());
|
---|
202 | } catch (Exception e)
|
---|
203 | {
|
---|
204 | e.printStackTrace();
|
---|
205 | log.error("EXCEPTION when marshalling subscribe response: " + e);
|
---|
206 | throw new RuntimeException();
|
---|
207 | }
|
---|
208 | auditMsg.getParticipantObjectIdentification().add(participantObject);
|
---|
209 |
|
---|
210 |
|
---|
211 |
|
---|
212 |
|
---|
213 | response.setAuditMessage(auditMsg);
|
---|
214 |
|
---|
215 | log.info("******************************************************************");
|
---|
216 | log.info("Exiting transformSubscribeResponseToAuditMessage() method.");
|
---|
217 | log.info("******************************************************************");
|
---|
218 |
|
---|
219 | return response;
|
---|
220 | }
|
---|
221 |
|
---|
222 | private PatientInfo extractPatientInfo(Subscribe subscribe)
|
---|
223 | {
|
---|
224 | PatientInfo patientInfo = new PatientInfo();
|
---|
225 | if (subscribe != null)
|
---|
226 | {
|
---|
227 | AdhocQueryType adhocQuery = getAdhocQuery(subscribe);
|
---|
228 | if (adhocQuery != null)
|
---|
229 | {
|
---|
230 | String formattedPatientId = getFormattedPatientId(adhocQuery);
|
---|
231 | if (NullChecker.isNotNullish(formattedPatientId))
|
---|
232 | {
|
---|
233 | patientInfo.setPatientId(PatientIdFormatUtil.parsePatientId(formattedPatientId));
|
---|
234 | patientInfo.setCommunityId(PatientIdFormatUtil.parseCommunityId(formattedPatientId));
|
---|
235 | }
|
---|
236 | }
|
---|
237 | }
|
---|
238 | return patientInfo;
|
---|
239 | }
|
---|
240 |
|
---|
241 | private AdhocQueryType getAdhocQuery(Subscribe nhinSubscribe)
|
---|
242 | {
|
---|
243 | AdhocQueryType adhocQuery = null;
|
---|
244 | log.info("begin getAdhocQuery");
|
---|
245 | List<Object> any = nhinSubscribe.getAny();
|
---|
246 | log.info("found " + any.size() + " any item(s)");
|
---|
247 |
|
---|
248 |
|
---|
249 | for (Object anyItem : any)
|
---|
250 | {
|
---|
251 | log.info("anyItem=" + anyItem);
|
---|
252 | if (anyItem instanceof oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType)
|
---|
253 | {
|
---|
254 | adhocQuery = (AdhocQueryType) anyItem;
|
---|
255 | }
|
---|
256 | if (anyItem instanceof JAXBElement)
|
---|
257 | {
|
---|
258 | log.info("jaxbelement.getValue=" + ((JAXBElement) anyItem).getValue());
|
---|
259 | if (((JAXBElement) anyItem).getValue() instanceof AdhocQueryType)
|
---|
260 | {
|
---|
261 | adhocQuery = (AdhocQueryType) ((JAXBElement) anyItem).getValue();
|
---|
262 | } else
|
---|
263 | {
|
---|
264 | log.warn("unhandled anyitem jaxbelement value " + ((JAXBElement) anyItem).getValue());
|
---|
265 | }
|
---|
266 | } else
|
---|
267 | {
|
---|
268 | log.warn("unhandled anyitem " + anyItem);
|
---|
269 | }
|
---|
270 | }
|
---|
271 | log.info("end getAdhocQuery");
|
---|
272 | return adhocQuery;
|
---|
273 | }
|
---|
274 |
|
---|
275 | private String getFormattedPatientId(AdhocQueryType adhocQuery)
|
---|
276 | {
|
---|
277 | String formattedPatientId = null;
|
---|
278 | List<SlotType1> slots = adhocQuery.getSlot();
|
---|
279 | if ((slots != null) && !(slots.isEmpty()))
|
---|
280 | {
|
---|
281 | for (SlotType1 slot : slots)
|
---|
282 | {
|
---|
283 | if (SLOT_NAME_PATIENT_ID.equals(slot.getName()))
|
---|
284 | {
|
---|
285 | if (slot.getValueList() != null)
|
---|
286 | {
|
---|
287 | List<String> slotValues = slot.getValueList().getValue();
|
---|
288 | for (String value : slotValues)
|
---|
289 | {
|
---|
290 | if (NullChecker.isNotNullish(value))
|
---|
291 | {
|
---|
292 | formattedPatientId = value;
|
---|
293 | break;
|
---|
294 | }
|
---|
295 | }
|
---|
296 | }
|
---|
297 | }
|
---|
298 | }
|
---|
299 | }
|
---|
300 | return formattedPatientId;
|
---|
301 | }
|
---|
302 |
|
---|
303 | private class PatientInfo
|
---|
304 | {
|
---|
305 |
|
---|
306 | private String communityId;
|
---|
307 | private String communityName;
|
---|
308 | private String patientId;
|
---|
309 |
|
---|
310 | public String getCommunityId()
|
---|
311 | {
|
---|
312 | return communityId;
|
---|
313 | }
|
---|
314 |
|
---|
315 | public void setCommunityId(String communityId)
|
---|
316 | {
|
---|
317 | this.communityId = communityId;
|
---|
318 | }
|
---|
319 |
|
---|
320 | public void setCommunityName(String communityName)
|
---|
321 | {
|
---|
322 | this.communityName = communityName;
|
---|
323 | }
|
---|
324 |
|
---|
325 | public String getCommunityName()
|
---|
326 | {
|
---|
327 | return communityName;
|
---|
328 | }
|
---|
329 |
|
---|
330 | public void setPatientId(String patientId)
|
---|
331 | {
|
---|
332 | this.patientId = patientId;
|
---|
333 | }
|
---|
334 |
|
---|
335 | public String getPatientId()
|
---|
336 | {
|
---|
337 | return patientId;
|
---|
338 | }
|
---|
339 | }
|
---|
340 |
|
---|
341 | }
|
---|