[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.subscription.dte;
|
---|
| 6 |
|
---|
| 7 | //import gov.hhs.fha.nhinc.NHINCLib.NullChecker;
|
---|
| 8 | import gov.hhs.fha.nhinc.common.nhinccommon.HomeCommunityType;
|
---|
| 9 | import gov.hhs.fha.nhinc.common.nhinccommon.QualifiedSubjectIdentifierType;
|
---|
| 10 | import gov.hhs.fha.nhinc.common.subscription.CommunityType;
|
---|
| 11 | import gov.hhs.fha.nhinc.common.subscription.CriteriaType;
|
---|
| 12 | import gov.hhs.fha.nhinc.common.subscription.CriterionType;
|
---|
| 13 | import gov.hhs.fha.nhinc.common.subscription.SubscribeeType;
|
---|
| 14 | import gov.hhs.fha.nhinc.common.subscription.SubscriberType;
|
---|
| 15 | import gov.hhs.fha.nhinc.common.subscription.SubscriptionCriteriaType;
|
---|
| 16 | import gov.hhs.fha.nhinc.common.subscription.SubscriptionItemType;
|
---|
| 17 | import gov.hhs.fha.nhinc.common.subscription.TopicExpressionType;
|
---|
| 18 | import gov.hhs.fha.nhinc.common.subscriptiondte.TransformNhinSubscribeToInternalSubscribeRequestType;
|
---|
| 19 | import gov.hhs.fha.nhinc.common.subscriptiondte.TransformNhinSubscribeToInternalSubscribeResponseType;
|
---|
| 20 |
|
---|
| 21 | //import java.util.logging.Level;
|
---|
| 22 | import gov.hhs.fha.nhinc.properties.PropertyAccessException;
|
---|
| 23 | import gov.hhs.fha.nhinc.properties.PropertyAccessor;
|
---|
| 24 | import gov.hhs.fha.nhinc.util.format.DocumentClassCodeParser;
|
---|
| 25 | import gov.hhs.fha.nhinc.util.format.PatientIdFormatUtil;
|
---|
| 26 | import java.util.List;
|
---|
| 27 | import javax.xml.transform.dom.DOMResult;
|
---|
| 28 | import javax.xml.ws.wsaddressing.W3CEndpointReference;
|
---|
| 29 | import org.oasis_open.docs.wsn.b_2.Subscribe;
|
---|
| 30 | //import java.util.logging.Logger;
|
---|
| 31 | import org.w3c.dom.Document;
|
---|
| 32 | //import oasis.names.tc.ebxml_regrep.xsd.rim._3.ValueListType;
|
---|
| 33 | import org.w3c.dom.Node;
|
---|
| 34 | //import org.netbeans.xml.schema.homecommunity.HomeCommunity;
|
---|
| 35 | //import org.oasis_open.docs.wsn.b_2.FilterType;
|
---|
| 36 | //import org.oasis_open.docs.wsn.b_2.Subscribe.SubscriptionPolicy;
|
---|
| 37 | //import org.w3c.dom.*;
|
---|
| 38 | //import gov.hhs.fha.nhinc.subscription.*;
|
---|
| 39 | //import gov.hhs.fha.nhinc.util.format.PatientIdFormatUtil;
|
---|
| 40 | //import java.util.ArrayList;
|
---|
| 41 | //import java.util.List;
|
---|
| 42 | //import javax.xml.bind.JAXBElement;
|
---|
| 43 | //import javax.xml.transform.dom.DOMResult;
|
---|
| 44 | //import javax.xml.ws.wsaddressing.W3CEndpointReference;
|
---|
| 45 | //import org.netbeans.xml.schema.QualifiedSubjectIdentifierType.QualifiedSubjectIdentifierType;
|
---|
| 46 | //import org.oasis_open.docs.wsn.b_2.Subscribe;
|
---|
| 47 | //import javax.xml.xpath.*;
|
---|
| 48 | //import oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType;
|
---|
| 49 | //import oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotType1;
|
---|
| 50 | //import gov.hhs.fha.nhinc.properties.PropertyAccessException;
|
---|
| 51 | //import gov.hhs.fha.nhinc.properties.PropertyAccessor;
|
---|
| 52 | //import gov.hhs.fha.nhinc.util.format.DocumentClassCodeParser;
|
---|
| 53 | /**
|
---|
| 54 | *
|
---|
| 55 | * @author rayj
|
---|
| 56 | */
|
---|
| 57 | public class TransformNhinSubscribeToInternalSubscribeHelper {
|
---|
| 58 |
|
---|
| 59 | private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(TransformNhinSubscribeToInternalSubscribeHelper.class);
|
---|
| 60 |
|
---|
| 61 | public static TransformNhinSubscribeToInternalSubscribeResponseType transformNhinSubscribeToInternalSubscribe(TransformNhinSubscribeToInternalSubscribeRequestType transformNhinSubscribeToInternalSubscribe) {
|
---|
| 62 | Subscribe nhinSubscribe = transformNhinSubscribeToInternalSubscribe.getSubscribe();
|
---|
| 63 | SubscriptionItemType subscriptionItem = TransformNhinSubscribeToInternalSubscribe(nhinSubscribe);
|
---|
| 64 | TransformNhinSubscribeToInternalSubscribeResponseType response = new TransformNhinSubscribeToInternalSubscribeResponseType();
|
---|
| 65 | response.setSubscriptionItem(subscriptionItem);
|
---|
| 66 | return response;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | public static SubscriptionItemType TransformNhinSubscribeToInternalSubscribe(Subscribe nhinSubscribe) {
|
---|
| 70 | log.info("begin TransformNhinSubscribeToInternalSubscribe");
|
---|
| 71 | SubscriptionItemType SubscriptionItem = new SubscriptionItemType();
|
---|
| 72 |
|
---|
| 73 | SubscriberType subscriber = new SubscriberType();
|
---|
| 74 | SubscriptionItem.setSubscriber(subscriber);
|
---|
| 75 |
|
---|
| 76 | String consumerReferenceAddress = getConsumerReferenceAddress(nhinSubscribe);
|
---|
| 77 | subscriber.setNotificationConsumerEndpointAddress(consumerReferenceAddress);
|
---|
| 78 | subscriber.setUserAddress(getConsumerReferenceUserAddress(nhinSubscribe));
|
---|
| 79 |
|
---|
| 80 | SubscribeeType subscribee = new SubscribeeType();
|
---|
| 81 | SubscriptionItem.setSubscribee(subscribee);
|
---|
| 82 | CommunityType myCommunity = Configuration.getMyCommunity();
|
---|
| 83 | subscribee.setCommunity(myCommunity);
|
---|
| 84 | subscribee.setNotificationProducerEndpointAddress(getNotificationConsumerEndpointAddress());
|
---|
| 85 |
|
---|
| 86 | SubscriptionCriteriaType criteria = new SubscriptionCriteriaType();
|
---|
| 87 | SubscriptionItem.setSubscriptionCriteria(criteria);
|
---|
| 88 | criteria.setSubscribeePatient(getSubscriptionCriteriaPatient(nhinSubscribe));
|
---|
| 89 |
|
---|
| 90 | CriteriaType genericCriteria = new CriteriaType();
|
---|
| 91 | criteria.setCriteria(genericCriteria);
|
---|
| 92 |
|
---|
| 93 | FillCriteriaList(genericCriteria.getCriterion(), nhinSubscribe);
|
---|
| 94 |
|
---|
| 95 |
|
---|
| 96 | org.oasis_open.docs.wsn.b_2.TopicExpressionType nhinTopicExpression = TopicHelper.GetTopic(nhinSubscribe);
|
---|
| 97 | TopicExpressionType entityTopic = TopicHelper.ConvertNhinTopicToEntityTopic(nhinTopicExpression);
|
---|
| 98 | if (entityTopic != null) {
|
---|
| 99 | criteria.setTopicExpression(entityTopic);
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 |
|
---|
| 104 |
|
---|
| 105 | log.info("end TransformNhinSubscribeToInternalSubscribe");
|
---|
| 106 | return SubscriptionItem;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | private static void FillCriteriaList(List<CriterionType> criteria, Subscribe nhinSubscribe) {
|
---|
| 110 | //todo: need to loop through the slots to dynamically handle other criteria (excluding patient)
|
---|
| 111 | AddCriteriaForDocumentClassCode(nhinSubscribe, criteria);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | private static void AddCriteriaForDocumentClassCode(Subscribe nhinSubscribe, List<CriterionType> criteria) {
|
---|
| 115 | List<String> rawDocumentTypeList = AdhocQueryHelper.findSlotValues(nhinSubscribe, Constants.DocumentClassCodeSlotName);
|
---|
| 116 | List<String> documentTypeList = DocumentClassCodeParser.parseFormattedParameter(rawDocumentTypeList);
|
---|
| 117 |
|
---|
| 118 | for (String documentType : documentTypeList) {
|
---|
| 119 | CriterionType criterion = new CriterionType();
|
---|
| 120 | criterion.setKey(Constants.DocumentClassCodeSlotName);
|
---|
| 121 | criterion.setValue(documentType);
|
---|
| 122 | criteria.add(criterion);
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | private static Document getConsumerReferenceEndpointNodeDoc(Subscribe nhinSubscribe) {
|
---|
| 126 | W3CEndpointReference endpointRef = nhinSubscribe.getConsumerReference();
|
---|
| 127 | Document endpointNodeDoc = null;
|
---|
| 128 |
|
---|
| 129 | if (endpointRef != null) {
|
---|
| 130 | DOMResult domresult = new DOMResult();
|
---|
| 131 | endpointRef.writeTo(domresult);
|
---|
| 132 | Node endpointNode = domresult.getNode();
|
---|
| 133 |
|
---|
| 134 | endpointNodeDoc = (Document) endpointNode;
|
---|
| 135 | }
|
---|
| 136 | return endpointNodeDoc;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | private static String getConsumerReferenceAddress(Subscribe nhinSubscribe) {
|
---|
| 140 | String consumerReferenceAddress = XmlHelper.getNodeValue(getConsumerReferenceEndpointNodeDoc(nhinSubscribe), Constants.ADDRESS_ELEM_NAME);
|
---|
| 141 | log.info("consumerReferenceAddress=" + consumerReferenceAddress);
|
---|
| 142 | return consumerReferenceAddress;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | private static String getConsumerReferenceUserAddress(Subscribe nhinSubscribe) {
|
---|
| 146 | String consumerReferenceUserAddress = XmlHelper.getNodeValue(getConsumerReferenceEndpointNodeDoc(nhinSubscribe), Constants.USER_ADDRESS_ELEM_NAME);
|
---|
| 147 | log.info("consumerReferenceUserAddress=" + consumerReferenceUserAddress);
|
---|
| 148 | return consumerReferenceUserAddress;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | private static String getNotificationConsumerEndpointAddress() {
|
---|
| 152 | String endPointAddress = "";
|
---|
| 153 | try {
|
---|
| 154 | endPointAddress = PropertyAccessor.getProperty("gateway", "NotificationConsumerEndpointAddress");
|
---|
| 155 | } catch (PropertyAccessException ex) {
|
---|
| 156 | log.info("Exception while reading property NotificationConsumerEndpointAddress from property file" + ex.getMessage());
|
---|
| 157 | }
|
---|
| 158 | return endPointAddress;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | private static QualifiedSubjectIdentifierType getSubscriptionCriteriaPatient(Subscribe nhinSubscribe) {
|
---|
| 162 | log.info("--Begin getSubscriptionCriteriaPatient");
|
---|
| 163 | QualifiedSubjectIdentifierType patient = new QualifiedSubjectIdentifierType();
|
---|
| 164 |
|
---|
| 165 | String hl7FormattedPatientId = getFormattedPatientId(nhinSubscribe);
|
---|
| 166 | log.info("hl7FormattedPatientId=" + hl7FormattedPatientId);
|
---|
| 167 |
|
---|
| 168 | patient.setSubjectIdentifier(PatientIdFormatUtil.parsePatientId(hl7FormattedPatientId));
|
---|
| 169 | log.info("patient.getSubjectId()=" + patient.getSubjectIdentifier());
|
---|
| 170 |
|
---|
| 171 | patient.setAssigningAuthorityIdentifier(PatientIdFormatUtil.parseCommunityId(hl7FormattedPatientId));
|
---|
| 172 | log.info("patient.getAssigningAuthorityIdentifier()=" + patient.getAssigningAuthorityIdentifier() );
|
---|
| 173 |
|
---|
| 174 | log.info("--End getSubscriptionCriteriaPatient");
|
---|
| 175 | return patient;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | private static String getFormattedPatientId(Subscribe nhinSubscribe) {
|
---|
| 179 | log.info("begin getFormattedPatientId");
|
---|
| 180 |
|
---|
| 181 | String formattedPatientId = null;
|
---|
| 182 | try {
|
---|
| 183 | formattedPatientId = AdhocQueryHelper.findSlotValue(nhinSubscribe, Constants.PatientIdSlotName);
|
---|
| 184 | } catch (MultipleSlotValuesFoundException ex) {
|
---|
| 185 | log.info("patient slot not found [multiple found]");
|
---|
| 186 | formattedPatientId = null;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | log.info("end getFormattedPatientId [" + formattedPatientId + "]");
|
---|
| 190 | return formattedPatientId;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | }
|
---|