Repository navigation
Expand file tree
/
Copy pathExtraFormSendDataChannel.xml
More file actions
374 lines (352 loc) · 16.6 KB
/
Copy pathExtraFormSendDataChannel.xml
File metadata and controls
374 lines (352 loc) · 16.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<channel version="3.1.1">
<id>b83fc07a-85e5-4ad6-8429-89b1185efbae</id>
<nextMetaDataId>4</nextMetaDataId>
<name>ExtraFormSendDataChannel</name>
<description>This Channel will query the openhds.form table and look for any data sets that contain a value in CORE_TABLE field and where the status field is set to 2 (READY). If it finds such an entry, it will query the matching CORE_TABLE in the ODK Aggregate database and process all contents that contain a PROCESSED_BY_MIRTH value of 0. It send these values as XML payload to the OpenHDS ExtraForm Controller. On error, will set the PROCESSED_BY_MIRTH flag for this entry to 2, in any other case, sets the flag to 1.</description>
<enabled>true</enabled>
<lastModified>
<time>1438337999764</time>
<timezone>Europe/Berlin</timezone>
</lastModified>
<revision>256</revision>
<sourceConnector version="3.1.1">
<metaDataId>0</metaDataId>
<name>sourceConnector</name>
<properties class="com.mirth.connect.connectors.js.JavaScriptReceiverProperties" version="3.1.1">
<pluginProperties/>
<pollConnectorProperties version="3.1.1">
<pollingType>interval</pollingType>
<pollingHour>0</pollingHour>
<pollingMinute>0</pollingMinute>
<pollingFrequency>5000</pollingFrequency>
</pollConnectorProperties>
<sourceConnectorProperties version="3.1.1">
<responseVariable>None</responseVariable>
<respondAfterProcessing>true</respondAfterProcessing>
<processBatch>false</processBatch>
<firstResponse>false</firstResponse>
</sourceConnectorProperties>
<script>var dbConn;
var list = new java.util.ArrayList();
try {
// dbConn = DatabaseConnectionFactory.createDatabaseConnection('com.mysql.jdbc.Driver','jdbc:mysql://localhost:3306/openhds','data','data');
dbConn = DatabaseConnectionFactory.createDatabaseConnection('com.mysql.jdbc.Driver',globalMap.get("OPENHDS_DATABASE_URL"), globalMap.get("OPENHDS_DATABASE_USER"),globalMap.get("OPENHDS_DATABASE_PASSWORD"));
// You may access this result below with $('column_name')
var result = dbConn.executeCachedQuery("SELECT uuid, formName, active, deleted, CORE_TABLE, status FROM form");
var resultSize = result.size();
if(resultSize>0){
for(var i = 0;i<resultSize;i++){
result.next();
var coreTable = result.getString("CORE_TABLE");
//logger.info("coreTable: " + coreTable);
var uuid = result.getString("uuid");
//logger.info("uuid: " + uuid);
var formName = result.getString("formName");
//logger.info("formName: " + formName);
var active = result.getString("active");
//logger.info("active: " + active);
var deleted = result.getBoolean("deleted");
//logger.info("deleted: " + deleted);
var status = result.getInt("status");
//logger.info("status: " + status);
if((coreTable.trim().length() > 0) && !deleted
&& (active != null && active.equalsIgnoreCase("yes"))
&& status == 2)
{
logger.info("status 2, Proceed...")
//channelMap.put("CORE_TABLE", coreTable); //For postprocessor
var listOfObjects = getExtraFormData(coreTable, 10);
var objectCount = listOfObjects.length;
logger.info("Data count: " + objectCount);
//channelMap.put("objectCount", objectCount); //For postprocessor and filter
if(objectCount > 0){
listOfObjects.forEach(function(object) {
var extraform = <extraform formName={formName} coreTable={coreTable} />;
var dataEntries = <></>;
var entriesCount = object.length;
logger.info("No. of entries: " + entriesCount);
if(entriesCount > 0){
object.forEach(function(entry) {
var columnName = entry['columnName'];
var value = entry['value'];
var columnTypeName = entry['columnTypeName'];
if(value == null)
value = "";
//logger.info(columnName + " " + value + " " + columnTypeName);
if(columnName == "_URI"){
//channelMap.put("_URI", value); //For postprocessor
//logger.info("Found columnName _URI with value: " + value);
extraform.@uri = value;
}
var data = <data columnName={columnName} type={columnTypeName}>{value}</data>;
dataEntries += data;
});
extraform.data = dataEntries;
logger.info("XML: " + extraform.toXMLString());
list.add(extraform);
}
});
}
}
}
}
logger.info("List contents: " + list);
logger.info("List size: " + list.size());
return list;
} finally {
if (dbConn) {
dbConn.close();
}
}</script>
</properties>
<transformer version="3.1.1">
<steps/>
<inboundDataType>XML</inboundDataType>
<outboundDataType>XML</outboundDataType>
<inboundProperties class="com.mirth.connect.plugins.datatypes.xml.XMLDataTypeProperties" version="3.1.1">
<serializationProperties class="com.mirth.connect.plugins.datatypes.xml.XMLSerializationProperties" version="3.1.1">
<stripNamespaces>true</stripNamespaces>
</serializationProperties>
<batchProperties class="com.mirth.connect.plugins.datatypes.xml.XMLBatchProperties" version="3.1.1">
<splitType>Element_Name</splitType>
<elementName></elementName>
<level>1</level>
<query></query>
<batchScript></batchScript>
</batchProperties>
</inboundProperties>
<outboundProperties class="com.mirth.connect.plugins.datatypes.xml.XMLDataTypeProperties" version="3.1.1">
<serializationProperties class="com.mirth.connect.plugins.datatypes.xml.XMLSerializationProperties" version="3.1.1">
<stripNamespaces>true</stripNamespaces>
</serializationProperties>
<batchProperties class="com.mirth.connect.plugins.datatypes.xml.XMLBatchProperties" version="3.1.1">
<splitType>Element_Name</splitType>
<elementName></elementName>
<level>1</level>
<query></query>
<batchScript></batchScript>
</batchProperties>
</outboundProperties>
</transformer>
<filter version="3.1.1">
<rules/>
</filter>
<transportName>JavaScript Reader</transportName>
<mode>SOURCE</mode>
<enabled>true</enabled>
<waitForPrevious>true</waitForPrevious>
</sourceConnector>
<destinationConnectors>
<connector version="3.1.1">
<metaDataId>2</metaDataId>
<name>Destination 1</name>
<properties class="com.mirth.connect.connectors.http.HttpDispatcherProperties" version="3.1.1">
<pluginProperties/>
<destinationConnectorProperties version="3.1.1">
<queueEnabled>false</queueEnabled>
<sendFirst>false</sendFirst>
<retryIntervalMillis>10000</retryIntervalMillis>
<regenerateTemplate>false</regenerateTemplate>
<retryCount>0</retryCount>
<rotate>false</rotate>
<threadCount>1</threadCount>
<validateResponse>false</validateResponse>
</destinationConnectorProperties>
<host>${OPENHDS_PATH}/extraform/insert</host>
<useProxyServer>false</useProxyServer>
<proxyAddress></proxyAddress>
<proxyPort></proxyPort>
<method>post</method>
<headers class="linked-hash-map"/>
<parameters class="linked-hash-map"/>
<responseXmlBody>false</responseXmlBody>
<responseParseMultipart>true</responseParseMultipart>
<responseIncludeMetadata>false</responseIncludeMetadata>
<responseBinaryMimeTypes></responseBinaryMimeTypes>
<responseBinaryMimeTypesRegex>false</responseBinaryMimeTypesRegex>
<multipart>false</multipart>
<useAuthentication>true</useAuthentication>
<authenticationType>Basic</authenticationType>
<usePreemptiveAuthentication>true</usePreemptiveAuthentication>
<username>${OPENHDS_USER}</username>
<password>${OPENHDS_PASSWORD}</password>
<content>${message.transformedData}</content>
<contentType>application/xml</contentType>
<dataTypeBinary>false</dataTypeBinary>
<charset>UTF-8</charset>
<socketTimeout>30000</socketTimeout>
</properties>
<transformer version="3.1.1">
<steps>
<step>
<sequenceNumber>0</sequenceNumber>
<name>Strip away arguments</name>
<script>/* Remove attributes we don't need before sending them. We put them in for using them in the postprocessor */
var formData = msg;
delete formData.@coreTable;
delete formData.@uri;</script>
<type>JavaScript</type>
<data>
<entry>
<string>Script</string>
<string>/* Remove attributes we don't need before sending them. We put them in for using them in the postprocessor */
var formData = msg;
delete formData.@coreTable;
delete formData.@uri;</string>
</entry>
</data>
</step>
</steps>
<inboundTemplate encoding="base64"></inboundTemplate>
<outboundTemplate encoding="base64"></outboundTemplate>
<inboundDataType>XML</inboundDataType>
<outboundDataType>XML</outboundDataType>
<inboundProperties class="com.mirth.connect.plugins.datatypes.xml.XMLDataTypeProperties" version="3.1.1">
<serializationProperties class="com.mirth.connect.plugins.datatypes.xml.XMLSerializationProperties" version="3.1.1">
<stripNamespaces>true</stripNamespaces>
</serializationProperties>
<batchProperties class="com.mirth.connect.plugins.datatypes.xml.XMLBatchProperties" version="3.1.1">
<splitType>Element_Name</splitType>
<elementName></elementName>
<level>1</level>
<query></query>
<batchScript></batchScript>
</batchProperties>
</inboundProperties>
<outboundProperties class="com.mirth.connect.plugins.datatypes.xml.XMLDataTypeProperties" version="3.1.1">
<serializationProperties class="com.mirth.connect.plugins.datatypes.xml.XMLSerializationProperties" version="3.1.1">
<stripNamespaces>true</stripNamespaces>
</serializationProperties>
<batchProperties class="com.mirth.connect.plugins.datatypes.xml.XMLBatchProperties" version="3.1.1">
<splitType>Element_Name</splitType>
<elementName></elementName>
<level>1</level>
<query></query>
<batchScript></batchScript>
</batchProperties>
</outboundProperties>
</transformer>
<responseTransformer version="3.1.1">
<steps/>
<inboundDataType>XML</inboundDataType>
<outboundDataType>XML</outboundDataType>
<inboundProperties class="com.mirth.connect.plugins.datatypes.xml.XMLDataTypeProperties" version="3.1.1">
<serializationProperties class="com.mirth.connect.plugins.datatypes.xml.XMLSerializationProperties" version="3.1.1">
<stripNamespaces>true</stripNamespaces>
</serializationProperties>
<batchProperties class="com.mirth.connect.plugins.datatypes.xml.XMLBatchProperties" version="3.1.1">
<splitType>Element_Name</splitType>
<elementName></elementName>
<level>1</level>
<query></query>
<batchScript></batchScript>
</batchProperties>
</inboundProperties>
<outboundProperties class="com.mirth.connect.plugins.datatypes.xml.XMLDataTypeProperties" version="3.1.1">
<serializationProperties class="com.mirth.connect.plugins.datatypes.xml.XMLSerializationProperties" version="3.1.1">
<stripNamespaces>true</stripNamespaces>
</serializationProperties>
<batchProperties class="com.mirth.connect.plugins.datatypes.xml.XMLBatchProperties" version="3.1.1">
<splitType>Element_Name</splitType>
<elementName></elementName>
<level>1</level>
<query></query>
<batchScript></batchScript>
</batchProperties>
</outboundProperties>
</responseTransformer>
<filter version="3.1.1">
<rules>
<rule>
<sequenceNumber>0</sequenceNumber>
<name>New Rule</name>
<data>
<entry>
<string>Script</string>
<string>var length = msg["data"].length();
return length > 0;</string>
</entry>
</data>
<type>JavaScript</type>
<script>var length = msg["data"].length();
return length > 0;</script>
<operator>NONE</operator>
</rule>
</rules>
</filter>
<transportName>HTTP Sender</transportName>
<mode>DESTINATION</mode>
<enabled>true</enabled>
<waitForPrevious>true</waitForPrevious>
</connector>
</destinationConnectors>
<preprocessingScript>// Modify the message variable below to pre process data
return message;</preprocessingScript>
<postprocessingScript>// This script executes once after a message has been processed
// Responses returned from here will be stored as "Postprocessor" in the response map
var channel_Id = 2;
var processedByMirthStatus = 1;
var status = message.getConnectorMessages().get(channel_Id).getStatus();
if(status == 'ERROR'){
logger.debug('Error while sending new data for ExtraFormTable. Status = ' + status);
var responseMessage = responseMap.get("d" + channel_Id);
logger.debug('responseMessage: ' + responseMessage);
var rawMessage = responseMap.get("d" + channel_Id).getMessage();
logger.debug('rawmsg: ' + rawMessage);
processedByMirthStatus = 2;
var connectorName = message.getConnectorMessages().get(channel_Id).getConnectorName();
logger.info("ERROR-CHANNEL channelError: " + connectorName);
logger.info("ERROR-CHANNEL requestError: " + responseMessage);
logger.info("ERROR-CHANNEL transformed: " + rawMessage);
//globalMap.put("channelError", connectorMessage.getConnectorName());
//globalMap.put("requestError", responseMap.get("d"+j).getMessage());
//globalMap.put("transformed", connectorMessage.getTransformedData());
}
var rawMessage = new XML(message.getConnectorMessages().get(channel_Id).getRawData());
logger.info("Postprocessor: " + rawMessage);
var tableName = rawMessage.@coreTable;
var _URI = rawMessage.@uri;
if(tableName && _URI){
logger.info("Set " + _URI + " in " + tableName + " to " + processedByMirthStatus);
var dbConn = DatabaseConnectionFactory.createDatabaseConnection('com.mysql.jdbc.Driver','jdbc:mysql://localhost:3306/odk_prod','data','data');
var result = dbConn.executeUpdate("UPDATE " + tableName + " SET PROCESSED_BY_MIRTH = " + processedByMirthStatus + " WHERE _URI = '" + _URI + "'");
dbConn.close();
}
else{
logger.info("Nothing to update");
}
return;</postprocessingScript>
<deployScript>// This script executes once when the channel is deployed
// You only have access to the globalMap and globalChannelMap here to persist data
return;</deployScript>
<undeployScript>// This script executes once when the channel is undeployed
// You only have access to the globalMap and globalChannelMap here to persist data
return;</undeployScript>
<properties version="3.1.1">
<clearGlobalChannelMap>true</clearGlobalChannelMap>
<messageStorageMode>DEVELOPMENT</messageStorageMode>
<encryptData>false</encryptData>
<removeContentOnCompletion>false</removeContentOnCompletion>
<removeAttachmentsOnCompletion>false</removeAttachmentsOnCompletion>
<initialState>STARTED</initialState>
<storeAttachments>false</storeAttachments>
<tags class="linked-hash-set"/>
<metaDataColumns>
<metaDataColumn>
<name>SOURCE</name>
<type>STRING</type>
<mappingName>mirth_source</mappingName>
</metaDataColumn>
<metaDataColumn>
<name>TYPE</name>
<type>STRING</type>
<mappingName>mirth_type</mappingName>
</metaDataColumn>
</metaDataColumns>
<attachmentProperties>
<type>None</type>
<properties/>
</attachmentProperties>
<archiveEnabled>true</archiveEnabled>
</properties>
</channel>