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 VerifyNHSNumberResponse.
34   *
35   * @author Michael Odling-Smee
36   * @author Nicholas Jones
37   * @since 0.1
38   */
39  public class VerifyNHSNumberResponse 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 verified indicator.
65  	 *
66  	 * @return the verified indicator
67  	 */
68  	public boolean getVerifiedIndicator() {
69  		return verifiedIndicator;
70  	}
71  	
72  	/**
73  	 * Sets the verified indicator.
74  	 *
75  	 * @param verifiedIndicator the new verified indicator
76  	 */
77  	public void setVerifiedIndicator(boolean verifiedIndicator) {
78  		this.verifiedIndicator = verifiedIndicator;
79  	}
80  	
81  	/**
82  	 * Gets the response code.
83  	 *
84  	 * @return the response code
85  	 */
86  	public String getResponseCode() {
87  		return responseCode;
88  	}
89  	
90  	/**
91  	 * Sets the response code.
92  	 *
93  	 * @param responseCode the new response code
94  	 */
95  	public void setResponseCode(String responseCode) {
96  		this.responseCode = responseCode;
97  	}
98  	
99  	/**
100 	 * Gets the response message.
101 	 *
102 	 * @return the response message
103 	 */
104 	public String getResponseMessage() {
105 		return responseMessage;
106 	}
107 	
108 	/**
109 	 * Sets the response message.
110 	 *
111 	 * @param responseMessage the new response message
112 	 */
113 	public void setResponseMessage(String responseMessage) {
114 		this.responseMessage = responseMessage;
115 	}
116 	
117 	/** The nhs number. */
118 	String nhsNumber;
119 	
120 	/** The verified indicator. */
121 	boolean verifiedIndicator;
122 	
123 	/** The response code. */
124 	String responseCode;
125 	
126 	/** The response message. */
127 	String responseMessage;
128 
129 	String payload;
130 	public String getPayload(){
131 		return payload;
132 	}
133 	
134 	/**
135 	 * Instantiates a new verify nhs number response.
136 	 *
137 	 * @param response the response
138 	 * @throws ITKMessagingException the iTK messaging exception
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 		// Build The Response
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 		// TODO: Read the specification re: response message doesn't appear to be in the message!
185 		this.responseMessage = "";
186 		this.payload = response.getBusinessPayload();
187 
188 	}
189 }