Skip to content

Instantly share code, notes, and snippets.

View MichaelLeeHobbs's full-sized avatar

Michael Hobbs MichaelLeeHobbs

  • United States
View GitHub Profile
@MichaelLeeHobbs
MichaelLeeHobbs / Check Slow Channels.md
Created January 29, 2026 21:31
Mirth 4.5.0 Slow Response Message Report

Mirth Connect: Check Slow Channels

A PostgreSQL function to quickly identify Mirth channels where the Source Connector is taking a long time to process messages. It aggregates statistics and lists specific Message IDs for easy troubleshooting.

1. Installation

Run this once to create the function in your Mirth database.

CREATE OR REPLACE FUNCTION check_slow_channels(
    threshold_seconds INT DEFAULT 15, 
@MichaelLeeHobbs
MichaelLeeHobbs / Mirth_4.5.0_TableSizeReportAdvance.sql
Created January 29, 2026 16:42
Mirth 4.5.0 Table Size Reports
WITH
-- 1. EXTRACT CONFIGURATION
CHANNEL_CONFIG AS (
SELECT
(XPATH('/entry/string/text()', ENTRY))[1]::TEXT AS CID
, (XPATH('/entry/*[2]/enabled/text()', ENTRY))[1]::TEXT::BOOLEAN AS CHANNEL_ENABLED
, (XPATH('/entry/*[2]/pruningSettings/archiveEnabled/text()', ENTRY))[1]::TEXT::BOOLEAN AS ARCHIVE_ENABLED
, (XPATH('/entry/*[2]/pruningSettings/pruneErroredMessages/text()', ENTRY))[1]::TEXT::BOOLEAN AS PRUNE_ERROR_MESSAGES
, COALESCE((XPATH('/entry/*[2]/pruningSettings/pruneMetaDataDays/text()', ENTRY))[1]::TEXT::INT, -1) AS PRUNE_DAYS
FROM (
@MichaelLeeHobbs
MichaelLeeHobbs / MirthSourceTransformerScript.js
Created April 8, 2021 15:06
Complete Mirth Source Transformer Script
/*** GLOBAL Scope ***/
/*** GLOBAL Scope --- Map Functions --- ***/
function $co(key, value) { if (arguments.length == 1) { return connectorMap.get(key); } else { return connectorMap.put(key, value); } }
function $c(key, value) { if (arguments.length == 1) { return channelMap.get(key); } else { return channelMap.put(key, value); } }
function $s(key, value) { if (arguments.length == 1) { return sourceMap.get(key); } else { return sourceMap.put(key, value); } }
function $gc(key, value) { if (arguments.length == 1) { return globalChannelMap.get(key); } else { return globalChannelMap.put(key, value); } }
function $g(key, value) { if (arguments.length == 1) { return globalMap.get(key); } else { return globalMap.put(key, value); } }
function $cfg(key, value) { if (arguments.length == 1) { return configurationMap.get(key); } else { return configurationMap.put(key, value); } }
@MichaelLeeHobbs
MichaelLeeHobbs / JaneDoeMemorialORU.js
Last active April 20, 2021 18:54
A new way to write Mirth Connect Messages
function JaneDoeMemorialORU(pacsORU) {
const reportURL = ''
const {
MSGDATETIME, MSGCONTROLID, ACCESSIONNUMBER, INSTITUTIONNAME, REQUESTEDPROCEDUREID, STUDYDESCRIPTION, STUDYINSTANCEUID, STUDYDATETIME, MODALITY,
PATIENTID, LASTNAME, FIRSTNAME, MIDDLENAME, SEX, BIRTHDATE,
REFPHY_NPI, REFPHY_LASTNAME, REFPHY_FIRSTNAME, OBSERVER_NPI, OBSERVER_LASTNAME, OBSERVER_FIRSTNAME, OBSERVER_MIDDLENAME, OBSERVER_SUFFIX, OBSERVER_DATETIME, BUFFERCONTENT, BUFFERCONTENT_PDF,
} = getReportDataFromPacsORU(pacsORU)
const xml =
<>
-- 20201125T1403 EST - Fix bug in xpath not correctly matching values to correct channel
-- 20201125T1430 EST - Updated formatting only using: http://poorsql.com/ with minor hand edits
-- 20201125T1430 EST - Updated formatting only using: http://poorsql.com/ with minor hand edits
-- 20210321T1140 EST - Postgres 12+ XPATH works differently and required entry/ where as 9.6 requires it to be missing
--
-- Jon Bartels
-- Similar query for SQL Server is here - https://stackoverflow.com/questions/58942371/get-space-used-by-mirth-per-channel-in-sql-server
--
SELECT NAME AS CHANNEL_NAME
// https://github.com/behnammodi/polyfill/blob/master/array.polyfill.js
/**
* Array.prototype.flat()
* version 0.0.0
* Feature Chrome Firefox Internet Explorer Opera Safari Edge
* Basic support 69 62 (No) 56 12 (No)
* -------------------------------------------------------------------------------
*/
if (!Array.prototype.flat) {
// https://github.com/behnammodi/polyfill/blob/master/array.polyfill.js
/**
* Array.prototype.copyWithin()
* version 0.0.0
* Feature Chrome Firefox Internet Explorer Opera Safari Edge
* Basic support 45 32 (No) 32 9 12
* -------------------------------------------------------------------------------
*/
if (!Array.prototype.copyWithin) {
Array.prototype.copyWithin = function (target, start /*, end*/) {
@MichaelLeeHobbs
MichaelLeeHobbs / ChannelUtils.js
Last active March 3, 2022 19:29
Mike's Mirth Utils
/**
* ChannelUtils
* @param config: {name, user, password, url, dbClass, cacheConnection, cacheName}
* @param config.name: a db connection name must be unique or will cause issues
* @param config.user: user name to use for db connection
* @param config.password: db user password
* @param config.url: db url
* @param config.dbClass: db class - Default: org.postgresql.Driver
* @param config.cacheConnection: Should cache the connection? true/false
* @param config.cacheName: default - cachedConnection:ChannelUtils:channelName:config.name
@MichaelLeeHobbs
MichaelLeeHobbs / MirthPostgresTableSizeByChannel.psql
Last active October 25, 2023 18:10
Mirth Postgres Table Size By Channel
-- 20201125T1403 EST - Fix bug in xpath not correctly matching values to correct channel
-- 20201125T1430 EST - Updated formatting only using: http://poorsql.com/ with minor hand edits
-- 20201125T1432 EST - Removed CID from final output as it was only there for debugging xpath issues
-- 20210321T1140 EST - Postgres 13+ XPATH works differently see: https://gist.github.com/MichaelLeeHobbs/40b4b7cf70ecbe30b73eed763367e626
--
-- Jon Bartels
-- Similar query for SQL Server is here - https://stackoverflow.com/questions/58942371/get-space-used-by-mirth-per-channel-in-sql-server
--
SELECT NAME AS CHANNEL_NAME
@MichaelLeeHobbs
MichaelLeeHobbs / youtubeUnsubscribeAll.js
Created February 29, 2020 20:12
Youtube Unsubscribe from all channels
// go to the url https://www.youtube.com/feed/channels
//window.location = 'https://www.youtube.com/feed/channels'
// hit f12 and paste the below into the dev console then wait
function unsubscribeAll(channels) {
channels = channels || document.getElementById("grid-container").getElementsByClassName("ytd-expanded-shelf-contents-renderer")
channels[0].querySelector("[aria-label^='Unsubscribe from']").click()
setTimeout(()=> {
document.getElementById("confirm-button").click()
channels[0].parentNode.removeChild(channels[0])