source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Adapters/General/AdapterReidentificationEJB/src/java/gov/hhs/fha/nhinc/adapter/reidentification/AdapterReidentificationImpl.java@ 507

Last change on this file since 507 was 507, checked in by George Lilly, 15 years ago

NHIN gateway and adaptor for use on linux with VistA EHR and RPMS

File size: 7.5 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package gov.hhs.fha.nhinc.adapter.reidentification;
6
7import java.util.List;
8import javax.xml.bind.JAXBElement;
9import org.hl7.v3.PIXConsumerPRPAIN201309UVRequestType;
10import org.hl7.v3.PIXConsumerPRPAIN201310UVRequestType;
11import org.hl7.v3.PRPAIN201309UV;
12import org.hl7.v3.PRPAIN201310UV;
13import org.hl7.v3.PRPAIN201309UVQUQIMT021001UV01ControlActProcess;
14import org.hl7.v3.PRPAMT201307UVQueryByParameter;
15import org.hl7.v3.PRPAMT201307UVParameterList;
16import org.hl7.v3.PRPAMT201307UVPatientIdentifier;
17import org.hl7.v3.II;
18import org.hl7.v3.MCCIMT000100UV01Sender;
19import org.hl7.v3.MCCIMT000100UV01Receiver;
20import org.hl7.v3.MCCIMT000100UV01Device;
21import gov.hhs.fha.nhinc.adapter.reidentification.data.PseudonymMap;
22import gov.hhs.fha.nhinc.transform.subdisc.HL7Constants;
23import gov.hhs.fha.nhinc.transform.subdisc.HL7PRPA201310Transforms;
24
25/**
26 * This provides the implementation of the adapter reidentification web service
27 */
28class AdapterReidentificationImpl {
29 //localDeviceId is currently just set to a default value
30 private String localDeviceId = HL7Constants.DEFAULT_LOCAL_DEVICE_ID;
31
32 PIXConsumerPRPAIN201310UVRequestType getRealIdentifier(PIXConsumerPRPAIN201309UVRequestType realIdentifierRequest) {
33 PIXConsumerPRPAIN201310UVRequestType ret201310RequestType = new PIXConsumerPRPAIN201310UVRequestType();
34
35 if (realIdentifierRequest != null) {
36 ret201310RequestType.setAssertion(realIdentifierRequest.getAssertion());
37
38 PRPAIN201310UV response201310 = null;
39 PRPAIN201309UV request201309 = realIdentifierRequest.getPRPAIN201309UV();
40 if (request201309 != null) {
41 // extract information from the 201309 request message
42 // extract sender OID and set to the receiver OID for the 201310
43 String receiverOID = extractSenderOID(request201309);
44
45 // extract receiver OID and set to the sender OID for the 201310
46 String senderOID = extractReceiverOID(request201309);
47
48 if (senderOID != null && receiverOID != null) {
49 // extract queryByParameter
50 PRPAMT201307UVQueryByParameter queryByParameter = extractQueryByParameter(request201309);
51
52 // extract pseudonymPatientId and pseudonymPatientIdAssigningAuthority
53 // and translate to real patient IDs
54 String realPatientId = null;
55 String realAssigningAuthority = null;
56 if (queryByParameter != null) {
57 II pseudoPatientItem = extractPseudoPatientIds(queryByParameter);
58 if (pseudoPatientItem != null) {
59 String pseudonymPatientIdAssigningAuthority = pseudoPatientItem.getRoot();
60 String pseudonymPatientId = pseudoPatientItem.getExtension();
61 if (pseudonymPatientIdAssigningAuthority != null && pseudonymPatientId != null) {
62 // look up real patient id and assigning authority
63 PseudonymMapManager.readMap();
64 PseudonymMap pseudonymMap = PseudonymMapManager.findPseudonymMap(pseudonymPatientIdAssigningAuthority, pseudonymPatientId);
65 if (pseudonymMap != null) {
66 realPatientId = pseudonymMap.getRealPatientId();
67 realAssigningAuthority = pseudonymMap.getRealPatientIdAssigningAuthority();
68 }
69 }
70 }
71 }
72 if (realPatientId != null && realAssigningAuthority != null) {
73 response201310 = HL7PRPA201310Transforms.createPRPA201310(realPatientId, realAssigningAuthority, localDeviceId, senderOID, receiverOID, queryByParameter);
74 } else {
75 response201310 = HL7PRPA201310Transforms.createFaultPRPA201310(senderOID, receiverOID);
76 }
77 } else {
78 response201310 = HL7PRPA201310Transforms.createFaultPRPA201310();
79 }
80 } else {
81 //create error response
82 response201310 = HL7PRPA201310Transforms.createFaultPRPA201310();
83 }
84 ret201310RequestType.setPRPAIN201310UV(response201310);
85 }
86 return ret201310RequestType;
87 }
88
89 private II extractPseudoPatientIds(PRPAMT201307UVQueryByParameter queryByParameter) {
90 II pseudoPatientItem = null;
91 if (queryByParameter != null) {
92 PRPAMT201307UVParameterList parameterList = queryByParameter.getParameterList();
93 if (parameterList != null) {
94 PRPAMT201307UVPatientIdentifier patientIdentifier = null;
95 List<PRPAMT201307UVPatientIdentifier> patientIdentifierList = parameterList.getPatientIdentifier();
96 if (patientIdentifierList != null && !patientIdentifierList.isEmpty()) {
97 patientIdentifier = patientIdentifierList.get(0);
98 List<II> iiList = patientIdentifier.getValue();
99 if (iiList != null && !iiList.isEmpty()) {
100 pseudoPatientItem = iiList.get(0);
101 }
102 }
103 }
104 }
105 return pseudoPatientItem;
106 }
107
108 private PRPAMT201307UVQueryByParameter extractQueryByParameter(PRPAIN201309UV request201309) {
109 PRPAMT201307UVQueryByParameter queryByParameter = null;
110 PRPAIN201309UVQUQIMT021001UV01ControlActProcess controlAct = request201309.getControlActProcess();
111 if (controlAct != null) {
112 JAXBElement<PRPAMT201307UVQueryByParameter> queryByParameterElem = controlAct.getQueryByParameter();
113 if (queryByParameterElem != null) {
114 queryByParameter = queryByParameterElem.getValue();
115 }
116 }
117 return queryByParameter;
118 }
119
120 private String extractReceiverOID(PRPAIN201309UV request201309) {
121 String receiverOID201309 = null;
122 List<MCCIMT000100UV01Receiver> receiver201309List = request201309.getReceiver();
123 if (receiver201309List != null && !receiver201309List.isEmpty()) {
124 MCCIMT000100UV01Receiver receiver201309 = receiver201309List.get(0);
125 MCCIMT000100UV01Device receiverDevice = receiver201309.getDevice();
126 if (receiverDevice != null) {
127 List<II> listDevices = receiverDevice.getId();
128 if (listDevices != null && !listDevices.isEmpty()) {
129 for (II item : listDevices) {
130 receiverOID201309 = item.getRoot();
131 }
132 }
133 }
134 }
135 return receiverOID201309;
136 }
137
138 private String extractSenderOID(PRPAIN201309UV request201309) {
139 String senderOID201309 = null;
140 MCCIMT000100UV01Sender sender201309 = request201309.getSender();
141 if (sender201309 != null) {
142 MCCIMT000100UV01Device senderDevice = sender201309.getDevice();
143 if (senderDevice != null) {
144 List<II> listDevices = senderDevice.getId();
145 if (listDevices != null && !listDevices.isEmpty()) {
146 for (II item : listDevices) {
147 senderOID201309 = item.getRoot();
148 }
149 }
150 }
151 }
152 return senderOID201309;
153 }
154}
Note: See TracBrowser for help on using the repository browser.