Skip to content

Instantly share code, notes, and snippets.

View jonbartels's full-sized avatar

Jon Bartels jonbartels

  • Louisville, KY
  • 10:19 (UTC -04:00)
View GitHub Profile
@jonbartels
jonbartels / Use AWS v2 SDK to call S3 buckets from Mirth.js
Created February 25, 2025 17:32
Stolen from DaniD in Mirth Connect Slack, "After looking at too many javadocs, I've put together code that uses the V2 sdk to get a list of keys in a bucket, via Javascript"
var clientBuilder = new Packages.software.amazon.awssdk.services.s3.S3Client.builder();
// Set the AWS account Access Key, AWS account Secret Key
var awsCreds = new Packages.software.amazon.awssdk.auth.credentials.AwsBasicCredentials.create(access_key, secret_key);
var awsCredProvider = new Packages.software.amazon.awssdk.auth.credentials.StaticCredentialsProvider.create(awsCreds)
var east_region = Packages.software.amazon.awssdk.regions.Region.US_EAST_1
// build s3client with options
var s3client = clientBuilder
@jonbartels
jonbartels / mirth-stats.sql
Created November 25, 2024 14:06
Mirth message processing time stats, stolen from Chris who borrowed it from Paul
-- replace d_mmX where X is the local channel ID of the channel you want to check
-- processing time
with started as (select message_id, received_date from d_mm19 where connector_name = 'Source' and status = 'T'),
max_send_date as (select message_id, max(response_date) as final_send_date
from d_mm19
where status = 'S'
and connector_name != 'Source'
group by message_id),
per_message_start_end as (select s.message_id,
@jonbartels
jonbartels / mirth-connections.js
Created November 19, 2024 20:01
Script to read the connection status data from Mirth and generate a useful data structure
//Credit to Mike Klemens and Chris Gibson in Mirth Slack
// Get the server ID using ConfigurationController
var serverInstance = Packages.com.mirth.connect.server.controllers.ConfigurationController.getInstance();
var serverId = serverInstance.getServerId();
//Use Dashboard Status plugin
var defController = Packages.com.mirth.connect.server.controllers.DefaultExtensionController.create();
var monitor = defController.getServicePlugins().get(com.mirth.connect.plugins.dashboardstatus.DashboardConnectorStatusServletInterface.PLUGIN_POINT);
connectorListener = monitor.getConnectorListener();
@jonbartels
jonbartels / Mirth Thread Dumps.md
Last active October 4, 2024 19:10
Thread Dumps for Mirth Connect

When to take thread dumps

  • You suspect long running, slow, or stuck connections
  • You suspect infinite loops
  • You have problems that are only fixed by redeploying channels or restarting Mirth
  • You have high memory usage
  • When Mirth just seems generally backed up and not right

How to take a thread dump

@jonbartels
jonbartels / mirth-channel-error.sql
Created February 2, 2024 20:20
Show Mirth Connect errors by destination with PID.3 and PV1.19 from source message with short error and detail description
select
dm.message_id, status,connector_name ,
to_char(received_date AT TIME ZONE 'US/Eastern', 'YYYY-MM-DD hh24:mi') || ' US/Eastern' as message_date,
(regexp_matches(mc.content, 'PID\|(?:.*?\|){2}(.*?)\|'))[1] as pid_3_mrns,
(regexp_matches(mc.content, 'PV1\|(?:.*?\|){18}(.*?)\|'))[1] as pv1_19_visit_id,
(regexp_matches(mc_error.content, '.*ERROR MESSAGE:\s+(.*?)', 'n'))[1] as error_message,
(regexp_matches(mc_error.content, '.*DETAILS:\s+(.*?)', 'n'))[1] as detail_message
from mirth.public.d_mm76 dm
inner join d_mc76 mc on mc.message_id = dm.message_id and mc.metadata_id = 0 and mc.content_type = 1
inner join d_mc76 mc_error on mc_error.message_id = dm.message_id and mc_error.metadata_id = dm.id and mc_error.content_type = 12
@jonbartels
jonbartels / mirthSourceTransformer.js
Last active January 12, 2024 18:17
Alert receiver channel which does not alert if a message queued
//can use this to get the message content and check state and send attempts
// we have channelId and messageId
// pass metadataIds as null -> the connector message returned will then have one or many connector messages. #0 is the source, and source has connectorMessage.getDestinationIdMap(); which we can iterate to turn our connector name into the numeric metadata id
var shouldAlert = true;
var metaDataIds = null;
var alertedChannelId = msg['channelId'];
var messageId = parseInt(msg['messageId']);
var messageController = Packages.com.mirth.connect.server.controllers.messageController.getInstance();
var message = messageController.getMessageContent(alertedChannelId, messageId, metaDataIds);
var sourceMessage = message.getConnectorMessages().get(0);
@jonbartels
jonbartels / mc_certs.sql
Last active December 22, 2023 16:44
Mirth Connect channels using SSL certs by cert
with channel_xml as (
select
name,
xmlparse(document channel) as channel_xml
from channel c
)
, destination_connector_xml as (
SELECT
name as channel_name,
unnest(xpath('//destinationConnectors/connector/name/text()', channel_xml))::TEXT as connector_name,
@jonbartels
jonbartels / Dockerfile
Created May 26, 2023 00:55
Use SumoLogic logging in Mirth Connect. Shows the JARs to load to get MC to tolerate the Sumo appender for Log4j2
FROM nextgenhealthcare/connect:4.3.0 as connect
#clone some boilerplate from MC image
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
#TODO using a tarball and ADD also sets us up to get these artifacts from artifactory instead of from git
#TODO the parent entrypoint.sh does something with a custom-extensions directory, review it and see if it does this unpacking for us
#TODO I still think ADD is best here since it can fetch from remote URLs, it sets us up to use artifactory
@jonbartels
jonbartels / mirth_connect_events_by_channel_name.sql
Created May 25, 2023 21:06
Query Mirth Connect event table by event name and pick out channel name and channel ID from the attributes. Postgres 13 and newer
WITH attribute_rows AS (select e.name,
e.date_created,
xml_element.*
from "event" e,
xmltable('//linked-hash-map/entry'
passing (e."attributes"::xml)
columns "key" text PATH 'string[1]',
"value" text PATH 'string[2]'
) as xml_element
where e.name like '%Deploy%'
@jonbartels
jonbartels / report_on_paid_mirth_connectors.sql
Last active May 12, 2023 01:56
Report on Usage of Paid Extension Connectors in Mirth Connect
with channel_xml as (
select
name,
xmlparse(document channel) as channel_xml
from channel c
)
, destination_connector_xml as (
SELECT
name as channel_name,
unnest(xpath('//destinationConnectors/connector/name/text()', channel_xml))::TEXT as connector_name,