1
2
3
4
5
6
7
8
9
10
11
12
13
14 package uk.nhs.interoperability.client.samples.smsp;
15
16 import java.io.IOException;
17 import java.io.Serializable;
18
19 import javax.xml.parsers.ParserConfigurationException;
20 import javax.xml.xpath.XPathExpressionException;
21
22 import org.w3c.dom.Document;
23 import org.xml.sax.SAXException;
24
25 import uk.nhs.interoperability.infrastructure.ITKMessagingException;
26 import uk.nhs.interoperability.payload.ITKMessage;
27 import uk.nhs.interoperability.util.Logger;
28 import uk.nhs.interoperability.util.xml.DomUtils;
29 import uk.nhs.interoperability.util.xml.XPaths;
30
31
32
33
34
35
36
37
38
39 public class VerifyNHSNumberResponse implements Serializable {
40
41
42
43
44 private static final long serialVersionUID = -510904168540955845L;
45
46
47
48
49
50 public String getNhsNumber() {
51 return nhsNumber;
52 }
53
54
55
56
57
58
59 public void setNhsNumber(String nhsNumber) {
60 this.nhsNumber = nhsNumber;
61 }
62
63
64
65
66
67
68 public boolean getVerifiedIndicator() {
69 return verifiedIndicator;
70 }
71
72
73
74
75
76
77 public void setVerifiedIndicator(boolean verifiedIndicator) {
78 this.verifiedIndicator = verifiedIndicator;
79 }
80
81
82
83
84
85
86 public String getResponseCode() {
87 return responseCode;
88 }
89
90
91
92
93
94
95 public void setResponseCode(String responseCode) {
96 this.responseCode = responseCode;
97 }
98
99
100
101
102
103
104 public String getResponseMessage() {
105 return responseMessage;
106 }
107
108
109
110
111
112
113 public void setResponseMessage(String responseMessage) {
114 this.responseMessage = responseMessage;
115 }
116
117
118 String nhsNumber;
119
120
121 boolean verifiedIndicator;
122
123
124 String responseCode;
125
126
127 String responseMessage;
128
129 String payload;
130 public String getPayload(){
131 return payload;
132 }
133
134
135
136
137
138
139
140 public VerifyNHSNumberResponse(ITKMessage response) throws ITKMessagingException {
141
142 if (response==null || response.getBusinessPayload() == null){
143 throw new ITKMessagingException("No payload returned from service");
144 }
145
146
147 String verified="";
148 String nhsNumber="";
149 String responseCode="";
150 try {
151 Document responseDoc = DomUtils.parse(response.getBusinessPayload());
152 responseCode = (String)XPaths.getXPathExpression(
153 "/hl7:verifyNHSNumberResponse-v1-0/hl7:value/@code")
154 .evaluate(responseDoc);
155 verified = (String)XPaths.getXPathExpression(
156 "/hl7:verifyNHSNumberResponse-v1-0/hl7:component/hl7:validIdentifier/hl7:value/@value")
157 .evaluate(responseDoc);
158 nhsNumber = (String)XPaths.getXPathExpression(
159 "/hl7:verifyNHSNumberResponse-v1-0/hl7:component/hl7:validIdentifier/hl7:subject/hl7:patient/hl7:id/@extension")
160 .evaluate(responseDoc);
161 } catch (SAXException e) {
162 Logger.error("SAXException parsing VerifyNHSNumberResponse", e);
163 throw new ITKMessagingException("SAXException parsing VerifyNHSNumberResponse");
164 } catch (IOException e) {
165 Logger.error("IOException parsing VerifyNHSNumberResponse", e);
166 throw new ITKMessagingException("IOException parsing VerifyNHSNumberResponse");
167 } catch (ParserConfigurationException e) {
168 Logger.error("ParserConfigurationException parsing VerifyNHSNumberResponse", e);
169 throw new ITKMessagingException("ParserConfigurationException parsing VerifyNHSNumberResponse");
170 } catch (XPathExpressionException e) {
171 Logger.error("XPathExpressionException parsing VerifyNHSNumberResponse", e);
172 throw new ITKMessagingException("XPathExpressionException parsing VerifyNHSNumberResponse");
173 }
174
175 if (verified.equalsIgnoreCase("TRUE")){
176 this.verifiedIndicator = true;
177 } else {
178 this.verifiedIndicator = false;
179 }
180
181 this.nhsNumber = nhsNumber;
182 this.responseCode = responseCode;
183
184
185 this.responseMessage = "";
186 this.payload = response.getBusinessPayload();
187
188 }
189 }