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.cda;
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 CDASenderWithAck.
30   *
31   * @author Michael Odling-Smee
32   * @author Nicholas Jones
33   * @since 0.1
34   */
35  public class CDASenderWithAck {
36  
37  	/** The Constant APPB. */
38  	private static final String APPB = "urn:nhs-uk:addressing:ods:TESTORGS:APPB";
39  
40  	/** The Constant ORGID. */
41  	private static final String ORGID = "urn:nhs-uk:identity:ods:TESTORGS:ORGA";
42  
43  	/** The Constant AUDITID. */
44  	private static final ITKIdentity AUDITID = new ITKIdentityImpl(ORGID);
45  	
46  	/** The Constant FROMADDRESS. */
47  	private static final String FROMADDRESS = "urn:nhs-uk:addressing:ods:R59:oncology";
48  
49  	/** The Constant NON_CODED_CDA. */
50  	private static final String NON_CODED_CDA = "urn:nhs-itk:services:201005:SendCDADocument-v2-0";
51  	
52  	/** The Constant NCDA_PROFILEID. */
53  	private static final String NCDA_PROFILEID = "urn:nhs-en:profile:nonCodedCDADocument-v2-0";
54  
55  	/**
56  	 * The main method.
57  	 *
58  	 * @param args the arguments
59  	 */
60  	public static void main(String[] args) {
61  
62  		CDASenderWithAck appA = new CDASenderWithAck();
63  		appA.sendCDAMessage();
64  	
65  	}
66  
67  	/**
68  	 * Send cda message.
69  	 */
70  	private void sendCDAMessage(){
71  		Logger.trace("*** CDASender: Starting sendCDAMessage");
72  		
73  		// Create the message
74  		ITKMessage msg = new SimpleMessage();
75  		NonCodedCDA req = new NonCodedCDA();
76  		req.setNHSNumber("1234556789");
77  		req.setDateOfBirth("20020831");
78  		req.setPresentationText("HELLO WORLD doc 5");
79  		msg.setBusinessPayload(req.serialise());
80  
81  		// Build the message properties.
82  		ITKMessageProperties mp = new ITKMessagePropertiesImpl();
83  		mp.setAuditIdentity(AUDITID);
84  		mp.setFromAddress(new ITKAddressImpl(FROMADDRESS));
85  		mp.setToAddress(new ITKAddressImpl(APPB));
86  		mp.setServiceId(NON_CODED_CDA);
87  		//mp.setBusinessPayloadId(req.getMessageId());
88  		mp.setBusinessPayloadId("HW5");
89  		mp.setProfileId(NCDA_PROFILEID);
90  
91  		mp.addHandlingSpecification(ITKMessageProperties.BUSINESS_ACK_HANDLING_SPECIFICATION_KEY, "true");
92  		
93  		// Add the properties to the message
94  		msg.setMessageProperties(mp);
95  		
96  		// Create the sender
97  		ITKMessageSender sender = new ITKMessageSenderImpl();
98  
99  		try {
100 			// Send this message asynchronously. The response message will be returned
101 			sender.sendAsync(msg);
102 		
103 			Logger.trace("CDASender sent message");
104 			
105 		} catch (ITKMessagingException e) {
106 			Logger.error("Error Sending ITK Message",e);
107 		}
108 		
109 		Logger.trace("*** CDASender: Ending sendCDAMessage");
110 	}
111 
112 }