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 GetNHSNumberResponse 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 String getResponseCode() {
69 return responseCode;
70 }
71
72
73
74
75
76
77 public void setResponseCode(String responseCode) {
78 this.responseCode = responseCode;
79 }
80
81
82
83
84
85
86 public String getResponseMessage() {
87 return responseMessage;
88 }
89
90
91
92
93
94
95 public void setResponseMessage(String responseMessage) {
96 this.responseMessage = responseMessage;
97 }
98
99
100 String nhsNumber;
101
102
103 String localIdentifier;
104
105 public String getLocalIdentifier() {
106 return localIdentifier;
107 }
108
109 public void setLocalIdentifier(String localIdentifier) {
110 this.localIdentifier = localIdentifier;
111 }
112
113
114 String responseCode;
115
116
117 String responseMessage;
118
119 String payload;
120 public String getPayload(){
121 return payload;
122 }
123
124
125
126
127
128
129
130 public GetNHSNumberResponse(ITKMessage response) throws ITKMessagingException {
131
132 if (response==null || response.getBusinessPayload() == null){
133 throw new ITKMessagingException("No payload returned from service");
134 }
135
136
137 String nhsNumber="";
138 String responseCode="";
139 String localIdentifier="";
140 try {
141 Document responseDoc = DomUtils.parse(response.getBusinessPayload());
142 responseCode = (String)XPaths.getXPathExpression(
143 "/hl7:getNHSNumberResponse-v1-0/hl7:value/@code")
144 .evaluate(responseDoc);
145 nhsNumber = (String)XPaths.getXPathExpression(
146 "/hl7:getNHSNumberResponse-v1-0/hl7:subject/hl7:patient/hl7:id[@root='2.16.840.1.113883.2.1.4.1']/@extension")
147 .evaluate(responseDoc);
148 localIdentifier = (String)XPaths.getXPathExpression(
149 "/hl7:getNHSNumberResponse-v1-0/hl7:subject/hl7:patient/hl7:id[@root='2.16.840.1.113883.2.1.3.2.4.18.24']/@extension")
150 .evaluate(responseDoc);
151 } catch (SAXException e) {
152 Logger.error("SAXException parsing GetNHSNumberResponse", e);
153 throw new ITKMessagingException("SAXException parsing GetNHSNumberResponse");
154 } catch (IOException e) {
155 Logger.error("IOException parsing GetNHSNumberResponse", e);
156 throw new ITKMessagingException("IOException parsing GetNHSNumberResponse");
157 } catch (ParserConfigurationException e) {
158 Logger.error("ParserConfigurationException parsing GetNHSNumberResponse", e);
159 throw new ITKMessagingException("ParserConfigurationException parsing GetNHSNumberResponse");
160 } catch (XPathExpressionException e) {
161 Logger.error("XPathExpressionException parsing GetNHSNumberResponse", e);
162 throw new ITKMessagingException("XPathExpressionException parsing GetNHSNumberResponse");
163 }
164
165 this.nhsNumber = nhsNumber;
166 this.localIdentifier = localIdentifier;
167 this.responseCode = responseCode;
168 this.responseMessage = "";
169 this.payload = response.getBusinessPayload();
170
171 }
172 }