简体   繁体   English

如何在 Mirth Connect JavaScript 阅读器源连接器中获取频道信息?

[英]How do I get channel information in a Mirth Connect JavaScript Reader Source Connector?

I'm working with Mirth Connect Server 3.8.1 and I'm using a JavaScript Reader as a channel's Source Connector.我正在使用 Mirth Connect Server 3.8.1,我正在使用 JavaScript 阅读器作为频道的源连接器。 I'm trying to get the current channel id, but it seems that that's not possible.我正在尝试获取当前频道 ID,但似乎这是不可能的。 After googling I've tried the following things to see if yielded any results but it did not:谷歌搜索后,我尝试了以下操作以查看是否产生了任何结果,但没有:

logger.info(typeof channelId != 'undefined' ? ChannelUtil.getDeployedChannelName(channelId) : 'N/A');
logger.info(typeof connector != 'undefined' ? connector : 'N/A');
logger.info(typeof channel != 'undefined' ? channel : 'N/A');

This just produces three "N/A" in the logs.这只会在日志中产生三个“N/A”。 Obviously I could hard-code the channel id, but I want to export this config eventually and be able to import it to other environments without needing to edit anything.显然我可以对频道 ID 进行硬编码,但我想最终导出此配置并能够将其导入其他环境而无需编辑任何内容。 Plus it feels like a Source Connector piece of JS should know who it is working for.另外,感觉 JS 的 Source Connector 部分应该知道它在为谁工作。

How do I get this information from within the script?我如何从脚本中获取这些信息?

Update: The answer "This should work" is essentially correct, because as it turns out this does work in a brand new channel.更新: “这应该有效”的答案基本上是正确的,因为事实证明这在全新的渠道中确实有效。 The channel I was working with was imported and although I could find no other scripts affecting that channel, it was clearly broken.我使用的频道是导入的,虽然我找不到影响该频道的其他脚本,但它显然已损坏。 So possible the real answer is "Mirth Connect Server 3.8.1 has a bug that causes this to sometimes not work and the workaround is creating a new channel."所以真正的答案可能是“Mirth Connect Server 3.8.1 有一个错误,导致它有时无法工作,解决方法是创建一个新频道。”

Update 2: The culprit turned out to be me using the channelId variable in a local scope later, something along the lines of:更新 2:罪魁祸首后来证明是我在本地范围内使用channelId变量,大致如下:

for (var i=0; i<allChannelIds.size(); i++) {
    var channelId = allChannelIds.get(i);
    // Other code
}

I wrote that before realizing there was a global scope channelId variable and before needing it.我在意识到有一个全局范围的channelId变量和需要它之前写了这篇文章。 Apparently this resets it to undefined .显然这会将其重置为undefined If the global channelId was set each time the script executes, this should not be a problem, but apparently that is not the case.如果每次脚本执行时都设置全局channelId ,这应该不是问题,但显然不是这样。

You might be overcomplicating things.你可能把事情复杂化了。

In Mirth 3.5.1 the following code worked fine for me in the Transformer on the source connector of a channel:在 Mirth 3.5.1 中,以下代码在通道源连接器上的 Transformer 中对我来说效果很好:

logger.info("Channel ID: "+channelId);

The result was something like this:结果是这样的:

[2020-02-25 13:03:30,033]  INFO  (transformer:?): Channel ID: 1122e1c7-34af-4141-9388-533005346d0b

This ID matches the ID that appears in the Mirth dashboard and on the channel summary page.此 ID 与 Mirth 仪表板和频道摘要页面上显示的 ID 相匹配。

I also verified that the code worked in a Javascript Reader.我还验证了代码在 Javascript 阅读器中工作。 In this case, the logged message was在这种情况下,记录的消息是

[2020-02-25 14:33:20,004]  INFO  (js-connector:?): Channel ID: 1122e1c7-34af-4141-9388-533005346d0b

To get Channel Name you can use this code:要获取频道名称,您可以使用以下代码:

var channelName = Packages.com.mirth.connect.server.controllers.ChannelController.getInstance().getDeployedChannelById(channelId).getName();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM