[507] | 1 | package gov.hhs.fha.nhinc.subscription.dte;
|
---|
| 2 |
|
---|
| 3 | //import gov.hhs.fha.nhinc.NHINCLib.NullChecker;
|
---|
| 4 | import gov.hhs.fha.nhinc.common.subscription.CriterionType;
|
---|
| 5 | import gov.hhs.fha.nhinc.common.subscription.KeyValuePairType;
|
---|
| 6 | import gov.hhs.fha.nhinc.common.subscription.SubscriptionItemType;
|
---|
| 7 | import gov.hhs.fha.nhinc.nhinclib.NullChecker;
|
---|
| 8 | import gov.hhs.fha.nhinc.util.format.DocumentClassCodeParser;
|
---|
| 9 | import gov.hhs.healthit.nhin.cdc.CdcBioPackageSubscriptionCriteriaType;
|
---|
| 10 | import gov.hhs.healthit.nhin.cdc.CdcBioPackageSubscriptionCriteriaType.Frequency;
|
---|
| 11 | import gov.hhs.healthit.nhin.cdc.MessageTypesType;
|
---|
| 12 | import java.math.BigInteger;
|
---|
| 13 | import java.util.ArrayList;
|
---|
| 14 | import java.util.List;
|
---|
| 15 | import javax.xml.bind.JAXBElement;
|
---|
| 16 | //import javax.xml.parsers.DocumentBuilderFactory;
|
---|
| 17 | //import javax.xml.parsers.ParserConfigurationException;
|
---|
| 18 | import javax.xml.ws.wsaddressing.W3CEndpointReference;
|
---|
| 19 | //import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
|
---|
| 20 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType;
|
---|
| 21 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotType1;
|
---|
| 22 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.ValueListType;
|
---|
| 23 | import org.oasis_open.docs.wsn.b_2.FilterType;
|
---|
| 24 | import org.oasis_open.docs.wsn.b_2.Subscribe;
|
---|
| 25 |
|
---|
| 26 | //import gov.hhs.healthit.nhin.cdc.CdcBioPackageSubscriptionCriteriaType.Frequency;
|
---|
| 27 | import org.oasis_open.docs.wsn.b_2.Subscribe.SubscriptionPolicy;
|
---|
| 28 | //import gov.hhs.healthit.nhin.cdc.MessageTypesType;
|
---|
| 29 | //import oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotType1;
|
---|
| 30 | //import oasis.names.tc.ebxml_regrep.xsd.rim._3.ValueListType;
|
---|
| 31 | //
|
---|
| 32 | //import gov.hhs.fha.nhinc.subscription.*;
|
---|
| 33 | //import gov.hhs.fha.nhinc.util.format.DocumentClassCodeParser;
|
---|
| 34 | //import gov.hhs.healthit.nhin.cdc.CdcBioPackageSubscriptionCriteriaType;
|
---|
| 35 | //import java.math.BigInteger;
|
---|
| 36 | //import java.util.ArrayList;
|
---|
| 37 | //import java.util.List;
|
---|
| 38 | //import javax.xml.bind.JAXBElement;
|
---|
| 39 | //import javax.xml.parsers.DocumentBuilderFactory;
|
---|
| 40 | //import javax.xml.parsers.ParserConfigurationException;
|
---|
| 41 | //import javax.xml.ws.wsaddressing.W3CEndpointReference;
|
---|
| 42 | //import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
|
---|
| 43 | //import oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType;
|
---|
| 44 | //import oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType;
|
---|
| 45 | //import oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotType1;
|
---|
| 46 | //import org.oasis_open.docs.wsn.b_2.*;
|
---|
| 47 | //import org.oasis_open.docs.wsn.b_2.Subscribe.SubscriptionPolicy;
|
---|
| 48 | /**
|
---|
| 49 | *
|
---|
| 50 | * @author rayj
|
---|
| 51 | */
|
---|
| 52 | public class NhinSubscribeBuilder {
|
---|
| 53 |
|
---|
| 54 | private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(NhinSubscribeBuilder.class);
|
---|
| 55 |
|
---|
| 56 | public static Subscribe transformInternalSubscriptionItemToNhinSubscribe(SubscriptionItemType subscriptionItem) {
|
---|
| 57 | log.debug("begin transformInternalSubscriptionItemToNhinSubscribe");
|
---|
| 58 | Subscribe nhinSubscribe = null;
|
---|
| 59 |
|
---|
| 60 | String topic = TopicHelper.GetTopicValue(subscriptionItem);
|
---|
| 61 | if (topic == null) {
|
---|
| 62 | topic = "";
|
---|
| 63 | }
|
---|
| 64 | if (topic.contentEquals("nhin-cdc:CdcBioPackage")) {
|
---|
| 65 | nhinSubscribe = transformInternalSubscriptionItemToNhinSubscribeCdc(subscriptionItem);
|
---|
| 66 | } else {
|
---|
| 67 | nhinSubscribe = transformInternalSubscriptionItemToNhinSubscribeDocument(subscriptionItem);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | log.debug("end transformInternalSubscriptionItemToNhinSubscribe");
|
---|
| 71 | return nhinSubscribe;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | public static Subscribe transformInternalSubscriptionItemToNhinSubscribeCdc(SubscriptionItemType subscriptionItem) {
|
---|
| 75 | log.debug("begin transformInternalSubscriptionItemToNhinSubscribeCdc");
|
---|
| 76 | Subscribe nhinSubscribe = new Subscribe();
|
---|
| 77 |
|
---|
| 78 | String notificationConsumerEndpointAddress = Configuration.getlocalNotificationConsumerEndpointAddress();
|
---|
| 79 | String userAddress = SubscriptionItemHelper.getSubscriberUserAddress(subscriptionItem);
|
---|
| 80 | AppendConsumerReference(nhinSubscribe, notificationConsumerEndpointAddress, userAddress);
|
---|
| 81 |
|
---|
| 82 | //filter
|
---|
| 83 | gov.hhs.fha.nhinc.common.subscription.TopicExpressionType internalTopic = TopicHelper.GetTopic(subscriptionItem);
|
---|
| 84 | if (internalTopic == null) {
|
---|
| 85 | internalTopic = TopicBuilder.createCdcBioPackageTopic();
|
---|
| 86 | }
|
---|
| 87 | FilterType filter = new FilterType();
|
---|
| 88 | org.oasis_open.docs.wsn.b_2.TopicExpressionType topicExpression = new org.oasis_open.docs.wsn.b_2.TopicExpressionType();
|
---|
| 89 |
|
---|
| 90 | topicExpression.setDialect(internalTopic.getDialect());
|
---|
| 91 | topicExpression.getContent().add(internalTopic.getValue());
|
---|
| 92 |
|
---|
| 93 | org.oasis_open.docs.wsn.b_2.ObjectFactory factory = new org.oasis_open.docs.wsn.b_2.ObjectFactory();
|
---|
| 94 | JAXBElement<org.oasis_open.docs.wsn.b_2.TopicExpressionType> topicExpressionJB = factory.createTopicExpression(topicExpression);
|
---|
| 95 | filter.getAny().add(topicExpressionJB);
|
---|
| 96 | nhinSubscribe.setFilter(filter);
|
---|
| 97 |
|
---|
| 98 | //subscription policy
|
---|
| 99 | SubscriptionPolicy nhinSubscriptionPolicy = new SubscriptionPolicy();
|
---|
| 100 | CdcBioPackageSubscriptionCriteriaType subscriptionCriteria = new CdcBioPackageSubscriptionCriteriaType();
|
---|
| 101 |
|
---|
| 102 | Frequency frequency = new Frequency();
|
---|
| 103 | subscriptionCriteria.setFrequency(frequency);
|
---|
| 104 |
|
---|
| 105 | MessageTypesType messageTypes = new MessageTypesType();
|
---|
| 106 | subscriptionCriteria.setMessageTypes(messageTypes);
|
---|
| 107 | BigInteger valueNumeric;
|
---|
| 108 |
|
---|
| 109 | for (KeyValuePairType policyItem : subscriptionItem.getSubscriptionCriteria().getSubscriptionPolicy().getGenericPolicyItems().getKeyValuePair()) {
|
---|
| 110 | if ("FrequenceUnits".contentEquals(policyItem.getKey())) {
|
---|
| 111 | valueNumeric = convertToBigInteger(policyItem.getValue());
|
---|
| 112 | frequency.setFrequencyUnits(valueNumeric);
|
---|
| 113 | } else if ("FrequenceDuration".contentEquals(policyItem.getKey())) {
|
---|
| 114 | frequency.setFrequencyDuration(policyItem.getValue());
|
---|
| 115 | } else if ("SizeThreshold".contentEquals(policyItem.getKey())) {
|
---|
| 116 | valueNumeric = convertToBigInteger(policyItem.getValue());
|
---|
| 117 | subscriptionCriteria.setSizeThreshold(valueNumeric);
|
---|
| 118 | } else if ("MessageType".contentEquals(policyItem.getKey())) {
|
---|
| 119 | subscriptionCriteria.getMessageTypes().getMessageType().add(policyItem.getValue());
|
---|
| 120 | } else {
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | gov.hhs.healthit.nhin.cdc.ObjectFactory cdcSubscriptionCriteriaFactory = new gov.hhs.healthit.nhin.cdc.ObjectFactory();
|
---|
| 125 | JAXBElement<CdcBioPackageSubscriptionCriteriaType> subscriptionCriteriaJB = cdcSubscriptionCriteriaFactory.createCdcBioPackageSubscriptionCriteria(subscriptionCriteria);
|
---|
| 126 |
|
---|
| 127 | nhinSubscriptionPolicy.getAny().add(subscriptionCriteriaJB);
|
---|
| 128 | nhinSubscribe.setSubscriptionPolicy(nhinSubscriptionPolicy);
|
---|
| 129 |
|
---|
| 130 | log.debug("end transformInternalSubscriptionItemToNhinSubscribeCdc");
|
---|
| 131 | return nhinSubscribe;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | private static BigInteger convertToBigInteger(String value) {
|
---|
| 135 | BigInteger valueNumericBigInteger = new BigInteger(value);
|
---|
| 136 | return valueNumericBigInteger;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | public static Subscribe transformInternalSubscriptionItemToNhinSubscribeDocument(SubscriptionItemType subscriptionItem) {
|
---|
| 140 | log.debug("begin transformInternalSubscriptionItemToNhinSubscribeDocument");
|
---|
| 141 | Subscribe nhinSubscribe = new Subscribe();
|
---|
| 142 |
|
---|
| 143 | String notificationConsumerEndpointAddress = Configuration.getlocalNotificationConsumerEndpointAddress();
|
---|
| 144 | String userAddress = SubscriptionItemHelper.getSubscriberUserAddress(subscriptionItem);
|
---|
| 145 | AppendConsumerReference(nhinSubscribe, notificationConsumerEndpointAddress, userAddress);
|
---|
| 146 |
|
---|
| 147 | // Add topic expression
|
---|
| 148 | //filter
|
---|
| 149 | gov.hhs.fha.nhinc.common.subscription.TopicExpressionType internalTopic = TopicHelper.GetTopic(subscriptionItem);
|
---|
| 150 | if (internalTopic == null) {
|
---|
| 151 | internalTopic = TopicBuilder.createDocumentTopic();
|
---|
| 152 | }
|
---|
| 153 | FilterType filter = new FilterType();
|
---|
| 154 | org.oasis_open.docs.wsn.b_2.TopicExpressionType topicExpression = new org.oasis_open.docs.wsn.b_2.TopicExpressionType();
|
---|
| 155 |
|
---|
| 156 | topicExpression.setDialect(internalTopic.getDialect());
|
---|
| 157 | topicExpression.getContent().add(internalTopic.getValue());
|
---|
| 158 |
|
---|
| 159 | org.oasis_open.docs.wsn.b_2.ObjectFactory wsntFactory = new org.oasis_open.docs.wsn.b_2.ObjectFactory();
|
---|
| 160 | JAXBElement<org.oasis_open.docs.wsn.b_2.TopicExpressionType> topicExpressionJB = wsntFactory.createTopicExpression(topicExpression);
|
---|
| 161 | filter.getAny().add(topicExpressionJB);
|
---|
| 162 | nhinSubscribe.setFilter(filter);
|
---|
| 163 |
|
---|
| 164 | //begin adhoc query
|
---|
| 165 | oasis.names.tc.ebxml_regrep.xsd.rim._3.ObjectFactory factory = new oasis.names.tc.ebxml_regrep.xsd.rim._3.ObjectFactory();
|
---|
| 166 | AdhocQueryType adhocQuery = factory.createAdhocQueryType();
|
---|
| 167 |
|
---|
| 168 | adhocQuery.setId(Constants.AdhocQueryId);
|
---|
| 169 |
|
---|
| 170 | String adhocQueryFormttedPatientId = SubscriptionItemHelper.getSubscriptionCriteriaSubscribeePatientInAdhocQueryFormat(subscriptionItem);
|
---|
| 171 | if (NullChecker.isNotNullish(adhocQueryFormttedPatientId)) {
|
---|
| 172 | adhocQuery.getSlot().add(SlotTypeFactory(Constants.PatientIdSlotName, adhocQueryFormttedPatientId));
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 |
|
---|
| 177 | List<String> documentClassCodeList = new ArrayList<String>();
|
---|
| 178 | List<CriterionType> criterionList = extractCriterionList(subscriptionItem);
|
---|
| 179 | if (criterionList != null) {
|
---|
| 180 | for (CriterionType criterion : criterionList) {
|
---|
| 181 | if (criterion.getKey().contentEquals(Constants.DocumentClassCodeSlotName)) {
|
---|
| 182 | documentClassCodeList.add(criterion.getValue());
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 | }
|
---|
| 186 | String documentClassCode = DocumentClassCodeParser.buildDocumentClassCodeItem(documentClassCodeList);
|
---|
| 187 | SlotType1 slot = SlotTypeFactory(Constants.DocumentClassCodeSlotName, documentClassCode);
|
---|
| 188 | adhocQuery.getSlot().add(slot);
|
---|
| 189 |
|
---|
| 190 | AppendAdhocQuery(nhinSubscribe, adhocQuery);
|
---|
| 191 |
|
---|
| 192 | log.debug("end transformInternalSubscriptionItemToNhinSubscribeDocument");
|
---|
| 193 | return nhinSubscribe;
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | private static List<CriterionType> extractCriterionList(SubscriptionItemType subscriptionItem) {
|
---|
| 197 | List<CriterionType> criterionList = null;
|
---|
| 198 | if (subscriptionItem != null && subscriptionItem.getSubscriptionCriteria() != null && subscriptionItem.getSubscriptionCriteria().getCriteria() != null) {
|
---|
| 199 | criterionList = subscriptionItem.getSubscriptionCriteria().getCriteria().getCriterion();
|
---|
| 200 | }
|
---|
| 201 | return criterionList;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | public static void AppendAdhocQuery(Subscribe subscribe, AdhocQueryType adhocQuery) {
|
---|
| 205 | oasis.names.tc.ebxml_regrep.xsd.rim._3.ObjectFactory factory = new oasis.names.tc.ebxml_regrep.xsd.rim._3.ObjectFactory();
|
---|
| 206 | JAXBElement<AdhocQueryType> adhodQueryElem = factory.createAdhocQuery(adhocQuery);
|
---|
| 207 | subscribe.getAny().add(adhodQueryElem);
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | public static void AppendConsumerReference(Subscribe subscribe, String notificationConsumerEndpointAddress, String userAddress) {
|
---|
| 211 | W3CEndpointReference ref = ConsumerReferenceHelper.CreateConsumerReference(notificationConsumerEndpointAddress, userAddress);
|
---|
| 212 | subscribe.setConsumerReference(ref);
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | public static SlotType1 SlotTypeFactory(String slotName, String slotValue) {
|
---|
| 216 | SlotType1 slot = new SlotType1();
|
---|
| 217 | slot.setName(slotName);
|
---|
| 218 |
|
---|
| 219 | ValueListType valueList = new ValueListType();
|
---|
| 220 | slot.setValueList(valueList);
|
---|
| 221 |
|
---|
| 222 | valueList.getValue().add(slotValue);
|
---|
| 223 |
|
---|
| 224 | return slot;
|
---|
| 225 | }
|
---|
| 226 | }
|
---|