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.notification;
15  
16  import uk.nhs.interoperability.infrastructure.ITKAddressImpl;
17  import uk.nhs.interoperability.infrastructure.ITKIdentity;
18  import uk.nhs.interoperability.infrastructure.ITKIdentityImpl;
19  import uk.nhs.interoperability.infrastructure.ITKMessageProperties;
20  import uk.nhs.interoperability.infrastructure.ITKMessagePropertiesImpl;
21  import uk.nhs.interoperability.infrastructure.ITKMessagingException;
22  import uk.nhs.interoperability.payload.ITKMessage;
23  import uk.nhs.interoperability.payload.SimpleMessage;
24  import uk.nhs.interoperability.source.ITKMessageSender;
25  import uk.nhs.interoperability.source.ITKMessageSenderImpl;
26  import uk.nhs.interoperability.util.Logger;
27  
28  /**
29   * The Class NotificationSender.
30   *
31   * @author Adam Hatherly
32   * @since 0.1
33   */
34  public class NotificationSender {
35  
36  	/** The Constant NOTIFICATIONSTORE. */
37  	private static final String NOTIFICATIONSTORE = "urn:nhs-uk:addressing:ods:TESTORGS:NOTIFICATIONSTORE";
38  
39  	/** The Constant ORGID. */
40  	private static final String ORGID = "urn:nhs-uk:identity:ods:TESTORGS:ORGA";
41  
42  	/** The Constant AUDITID. */
43  	private static final ITKIdentity AUDITID = new ITKIdentityImpl(ORGID);
44  
45  	/** The Constant FROMADDRESS. */
46  	private static final String FROMADDRESS = "urn:nhs-uk:addressing:ods:R59:oncology";
47  
48  	/** The Constant NOTIFICATION_SERVICENAME. */
49  	private static final String NOTIFICATION_SERVICENAME = "urn:nhs-itk:services:201005:SendEventNotification-v1-0";
50  	
51  	/** The Constant NOTIFICATION_PROFILEID. */
52  	private static final String NOTIFICATION_PROFILEID = "urn:nhs-en:profile:EventNotification-v1-0";
53  
54  	/**
55  	 * The main method.
56  	 *
57  	 * @param args the arguments
58  	 */
59  	public static void main(String[] args) {
60  
61  		NotificationSender appA = new NotificationSender();
62  		appA.sendNotificationMessage();
63  	
64  	}
65  
66  	/**
67  	 * Send notification message.
68  	 */
69  	private void sendNotificationMessage(){
70  		Logger.trace("*** NotificationSender: Starting sendNotificationMessage");
71  		
72  		// Create the message
73  		ITKMessage msg = new SimpleMessage();
74  		Notification n = new Notification();
75  		n.setMessageId("NOTIFICATIONTEST");
76  		n.setEffectiveTime("20121127151500+0000");
77  		n.setDateOfBirth("20020831");
78  		n.setSenderOrg("Organisation1");
79  		n.setRecipientOrg("Organisation2");
80  		n.setRecipientAddress("Leeds, LS1 4HY");
81  		n.setPatientName("Joe Bloggs");
82  		n.setPatientAddress("Cleckheaton, BD19 3RH");
83  		n.setNHSNumber("1234556789");
84  		n.setEventTypeCode("01");
85  		n.setEventTypeDesc("DocumentEvent");
86  		n.setContactName("Fred Bloggs");
87  		n.setContactAddress("Bradford, BD1 1HY");
88  		n.setContactOrg("Organisation3");
89  		msg.setBusinessPayload(n.serialise());
90  
91  		// Build the message properties.
92  		ITKMessageProperties mp = new ITKMessagePropertiesImpl();
93  		mp.setAuditIdentity(AUDITID);
94  		mp.setFromAddress(new ITKAddressImpl(FROMADDRESS));
95  		mp.setToAddress(new ITKAddressImpl(NOTIFICATIONSTORE));
96  		mp.setServiceId(NOTIFICATION_SERVICENAME);
97  		//mp.setBusinessPayloadId(req.getMessageId());
98  		mp.setBusinessPayloadId("NOTIFICATION");
99  		mp.setProfileId(NOTIFICATION_PROFILEID);	// Not sure what the profile ID should be?
100 
101 		// Add the properties to the message
102 		msg.setMessageProperties(mp);
103 		
104 		// Create the sender
105 		ITKMessageSender sender = new ITKMessageSenderImpl();
106 
107 		try {
108 			// Send this message asynchronously. The response message will be returned
109 			sender.sendAsync(msg);
110 		
111 			Logger.trace("Notification Sender sent message");
112 			
113 		} catch (ITKMessagingException e) {
114 			Logger.error("Error Sending ITK Message",e);
115 		}
116 		
117 		Logger.trace("*** Notification Sender: Ending sendNotificationMessage");
118 	}
119 
120 }