View Javadoc

1   /*
2      Licensed under the Apache License, Version 2.0 (the "License");
3      you may not use this file except in compliance with the License.
4      You may obtain a copy of the License at
5   
6        http://www.apache.org/licenses/LICENSE-2.0
7   
8      Unless required by applicable law or agreed to in writing, software
9      distributed under the License is distributed on an "AS IS" BASIS,
10     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11     See the License for the specific language governing permissions and
12     limitations under the License.
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   * The Class GetNHSNumberResponse.
34   *
35   * @author Michael Odling-Smee
36   * @author Nicholas Jones
37   * @since 0.1
38   */
39  public class GetNHSNumberResponse implements Serializable {
40  
41  	/**
42  	 * 
43  	 */
44  	private static final long serialVersionUID = -510904168540955845L;
45  	/**
46  	 * Gets the nhs number.
47  	 *
48  	 * @return the nhs number
49  	 */
50  	public String getNhsNumber() {
51  		return nhsNumber;
52  	}
53  	
54  	/**
55  	 * Sets the nhs number.
56  	 *
57  	 * @param nhsNumber the new nhs number
58  	 */
59  	public void setNhsNumber(String nhsNumber) {
60  		this.nhsNumber = nhsNumber;
61  	}
62  		
63  	/**
64  	 * Gets the response code.
65  	 *
66  	 * @return the response code
67  	 */
68  	public String getResponseCode() {
69  		return responseCode;
70  	}
71  	
72  	/**
73  	 * Sets the response code.
74  	 *
75  	 * @param responseCode the new response code
76  	 */
77  	public void setResponseCode(String responseCode) {
78  		this.responseCode = responseCode;
79  	}
80  	
81  	/**
82  	 * Gets the response message.
83  	 *
84  	 * @return the response message
85  	 */
86  	public String getResponseMessage() {
87  		return responseMessage;
88  	}
89  	
90  	/**
91  	 * Sets the response message.
92  	 *
93  	 * @param responseMessage the new response message
94  	 */
95  	public void setResponseMessage(String responseMessage) {
96  		this.responseMessage = responseMessage;
97  	}
98  	
99  	/** The nhs number. */
100 	String nhsNumber;
101 	
102 	/** The local identifier. */
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 	/** The response code. */
114 	String responseCode;
115 	
116 	/** The response message. */
117 	String responseMessage;
118 
119 	String payload;
120 	public String getPayload(){
121 		return payload;
122 	}
123 	
124 	/**
125 	 * Instantiates a new verify nhs number response.
126 	 *
127 	 * @param response the response
128 	 * @throws ITKMessagingException the iTK messaging exception
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 		// Build The Response
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 }