[507] | 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 java.util.List;
|
---|
| 8 | import java.io.ByteArrayOutputStream;
|
---|
| 9 | import javax.xml.bind.Marshaller;
|
---|
| 10 | import javax.xml.bind.JAXBElement;
|
---|
| 11 | import javax.xml.bind.JAXBContext;
|
---|
| 12 |
|
---|
| 13 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotType1;
|
---|
| 14 | import org.apache.commons.logging.Log;
|
---|
| 15 | import org.apache.commons.logging.LogFactory;
|
---|
| 16 |
|
---|
| 17 | import com.services.nhinc.schema.auditmessage.AuditMessageType;
|
---|
| 18 | import com.services.nhinc.schema.auditmessage.AuditSourceIdentificationType;
|
---|
| 19 | import com.services.nhinc.schema.auditmessage.CodedValueType;
|
---|
| 20 | import com.services.nhinc.schema.auditmessage.EventIdentificationType;
|
---|
| 21 | import com.services.nhinc.schema.auditmessage.ParticipantObjectIdentificationType;
|
---|
| 22 |
|
---|
| 23 | import oasis.names.tc.ebxml_regrep.xsd.query._3.AdhocQueryResponse;
|
---|
| 24 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.ExtrinsicObjectType;
|
---|
| 25 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.IdentifiableType;
|
---|
| 26 |
|
---|
| 27 | import gov.hhs.fha.nhinc.common.nhinccommon.UserType;
|
---|
| 28 | import gov.hhs.fha.nhinc.common.auditlog.LogAdhocQueryRequestType;
|
---|
| 29 | import gov.hhs.fha.nhinc.common.auditlog.LogAdhocQueryResultRequestType;
|
---|
| 30 | import gov.hhs.fha.nhinc.common.auditlog.LogEventRequestType;
|
---|
| 31 |
|
---|
| 32 | /**
|
---|
| 33 | *
|
---|
| 34 | * @author MFLYNN02
|
---|
| 35 | */
|
---|
| 36 | public class DocumentQueryTransforms {
|
---|
| 37 |
|
---|
| 38 | private static Log log = LogFactory.getLog(DocumentQueryTransforms.class);
|
---|
| 39 | private static final String PATIENT_ID_SLOT = "$XDSDocumentEntryPatientId";
|
---|
| 40 |
|
---|
| 41 | public static LogEventRequestType transformDocQueryReq2AuditMsg(LogAdhocQueryRequestType message) {
|
---|
| 42 | AuditMessageType auditMsg = new AuditMessageType();
|
---|
| 43 | LogEventRequestType response = new LogEventRequestType();
|
---|
| 44 | response.setDirection(message.getDirection());
|
---|
| 45 | response.setInterface(message.getInterface());
|
---|
| 46 |
|
---|
| 47 | log.info("******************************************************************");
|
---|
| 48 | log.info("Entering transformDocQueryReq2AuditMsg() method.");
|
---|
| 49 | log.info("******************************************************************");
|
---|
| 50 |
|
---|
| 51 | // Extract UserInfo from Message.Assertion
|
---|
| 52 | UserType userInfo = new UserType();
|
---|
| 53 | if (message != null &&
|
---|
| 54 | message.getMessage() != null &&
|
---|
| 55 | message.getMessage().getAssertion() != null &&
|
---|
| 56 | message.getMessage().getAssertion().getUserInfo() != null) {
|
---|
| 57 | userInfo = message.getMessage().getAssertion().getUserInfo();
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | // Create Event Identification Section
|
---|
| 62 | // TODO: Determine what to do with Event Code and Event Code System (either auto-generate or map in AdhocQueryRequest
|
---|
| 63 | CodedValueType eventId = AuditDataTransformHelper.createEventId(AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_DOC, AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_DOCQUERY, AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_DOC, AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_DOCQUERY);
|
---|
| 64 | EventIdentificationType eventIdentification = AuditDataTransformHelper.createEventIdentification(AuditDataTransformConstants.EVENT_ACTION_CODE_EXECUTE, AuditDataTransformConstants.EVENT_OUTCOME_INDICATOR_SUCCESS, eventId);
|
---|
| 65 | auditMsg.setEventIdentification(eventIdentification);
|
---|
| 66 |
|
---|
| 67 | // Create Active Participant Section
|
---|
| 68 | if (userInfo != null) {
|
---|
| 69 | AuditMessageType.ActiveParticipant participant = AuditDataTransformHelper.createActiveParticipantFromUser(userInfo, true);
|
---|
| 70 | auditMsg.getActiveParticipant().add(participant);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | // Create Audit Source Identification Section
|
---|
| 74 | AuditSourceIdentificationType auditSrcId = AuditDataTransformHelper.createAuditSourceIdentificationFromUser(userInfo);
|
---|
| 75 | auditMsg.getAuditSourceIdentification().add(auditSrcId);
|
---|
| 76 |
|
---|
| 77 | String patientId = "";
|
---|
| 78 | if (message != null &&
|
---|
| 79 | message.getMessage() != null &&
|
---|
| 80 | message.getMessage().getAdhocQueryRequest() != null &&
|
---|
| 81 | message.getMessage().getAdhocQueryRequest().getAdhocQuery() != null &&
|
---|
| 82 | message.getMessage().getAdhocQueryRequest().getAdhocQuery().getSlot() != null &&
|
---|
| 83 | message.getMessage().getAdhocQueryRequest().getAdhocQuery().getSlot().size() > 0) {
|
---|
| 84 | List<SlotType1> slotItemsList = message.getMessage().getAdhocQueryRequest().getAdhocQuery().getSlot();
|
---|
| 85 | for (SlotType1 slotItem : slotItemsList) {
|
---|
| 86 | if (slotItem != null) {
|
---|
| 87 | if (PATIENT_ID_SLOT.equals(slotItem.getName())) {
|
---|
| 88 | if (slotItem.getValueList() != null &&
|
---|
| 89 | slotItem.getValueList().getValue() != null &&
|
---|
| 90 | slotItem.getValueList().getValue().size() > 0) {
|
---|
| 91 | patientId = slotItem.getValueList().getValue().get(0);
|
---|
| 92 | break;
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | // Create Participation Object Identification Section
|
---|
| 99 | ParticipantObjectIdentificationType partObjId = new ParticipantObjectIdentificationType();
|
---|
| 100 | partObjId = AuditDataTransformHelper.createParticipantObjectIdentification(patientId);
|
---|
| 101 |
|
---|
| 102 | // Fill in the message field with the contents of the event message
|
---|
| 103 | try {
|
---|
| 104 | JAXBContext jc = JAXBContext.newInstance("oasis.names.tc.ebxml_regrep.xsd.query._3");
|
---|
| 105 | Marshaller marshaller = jc.createMarshaller();
|
---|
| 106 | ByteArrayOutputStream baOutStrm = new ByteArrayOutputStream();
|
---|
| 107 | baOutStrm.reset();
|
---|
| 108 | marshaller.marshal(message.getMessage().getAdhocQueryRequest(), baOutStrm);
|
---|
| 109 |
|
---|
| 110 | partObjId.setParticipantObjectQuery(baOutStrm.toByteArray());
|
---|
| 111 | } catch (Exception e) {
|
---|
| 112 | e.printStackTrace();
|
---|
| 113 | throw new RuntimeException();
|
---|
| 114 | }
|
---|
| 115 | auditMsg.getParticipantObjectIdentification().add(partObjId);
|
---|
| 116 | response.setAuditMessage(auditMsg);
|
---|
| 117 |
|
---|
| 118 | log.info("******************************************************************");
|
---|
| 119 | log.info("Exiting transformDocQueryReq2AuditMsg() method.");
|
---|
| 120 | log.info("******************************************************************");
|
---|
| 121 |
|
---|
| 122 | return response;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | public static LogEventRequestType transformDocQueryResp2AuditMsg(LogAdhocQueryResultRequestType message) {
|
---|
| 126 | AuditMessageType auditMsg = new AuditMessageType();
|
---|
| 127 | LogEventRequestType response = new LogEventRequestType();
|
---|
| 128 | response.setDirection(message.getDirection());
|
---|
| 129 | response.setInterface(message.getInterface());
|
---|
| 130 |
|
---|
| 131 | log.info("******************************************************************");
|
---|
| 132 | log.info("Entering transformDocQueryResp2AuditMsg() method.");
|
---|
| 133 | log.info("******************************************************************");
|
---|
| 134 |
|
---|
| 135 | // Extract UserInfo from Message.Assertion
|
---|
| 136 | UserType userInfo = new UserType();
|
---|
| 137 | if (message != null &&
|
---|
| 138 | message.getMessage() != null &&
|
---|
| 139 | message.getMessage().getAssertion() != null &&
|
---|
| 140 | message.getMessage().getAssertion().getUserInfo() != null) {
|
---|
| 141 | userInfo = message.getMessage().getAssertion().getUserInfo();
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | // Create Event Identification Section
|
---|
| 145 | // TODO: Figure out what to do with Event Code and Event Code System
|
---|
| 146 | CodedValueType eventId = AuditDataTransformHelper.createEventId(AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_DOC, AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_DOCQUERY, AuditDataTransformConstants.EVENT_ID_CODE_SYS_NAME_DOC, AuditDataTransformConstants.EVENT_ID_DISPLAY_NAME_DOCQUERY);
|
---|
| 147 | EventIdentificationType eventIdentification = AuditDataTransformHelper.createEventIdentification(AuditDataTransformConstants.EVENT_ACTION_CODE_EXECUTE, AuditDataTransformConstants.EVENT_OUTCOME_INDICATOR_SUCCESS, eventId);
|
---|
| 148 | auditMsg.setEventIdentification(eventIdentification);
|
---|
| 149 |
|
---|
| 150 | // Create Active Participant Section
|
---|
| 151 | if (userInfo != null) {
|
---|
| 152 | AuditMessageType.ActiveParticipant participant = AuditDataTransformHelper.createActiveParticipantFromUser(userInfo, true);
|
---|
| 153 | auditMsg.getActiveParticipant().add(participant);
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | if ((message != null) &&
|
---|
| 157 | (message.getMessage().getAdhocQueryResponse().getRegistryObjectList() != null) &&
|
---|
| 158 | (message.getMessage().getAdhocQueryResponse().getRegistryObjectList().getIdentifiable() != null) &&
|
---|
| 159 | (message.getMessage().getAdhocQueryResponse().getRegistryObjectList().getIdentifiable().size() > 0)) {
|
---|
| 160 | // Create Audit Source Identification Section
|
---|
| 161 | List<JAXBElement<? extends IdentifiableType>> objList = message.getMessage().getAdhocQueryResponse().getRegistryObjectList().getIdentifiable();
|
---|
| 162 | ExtrinsicObjectType oExtObj = null;
|
---|
| 163 |
|
---|
| 164 | // Look for the first ExtrinsicObject type.. We will use that one to extract the data.
|
---|
| 165 | //-------------------------------------------------------------------------------------
|
---|
| 166 | for (int i = 0; i < objList.size(); i++) {
|
---|
| 167 | JAXBElement<? extends IdentifiableType> oJAXBObj = objList.get(i);
|
---|
| 168 |
|
---|
| 169 | if ((oJAXBObj != null) &&
|
---|
| 170 | (oJAXBObj.getDeclaredType() != null) &&
|
---|
| 171 | (oJAXBObj.getDeclaredType().getCanonicalName() != null) &&
|
---|
| 172 | (oJAXBObj.getDeclaredType().getCanonicalName().equals("oasis.names.tc.ebxml_regrep.xsd.rim._3.ExtrinsicObjectType")) &&
|
---|
| 173 | (oJAXBObj.getValue() != null)) {
|
---|
| 174 | oExtObj = (ExtrinsicObjectType) oJAXBObj.getValue();
|
---|
| 175 | break; // We have what we want let's get out of here...
|
---|
| 176 | }
|
---|
| 177 | } //for (int i = 0; i < objList.size(); i++)
|
---|
| 178 |
|
---|
| 179 | // Home Community ID
|
---|
| 180 | //-------------------
|
---|
| 181 | if ((oExtObj != null) &&
|
---|
| 182 | (oExtObj.getHome() != null) &&
|
---|
| 183 | (oExtObj.getHome().length() > 0)) {
|
---|
| 184 | String communityId = oExtObj.getHome();
|
---|
| 185 | AuditSourceIdentificationType auditSrcId = AuditDataTransformHelper.createAuditSourceIdentification(communityId, null);
|
---|
| 186 | auditMsg.getAuditSourceIdentification().add(auditSrcId);
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 |
|
---|
| 190 | // Patient ID
|
---|
| 191 | //------------
|
---|
| 192 | ParticipantObjectIdentificationType partObjId = new ParticipantObjectIdentificationType();
|
---|
| 193 | String patientId = "";
|
---|
| 194 | if (oExtObj != null &&
|
---|
| 195 | oExtObj.getExternalIdentifier() != null &&
|
---|
| 196 | oExtObj.getExternalIdentifier().size() > 0) {
|
---|
| 197 | patientId = oExtObj.getExternalIdentifier().get(0).getValue();
|
---|
| 198 | }
|
---|
| 199 | if (userInfo != null) {
|
---|
| 200 | partObjId = AuditDataTransformHelper.createParticipantObjectIdentification(patientId);
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | // Fill in the message field with the contents of the event message
|
---|
| 204 | try {
|
---|
| 205 | JAXBContext jc = JAXBContext.newInstance("oasis.names.tc.ebxml_regrep.xsd.query._3");
|
---|
| 206 | Marshaller marshaller = jc.createMarshaller();
|
---|
| 207 | ByteArrayOutputStream baOutStrm = new ByteArrayOutputStream();
|
---|
| 208 | baOutStrm.reset();
|
---|
| 209 | marshaller.marshal(message.getMessage().getAdhocQueryResponse(), baOutStrm);
|
---|
| 210 |
|
---|
| 211 | partObjId.setParticipantObjectQuery(baOutStrm.toByteArray());
|
---|
| 212 | } catch (Exception e) {
|
---|
| 213 | e.printStackTrace();
|
---|
| 214 | throw new RuntimeException();
|
---|
| 215 | }
|
---|
| 216 | auditMsg.getParticipantObjectIdentification().add(partObjId);
|
---|
| 217 | }
|
---|
| 218 | response.setAuditMessage(auditMsg);
|
---|
| 219 |
|
---|
| 220 | log.info("******************************************************************");
|
---|
| 221 | log.info("Exiting transformDocQueryResp2AuditMsg() method.");
|
---|
| 222 | log.info("******************************************************************");
|
---|
| 223 | return response;
|
---|
| 224 | }
|
---|
| 225 | }
|
---|