1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 | package gov.hhs.fha.nhinc.gateway.policyenginetransformation;
|
---|
6 |
|
---|
7 | import gov.hhs.fha.nhinc.common.nhinccommonadapter.CheckPolicyRequestType;
|
---|
8 | import gov.hhs.fha.nhinc.common.eventcommon.SubscribeEventType;
|
---|
9 | import gov.hhs.fha.nhinc.common.eventcommon.SubscribeMessageType;
|
---|
10 | import gov.hhs.fha.nhinc.gateway.policyenginetransformation.Helpers.ActionHelper;
|
---|
11 | import gov.hhs.fha.nhinc.gateway.policyenginetransformation.Helpers.AttributeHelper;
|
---|
12 | import gov.hhs.fha.nhinc.gateway.policyenginetransformation.Helpers.Constants;
|
---|
13 | import gov.hhs.fha.nhinc.gateway.policyenginetransformation.Helpers.InboundOutboundChecker;
|
---|
14 | import gov.hhs.fha.nhinc.gateway.policyenginetransformation.Helpers.SubjectHelper;
|
---|
15 | import gov.hhs.fha.nhinc.nhinclib.NullChecker;
|
---|
16 | import java.util.List;
|
---|
17 | import javax.xml.bind.JAXBElement;
|
---|
18 | import oasis.names.tc.ebxml_regrep.xsd.query._3.AdhocQueryRequest;
|
---|
19 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType;
|
---|
20 | import oasis.names.tc.xacml._2_0.context.schema.os.RequestType;
|
---|
21 | import oasis.names.tc.xacml._2_0.context.schema.os.ResourceType;
|
---|
22 | import oasis.names.tc.xacml._2_0.context.schema.os.SubjectType;
|
---|
23 | import org.oasis_open.docs.wsn.b_2.Subscribe;
|
---|
24 | import org.w3c.dom.Element;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | *
|
---|
28 | * @author svalluripalli
|
---|
29 | */
|
---|
30 | public class SubscribeTransformHelper {
|
---|
31 |
|
---|
32 | private static final String ActionInValue = "HIEMSubscriptionRequestIn";
|
---|
33 | private static final String ActionOutValue = "HIEMSubscriptionRequestOut";
|
---|
34 | private static final String PatientAssigningAuthorityAttributeId = Constants.AssigningAuthorityAttributeId;
|
---|
35 | private static final String PatientIdAttributeId = Constants.ResourceIdAttributeId;
|
---|
36 |
|
---|
37 | public static CheckPolicyRequestType transformSubscribeToCheckPolicy(SubscribeEventType event) {
|
---|
38 | CheckPolicyRequestType genericPolicyRequest = new CheckPolicyRequestType();
|
---|
39 | SubscribeMessageType message = event.getMessage();
|
---|
40 | RequestType request = new RequestType();
|
---|
41 | if (InboundOutboundChecker.IsInbound(event.getDirection())) {
|
---|
42 | request.setAction(ActionHelper.actionFactory(ActionInValue));
|
---|
43 | }
|
---|
44 | if (InboundOutboundChecker.IsOutbound(event.getDirection())) {
|
---|
45 | request.setAction(ActionHelper.actionFactory(ActionOutValue));
|
---|
46 | }
|
---|
47 |
|
---|
48 | SubjectType subject = SubjectHelper.subjectFactory(event.getSendingHomeCommunity(), event.getMessage().getAssertion());
|
---|
49 | request.getSubject().add(subject);
|
---|
50 |
|
---|
51 | AdhocQueryRequest adhocReq = new AdhocQueryRequest();
|
---|
52 | AdhocQueryType adhocQuery = new AdhocQueryType();
|
---|
53 | adhocQuery = getAdhocQuery(event.getMessage().getSubscribe());
|
---|
54 | adhocReq.setAdhocQuery(adhocQuery);
|
---|
55 | String patId = AdhocQueryTransformHelper.extractPatientIdentifierId(adhocReq);
|
---|
56 | String assignAuth = AdhocQueryTransformHelper.extractPatientIdentifierAssigningAuthority(adhocReq);
|
---|
57 |
|
---|
58 | ResourceType resource = new ResourceType();
|
---|
59 |
|
---|
60 | if (NullChecker.isNotNullish(assignAuth)) {
|
---|
61 | resource.getAttribute().add(AttributeHelper.attributeFactory(PatientAssigningAuthorityAttributeId, Constants.DataTypeString, assignAuth));
|
---|
62 | }
|
---|
63 |
|
---|
64 | if (NullChecker.isNotNullish(patId)) {
|
---|
65 | resource.getAttribute().add(AttributeHelper.attributeFactory(PatientIdAttributeId, Constants.DataTypeString, patId));
|
---|
66 | }
|
---|
67 |
|
---|
68 | request.getResource().add(resource);
|
---|
69 |
|
---|
70 | genericPolicyRequest.setRequest(request);
|
---|
71 | return genericPolicyRequest;
|
---|
72 | }
|
---|
73 |
|
---|
74 | public static AdhocQueryType getAdhocQuery(Subscribe nhinSubscribe) {
|
---|
75 | AdhocQueryType adhocQuery = null;
|
---|
76 | List<Object> any = nhinSubscribe.getAny();
|
---|
77 |
|
---|
78 |
|
---|
79 | for (Object anyItem : any) {
|
---|
80 | if (anyItem instanceof oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType) {
|
---|
81 | adhocQuery = (AdhocQueryType) anyItem;
|
---|
82 | }
|
---|
83 | if (anyItem instanceof Element) {
|
---|
84 | Element element = (Element) anyItem;
|
---|
85 |
|
---|
86 | Object o = (JAXBElement<oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType>) nhinSubscribe.getAny();
|
---|
87 |
|
---|
88 | // Object o = (JAXBElement<oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType>) anyItem;
|
---|
89 | }
|
---|
90 | if (anyItem instanceof JAXBElement) {
|
---|
91 | if (((JAXBElement) anyItem).getValue() instanceof AdhocQueryType) {
|
---|
92 | adhocQuery = (AdhocQueryType) ((JAXBElement) anyItem).getValue();
|
---|
93 | }
|
---|
94 | }
|
---|
95 | }
|
---|
96 | return adhocQuery;
|
---|
97 | }
|
---|
98 | }
|
---|