[507] | 1 | package gov.hhs.fha.nhinc.adapters.general.adapterpolicyenginetransformejb.adapterpolicyenginetransform;
|
---|
| 2 |
|
---|
| 3 | import java.util.List;
|
---|
| 4 | import java.util.UUID;
|
---|
| 5 |
|
---|
| 6 | import gov.hhs.fha.nhinc.common.nhinccommonadapter.TransformXACMLRequestToCppAQRResponseType;
|
---|
| 7 | import gov.hhs.fha.nhinc.common.nhinccommonadapter.TransformXACMLRequestToCppAQRRequestType;
|
---|
| 8 | import gov.hhs.fha.nhinc.common.nhinccommonadapter.TransformAQRToCppRDSRResponseType;
|
---|
| 9 | import gov.hhs.fha.nhinc.common.nhinccommonadapter.TransformAQRToCppRDSRRequestType;
|
---|
| 10 | import gov.hhs.fha.nhinc.common.nhinccommonadapter.CheckPatientOptInResponseType;
|
---|
| 11 | import gov.hhs.fha.nhinc.common.nhinccommonadapter.CheckPatientOptInRequestType;
|
---|
| 12 | import gov.hhs.fha.nhinc.common.nhinccommonadapter.TransformXACMLRequestToAQRForPatientIdResponseType;
|
---|
| 13 | import gov.hhs.fha.nhinc.common.nhinccommonadapter.TransformXACMLRequestToAQRForPatientIdRequestType;
|
---|
| 14 | import gov.hhs.fha.nhinc.common.nhinccommonadapter.TransformPatientIdAQRToCppXACMLResponseType;
|
---|
| 15 | import gov.hhs.fha.nhinc.common.nhinccommonadapter.TransformPatientIdAQRToCppXACMLRequestType;
|
---|
| 16 |
|
---|
| 17 | import javax.xml.bind.JAXBElement;
|
---|
| 18 | import oasis.names.tc.xacml._2_0.policy.schema.os.PolicyType;
|
---|
| 19 | import oasis.names.tc.xacml._2_0.context.schema.os.ResourceType;
|
---|
| 20 | import oasis.names.tc.xacml._2_0.context.schema.os.AttributeType;
|
---|
| 21 | import oasis.names.tc.ebxml_regrep.xsd.query._3.AdhocQueryRequest;
|
---|
| 22 | import ihe.iti.xds_b._2007.RetrieveDocumentSetRequestType;
|
---|
| 23 |
|
---|
| 24 | import ihe.iti.xds_b._2007.RetrieveDocumentSetRequestType.DocumentRequest;
|
---|
| 25 | import ihe.iti.xds_b._2007.RetrieveDocumentSetResponseType.DocumentResponse;
|
---|
| 26 | import java.io.StringReader;
|
---|
| 27 | import javax.xml.bind.JAXBContext;
|
---|
| 28 | import javax.xml.bind.Unmarshaller;
|
---|
| 29 | import oasis.names.tc.ebxml_regrep.xsd.query._3.AdhocQueryResponse;
|
---|
| 30 | import oasis.names.tc.ebxml_regrep.xsd.query._3.ResponseOptionType;
|
---|
| 31 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType;
|
---|
| 32 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.ExternalIdentifierType;
|
---|
| 33 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.ExtrinsicObjectType;
|
---|
| 34 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.IdentifiableType;
|
---|
| 35 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotType1;
|
---|
| 36 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.ValueListType;
|
---|
| 37 | import oasis.names.tc.xacml._2_0.context.schema.os.AttributeValueType;
|
---|
| 38 | import oasis.names.tc.xacml._2_0.context.schema.os.RequestType;
|
---|
| 39 | import org.apache.commons.logging.Log;
|
---|
| 40 | import org.apache.commons.logging.LogFactory;
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | /**
|
---|
| 44 | * This class does the work of transforming messages from one format
|
---|
| 45 | * to another.
|
---|
| 46 | *
|
---|
| 47 | * @author Les Westberg
|
---|
| 48 | */
|
---|
| 49 | public class AdapterPolicyEngineTransformHelper
|
---|
| 50 | {
|
---|
| 51 | // Constants used in this class
|
---|
| 52 | //-----------------------------
|
---|
| 53 | private static final String XACML_POLICY_PATIENT_ID = "urn:oasis:names:tc:xacml:1.0:resource:resource-id";
|
---|
| 54 | private static final String LEAF_CLASS = "LeafClass";
|
---|
| 55 | private static final String SLOT_NAME_CPP_PATIENT_ID = "$XDSDocumentEntryPatientId";
|
---|
| 56 | private static final String SLOT_NAME_DOCUMENT_CLASS_CODE = "$XDSDocumentEntryClassCode";
|
---|
| 57 | private static final String SLOT_NAME_DOCUMENT_CLASS_CODE_VALUE = "XNHIN-CONSENT";
|
---|
| 58 | private static final String SLOT_NAME_REPOSITORY_UNIQUE_ID = "repositoryUniqueId";
|
---|
| 59 | private static final String SLOT_NAME_SOURCE_PATIENT_ID = "sourcePatientId";
|
---|
| 60 | private static final String DOCUMENT_ID_IDENT_SCHEME = "urn:uuid:2e82c1f6-a085-4c72-9da3-8640a32e42ab";
|
---|
| 61 | private static final String XACML_DOCUMENT_REPOSITORY_ID = "urn:gov:hhs:fha:nhinc:document-repository-id";
|
---|
| 62 | private static final String XACML_DOCUMENT_ID = "urn:gov:hhs:fha:nhinc:document-id";
|
---|
| 63 | private static final String SLOT_NAME_DOC_RETRIEVE_REPOSITORY_UNIQUE_ID = "$NHINCRepositoryId";
|
---|
| 64 | private static final String SLOT_NAME_DOC_RETRIEVE_DOCUMENT_ID = "$NHINCDocumentId";
|
---|
| 65 |
|
---|
| 66 | private static Log log = LogFactory.getLog(AdapterPolicyEngineTransformHelper.class);
|
---|
| 67 |
|
---|
| 68 | /**
|
---|
| 69 | * This message transforms a XACML request message to an AdhocQueryRequest
|
---|
| 70 | * message that can be used to find the CPP (Consumer Preferences Profile)
|
---|
| 71 | * document for the patient.
|
---|
| 72 | *
|
---|
| 73 | * @param transformXACMLRequestToCppAQRRequest The XACML request to be
|
---|
| 74 | * transformed.
|
---|
| 75 | *
|
---|
| 76 | * @return The AdhocQueryRequest to get the CPP document.
|
---|
| 77 | */
|
---|
| 78 | public static TransformXACMLRequestToCppAQRResponseType transformXACMLRequestToCppAQR(TransformXACMLRequestToCppAQRRequestType transformXACMLRequestToCppAQRRequest)
|
---|
| 79 | throws AdapterPolicyEngineTransformException
|
---|
| 80 | {
|
---|
| 81 | TransformXACMLRequestToCppAQRResponseType oResponse = new TransformXACMLRequestToCppAQRResponseType();
|
---|
| 82 |
|
---|
| 83 | String sPatientId = "";
|
---|
| 84 |
|
---|
| 85 | if ((transformXACMLRequestToCppAQRRequest != null) &&
|
---|
| 86 | (transformXACMLRequestToCppAQRRequest.getRequest() != null) &&
|
---|
| 87 | (transformXACMLRequestToCppAQRRequest.getRequest().getResource() != null) &&
|
---|
| 88 | (transformXACMLRequestToCppAQRRequest.getRequest().getResource().size() > 0))
|
---|
| 89 | {
|
---|
| 90 | List<ResourceType> olResource = transformXACMLRequestToCppAQRRequest.getRequest().getResource();
|
---|
| 91 | for (ResourceType oResource : olResource)
|
---|
| 92 | {
|
---|
| 93 | if ((oResource.getAttribute() != null) &&
|
---|
| 94 | (oResource.getAttribute().size() > 0))
|
---|
| 95 | {
|
---|
| 96 | List<AttributeType> olAttribute = oResource.getAttribute();
|
---|
| 97 | for (AttributeType oAttribute : olAttribute)
|
---|
| 98 | {
|
---|
| 99 | if ((oAttribute.getAttributeId() != null) &&
|
---|
| 100 | (oAttribute.getAttributeId().equals(XACML_POLICY_PATIENT_ID)) &&
|
---|
| 101 | (oAttribute.getAttributeValue() != null) &&
|
---|
| 102 | (oAttribute.getAttributeValue().size() > 0) &&
|
---|
| 103 | (oAttribute.getAttributeValue().get(0) != null) &&
|
---|
| 104 | (oAttribute.getAttributeValue().get(0).getContent() != null) &&
|
---|
| 105 | (oAttribute.getAttributeValue().get(0).getContent().size() > 0))
|
---|
| 106 | {
|
---|
| 107 | List<Object> olObjectValue = oAttribute.getAttributeValue().get(0).getContent();
|
---|
| 108 | for (Object oObjectValue : olObjectValue)
|
---|
| 109 | {
|
---|
| 110 | if ((oObjectValue instanceof String) &&
|
---|
| 111 | (((String) oObjectValue).length() > 0))
|
---|
| 112 | {
|
---|
| 113 | sPatientId = ((String) oObjectValue).trim();
|
---|
| 114 | break; // get out of the for loop
|
---|
| 115 | }
|
---|
| 116 | } //for (Object oObjectValue : olObjectValue)
|
---|
| 117 |
|
---|
| 118 | // If we found what we wanted get out of the for loop
|
---|
| 119 | //---------------------------------------------------
|
---|
| 120 | if (sPatientId.length() > 0)
|
---|
| 121 | {
|
---|
| 122 | break;
|
---|
| 123 | }
|
---|
| 124 | } // if ((oAttribute.getAttributeId() != null) &&
|
---|
| 125 | } // for (AttributeType oAttribute : olAttribute)
|
---|
| 126 |
|
---|
| 127 | // If we found what we wanted get out of the for loop
|
---|
| 128 | //---------------------------------------------------
|
---|
| 129 | if (sPatientId.length() > 0)
|
---|
| 130 | {
|
---|
| 131 | break;
|
---|
| 132 | }
|
---|
| 133 | } // if ((oResource.getAttribute() != null) &&
|
---|
| 134 | } // for (ResourceType oResource : olResource)
|
---|
| 135 |
|
---|
| 136 | // If we found the patient ID, create the request to get the CPP
|
---|
| 137 | // document.
|
---|
| 138 | //---------------------------------------------------------------
|
---|
| 139 | if (sPatientId.length() > 0)
|
---|
| 140 | {
|
---|
| 141 | AdhocQueryRequest oAQR = new AdhocQueryRequest();
|
---|
| 142 | oResponse.setAdhocQueryRequest(oAQR);
|
---|
| 143 |
|
---|
| 144 | // ResponseOption
|
---|
| 145 | //----------------
|
---|
| 146 | ResponseOptionType oResponseOption = new ResponseOptionType();
|
---|
| 147 | oAQR.setResponseOption(oResponseOption);
|
---|
| 148 | oResponseOption.setReturnComposedObjects(true);
|
---|
| 149 | oResponseOption.setReturnType(LEAF_CLASS);
|
---|
| 150 |
|
---|
| 151 | AdhocQueryType oAQ = new AdhocQueryType();
|
---|
| 152 | oAQR.setAdhocQuery(oAQ);
|
---|
| 153 | oAQ.setId(UUID.randomUUID().toString());
|
---|
| 154 |
|
---|
| 155 | List<SlotType1> olSlot = oAQ.getSlot();
|
---|
| 156 |
|
---|
| 157 | // Patient ID
|
---|
| 158 | //------------
|
---|
| 159 | SlotType1 oSlot = new SlotType1();
|
---|
| 160 | olSlot.add(oSlot);
|
---|
| 161 | oSlot.setName(SLOT_NAME_CPP_PATIENT_ID);
|
---|
| 162 | ValueListType oValueList = new ValueListType();
|
---|
| 163 | oSlot.setValueList(oValueList);
|
---|
| 164 | oValueList.getValue().add(sPatientId);
|
---|
| 165 |
|
---|
| 166 | // Document Class Code
|
---|
| 167 | //--------------------
|
---|
| 168 | oSlot = new SlotType1();
|
---|
| 169 | olSlot.add(oSlot);
|
---|
| 170 | oSlot.setName(SLOT_NAME_DOCUMENT_CLASS_CODE);
|
---|
| 171 | oValueList = new ValueListType();
|
---|
| 172 | oSlot.setValueList(oValueList);
|
---|
| 173 | oValueList.getValue().add(SLOT_NAME_DOCUMENT_CLASS_CODE_VALUE);
|
---|
| 174 | }
|
---|
| 175 | } // if ((transformXACMLRequestToCppAQRRequest != null) &&
|
---|
| 176 |
|
---|
| 177 | return oResponse;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | /**
|
---|
| 181 | * This method transforms a message from a CPP AdhocQueryResponse message to
|
---|
| 182 | * a RetrieveDocumentSetRequest message that can be used to retrieve the
|
---|
| 183 | * CPP document.
|
---|
| 184 | *
|
---|
| 185 | * @param transformAQRToCppRDSRRequest The AdhocQueryResponse message that
|
---|
| 186 | * was returned form the Document Query to get the CPP document.
|
---|
| 187 | * @return The RetrieveDocumentSetRequest that can be used to retrieve
|
---|
| 188 | * the CPP document.
|
---|
| 189 | */
|
---|
| 190 | public static TransformAQRToCppRDSRResponseType transformAQRToCppRDSR(TransformAQRToCppRDSRRequestType transformAQRToCppRDSRRequest)
|
---|
| 191 | throws AdapterPolicyEngineTransformException
|
---|
| 192 | {
|
---|
| 193 | TransformAQRToCppRDSRResponseType oResponse = new TransformAQRToCppRDSRResponseType();
|
---|
| 194 |
|
---|
| 195 | String sHomeCommunityId = "";
|
---|
| 196 | String sRepositoryId = "";
|
---|
| 197 | String sDocumentId = "";
|
---|
| 198 |
|
---|
| 199 | if ((transformAQRToCppRDSRRequest != null) &&
|
---|
| 200 | (transformAQRToCppRDSRRequest.getAdhocQueryResponse() != null) &&
|
---|
| 201 | (transformAQRToCppRDSRRequest.getAdhocQueryResponse().getRegistryObjectList() != null) &&
|
---|
| 202 | (transformAQRToCppRDSRRequest.getAdhocQueryResponse().getRegistryObjectList().getIdentifiable() != null) &&
|
---|
| 203 | (transformAQRToCppRDSRRequest.getAdhocQueryResponse().getRegistryObjectList().getIdentifiable().size() > 0))
|
---|
| 204 | {
|
---|
| 205 | List<JAXBElement<? extends IdentifiableType>> olRegObjs = transformAQRToCppRDSRRequest.getAdhocQueryResponse().getRegistryObjectList().getIdentifiable();
|
---|
| 206 |
|
---|
| 207 | for (JAXBElement<? extends IdentifiableType> oJAXBObj : olRegObjs)
|
---|
| 208 | {
|
---|
| 209 | if ((oJAXBObj != null) &&
|
---|
| 210 | (oJAXBObj.getDeclaredType() != null) &&
|
---|
| 211 | (oJAXBObj.getDeclaredType().getCanonicalName() != null) &&
|
---|
| 212 | (oJAXBObj.getDeclaredType().getCanonicalName().equals("oasis.names.tc.ebxml_regrep.xsd.rim._3.ExtrinsicObjectType")) &&
|
---|
| 213 | (oJAXBObj.getValue() != null))
|
---|
| 214 | {
|
---|
| 215 | ExtrinsicObjectType oExtObj = (ExtrinsicObjectType) oJAXBObj.getValue();
|
---|
| 216 |
|
---|
| 217 | // Home Community ID
|
---|
| 218 | //-------------------
|
---|
| 219 | if ((oExtObj != null) &&
|
---|
| 220 | (oExtObj.getHome() != null) &&
|
---|
| 221 | (oExtObj.getHome().length() > 0))
|
---|
| 222 | {
|
---|
| 223 | sHomeCommunityId = oExtObj.getHome().trim();
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | // Repository ID
|
---|
| 227 | //---------------
|
---|
| 228 | if ((oExtObj.getSlot() != null) &&
|
---|
| 229 | (oExtObj.getSlot().size() > 0))
|
---|
| 230 | {
|
---|
| 231 | List<SlotType1> olSlot = oExtObj.getSlot();
|
---|
| 232 | for (SlotType1 oSlot : olSlot)
|
---|
| 233 | {
|
---|
| 234 | if ((oSlot.getName() != null) &&
|
---|
| 235 | (oSlot.getName().equals(SLOT_NAME_REPOSITORY_UNIQUE_ID)) &&
|
---|
| 236 | (oSlot.getValueList() != null) &&
|
---|
| 237 | (oSlot.getValueList().getValue() != null) &&
|
---|
| 238 | (oSlot.getValueList().getValue().size() > 0) &&
|
---|
| 239 | (oSlot.getValueList().getValue().get(0).length() > 0))
|
---|
| 240 | {
|
---|
| 241 | sRepositoryId = oSlot.getValueList().getValue().get(0).trim();
|
---|
| 242 | }
|
---|
| 243 | } // for (SlotType1 oSlot : olSlot)
|
---|
| 244 | } // if ((oExtObj.getSlot() != null) && ...
|
---|
| 245 |
|
---|
| 246 | // Document Unique ID
|
---|
| 247 | //-------------------
|
---|
| 248 | if ((oExtObj.getExternalIdentifier() != null) &&
|
---|
| 249 | (oExtObj.getExternalIdentifier().size() > 0))
|
---|
| 250 | {
|
---|
| 251 | List<ExternalIdentifierType> olExtId = oExtObj.getExternalIdentifier();
|
---|
| 252 | for (ExternalIdentifierType oExtId : olExtId)
|
---|
| 253 | {
|
---|
| 254 | if ((oExtId.getIdentificationScheme() != null) &&
|
---|
| 255 | (oExtId.getIdentificationScheme().equals(DOCUMENT_ID_IDENT_SCHEME)) &&
|
---|
| 256 | (oExtId.getValue() != null) &&
|
---|
| 257 | (oExtId.getValue().length() > 0))
|
---|
| 258 | {
|
---|
| 259 | sDocumentId = oExtId.getValue().trim();
|
---|
| 260 | }
|
---|
| 261 | } // for (ExternalIdentifierType oExtid : olExtId)
|
---|
| 262 | } // if ((oExtObj.getExternalIdentifier() != null) &&
|
---|
| 263 | } // if ((oJAXBObj != null) &&
|
---|
| 264 | } // for (JAXBElement<? extends IdentifiableType> oJAXBObj : olRegObjs)
|
---|
| 265 |
|
---|
| 266 | // Now lets create the response...
|
---|
| 267 | //---------------------------------
|
---|
| 268 | RetrieveDocumentSetRequestType oRDSR = new RetrieveDocumentSetRequestType();
|
---|
| 269 | oResponse.setRetrieveDocumentSetRequest(oRDSR);
|
---|
| 270 | List<DocumentRequest> olDocRequest = oRDSR.getDocumentRequest();
|
---|
| 271 | DocumentRequest oDocRequest = new DocumentRequest();
|
---|
| 272 | olDocRequest.add(oDocRequest);
|
---|
| 273 | oDocRequest.setHomeCommunityId(sHomeCommunityId);
|
---|
| 274 | oDocRequest.setRepositoryUniqueId(sRepositoryId);
|
---|
| 275 | oDocRequest.setDocumentUniqueId(sDocumentId);
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | return oResponse;
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 | /**
|
---|
| 282 | * This method takes the RetrieveDocumentSetResponse message from the
|
---|
| 283 | * document repository that contains the CPP document and looks at the
|
---|
| 284 | * CPP document and returns TRUE if the patient has opted in and false if
|
---|
| 285 | * they have not. If the document does not exist or the input parameter
|
---|
| 286 | * is null, then it means that the patient has opted out and false is
|
---|
| 287 | * returned.
|
---|
| 288 | *
|
---|
| 289 | * @param checkPatientOptInRequest The RetrieveDocumentSetResponse containing
|
---|
| 290 | * the CPP document.
|
---|
| 291 | * @return TRUE if the patient has opted in and false if they have not.
|
---|
| 292 | */
|
---|
| 293 | public static CheckPatientOptInResponseType checkPatientOptIn(CheckPatientOptInRequestType checkPatientOptInRequest)
|
---|
| 294 | throws AdapterPolicyEngineTransformException
|
---|
| 295 | {
|
---|
| 296 | CheckPatientOptInResponseType oResponse = new CheckPatientOptInResponseType();
|
---|
| 297 | oResponse.setPatientOptedIn(false); // default is opt out.
|
---|
| 298 |
|
---|
| 299 | if ((checkPatientOptInRequest != null) &&
|
---|
| 300 | (checkPatientOptInRequest.getRetrieveDocumentSetResponse() != null) &&
|
---|
| 301 | (checkPatientOptInRequest.getRetrieveDocumentSetResponse().getDocumentResponse() != null) &&
|
---|
| 302 | (checkPatientOptInRequest.getRetrieveDocumentSetResponse().getDocumentResponse().size() > 0))
|
---|
| 303 | {
|
---|
| 304 | // A patient should only have one document - so if there are more than one, we
|
---|
| 305 | // will use the first one...
|
---|
| 306 | //-----------------------------------------------------------------------------
|
---|
| 307 | DocumentResponse oDocResponse = checkPatientOptInRequest.getRetrieveDocumentSetResponse().getDocumentResponse().get(0);
|
---|
| 308 |
|
---|
| 309 | if ((oDocResponse.getDocument() != null) &&
|
---|
| 310 | (oDocResponse.getDocument().length > 0))
|
---|
| 311 | {
|
---|
| 312 | String sCpp = new String(oDocResponse.getDocument());
|
---|
| 313 | log.error("CPP Document: '" + sCpp + "'");
|
---|
| 314 |
|
---|
| 315 | // The CPP defined by NHIN does not appear to be compatible with the XACML 2.0
|
---|
| 316 | // I cannot use that to unmarshal the XML to an object. We are just going to
|
---|
| 317 | // have to search for the piece we want - since we created this document - at
|
---|
| 318 | // least for now, we will look for exactly the match on the string that we want.
|
---|
| 319 | //------------------------------------------------------------------------------
|
---|
| 320 |
|
---|
| 321 | // Search for <Rule, then Search for the word "Effect=" use that value...
|
---|
| 322 | //-------------------------------------------------------------------------
|
---|
| 323 | int iRuleIdx = sCpp.indexOf("<Rule");
|
---|
| 324 | if (iRuleIdx > 0)
|
---|
| 325 | {
|
---|
| 326 | log.error("iRuleIdx: " + iRuleIdx);
|
---|
| 327 | int iEffectIdx = sCpp.indexOf("Effect=\"", iRuleIdx);
|
---|
| 328 | if (iEffectIdx >= 0)
|
---|
| 329 | {
|
---|
| 330 | log.error("iEffectIdx: " + iRuleIdx);
|
---|
| 331 | String sRestOfString = sCpp.substring(iEffectIdx + 8);
|
---|
| 332 | log.error("sRestOfString: " + sRestOfString);
|
---|
| 333 | if (sRestOfString.startsWith("Permit"))
|
---|
| 334 | {
|
---|
| 335 | oResponse.setPatientOptedIn(true);
|
---|
| 336 | } // if (sRestOfString.startsWith("Permit"))
|
---|
| 337 | } // if (iEffectIdx >= 0)
|
---|
| 338 | } // if (iRuleIdx > 0)
|
---|
| 339 | } // if ((oDocResponse.getDocument() != null) &&
|
---|
| 340 | } // if ((checkPatientOptInRequest != null) &&
|
---|
| 341 |
|
---|
| 342 | return oResponse;
|
---|
| 343 | }
|
---|
| 344 |
|
---|
| 345 | /**
|
---|
| 346 | * This method transforms a XACML request to the information needed to
|
---|
| 347 | * retrienve the patient ID from the Document Registry based on the
|
---|
| 348 | * document information. This will return an AdhocQueryRequest.
|
---|
| 349 | *
|
---|
| 350 | * @param transformXACMLRequestToAQRForPatientIdRequest The XACML information
|
---|
| 351 | * that contains the document identifiers.
|
---|
| 352 | * @return The AdhocQueryRequest to retrieve the patient ID
|
---|
| 353 | * information based on the document identifiers.
|
---|
| 354 | */
|
---|
| 355 | public static TransformXACMLRequestToAQRForPatientIdResponseType transformXACMLRequestToAQRForPatientId(TransformXACMLRequestToAQRForPatientIdRequestType transformXACMLRequestToAQRForPatientIdRequest)
|
---|
| 356 | throws AdapterPolicyEngineTransformException
|
---|
| 357 | {
|
---|
| 358 | TransformXACMLRequestToAQRForPatientIdResponseType oResponse = new TransformXACMLRequestToAQRForPatientIdResponseType();
|
---|
| 359 |
|
---|
| 360 | String sRepositoryId = "";
|
---|
| 361 | String sDocumentId = "";
|
---|
| 362 |
|
---|
| 363 | if ((transformXACMLRequestToAQRForPatientIdRequest != null) &&
|
---|
| 364 | (transformXACMLRequestToAQRForPatientIdRequest.getRequest() != null) &&
|
---|
| 365 | (transformXACMLRequestToAQRForPatientIdRequest.getRequest().getResource() != null) &&
|
---|
| 366 | (transformXACMLRequestToAQRForPatientIdRequest.getRequest().getResource().size() > 0))
|
---|
| 367 | {
|
---|
| 368 | List<ResourceType> olResource = transformXACMLRequestToAQRForPatientIdRequest.getRequest().getResource();
|
---|
| 369 | for (ResourceType oResource : olResource)
|
---|
| 370 | {
|
---|
| 371 | if ((oResource.getAttribute() != null) &&
|
---|
| 372 | (oResource.getAttribute().size() > 0))
|
---|
| 373 | {
|
---|
| 374 | List<AttributeType> olAttribute = oResource.getAttribute();
|
---|
| 375 | for (AttributeType oAttribute : olAttribute)
|
---|
| 376 | {
|
---|
| 377 | if ((oAttribute.getAttributeId() != null) &&
|
---|
| 378 | (oAttribute.getAttributeId().equals(XACML_DOCUMENT_ID)) &&
|
---|
| 379 | (oAttribute.getAttributeValue() != null) &&
|
---|
| 380 | (oAttribute.getAttributeValue().size() > 0) &&
|
---|
| 381 | (oAttribute.getAttributeValue().get(0) != null) &&
|
---|
| 382 | (oAttribute.getAttributeValue().get(0).getContent() != null) &&
|
---|
| 383 | (oAttribute.getAttributeValue().get(0).getContent().size() > 0))
|
---|
| 384 | {
|
---|
| 385 | List<Object> olObjectValue = oAttribute.getAttributeValue().get(0).getContent();
|
---|
| 386 | for (Object oObjectValue : olObjectValue)
|
---|
| 387 | {
|
---|
| 388 | if ((oObjectValue instanceof String) &&
|
---|
| 389 | (((String) oObjectValue).length() > 0))
|
---|
| 390 | {
|
---|
| 391 | sDocumentId = ((String) oObjectValue).trim();
|
---|
| 392 | break; // get out of the for loop
|
---|
| 393 | }
|
---|
| 394 | } //for (Object oObjectValue : olObjectValue)
|
---|
| 395 | } // if ((oAttribute.getAttributeId() != null) &&
|
---|
| 396 | else if ((oAttribute.getAttributeId() != null) &&
|
---|
| 397 | (oAttribute.getAttributeId().equals(XACML_DOCUMENT_REPOSITORY_ID)) &&
|
---|
| 398 | (oAttribute.getAttributeValue() != null) &&
|
---|
| 399 | (oAttribute.getAttributeValue().size() > 0) &&
|
---|
| 400 | (oAttribute.getAttributeValue().get(0) != null) &&
|
---|
| 401 | (oAttribute.getAttributeValue().get(0).getContent() != null) &&
|
---|
| 402 | (oAttribute.getAttributeValue().get(0).getContent().size() > 0))
|
---|
| 403 | {
|
---|
| 404 | List<Object> olObjectValue = oAttribute.getAttributeValue().get(0).getContent();
|
---|
| 405 | for (Object oObjectValue : olObjectValue)
|
---|
| 406 | {
|
---|
| 407 | if ((oObjectValue instanceof String) &&
|
---|
| 408 | (((String) oObjectValue).length() > 0))
|
---|
| 409 | {
|
---|
| 410 | sRepositoryId = ((String) oObjectValue).trim();
|
---|
| 411 | break; // get out of the for loop
|
---|
| 412 | }
|
---|
| 413 | } //for (Object oObjectValue : olObjectValue)
|
---|
| 414 | } // if ((oAttribute.getAttributeId() != null) &&
|
---|
| 415 |
|
---|
| 416 |
|
---|
| 417 | // If we found what we wanted get out of the for loop
|
---|
| 418 | //---------------------------------------------------
|
---|
| 419 | if ((sDocumentId.length() > 0) && (sRepositoryId.length() > 0))
|
---|
| 420 | {
|
---|
| 421 | break;
|
---|
| 422 | }
|
---|
| 423 |
|
---|
| 424 | } // for (AttributeType oAttribute : olAttribute)
|
---|
| 425 |
|
---|
| 426 | // If we found what we wanted get out of the for loop
|
---|
| 427 | //---------------------------------------------------
|
---|
| 428 | if ((sDocumentId.length() > 0) && (sRepositoryId.length() > 0))
|
---|
| 429 | {
|
---|
| 430 | break;
|
---|
| 431 | }
|
---|
| 432 | } // if ((oResource.getAttribute() != null) &&
|
---|
| 433 | } // for (ResourceType oResource : olResource)
|
---|
| 434 |
|
---|
| 435 | // If we found what we are looking for, create the request to
|
---|
| 436 | //---------------------------------------------------------------
|
---|
| 437 | if ((sDocumentId.length() > 0) || (sRepositoryId.length() > 0))
|
---|
| 438 | {
|
---|
| 439 | AdhocQueryRequest oAQR = new AdhocQueryRequest();
|
---|
| 440 | oResponse.setAdhocQueryRequest(oAQR);
|
---|
| 441 |
|
---|
| 442 | // ResponseOption
|
---|
| 443 | //----------------
|
---|
| 444 | ResponseOptionType oResponseOption = new ResponseOptionType();
|
---|
| 445 | oAQR.setResponseOption(oResponseOption);
|
---|
| 446 | oResponseOption.setReturnComposedObjects(true);
|
---|
| 447 | oResponseOption.setReturnType(LEAF_CLASS);
|
---|
| 448 |
|
---|
| 449 | AdhocQueryType oAQ = new AdhocQueryType();
|
---|
| 450 | oAQR.setAdhocQuery(oAQ);
|
---|
| 451 | oAQ.setId(UUID.randomUUID().toString());
|
---|
| 452 |
|
---|
| 453 | List<SlotType1> olSlot = oAQ.getSlot();
|
---|
| 454 |
|
---|
| 455 | // Document ID
|
---|
| 456 | //------------
|
---|
| 457 | if (sDocumentId.length() > 0)
|
---|
| 458 | {
|
---|
| 459 | SlotType1 oSlot = new SlotType1();
|
---|
| 460 | olSlot.add(oSlot);
|
---|
| 461 | oSlot.setName(SLOT_NAME_DOC_RETRIEVE_DOCUMENT_ID);
|
---|
| 462 | ValueListType oValueList = new ValueListType();
|
---|
| 463 | oSlot.setValueList(oValueList);
|
---|
| 464 | oValueList.getValue().add(sDocumentId);
|
---|
| 465 | }
|
---|
| 466 |
|
---|
| 467 | // Repository ID
|
---|
| 468 | //--------------
|
---|
| 469 | if (sRepositoryId.length() > 0)
|
---|
| 470 | {
|
---|
| 471 | SlotType1 oSlot = new SlotType1();
|
---|
| 472 | olSlot.add(oSlot);
|
---|
| 473 | oSlot.setName(SLOT_NAME_DOC_RETRIEVE_REPOSITORY_UNIQUE_ID);
|
---|
| 474 | ValueListType oValueList = new ValueListType();
|
---|
| 475 | oSlot.setValueList(oValueList);
|
---|
| 476 | oValueList.getValue().add(sRepositoryId);
|
---|
| 477 | }
|
---|
| 478 | } // if ((sDocumentId.length() > 0) || (sRepositoryId.length() > 0))
|
---|
| 479 | } // if ((transformXACMLRequestToAQRForPatientIdRequest != null) &&
|
---|
| 480 |
|
---|
| 481 | return oResponse;
|
---|
| 482 | }
|
---|
| 483 |
|
---|
| 484 | /**
|
---|
| 485 | * This method takes the AdhocQueryResponse containing the document
|
---|
| 486 | * meta data including the Patient ID and it will create a XACML request
|
---|
| 487 | * containing the patient ID so that it can be passed into the
|
---|
| 488 | * CheckPolicyPatientOptIn method to determine if the patient has opted in.
|
---|
| 489 | *
|
---|
| 490 | * @param transformPatientIdAQRToCppXACMLRequest The AdhocQueryResponse
|
---|
| 491 | * containing the patient ID for the patient associated with the document.
|
---|
| 492 | * @return The XACML policy containing the patient ID.
|
---|
| 493 | *
|
---|
| 494 | */
|
---|
| 495 | public static TransformPatientIdAQRToCppXACMLResponseType transformPatientIdAQRToCppXACML(TransformPatientIdAQRToCppXACMLRequestType transformPatientIdAQRToCppXACMLRequest)
|
---|
| 496 | throws AdapterPolicyEngineTransformException
|
---|
| 497 | {
|
---|
| 498 | TransformPatientIdAQRToCppXACMLResponseType oResponse = new TransformPatientIdAQRToCppXACMLResponseType();
|
---|
| 499 |
|
---|
| 500 | // If we are given a basis of our XACML, use it and put the PatientId into it. Otherwise,
|
---|
| 501 | // we will have to create it from scratch.
|
---|
| 502 | //----------------------------------------------------------------------------------------
|
---|
| 503 | if ((transformPatientIdAQRToCppXACMLRequest != null) &&
|
---|
| 504 | (transformPatientIdAQRToCppXACMLRequest.getRequest() != null))
|
---|
| 505 | {
|
---|
| 506 | oResponse.setRequest(transformPatientIdAQRToCppXACMLRequest.getRequest());
|
---|
| 507 | }
|
---|
| 508 | else
|
---|
| 509 | {
|
---|
| 510 | RequestType oRequest = new RequestType();
|
---|
| 511 | oResponse.setRequest(oRequest);
|
---|
| 512 | }
|
---|
| 513 |
|
---|
| 514 | String sPatientId = "";
|
---|
| 515 |
|
---|
| 516 | // Find the Patient ID in the response...
|
---|
| 517 | //---------------------------------------
|
---|
| 518 | if ((transformPatientIdAQRToCppXACMLRequest != null) &&
|
---|
| 519 | (transformPatientIdAQRToCppXACMLRequest.getAdhocQueryResponse() != null) &&
|
---|
| 520 | (transformPatientIdAQRToCppXACMLRequest.getAdhocQueryResponse().getRegistryObjectList() != null) &&
|
---|
| 521 | (transformPatientIdAQRToCppXACMLRequest.getAdhocQueryResponse().getRegistryObjectList().getIdentifiable() != null) &&
|
---|
| 522 | (transformPatientIdAQRToCppXACMLRequest.getAdhocQueryResponse().getRegistryObjectList().getIdentifiable().size() > 0))
|
---|
| 523 | {
|
---|
| 524 | List<JAXBElement<? extends IdentifiableType>> olRegObjs = transformPatientIdAQRToCppXACMLRequest.getAdhocQueryResponse().getRegistryObjectList().getIdentifiable();
|
---|
| 525 |
|
---|
| 526 | for (JAXBElement<? extends IdentifiableType> oJAXBObj : olRegObjs)
|
---|
| 527 | {
|
---|
| 528 | if ((oJAXBObj != null) &&
|
---|
| 529 | (oJAXBObj.getDeclaredType() != null) &&
|
---|
| 530 | (oJAXBObj.getDeclaredType().getCanonicalName() != null) &&
|
---|
| 531 | (oJAXBObj.getDeclaredType().getCanonicalName().equals("oasis.names.tc.ebxml_regrep.xsd.rim._3.ExtrinsicObjectType")) &&
|
---|
| 532 | (oJAXBObj.getValue() != null))
|
---|
| 533 | {
|
---|
| 534 | ExtrinsicObjectType oExtObj = (ExtrinsicObjectType) oJAXBObj.getValue();
|
---|
| 535 |
|
---|
| 536 | // Patient ID
|
---|
| 537 | //-----------
|
---|
| 538 | if ((oExtObj.getSlot() != null) &&
|
---|
| 539 | (oExtObj.getSlot().size() > 0))
|
---|
| 540 | {
|
---|
| 541 | List<SlotType1> olSlot = oExtObj.getSlot();
|
---|
| 542 | for (SlotType1 oSlot : olSlot)
|
---|
| 543 | {
|
---|
| 544 | if ((oSlot.getName() != null) &&
|
---|
| 545 | (oSlot.getName().equals(SLOT_NAME_SOURCE_PATIENT_ID)) &&
|
---|
| 546 | (oSlot.getValueList() != null) &&
|
---|
| 547 | (oSlot.getValueList().getValue() != null) &&
|
---|
| 548 | (oSlot.getValueList().getValue().size() > 0) &&
|
---|
| 549 | (oSlot.getValueList().getValue().get(0).length() > 0))
|
---|
| 550 | {
|
---|
| 551 | sPatientId = oSlot.getValueList().getValue().get(0).trim();
|
---|
| 552 | break; // Get out of the loop - we found what we want.
|
---|
| 553 | }
|
---|
| 554 | } // for (SlotType1 oSlot : olSlot)
|
---|
| 555 | } // if ((oExtObj.getSlot() != null) && ...
|
---|
| 556 | } // if ((oJAXBObj != null) &&
|
---|
| 557 | } // for (JAXBElement<? extends IdentifiableType> oJAXBObj : olRegObjs)
|
---|
| 558 | } // if ((transformPatientIdAQRToCppXACMLRequest != null) &&
|
---|
| 559 |
|
---|
| 560 | // Now lets get the patient ID and put it in the XACML request. If
|
---|
| 561 | // there is already a node in there with a patient ID, then this will
|
---|
| 562 | // replace it, otherwise it will add in a new node with the patient ID.
|
---|
| 563 | //----------------------------------------------------------------------
|
---|
| 564 | if (sPatientId.length() > 0)
|
---|
| 565 | {
|
---|
| 566 | RequestType oRequest = oResponse.getRequest();
|
---|
| 567 | List<ResourceType> olResource = oRequest.getResource();
|
---|
| 568 | AttributeType oPatientIdAttribute = null;
|
---|
| 569 | ResourceType oPatientIdResource = null;
|
---|
| 570 |
|
---|
| 571 | if (olResource.size() > 0)
|
---|
| 572 | {
|
---|
| 573 |
|
---|
| 574 | // See if the patient ID is already in here...
|
---|
| 575 | //--------------------------------------------
|
---|
| 576 | for (ResourceType oResource : olResource)
|
---|
| 577 | {
|
---|
| 578 | List<AttributeType> olAttribute = oResource.getAttribute();
|
---|
| 579 | for (AttributeType oAttribute : olAttribute)
|
---|
| 580 | {
|
---|
| 581 | if ((oAttribute.getAttributeId() != null) &&
|
---|
| 582 | (oAttribute.getAttributeId().equals(XACML_POLICY_PATIENT_ID)))
|
---|
| 583 | {
|
---|
| 584 | oPatientIdResource = oResource;
|
---|
| 585 | oPatientIdAttribute = oAttribute;
|
---|
| 586 | break;
|
---|
| 587 | }
|
---|
| 588 | } // for (AttributeType oAttribute : olAttribute)
|
---|
| 589 |
|
---|
| 590 | if (oPatientIdAttribute != null)
|
---|
| 591 | {
|
---|
| 592 | break;
|
---|
| 593 | }
|
---|
| 594 | } // for (ResourceType oResource : olResource)
|
---|
| 595 | } // if (oRequest.getResource().size() > 0)
|
---|
| 596 | else
|
---|
| 597 | {
|
---|
| 598 | oPatientIdResource = new ResourceType();
|
---|
| 599 | olResource.add(oPatientIdResource);
|
---|
| 600 | }
|
---|
| 601 |
|
---|
| 602 | // If we did not find it, then we need to create the attribute and fill
|
---|
| 603 | // it in.
|
---|
| 604 | //----------------------------------------------------------------------
|
---|
| 605 | if (oPatientIdAttribute == null)
|
---|
| 606 | {
|
---|
| 607 | oPatientIdAttribute = new AttributeType();
|
---|
| 608 | oPatientIdAttribute.setAttributeId(XACML_POLICY_PATIENT_ID);
|
---|
| 609 | oPatientIdResource.getAttribute().add(oPatientIdAttribute);
|
---|
| 610 | }
|
---|
| 611 |
|
---|
| 612 | // Now lets set the value...
|
---|
| 613 | //---------------------------
|
---|
| 614 | oPatientIdAttribute.getAttributeValue().clear();
|
---|
| 615 | AttributeValueType oAttributeValue = new AttributeValueType();
|
---|
| 616 | oPatientIdAttribute.getAttributeValue().add(oAttributeValue);
|
---|
| 617 | oAttributeValue.getContent().add(sPatientId);
|
---|
| 618 | } // if (sPatientId.length() > 0)
|
---|
| 619 |
|
---|
| 620 | return oResponse;
|
---|
| 621 | }
|
---|
| 622 |
|
---|
| 623 | }
|
---|