1
2
3
4
5
6
7
8
9
10
11
12
13
14 package uk.nhs.interoperability.client.samples.cda;
15
16 import java.io.IOException;
17
18 import javax.servlet.ServletException;
19 import javax.servlet.http.HttpServlet;
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22 import javax.servlet.http.HttpSession;
23
24 import uk.nhs.interoperability.infrastructure.ITKAddress;
25 import uk.nhs.interoperability.infrastructure.ITKAddressImpl;
26 import uk.nhs.interoperability.infrastructure.ITKIdentity;
27 import uk.nhs.interoperability.infrastructure.ITKIdentityImpl;
28 import uk.nhs.interoperability.infrastructure.ITKMessageProperties;
29 import uk.nhs.interoperability.infrastructure.ITKMessagePropertiesImpl;
30 import uk.nhs.interoperability.infrastructure.ITKMessagingException;
31 import uk.nhs.interoperability.payload.ITKMessage;
32 import uk.nhs.interoperability.payload.SimpleMessage;
33 import uk.nhs.interoperability.source.ITKMessageSender;
34 import uk.nhs.interoperability.source.ITKMessageSenderImpl;
35 import uk.nhs.interoperability.util.Logger;
36
37
38
39
40
41
42
43
44 public class HelloWorldCDASourceServlet extends HttpServlet {
45
46
47 private static final long serialVersionUID = 1L;
48
49
50 private static final String ORGID = "urn:nhs-uk:identity:ods:TESTORGS:ORGA";
51
52
53 private static final ITKIdentity AUDITID = new ITKIdentityImpl(ORGID);
54
55
56 private static final String FROMADDRESS = "urn:nhs-uk:addressing:ods:R59:oncology";
57
58
59 private static final String NON_CODED_CDA = "urn:nhs-itk:services:201005:SendCDADocument-v2-0";
60
61
62 private static final String NCDA_PROFILEID = "urn:nhs-en:profile:nonCodedCDADocument-v2-0";
63
64
65
66
67 public HelloWorldCDASourceServlet() {
68 super();
69 }
70
71
72
73
74 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
75 processRequest(request, response);
76 }
77
78
79
80
81 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
82 processRequest(request, response);
83 }
84
85
86
87
88
89
90
91
92
93 private void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
94
95 System.out.println("this is HelloWorldCDASource.processRequest");
96 String docId = request.getParameter("docId");
97 String docText = request.getParameter("docText");
98 String nhsNumber = request.getParameter("nhsNumber");
99 String dateOfBirth = request.getParameter("dateOfBirth");
100 String businessAckRequired = request.getParameter("businessAckRequired");
101 String serviceAddress = request.getParameter("serviceAddress");
102 ITKAddress itkServiceAddress = new ITKAddressImpl(serviceAddress);
103
104 HttpSession session = request.getSession(true);
105 session.removeAttribute("errorMessage");
106 session.removeAttribute("outcomeMessage");
107 session.removeAttribute("responseMessage");
108
109 NonCodedCDA doc = new NonCodedCDA();
110 doc.messageId = docId;
111 doc.nhsNumber = nhsNumber;
112 doc.dateOfBirth = dateOfBirth;
113 doc.presentationText = docText;
114
115
116 ITKMessage msg = new SimpleMessage();
117 msg.setBusinessPayload(doc.serialise());
118
119
120 ITKMessageProperties mp = new ITKMessagePropertiesImpl();
121 mp.setAuditIdentity(AUDITID);
122 mp.setFromAddress(new ITKAddressImpl(FROMADDRESS));
123 mp.setToAddress(itkServiceAddress);
124 mp.setServiceId(NON_CODED_CDA);
125 mp.setBusinessPayloadId(doc.getMessageId());
126 mp.setProfileId(NCDA_PROFILEID);
127
128 if (businessAckRequired.equalsIgnoreCase("Y")){
129 mp.addHandlingSpecification(ITKMessageProperties.BUSINESS_ACK_HANDLING_SPECIFICATION_KEY, "true");
130 }
131
132
133 msg.setMessageProperties(mp);
134
135
136 ITKMessageSender sender = new ITKMessageSenderImpl();
137
138 try {
139
140 sender.sendAsync(msg);
141
142 Logger.info("CDA Message Sent.");
143 session.setAttribute("outcomeMessage", "CDA Message Sent.");
144
145 } catch (ITKMessagingException e) {
146 Logger.error("Error Sending ITK Message",e);
147 session.setAttribute("errorMessage", "Sorry - I couldn't send the message this time.");
148 }
149
150 response.sendRedirect("./CDASent.jsp");
151 Logger.trace("*** HelloWorldCDASource: Ending send");
152 }
153
154 }