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 |
|
---|
8 | import gov.hhs.fha.nhinc.common.eventcommon.AdhocQueryRequestEventType;
|
---|
9 | import gov.hhs.fha.nhinc.common.nhinccommon.AssertionType;
|
---|
10 | import gov.hhs.fha.nhinc.common.nhinccommonadapter.CheckPolicyRequestType;
|
---|
11 | import gov.hhs.fha.nhinc.gateway.policyenginetransformation.Helpers.ActionHelper;
|
---|
12 | import gov.hhs.fha.nhinc.gateway.policyenginetransformation.Helpers.AttributeHelper;
|
---|
13 | import gov.hhs.fha.nhinc.gateway.policyenginetransformation.Helpers.CommunityHelper;
|
---|
14 | import gov.hhs.fha.nhinc.gateway.policyenginetransformation.Helpers.Constants;
|
---|
15 | import gov.hhs.fha.nhinc.gateway.policyenginetransformation.Helpers.InboundOutboundChecker;
|
---|
16 | import gov.hhs.fha.nhinc.gateway.policyenginetransformation.Helpers.SubjectHelper;
|
---|
17 | import gov.hhs.fha.nhinc.util.format.PatientIdFormatUtil;
|
---|
18 | import java.util.List;
|
---|
19 | import oasis.names.tc.ebxml_regrep.xsd.query._3.AdhocQueryRequest;
|
---|
20 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotType1;
|
---|
21 | import oasis.names.tc.xacml._2_0.context.schema.os.ActionType;
|
---|
22 | import oasis.names.tc.xacml._2_0.context.schema.os.AttributeType;
|
---|
23 | import oasis.names.tc.xacml._2_0.context.schema.os.AttributeValueType;
|
---|
24 | import oasis.names.tc.xacml._2_0.context.schema.os.RequestType;
|
---|
25 | import oasis.names.tc.xacml._2_0.context.schema.os.ResourceType;
|
---|
26 | import oasis.names.tc.xacml._2_0.context.schema.os.SubjectType;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | *
|
---|
30 | * @author rayj
|
---|
31 | */
|
---|
32 | public class AdhocQueryTransformHelper {
|
---|
33 |
|
---|
34 | private static final String ActionValue = "DocumentQueryIn";
|
---|
35 | private static final String PatientAssigningAuthorityAttributeId = Constants.AssigningAuthorityAttributeId;
|
---|
36 | private static final String PatientIdAttributeId = Constants.ResourceIdAttributeId;
|
---|
37 |
|
---|
38 | public static CheckPolicyRequestType transformAdhocQueryToCheckPolicy(AdhocQueryRequestEventType event) {
|
---|
39 | CheckPolicyRequestType result = null;
|
---|
40 | if (InboundOutboundChecker.IsInbound(event.getDirection())) {
|
---|
41 | result = transformAdhocQueryInboundToCheckPolicy(event);
|
---|
42 | }
|
---|
43 | if (InboundOutboundChecker.IsOutbound(event.getDirection())) {
|
---|
44 | result = transformAdhocQueryOutboundToCheckPolicy(event);
|
---|
45 | }
|
---|
46 | return result;
|
---|
47 | }
|
---|
48 |
|
---|
49 | private static CheckPolicyRequestType transformAdhocQueryToCheckPolicyBase(AdhocQueryRequestEventType event) {
|
---|
50 | CheckPolicyRequestType genericPolicyRequest = new CheckPolicyRequestType();
|
---|
51 |
|
---|
52 | AdhocQueryRequest docQuery = event.getMessage().getAdhocQueryRequest();
|
---|
53 |
|
---|
54 | RequestType request = new RequestType();
|
---|
55 |
|
---|
56 | request.setAction(ActionHelper.actionFactory(ActionValue));
|
---|
57 |
|
---|
58 | ResourceType resource = new ResourceType();
|
---|
59 | resource.getAttribute().add(AttributeHelper.attributeFactory(PatientAssigningAuthorityAttributeId, Constants.DataTypeString, extractPatientIdentifierAssigningAuthority(docQuery)));
|
---|
60 | resource.getAttribute().add(AttributeHelper.attributeFactory(PatientIdAttributeId, Constants.DataTypeString, extractPatientIdentifierId(docQuery)));
|
---|
61 | request.getResource().add(resource);
|
---|
62 |
|
---|
63 | SubjectType subject = SubjectHelper.subjectFactory(event.getSendingHomeCommunity() , event.getMessage().getAssertion());
|
---|
64 | request.getSubject().add(subject);
|
---|
65 |
|
---|
66 | genericPolicyRequest.setRequest(request);
|
---|
67 | return genericPolicyRequest;
|
---|
68 | }
|
---|
69 |
|
---|
70 | private static CheckPolicyRequestType transformAdhocQueryInboundToCheckPolicy(AdhocQueryRequestEventType event) {
|
---|
71 | return transformAdhocQueryToCheckPolicyBase(event);
|
---|
72 | }
|
---|
73 | private static CheckPolicyRequestType transformAdhocQueryOutboundToCheckPolicy(AdhocQueryRequestEventType event) {
|
---|
74 | CheckPolicyRequestType checkPolicy = transformAdhocQueryToCheckPolicyBase(event);
|
---|
75 | checkPolicy.getRequest().getResource().get(0).getAttribute().add(AttributeHelper.attributeFactory(Constants.HomeCommunityAttributeId, Constants.DataTypeString, CommunityHelper.extractCommunityId(event.getReceivingHomeCommunity())));
|
---|
76 | return checkPolicy;
|
---|
77 | }
|
---|
78 |
|
---|
79 | public static String extractPatientIdentifierId(AdhocQueryRequest docQuery) {
|
---|
80 | return PatientIdFormatUtil.parsePatientId(extractPatientIdentifier(docQuery));
|
---|
81 | }
|
---|
82 |
|
---|
83 | public static String extractPatientIdentifierAssigningAuthority(AdhocQueryRequest docQuery) {
|
---|
84 | return PatientIdFormatUtil.parseCommunityId(extractPatientIdentifier(docQuery));
|
---|
85 | }
|
---|
86 |
|
---|
87 | private static String extractPatientIdentifier(AdhocQueryRequest docQuery) {
|
---|
88 | String patientIdentifier = null;
|
---|
89 |
|
---|
90 | if ((docQuery != null) && (docQuery.getAdhocQuery() != null)) {
|
---|
91 | List<SlotType1> slots = docQuery.getAdhocQuery().getSlot();
|
---|
92 | for (SlotType1 slot : slots) {
|
---|
93 | if ((slot.getName() != null) && (slot.getName().contentEquals("$XDSDocumentEntryPatientId"))) {
|
---|
94 | if (slot.getValueList() != null) {
|
---|
95 | if (slot.getValueList().getValue().size() == 1) {
|
---|
96 | patientIdentifier = slot.getValueList().getValue().get(0);
|
---|
97 | }
|
---|
98 | }
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|
102 | return patientIdentifier;
|
---|
103 | }
|
---|
104 | }
|
---|