1
2
3
4
5
6
7
8
9
10
11
12
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
31
32
33
34
35
36 public class SpineMiniServicesClient {
37
38
39 private static final String ORGB = "urn:nhs-uk:addressing:ods:TESTORGS:ORGB";
40
41
42 private static final String ORGA = "urn:nhs-uk:addressing:ods:TESTORGS:ORGA";
43
44
45 private static final String CLOUDHARNESS = "urn:nhs-uk:addressing:ods:TESTORGS:CLOUDHARNESS";
46
47
48 private static final ITKIdentity AUDITID = new ITKIdentityImpl(ORGA);
49
50
51 private static final String FROMADDRESS = ORGA;
52
53
54 private static final String VERIFY_NHS = "urn:nhs-itk:services:201005:verifyNHSNumber-v1-0";
55
56
57 private static final String GET_NHS = "urn:nhs-itk:services:201005:getNHSNumber-v1-0";
58
59
60 private static final String GNN_PROFILEID = "urn:nhs-en:profile:getNHSNumberRequest-v1-0";
61
62
63 private static final String VN_PROFILEID = "urn:nhs-en:profile:verifyNHSNumberRequest-v1-0";
64
65
66 private static final String GET_PD_NHS = "urn:nhs-itk:services:201005:getPatientDetailsByNHSNumber-v1-0";
67
68
69 private static final String GPDN_PROFILEID = "urn:nhs-en:profile:getPatientDetailsByNHSNumberRequest-v1-0";
70
71
72
73
74
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
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
126
127
128
129
130
131 public VerifyNHSNumberResponse verifyNHSNumber(VerifyNHSNumberRequest request,
132 ITKAddress toAddress){
133
134 Logger.info("*** SpineMiniServicesClient: Starting verifyNHSNumber");
135
136 VerifyNHSNumberResponse response = null;
137
138 ITKMessage msg = new SimpleMessage();
139 msg.setBusinessPayload(request.serialise());
140
141
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
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
170
171
172
173
174
175 public GetNHSNumberResponse getNHSNumber(GetNHSNumberRequest request,
176 ITKAddress toAddress){
177
178 Logger.info("*** SpineMiniServicesClient: Starting getNHSNumber");
179
180 GetNHSNumberResponse response = null;
181
182 ITKMessage msg = new SimpleMessage();
183 msg.setBusinessPayload(request.serialise());
184
185
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
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
214
215
216
217
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
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
240 msg.setMessageProperties(mp);
241
242
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 }