Attach document to the encounter

midder wrote on Friday, October 22, 2010:

Hello

I’m looking for a way to upload and attach a document and associate it with a specific encounter. We’re able to upload the documents into the Medical Record folder, but I don’t see how to attach it to a specific encounter. Is this something that is possible? If it is not possible out of the box, is there some work-around that you might suggest? Right now we’re able to correlate the date on the document with the date of the visit, but I was hoping for something in the encounter itself.

I am supporting a mental health facility. They feel it is invasive to have an electronic device in with their patients, so they take notes on paper. They would then like to associate these notes with that specific visit.

Thanks for your assistance and ideas.

Brian

sunsetsystems wrote on Friday, October 22, 2010:

There is a “scanned notes” encounter form in contrib/forms/ that does this.  The fax/scan dispatch window also has an option to load documents for it.

Rod
www.sunsetsystems.com

midder wrote on Saturday, October 23, 2010:

Thanks Rod

How do I enable something like that? I see the scanned_notes folder in that directory, but I’m not sure how to do anything meaningful with it.

Thanks again.

midder wrote on Sunday, October 24, 2010:

For those interested, I took the directory from the location Rod mentioned above and copied it to /interface/forms. After this it was available in administration -> other -> forms, where I was able to enable and install it.

As I was testing my first upload, I got this message from the interface:

“convert -density 96 ‘/tmp/phpjbtYAk’ ‘/home/bcesolut/public_html/emr/documents/1/encounters/2_2.jpg’” returned 1:

/home/bcesolut/public_html/emr is my EMR home directory.

I tried uploading a Microsoft Word document. Is this a permissions issue?

Thanks again. I’m really enjoying this software the more I learn about it. The modular parts are excellent.

midder wrote on Sunday, October 24, 2010:

Sorry just a quick update.

I uploaded a PNG file and it looks like it converted it to JPG. But it just showed up as a broken image in the form itself. So then I tried to upload a JPG. The same thing happened.

Is it not possible to upload a PDF or other type of document here? Does it need to be an image file? And does anyone know why the document is not retrievable once I upload it? I can see it in the directory via FTP. I’m using Chrome as my browser, if that matters.

aethelwulffe wrote on Friday, December 10, 2010:

I really think this should be in the “Help” forum, so if a moderator finds this, sorry, I’m just a thread hijacker/necroposter/jerk, and I apologize for adding to this.

I, being volunteer admin for a non-prof mental health agency myself, need this very same thing.  I found TWO contributed forms in the directory.  One named “scanned_notes” which was broken and could not make the directory it needed, and another called “documents”  “documents” works, and even has some crude install notes written in Pigeon English (also called “IT_Guy_Phonics”).  “documents” include, as I said, works, but I was also not able to upload a .png, or .pdf.

I noticed it does an extension check like this:

if (($HTTP_POST_FILES['document_image']['type'] == 'image/gif') || 
	($HTTP_POST_FILES['document_image']['type'] == 'image/jpg') ||
	($HTTP_POST_FILES['document_image']['type'] == 'image/pjpeg') ||
	($HTTP_POST_FILES['document_image']['type'] == 'image/jpeg') ||
	($HTTP_POST_FILES['document_image']['type'] == 'image/bmp')){ 
	$checktype='ok';
}

I tried inserting the following:

($HTTP_POST_FILES['document_image']['type'] == 'image/pdf') ||

But that changed nothing at all.  No difference in the behavior when I uploaded.
I am a php N00B.
I imagine that image/ would have a specific use here, as it is obviously NOT a path.  I bet another format would be ‘text/txt’ etc…

I found some code that looked helpful.

<?php
   // begin Dave B's Q&D file upload security code
  $allowedExtensions = array("txt","csv","htm","html","xml",
    "css","doc","xls","rtf","ppt","pdf","swf","flv","avi",
    "wmv","mov","jpg","jpeg","gif","png");
  foreach ($_FILES as $file) {
    if ($file['tmp_name'] > '') {
      if (!in_array(end(explode(".",
            strtolower($file['name']))),
            $allowedExtensions)) {
       die($file['name'].' is an invalid file type!<br/>'.
        '<a href="javascript:history.go(-1);">'.
        '&lt;&lt Go Back</a>');
      }
    }
  }
  // end Dave B's Q&D file upload security code
?>

I also found out that $_FILES depreciated $HTTP_POST_FILES, and I havn’e located and API or manual that explains more about this php “array” (which really doesn’t seem to be an array at all to me, further confusing me).

Next issue that we will probably have is that to display a pdf, we are going to have to show it as a frame with an href in it, or something like that (I ain’t that great in HTML either…not a web dev type …yet…)

This code stores the file in a directory, not an sql blob, right?  We should just be able to add some (ok, quite a bit of) code in here and get this form doing an html frame displaying adobe reader, html, .odt etc, right?

I thought looking for the interface for the regular patient’s documents would help as an example, but I havn’t been able to find the files/includes responsible for that behavior.  The source of the frame points me to “controller.php” but that isn’t really it.  There is just so much extraneous and supplanted stuff (freeB, broken style sheets, broken contribs, sql ledger etc…) in the code it is hard to track things down for an idiot noob.  Anyone got any pointers for me/us?

aethelwulffe wrote on Friday, December 10, 2010:

P.S.> I am gonna do something evile and set $checktype=‘ok’; after the if statement.

….everyone step back….

midder wrote on Friday, December 10, 2010:

For a PDF, you want to set it as application/pdf. But I’m not sure that it would allow that since it’s not an image type.

I’ve done a bit of work on this for the clinics I’m supporting. I hope to report back in the next few days. The scanned notes have been incredibly helpful and worked OK for me. When you say it was “broken” what does that mean?

aethelwulffe wrote on Friday, December 10, 2010:

Hi midder, thank you very much for the reply.
First "broken, would be the “scanned_documents” version that would not create a file to put the documents in.  Returned an error…cant remember what exactly, 'cause I disabled the form soon after and tried the other “documents” contribution that actually worked.  as for the broken style sheets, they are all a bit goofy (frame heights wrong for the text etc…) except for sky_blue.

I figured out the whole MIME type thing….and yes, I switched it to application/pdf as well as finding mime types for odt, doc etc… but thank you very much for the input nonetheless!!!

Next little issue after the $checktype variable:

I knew that the same code that displayed images wasn’t gonna work for pdf’s, and I knew I needed a frame.
I havn’t found where it displays the image in the note, but it has the ability to open another frame or something with the “print.php” code, so I attacked that.
I modified the contrib’s “print.php” to this:

<?
# print scanned documents
include("../../../library/api.inc");
formHeader("Patient's Scanned Documents");
$row = formFetch('form_documents', $_GET['id']);
$doc=$row["document_path"]."/".$row["document_image"];
$thatfile=$row["document_image"];
$localpath="../../forms/documents/scanned/".$GLOBALS['pid'];
$relink=$localpath."/".$thatfile;
echo ("<span class=text>Document path on server is: $doc ");
echo ("<br>");
echo ("Document Source is: ");
echo $row["document_source"];
echo ("<br>");
echo $row["document_description"];
echo ("<br>");
//*****adding in an iframe here to display the pdf********
echo ("<IFRAME SRC=\"$relink\"width=\"80%\"height=\"80%\"></iframe>");
echo ("<IMG SRC=\"$relink\" ALT=\"$relink\">");
?>
<hr>
<a href="<?php echo $GLOBALS['form_exit_url']; ?>" onclick="top.restoreSession()">Done</a>
<?php
formFooter();
?>

…terrible code, I know 'cause it is not checking if the file is an application or an image before it displays it.
Well, that still shows a broken link icon on the encounter form, but when you click on it it DOES load the iframe, and even allows room for the “top.restoresession()” little “done” button (which btw should be replaced with an image button).

OK, so it kind of works.  I can upload and read pdf’s etc…pretty good for someone that touched his first php code today!
I had to learn all about echo, and how to escape quotes in php so that I could echo as well as have “80%” in my code.  Thank-you Crimson Editor’s purple color coding of strings!
Where pray tell oh PHP GURUs, shall I find files to mod so that the main encounter form will display my pdf?

aethelwulffe wrote on Friday, December 10, 2010:

Oh, and midder, check out the other add-on form called “documents”.  Then try out this junk code for forms\documents\print.php

aethelwulffe wrote on Friday, December 10, 2010:

Just one more note:
Looks like the version you are using converts all the files to .jpg, at 96 or 72 dpi in the file view.php.  I suppose that was useful, as it enabled “Two Thumbs Tammy” behind the desk to upload a 25meg .bmp, and then have it converted to a reasonable size .jpg on the other end.  The developer also was pushing for read-only files, thus the change to the simpler format version I am using, and took away the “view.php” file contents and redirected that file to include print.php.

  The more I read into php, the more I realize how easily php can manipulate .pdf files

aethelwulffe wrote on Friday, December 10, 2010:

in report.php in the “documents” form:
adding in

echo ("<tr><td><iframe src=\"../../forms/documents/scanned/${pid}/${doc_image}\"width=\"80%\"height=\"80%\"></iframe></td></tr>");

Got me a display of the pdf, but aalso a broken link symbol.  I could take out the one that just shows the image, and figure out a good way to format the table and row this stuff is on, and probably have a clean install of this.

aethelwulffe wrote on Friday, December 10, 2010:

Finished up:

http://starfrontiers.org/khvcode/documents.zip
Unzip the contents to the forms directory, then register/install tables etc… if you have not done so for this add-on form yet.

It’s pretty slick.  It displays the documents in a wide/short aspect.  PDF’s are pretty readable in this display, using the scroll bar.  For the images of scanned documents, you see a thumbnail sized view that is scaled to the height of the frame, and if you click on it, it zooms and is scrollable like the PDF. IF you click on “Scanned Document” form header, you get the larger window with a 90% frame that lets you pretty much read the whole document if you have the navbar view set to only top or only bottom and/or have otherwise maximized your viewing area.
  I am sure that I should continue with this and add many more MIME types, as well as trying to find the documents display code for an example of differentiating between text, image, and applications.  The documents display probably needs some help as well, as it does not display .doc or odt stuff for us.  I KNOW that can be fixed.

bradymiller wrote on Saturday, December 11, 2010:

hey,
Is this a new form or modification of a current. Trying to figure out whether should consider adding this to the openemr development codebase.
-brady

aethelwulffe wrote on Saturday, December 11, 2010:

It’s just a modification of the original.
   If it was ME writing something, I would have made the directory names etc… more meaningful, so you don’t have to give the form a nickname that uses capitalization and is called something other than “documents”.   I did change some of the response text that sounds like standard English, but I didn’t add any button images for the “done” link etc… or anything else that a published item should have.   If I did it, we would have a full color user’s guide to go along with it! :) 
  -I didn’t originate the source code, but I am willing to dress it up and finish adding more MIME types if someone wants to post it in a repository.  Can’t take credit for the base form though, limited as it is, but as a mod, it should be put out though.  It’s better than what is available.
I probably would have continued working on it today, except I found a bug in the 837 claims generator that I have to work out so we can finish submitting our first EDI billing (location code 03: School generates a 3 instead of  “03”).

aethelwulffe wrote on Saturday, December 11, 2010:

Just noticed that this contrib mod works MUCH better on firefox than on IE.  Can’t see the frame with the scaled image in the normal note view in IE, you gotta open the document.  Ie is better with .asp, or else it has something to do with compatability settings.  Doesn’t matter.  Everyone on the EMR should use FF anyway for other reasons.

aethelwulffe wrote on Monday, December 13, 2010:

Changed download directory:
http://starfrontiers.org/khvcode/openemr/documents.zip

arnabnaha wrote on Monday, December 13, 2010:

Hi…
The document form works really nice…but the problem is…when the work on the form is over and we press “done” on it…it returns to the encounter. In the encounter there is a new addition of the “Scanned Document” but it is blank…I guess it would be nice if some piece of text could be there with a link to the document scanned on the user Interface…Right now we need to click on edit and see the document…

aethelwulffe wrote on Monday, December 13, 2010:

Ah,
  If you are using Firefox you should see the “small” version of the uploaded document.  In Internet Explorer, you won’t see the frame containing the document.  I really don’t know why this is so.  We may need a real .php coder to work on this.

Here is an example of what you >should< see in Firefox with updated java etc…

aethelwulffe wrote on Monday, December 13, 2010:

OH, BTW, you may see that the link to the document in this example says “Scanned Document” and not “documents”.  This is because I have given the form “documents” a nickname in the forums admin settings.  I need to check with the original authors of this form to get the OK to submit a completely updated version renaming the directories etc…