Hello Friends,
For the two other people in the world who really want to use Hylafax from within OEMR itself …I’ve finally gotten it to work!!
(I’m using Linux as OS on the server.)
In summary, the process as it works in fax_dispatch.php (see above for details):
- A pdf gets converted to a tif; //through “convert” command
- The tif gets split by page into individual tifs; //through “tiffsplit” command
- The individual tifs get converted to individual jpgs ; //through “mogrify” command
- The individual tifs get combined to a temp.tif; //through “tiffcp” command
- The temp.tif gets faxed out; //through “sendfax” command
- Or the temp.tif gets copied to the chart by getting converted to a pdf again. //through “tiff2pdf” command.
Note that if you use a scanner to scan to tif, step 1 is bypassed.
The errors I would keep getting were with tiff2pdf when trying to copy to patient chart, with sendfax sometimes when trying to fax out, and with mogrify oftentimes when the jpg images were to be shown on the preview screen in Fax Dispatch.
The trouble is with convert: it creates huge files. I mean, really really, really huge. That’s where it all breaks bad. Many times, the file becomes too huge to go through subsequent conversion processes and/or fax-outs.
Convert and mogrify are from Imagemagick. I switched from Imagemagick to GraphicsMagick, which uses the command “gm convert.” This is much better in that it creates a significantly smaller tif file. But sometimes it can still be too big, especially with multi-page pdfs. So part one of the solution is to completely avoid step 1 above. To do that, always scan to a tif – not to a pdf.
Now you have a small tif getting tiffsplit to small individual-page tiffs, mogrified to jpgs, and getting tiffcp to a small temp.tif. With a small temp.tif, tiff2pdf works perfect, creating manageable-sized pdfs. You don’t even need the -j option to compress the file. But you do have to add an option which is not in the original code: -F. This expands the tif to fill the pdf page. Tifs now get nicely converted to pdfs, to be copied to chart!
Mogrify still wasn’t always working though, because of memory exceeded issues which I didn’t totally understand. Which meant the preview jpg images wouldn’t always show. Which meant you couldn’t select any images to send to chart as a pdf.
Part two of the solution turned out to be quite simple: GraphicsMagick also has “gm mogrify.” Just using that in the code had every preview image getting created and loading like a charm.
One final problem: Sending out faxes starting as pdfs went weird. Everything we store as documents is in pdf form (so that the doc preview box works as it should), so all send-out faxes start as pdfs. And sometimes I need to annotate pdfs, say, for prescription refill requests that are faxed in (I do not use e-scripting). But the crazy convert/gm convert would lead to weird fax outputs, like shrinking the image to just the lower left-hand corner of the page (it strangely only seems to happen with prescription refill requests – maybe something about the bar codes on them??). Part three of the solution was to have sendfax bypass using the temp.tif (downstream from convert) and just use the original pdf itself. No more funky fax outputs. The compromise here is that you can’t deselect individual pages before the faxing out (because you’re no longer using temp.tif). But I have no practical reason for deselecting pages on a fax-out; that only makes sense on bulk scan-ins to sort, or fax-ins to crop pages before copying to chart…which still works fine, because scan-ins and fax-ins are all tifs.
One last piece: the Job ID hyperlinks on the Faxes Out tab wouldn’t always open, so I added code in fax_view.php to get that to work with all different file types.
TL;DR
For fax_dispatch.php:
- Modify line 159 to
$tmp0 = exec("tiff2pdf -p letter -F -o " . escapeshellarg($target) . " " . escapeshellarg($faxcache.’/temp.tif’), $tmp1, $tmp2);
- Modify line 327 to
"sendfax -A -n " . escapeshellarg($form_finemode) . " -d " .
escapeshellarg($form_fax) . " " . escapeshellarg($tmpfn2) . " " . escapeshellarg($filepath),
$tmp1,
$tmp2
);
- Modify line 432 to
$tmp0 = exec("gm convert -density 203x196 " . escapeshellarg($filepath) . " " . escapeshellarg($faxcache.’/deleteme.tif’), $tmp1, $tmp2); //But you really want to bypass this command.
(Be sure to install GraphicsMagick first.)
- Modify line 448 to
$tmp0 = exec("cd " . escapeshellarg($faxcache) . “; gm mogrify -resize 750x970 -format jpg *.tif”, $tmp1, $tmp2);
For fax_view.php:
- Add between line 41 and 42
elseif (substr($line, 0, 5) == ‘!pdf:’) {
$ffname = $GLOBALS[‘hylafax_basedir’] . ‘/’. substr($line, strrpos($line, ‘:’)+1);
elseif (substr($line, 0, 6) == ‘!tiff:’) {
$ffname = $GLOBALS[‘hylafax_basedir’] . ‘/’ . substr($line, strrpos($line, ‘:’)+1);
That’s it. I hope this helps. For someone who knew absolutely nothing about Linux or coding just two years ago when I started on OEMR, it is such an awesome feeling to figure all this out. I feel like Neo in The Matrix. I know kung fu. Thanks to this community of Morpheuses.
Cheers,
Venu