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 uk.nhs.interoperability.infrastructure.ITKAddress;
17  import uk.nhs.interoperability.infrastructure.ITKAddressImpl;
18  import uk.nhs.interoperability.infrastructure.ITKIdentity;
19  import uk.nhs.interoperability.infrastructure.ITKIdentityImpl;
20  import uk.nhs.interoperability.infrastructure.ITKMessageProperties;
21  import uk.nhs.interoperability.infrastructure.ITKMessagePropertiesImpl;
22  import uk.nhs.interoperability.infrastructure.ITKMessagingException;
23  import uk.nhs.interoperability.payload.ITKMessage;
24  import uk.nhs.interoperability.payload.SimpleMessage;
25  import uk.nhs.interoperability.source.ITKMessageSender;
26  import uk.nhs.interoperability.source.ITKMessageSenderImpl;
27  import uk.nhs.interoperability.util.Logger;
28  
29  /**
30   * The Class SpineMiniServicesClient.
31   *
32   * @author Michael Odling-Smee
33   * @author Nicholas Jones
34   * @since 0.1
35   */
36  public class SpineMiniServicesClient {
37  
38  	/** The Constant ORGB. */
39  	private static final String ORGB = "urn:nhs-uk:addressing:ods:TESTORGS:ORGB";
40  	
41  	/** The Constant ORGA. */
42  	private static final String ORGA = "urn:nhs-uk:addressing:ods:TESTORGS:ORGA";
43  	
44  	/** The Constant CLOUDHARNESS. */
45  	private static final String CLOUDHARNESS = "urn:nhs-uk:addressing:ods:TESTORGS:CLOUDHARNESS";
46  
47  	/** The Constant AUDITID. */
48  	private static final ITKIdentity AUDITID = new ITKIdentityImpl(ORGA);
49  	
50  	/** The Constant FROMADDRESS. */
51  	private static final String FROMADDRESS = ORGA;
52  
53  	/** The Constant VERIFY_NHS. */
54  	private static final String VERIFY_NHS = "urn:nhs-itk:services:201005:verifyNHSNumber-v1-0";
55  	
56  	/** The Constant GET_NHS. */
57  	private static final String GET_NHS = "urn:nhs-itk:services:201005:getNHSNumber-v1-0";
58  
59  	/** The Constant VN_PROFILEID. */
60  	private static final String GNN_PROFILEID = "urn:nhs-en:profile:getNHSNumberRequest-v1-0";
61  
62  	/** The Constant VN_PROFILEID. */
63  	private static final String VN_PROFILEID = "urn:nhs-en:profile:verifyNHSNumberRequest-v1-0";
64  
65  	/** The Constant GET_PD_NHS. */
66  	private static final String GET_PD_NHS = "urn:nhs-itk:services:201005:getPatientDetailsByNHSNumber-v1-0";
67  	
68  	/** The Constant GPDN_PROFILEID. */
69  	private static final String GPDN_PROFILEID = "urn:nhs-en:profile:getPatientDetailsByNHSNumberRequest-v1-0";
70  	
71  	/**
72  	 * The main method.
73  	 *
74  	 * @param args the arguments
75  	 */
76  	public static void main(String[] args) {
77  
78  		if ( args.length < 3){
79  			Logger.warn("Usage : SpineMiniServicesClient verify|get NHSNumber DOB [destination (ORGB | CLOUDHARNESS)]");
80  			System.exit(1);
81  		}
82  		String service = args[0].toUpperCase();
83  		if (!( (service.equals("VERIFY")) || 
84  				(service.equals("GET")) ) ){
85  			Logger.warn("Usage : SpineMiniServicesClient verify|get NHSNumber DOB");
86  			System.exit(1);
87  		}
88  		
89  		ITKAddress toAddress = new ITKAddressImpl(ORGB);
90  
91  		String nhsNumber = args[1];
92  		String DOB = args[2];
93  		SpineMiniServicesClient client = new SpineMiniServicesClient();
94  		
95  		//Work out whether to send to a local server or cloudharness
96  		if (args.length == 4) {
97  			if ("CLOUDHARNESS".equalsIgnoreCase(args[3])) {
98  				toAddress = new ITKAddressImpl(CLOUDHARNESS);
99  			}
100 		}
101 		
102 		if (service.equals("GET")){
103 			GetPatientDetailsByNHSNumberRequest req1 = new GetPatientDetailsByNHSNumberRequest();
104 			req1.setNHSNumber(nhsNumber);
105 			req1.setDateOfBirth(DOB);
106 			GetPatientDetailsByNHSNumberResponse resp1 = client.getPatientDetailsByNHSNumber(req1, toAddress);
107 			if (resp1 != null) {
108 				Logger.info("SMSP GPDBNN COMPLETE. RESPONSE CODE:" + resp1.getResponseCode());
109 			}
110 		}
111 
112 		if (service.equals("VERIFY")){
113 			VerifyNHSNumberRequest req2 = new VerifyNHSNumberRequest();
114 			req2.setNHSNumber(nhsNumber);
115 			req2.setDateOfBirth(DOB);
116 			VerifyNHSNumberResponse resp2 = client.verifyNHSNumber(req2, toAddress);
117 			if (resp2 != null) {
118 				Logger.info("SMSP VNN COMPLETE. RESPONSE CODE:" + resp2.getResponseCode());
119 			}
120 		}
121 	
122 	}
123 
124 	/**
125 	 * Verify nhs number.
126 	 *
127 	 * @param request the request
128 	 * @param toAddress the to address
129 	 * @return the verify nhs number response
130 	 */
131 	public VerifyNHSNumberResponse verifyNHSNumber(VerifyNHSNumberRequest request, 
132 													ITKAddress toAddress){
133 
134 		Logger.info("*** SpineMiniServicesClient: Starting verifyNHSNumber");
135 		
136 		VerifyNHSNumberResponse response = null;
137 		// Create the message
138 		ITKMessage msg = new SimpleMessage();
139 		msg.setBusinessPayload(request.serialise());
140 
141 		// Build the message properties.
142 		ITKMessageProperties mp = new ITKMessagePropertiesImpl();
143 		mp.setAuditIdentity(AUDITID);
144 		mp.setFromAddress(new ITKAddressImpl(FROMADDRESS));
145 		mp.setToAddress(toAddress);
146 		mp.setServiceId(VERIFY_NHS);
147 		mp.setBusinessPayloadId(request.getMessageId());
148 		mp.setProfileId(VN_PROFILEID);
149 
150 		// Add the properties to the message
151 		msg.setMessageProperties(mp);
152 		
153 		ITKMessageSender sender = new ITKMessageSenderImpl();
154 		try {
155 			ITKMessage resp = sender.sendSync(msg);
156 			response = new VerifyNHSNumberResponse(resp);
157 			Logger.trace("SendingApplicationA received response from verifyNHSNumber call:"+resp.getBusinessPayload());
158 			
159 		} catch (ITKMessagingException e) {
160 			Logger.error("Error Sending ITK Message",e);
161 		}
162 		
163 		Logger.info("*** SpineMiniServicesClient: Ending verifyNHSNumber");
164 		
165 		return response;
166 	}
167 	
168 	/**
169 	 * Get NHS number. A Trace Request
170 	 *
171 	 * @param request the request
172 	 * @param toAddress the to address
173 	 * @return the verify nhs number response
174 	 */
175 	public GetNHSNumberResponse getNHSNumber(GetNHSNumberRequest request, 
176 													ITKAddress toAddress){
177 
178 		Logger.info("*** SpineMiniServicesClient: Starting getNHSNumber");
179 		
180 		GetNHSNumberResponse response = null;
181 		// Create the message
182 		ITKMessage msg = new SimpleMessage();
183 		msg.setBusinessPayload(request.serialise());
184 
185 		// Build the message properties.
186 		ITKMessageProperties mp = new ITKMessagePropertiesImpl();
187 		mp.setAuditIdentity(AUDITID);
188 		mp.setFromAddress(new ITKAddressImpl(FROMADDRESS));
189 		mp.setToAddress(toAddress);
190 		mp.setServiceId(GET_NHS);
191 		mp.setBusinessPayloadId(request.getMessageId());
192 		mp.setProfileId(GNN_PROFILEID);
193 
194 		// Add the properties to the message
195 		msg.setMessageProperties(mp);
196 		
197 		ITKMessageSender sender = new ITKMessageSenderImpl();
198 		try {
199 			ITKMessage resp = sender.sendSync(msg);
200 			response = new GetNHSNumberResponse(resp);
201 			Logger.trace("SendingApplicationA received response from getNHSNumber call:"+resp.getBusinessPayload());
202 			
203 		} catch (ITKMessagingException e) {
204 			Logger.error("Error Sending ITK Message",e);
205 		}
206 		
207 		Logger.info("*** SpineMiniServicesClient: Ending getNHSNumber");
208 		
209 		return response;
210 	}
211 
212 	/**
213 	 * Gets the patient details by nhs number.
214 	 *
215 	 * @param request the request
216 	 * @param toAddress the to address
217 	 * @return the patient details by nhs number
218 	 */
219 	public GetPatientDetailsByNHSNumberResponse getPatientDetailsByNHSNumber(
220 													GetPatientDetailsByNHSNumberRequest request, 
221 													ITKAddress toAddress){
222 
223 		Logger.info("*** SpineMiniServicesClient: Starting getPatientDetailsByNHSNumber");
224 		
225 		GetPatientDetailsByNHSNumberResponse response = null;
226 		
227 		ITKMessage msg = new SimpleMessage();
228 		msg.setBusinessPayload(request.serialise());
229 		
230 		// Build the message properties.
231 		ITKMessageProperties mp = new ITKMessagePropertiesImpl();
232 		mp.setAuditIdentity(AUDITID);
233 		mp.setFromAddress(new ITKAddressImpl(FROMADDRESS));
234 		mp.setToAddress(toAddress);
235 		mp.setServiceId(GET_PD_NHS);
236 		mp.setBusinessPayloadId(request.getMessageId());
237 		mp.setProfileId(GPDN_PROFILEID);
238 
239 		// Add the properties to the message
240 		msg.setMessageProperties(mp);
241 		
242 		// Create the sender
243 		ITKMessageSender sender = new ITKMessageSenderImpl();
244 		try {
245 			ITKMessage resp = sender.sendSync(msg);
246 			response = new GetPatientDetailsByNHSNumberResponse(resp);
247 			Logger.trace("SendingApplicationA received response from getPatientDetailsByNHSNumber call:"+resp.getBusinessPayload());
248 			
249 		} catch (ITKMessagingException e) {
250 			Logger.error("Error Sending ITK Message",e);
251 		}
252 		
253 		Logger.info("*** SpineMiniServicesClient: Ending getPatientDetailsByNHSNumber");
254 		
255 		return response;
256 	}
257 
258 }