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