Mirth getMessageCount 使用 Javascript 不工作

Mirth getMessageCount using Javascript not working

我想使用 getMessageCount() 获取特定频道在特定日期范围内发送的消息数。所以“过滤器”由 3 个项目组成:status=SENT startDate=2020-10-15 endDate=2020-10-16

这是我使用的代码:

var client = new com.mirth.connect.client.core.Client('https://localhost:8443');

var loginStatus = client.login('myusername', 'mypassword');
if (loginStatus.getStatus() != com.mirth.connect.model.LoginStatus.Status.SUCCESS) {
    logger.error('Unable to log-on the server (status ' + loginStatus.getStatus() + ')');
    return;
} 

var channelId = 'b544f44c-xxxxxxxxxx-xxxxxxx';

var count = client.getMessageCount(channelId,'status=SENT,startDate=2020-10-15,endDate=2020-10-16');  // THIS FAILS, because 2nd parameter is not a string   

我收到一个错误:找不到方法 com.mirth.connect.client.core.Client.getMessageCount(string,string).

getMessageCount 的语法是:getMessageCount(String channelId, MessageFilter 过滤器)

那么如何construct/pass包含上述3项的“filter”参数呢?请举个清楚的例子。

要获取“昨天”的 SENT 计数,以下是解决方案并且效果很好:

// create a client instance and initialize it with the server to which it should connect
var client = new com.mirth.connect.client.core.Client('https://localhost:8443');

// log on to the server
try{
   var loginStatus = client.login($g('apiUsername'), $g('apiPassword'));
} catch(ex) {
   throw 'Unable to log-on the server "' + server + '"   Error: ' + ex.message;
}

// check if login was successful
if (loginStatus.getStatus() != com.mirth.connect.model.LoginStatus.Status.SUCCESS) {
   logger.error('Unable to log-on the server (status ' + loginStatus.getStatus() + ')');
   return;
} 

var filter = new com.mirth.connect.model.filters.MessageFilter;
var calendar = java.util.Calendar;

var startDate = new calendar.getInstance();
var endDate = new calendar.getInstance();

startDate.add(calendar.DATE, -1);   // set to YESTERDAY
endDate.add(calendar.DATE, -1);     // set to YESTERDAY

startDate.set(startDate.get(calendar.YEAR), startDate.get(calendar.MONTH), startDate.get(calendar.DAY_OF_MONTH), 0, 0, 0);    
startDate.set(calendar.MILLISECOND, 0); 

// Set endDate to 1 millisecond right before Midnight
// Ex: 2020-10-15 23:59:59.999 (right before midnight)
endDate.set(endDate.get(calendar.YEAR), endDate.get(calendar.MONTH), endDate.get(calendar.DAY_OF_MONTH), 23, 59, 59);  
endDate.set(calendar.MILLISECOND, 999); 

filter.setStartDate(startDate);
filter.setEndDate(endDate);

var statuses = new java.util.HashSet();
var Status = com.mirth.connect.donkey.model.message.Status;

var channelId = 'b544f44c-xxxxxxxxxx-xxxxxxx';

statuses.add(Status.SENT);
filter.setStatuses(statuses);

var sentCount= client.getMessageCount(channelId, filter); 

logger.info('Number of messages SENT Yesterday: ' + sentCount);