web stats
How do YOU handle "namespaces"? - Mirth Community

Go Back   Mirth Community > Mirth Connect > General Discussion

Reply
 
Thread Tools Display Modes
  #1  
Old 10-28-2019, 07:37 AM
jonathanlent jonathanlent is offline
OBX.1 Kenobi
 
Join Date: Aug 2014
Location: Denton, TX
Posts: 43
jonathanlent is on a distinguished road
Default How do YOU handle "namespaces"?

So, in an effort to make sure that code template names don't collide, my team has settled on a snake-case-prefix convention that works well enough -- but still gives me the heebie jeebies from a code cleanliness standpoint.

So, a common library with useful templates for manipulating HL7v2 would be called "common_hl7v2", for example. Templates in that library are then prefixed with the library name to make sure they don't collide.

common_hl7v2_inlineOBX()
common_hl7v2_burstFormattedTextOBX()
common_hl7v2_removeZsegments()

It's not so critical with the common libraries as it is with some of the ones that allow us to share common code across a set of participant channels, but you get the idea.

This all works well enough, but it's just plain ugly to look at. Anybody have an alternate way of doing this that is cleaner?
Reply With Quote
  #2  
Old 11-08-2019, 03:52 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,176
agermano is on a distinguished road
Default

So, this breaks the mirth drag-and-drop and code completion for your functions, but it does still work.

Say you have a library Common (or Common.hl7v2 if you need to break it down farther) and a Site 1 that needs to have its own version of some function. If you happen to have a Common.json library set up the same way, and a channel includes both, they will get merged under the same Common object.

Library: Common.hl7v2
Template: inlineOBX
Code:
if (typeof Common === 'undefined') Common = {};
if (typeof Common.hl7v2 === 'undefined') Common.hl7v2 = {};
/**
	This function does common stuff.

	@param {Any} arg1 - a thing
	@return {String} return description
*/
Common.hl7v2.inlineOBX = function inlineOBX(arg1) {
    return 'common';
}
Template: removeZsegments
Code:
if (typeof Common === 'undefined') Common = {};
if (typeof Common.hl7v2 === 'undefined') Common.hl7v2 = {};
/**
	This function does common stuff.

	@param {Any} arg1 - a thing
	@return {String} return description
*/
Common.hl7v2.removeZsegments = function removeZsegments(arg1) {
    return 'common';
}
Library: Site1
Template: inlineOBX
Code:
if (typeof Site1 === 'undefined') Site1 = {};
if (typeof Site1.hl7v2 === 'undefined') Site1.hl7v2 = {};
/**
	This function does stuff for site 1.

	@param {Any} arg1 - a thing
	@return {String} return description
*/
Site1.hl7v2.inlineOBX = function inlineOBX(arg1) {
    return 'site1';
}
Channels
Then in your code, suppose a channel only uses the common functions. You could do this (ES6 mode syntax):
Code:
var {inlineOBX, removeZsegments} = Common.hl7v2;

logger.info('inlineOBX: ' + inlineOBX(msg));
logger.info('removeZsegments: ' + removeZsegments(msg));
In your Site 1 channel (older mirth without ES6 can list them individually):
Code:
var removeZsegments = Common.hl7v2.removeZsegments;
var inlineOBX = Site1.hl7v2.inlineOBX;

logger.info('inlineOBX: ' + inlineOBX(msg));
logger.info('removeZsegments: ' + removeZsegments(msg));
If there are a huge number to import, this works on new or older mirth versions. If this in the code is anything besides the global scope, you hopefully already know what you are doing.
Code:
// Import all Common.hl7v2 functions
Object.keys(Common.hl7v2).forEach(function(func) {
    this[func] = Common.hl7v2[func];
})

// Import and override selected Site1.hl7v2 functions
var siteImports = [
    'inlineOBX'
];
siteImports.forEach(function(func) {
    this[func] = Site1.hl7v2[func];
});

logger.info('inlineOBX: ' + inlineOBX(msg));
logger.info('removeZsegments: ' + removeZsegments(msg));

Last edited by agermano; 11-08-2019 at 03:59 PM.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 05:31 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation