web stats
Mirth Community - View Single Post - Message Generator Plugin - Can it create new messages?
View Single Post
  #4  
Old 12-14-2016, 06:54 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,098
narupley is on a distinguished road
Default

Indeed, we do have that on our roadmap!

In the meantime, you can technically do it in a JavaScript Reader. The generator unfortunately isn't yet built/refactored for dynamic classloaders, so you'll have to do a sort of workaround.

Take everything from extensions/generator/lib and place it inside your custom-lib folder (optionally inside a subfolder like custom-lib/gen-lib if you wish for organization purposes). Then also put client-lib/swingx-core-1.6.2.jar in there.

Next, you need to include those libraries on the overall server classpath, so edit mirth.properties, set "server.includecustomlib" to true, and restart MC.

Then you'll want to launch the Administrator again, and open up the generator dialog. Set whatever properties you want:



You can customize how many fields/components/subcomponents to include and what to generate for them to a great detail, even supply regular expressions for them:



Once your done, hit Export and save the XML file somewhere. Put it somewhere on the server running MC so that a channel can access it.

Then in a JavaScript Reader you can do this:

Code:
var generator = $gc('generator');
if (generator == null) {
	var xstream = new com.thoughtworks.xstream.XStream();
	var properties = xstream.fromXML(FileUtil.read('/path/to/properties.xml'));
	generator = new com.mirth.generator.model.Generator();
	generator.setGeneratorProperties(properties);
	$gc('generator', generator);
}

generator.generate(generator.getGeneratorProperties().getSelectedDataType());
var list = new java.util.ArrayList();
while (generator.hasNext()) {
	list.add(generator.next());
}

return list;
And there you go! Now your channel will automatically generate random fake messages to your generator specifications:

Code:
MSH|^~\&|||||19380702222617||ADT^A04|MSG0000000006|P|2.5
EVN|A04|19400318171515||U
PID|1||949107234~949107234||ORTIS^GEORGE^R|HUTCHINSON^JAMES^Q||A|GADDIS^VIOLET^N|||||||||822778712
PV1|1|C||U||||||||||||||||||||||||xx
PR1|1||||19330318220223||+28.
IN1|1||xxTESTxx|||MERLETTE^ERIC^Y||||||||||MONDRAGON^ANTONIO^Z~SMUIN^ANDREW^Q||||||||||||||||xx||-||||||||||||||||||xxTESTxx

MSH|^~\&|||||19810102141835||ADT^A04|MSG0000000007|P|2.5
EVN|A04|19810512224407||||19890604234531
PID|1||276922612||WEISSBERG^RICHARD^V|MCCUAN^LOYD^D~DOKER^ASHLEY^D||M|SOHNS^STEPHEN^L
PV1|1|C|||||||||||||||||||||||19550414||||||||||19050401||||||xx
PR1|1||||19481007234542|||||||||2
IN1|1||xxTESTxx|||BRULE^LISA^N||||||||||OLEA^MICHAEL^D||||Y|||||||||||||||||||.0

MSH|^~\&|||||19940513212643||ADT^A04|MSG0000000008|P|2.5
EVN|A04|19441105134222
PID|1||674106993||ROCHESTER^PATRICIA^C|NOCKET^RONALD^V~EDDY^ROBERT^W||U|SLONAKER^VICTORIA^D||||||||||488-75-0000||||||||||||||19360412153338
PV1|1|C||||||||||xx||||||||xxTESTxx|||xx
PR1|1||||19460529221236
IN1|1||xxTESTxx|||RODRIGUEZ^SARAH^T||||||||||SCHULTHEIS^NELLIE^V~WILLILAMS^SYDNEY^F||||N

...
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote