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.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 CDASender.
31   *
32   * @author Michael Odling-Smee
33   * @author Nicholas Jones
34   * @since 0.1
35   */
36  public class CDASender {
37  
38  	/** The Constant CDASTORE. */
39  	private static final String CDASTORE = "urn:nhs-uk:addressing:ods:TESTORGS:CDASTORE";
40  
41  	/** The Constant ORGID. */
42  	private static final String ORGID = "urn:nhs-uk:identity:ods:TESTORGS:ORGA";
43  
44  	/** The Constant AUDITID. */
45  	private static final ITKIdentity AUDITID = new ITKIdentityImpl(ORGID);
46  	
47  	/** The Constant FROMADDRESS. */
48  	private static final String FROMADDRESS = "urn:nhs-uk:addressing:ods:R59:oncology";
49  
50  	/** The Constant NON_CODED_CDA. */
51  	private static final String NON_CODED_CDA = "urn:nhs-itk:services:201005:SendCDADocument-v2-0";
52  	
53  	/** The Constant NCDA_PROFILEID. */
54  	private static final String NCDA_PROFILEID = "urn:nhs-en:profile:nonCodedCDADocument-v2-0";
55  
56  	/**
57  	 * The main method.
58  	 *
59  	 * @param args the arguments
60  	 */
61  	public static void main(String[] args) {
62  
63  		CDASender appA = new CDASender();
64  		appA.sendCDAMessage();
65  	
66  	}
67  
68  	/**
69  	 * Send cda message.
70  	 */
71  	private void sendCDAMessage(){
72  		Logger.trace("*** CDASender: Starting sendCDAMessage");
73  		
74  		// Create the message
75  		ITKMessage msg = new SimpleMessage();
76  		NonCodedCDA req = new NonCodedCDA();
77  		req.setNHSNumber("1234556789");
78  		req.setDateOfBirth("20020831");
79  		req.setPresentationText("Please look after this bear!!");
80  		msg.setBusinessPayload(req.serialise());
81  
82  		// Build the message properties.
83  		ITKMessageProperties mp = new ITKMessagePropertiesImpl();
84  		mp.setAuditIdentity(AUDITID);
85  		mp.setFromAddress(new ITKAddressImpl(FROMADDRESS));
86  		mp.setToAddress(new ITKAddressImpl(CDASTORE));
87  		mp.setServiceId(NON_CODED_CDA);
88  		//mp.setBusinessPayloadId(req.getMessageId());
89  		mp.setBusinessPayloadId("CAREPLAN");
90  		mp.setProfileId(NCDA_PROFILEID);
91  
92  		// Add the properties to the message
93  		msg.setMessageProperties(mp);
94  		
95  		// Create the sender
96  		ITKMessageSender sender = new ITKMessageSenderImpl();
97  
98  		try {
99  			// Send this message asynchronously. The response message will be returned
100 			sender.sendAsync(msg);
101 		
102 			Logger.trace("CDASender sent message");
103 			
104 		} catch (ITKMessagingException e) {
105 			Logger.error("Error Sending ITK Message",e);
106 		}
107 		
108 		Logger.trace("*** CDASender: Ending sendCDAMessage");
109 	}
110 	
111 	/**
112 	 * Send.
113 	 *
114 	 * @param request the request
115 	 * @param targetAddress the target address
116 	 */
117 	public void send(NonCodedCDA request, ITKAddress targetAddress ){
118 		Logger.trace("*** CDASender: Starting send");
119 		
120 		// Create the message
121 		ITKMessage msg = new SimpleMessage();
122 		msg.setBusinessPayload(request.serialise());
123 
124 		// Build the message properties.
125 		ITKMessageProperties mp = new ITKMessagePropertiesImpl();
126 		mp.setAuditIdentity(AUDITID);
127 		mp.setFromAddress(new ITKAddressImpl(FROMADDRESS));
128 		mp.setToAddress(targetAddress);
129 		mp.setServiceId(NON_CODED_CDA);
130 		mp.setBusinessPayloadId(request.getMessageId());
131 		mp.setProfileId(NCDA_PROFILEID);
132 
133 		// Add the properties to the message
134 		msg.setMessageProperties(mp);
135 		
136 		// Create the sender
137 		ITKMessageSender sender = new ITKMessageSenderImpl();
138 
139 		try {
140 			// Send this message asynchronously. The response message will be returned
141 			sender.sendAsync(msg);
142 		
143 			Logger.trace("CDASender sent message");
144 			
145 		} catch (ITKMessagingException e) {
146 			Logger.error("Error Sending ITK Message",e);
147 		}
148 		
149 		Logger.trace("*** CDASender: Ending send");
150 	}
151 
152 }