Ejemplo n.º 1
0
/**
 *  This function makes and stores a document that we want to deliver.
 */
function make_document($task)
{
    global $providerNAME;
    global $encounter;
    /**
     * We want to store the current PDF version of this task.
     */
    $query = "SELECT * FROM users WHERE id=?";
    $to_data = sqlQuery($query, array($task['TO_ID']));
    $from_data = sqlQuery($query, array($task['FROM_ID']));
    $sql = "SELECT * FROM facility ORDER BY billing_location DESC LIMIT 1";
    $facility_data = sqlQuery($sql);
    $query = "SELECT * FROM patient_data where pid=?";
    $patientData = sqlQuery($query, array($task['PATIENT_ID']));
    $from_fax = preg_replace("/[^0-9]/", "", $facility_data['fax']);
    $from_name = $from_data['fname'] . " " . $from_data['lname'];
    if ($from_data['suffix']) {
        $from_name .= ", " . $from_data['suffix'];
    }
    $from_fac = $from_facility['name'];
    $to_fax = preg_replace("/[^0-9]/", "", $to_data['fax']);
    $to_name = $to_data['fname'] . " " . $to_data['lname'];
    if ($to_data['suffix']) {
        $to_name .= ", " . $to_data['suffix'];
    }
    $pt_name = $patientData['fname'] . ' ' . $patientData['lname'];
    $encounter = $task['ENC_ID'];
    $query = "select form_encounter.date as encounter_date,form_eye_mag.id as form_id,form_encounter.*, form_eye_mag.* \n            from form_eye_mag ,forms,form_encounter \n            where \n            form_encounter.encounter =? and \n            form_encounter.encounter = forms.encounter and \n            form_eye_mag.id=forms.form_id and\n            forms.deleted != '1' and \n            form_eye_mag.pid=? ";
    $encounter_data = sqlQuery($query, array($encounter, $task['PATIENT_ID']));
    @extract($encounter_data);
    $providerID = getProviderIdOfEncounter($encounter);
    $providerNAME = getProviderName($providerID);
    $dated = new DateTime($encounter_date);
    $dated = $dated->format('Y/m/d');
    $visit_date = oeFormatShortDate($dated);
    //$visit_date = $encounter_date;
    $pid = $task['PATIENT_ID'];
    $PDF_OUTPUT = '1';
    $filepath = $GLOBALS['oer_config']['documents']['repository'] . $task['PATIENT_ID'];
    //so far we make A "Report", one per encounter, and "Faxes", as many as we need per encounter.
    //So delete any prior report if that is what we are doing. and replace it.
    //If it is a fax, can we check to see if the report is already here, and if it is add it, or do we have to
    // always remake it?  For now, REMAKE IT...
    if ($task['DOC_TYPE'] == 'Fax') {
        $category_name = "Communication";
        //Faxes are stored in the Documents->Communication category.  Do we need to translate this?
        //$category_name = xl('Communication');
        $query = "select id from categories where name =?";
        $ID = sqlQuery($query, array($category_name));
        $category_id = $ID['id'];
        $filename = "Fax_" . $encounter . "_" . $to_data['lname'] . ".pdf";
        while (file_exists($filepath . '/' . $filename)) {
            $count++;
            $filename = "FAX_" . $encounter . "_" . $to_data['lname'] . "_" . $count . ".pdf";
        }
    } else {
        $category_name = "Encounters";
        $query = "select id from categories where name =?";
        $ID = sqlQuery($query, array($category_name));
        $category_id = $ID['id'];
        $filename = "Report_" . $encounter . ".pdf";
        foreach (glob($filepath . '/' . $filename) as $file) {
            unlink($file);
            //maybe shorten to just unlink($filepath.'/'.$filename); - well this does test to see if it is there
        }
        $sql = "DELETE from categories_to_documents where document_id IN (SELECT id from documents where documents.url like ?)";
        sqlQuery($sql, array("%" . $filename));
        $sql = "DELETE from documents where documents.url like ?";
        sqlQuery($sql, array("%" . $filename));
    }
    $pdf = new HTML2PDF($GLOBALS['pdf_layout'], $GLOBALS['pdf_size'], $GLOBALS['pdf_language'], true, 'UTF-8', array($GLOBALS['pdf_left_margin'], $GLOBALS['pdf_top_margin'], $GLOBALS['pdf_right_margin'], $GLOBALS['pdf_bottom_margin']), $_SESSION['language_direction'] == 'rtl' ? true : false);
    ob_start();
    ?>
<html>
	<head> 
		<TITLE><?php 
    echo xlt('Taskman: Documents in openEMR');
    ?>
</TITLE> 
		<style>
			.wrapper {
				margin:20px;
			}
			.col1 {
				font-weight:bold;
				width:100px;
				padding:10px;
				text-align:right;
			}
			.col2 {
				width:375px;
				padding:10px;
			}
		</style>
    	<link rel="stylesheet" href="<?php 
    echo $webserver_root;
    ?>
/interface/themes/style_pdf.css" type="text/css">
	</head>
	<body>
	<?php 
    if ($task['DOC_TYPE'] == 'Fax') {
        ?>
		<div class='wrapper'>
	 		<?php 
        echo report_header($task['PATIENT_ID'], 'PDF');
        ?>
			<br />
	 		<br />
	 		<br />
	 		<br />
	 		<br />
	 		<br />
	 		<br />
	 		<hr />
   			<table>
					<tr>
						<td class='col1'><?php 
        echo xlt('From');
        ?>
:</td>
						<td class='col2'>
							<?php 
        echo text($from_name);
        ?>
<br />
							
						</td>
					</tr>
					<tr>
						<td class='col1'><?php 
        echo xlt('Address');
        ?>
:</td>
						<td class='col2'>
							<?php 
        if ($from_data['name']) {
            echo text($from_data['name']) . "<br />";
        }
        ?>
							<?php 
        echo text($from_data['street']);
        ?>
<br />
				 			<?php 
        echo text($from_data['city']);
        ?>
, <?php 
        echo text($from_data['state']) . " " . text($from_data['zip']);
        ?>
				 			<br />
				 		</td>
				 	</tr>
				 	<tr>
				 		<td class='col1'>
				 			<?php 
        echo xlt('Phone');
        ?>
:
				 		</td>
				 		<td class='col2'>
				 			<?php 
        echo text($from_data['phonew1']);
        ?>
				 		</td>
				 	</tr>
				 	<tr>
				 		<td class='col1'>
				 			<?php 
        echo xlt('Fax');
        ?>
: 
				 		</td>
				 		<td class='col2'><?php 
        echo text($from_data['fax']);
        ?>
<br />
				 		</td>
				 	</tr>
				 	<tr>
				 		<td class='col1'><?php 
        echo xlt('To');
        ?>
:</td>
				 		<td class='col2'><?php 
        echo text($to_name);
        ?>
</td>
				 	</tr>
				 	<tr>
						<td class='col1'><?php 
        echo xlt('Address');
        ?>
:</td>
						<td class='col2'>
							<?php 
        echo text($to_data['street']) . "<br />\n\t\t\t\t \t\t\t" . text($to_data['city']) . ", " . text($to_data['state']) . " " . text($to_data['zip']);
        ?>
				 			<br />
				 		</td>
				 	</tr>
				 	<tr>
				 		<td class='col1'>
				 			<?php 
        echo xlt('Phone');
        ?>
:
				 		</td>
				 		<td class='col2'>
				 			<?php 
        echo text($to_data['phonew1']);
        ?>
				 		</td>
				 	</tr>
				 	<tr>
				 		<td class='col1'>
				 			<?php 
        echo xlt('Fax');
        ?>
: 
				 		</td>
				 		<td class='col2'>
				 			<?php 
        echo text($to_data['fax']);
        ?>
				 		</td>
				 	</tr>
				 	<tr><td colspan="2"><br /><hr /></td></tr>
				 	<tr>
				 		<td class='col1'>
				 			<?php 
        echo xlt('Comments');
        ?>
: 
				 		</td>
						<td class='col2'><?php 
        echo xlt('Report of visit');
        ?>
: <?php 
        echo text($pt_name);
        ?>
 on <?php 
        echo $visit_date;
        ?>
						</td>
					</tr>
			</table>
		</div>
    <?php 
        echo '<page></page><div style="page-break-after:always; clear:both"></div>';
    }
    // 	If the doc_id does exit, why remake it?
    //	We could just add another attachment, stopping here at the coversheet, and adding the doc_name that we sent...
    //	No.  We actually need a physical copy of what we sent, since the report itself can be overwritten.  Keep it legal.
    //	Unless the Report.pdf can be merged with the cover sheet.  Until then, just redo it all.
    echo narrative($pid, $encounter, $task['DOC_TYPE'], $form_id);
    ?>
    </body>
	</html>
    <?php 
    global $web_root, $webserver_root;
    $content = ob_get_clean();
    // Fix a nasty html2pdf bug - it ignores document root!
    $i = 0;
    $wrlen = strlen($web_root);
    $wsrlen = strlen($webserver_root);
    while (true) {
        $i = stripos($content, " src='/", $i + 1);
        if ($i === false) {
            break;
        }
        if (substr($content, $i + 6, $wrlen) === $web_root && substr($content, $i + 6, $wsrlen) !== $webserver_root) {
            $content = substr($content, 0, $i + 6) . $webserver_root . substr($content, $i + 6 + $wrlen);
        }
    }
    $pdf->writeHTML($content, false);
    $temp_filename = '/tmp/' . $filename;
    $content_pdf = $pdf->Output($temp_filename, 'F');
    $type = "application/pdf";
    $size = filesize($temp_filename);
    $return = addNewDocument($filename, $type, $temp_filename, 0, $size, $task['FROM_ID'], $task['PATIENT_ID'], $category_id);
    $task['DOC_ID'] = $return['doc_id'];
    $task['DOC_url'] = $filepath . '/' . $filename;
    $sql = "UPDATE documents set encounter_id=? where id=?";
    //link it to this encounter
    sqlQuery($sql, array($encounter, $task['DOC_ID']));
    return $task;
}
Ejemplo n.º 2
0
    $category_id = $ID['id'];
    // We want to overwrite so only one image is stored per zone per form/encounter
    // I do not believe this function exists in the current library, ie "UpdateDocument" function, so...
    //  we need to delete the previous file from the documents and categories to documents tables and the actual file
    //  There must be a delete_file function in documents class?
    // cannot find it.
    // this will work for harddisk people, not sure about couchDB people:
    $filepath = $GLOBALS['oer_config']['documents']['repository'] . $pid . "/";
    foreach (glob($filepath . '/' . $filename) as $file) {
        unlink($file);
    }
    $sql = "DELETE from categories_to_documents where document_id IN (SELECT id from documents where documents.url like '%" . $filename . "')";
    sqlQuery($sql);
    $sql = "DELETE from documents where documents.url like '%" . $filename . "'";
    sqlQuery($sql);
    $return = addNewDocument($filename, $type, $_POST["imgBase64"], 0, $size, $_SESSION['authUserID'], $pid, $category_id);
    $doc_id = $return['doc_id'];
    $sql = "UPDATE documents set encounter_id=? where id=?";
    //link it to this encounter
    sqlQuery($sql, array($encounter, $doc_id));
    exit;
}
if ($_REQUEST['copy']) {
    copy_forward($_REQUEST['zone'], $_REQUEST['copy_from'], $_SESSION['ID'], $pid);
    return;
}
function QuotedOrNull($fld)
{
    if ($fld) {
        return "'" . add_escape_custom($fld) . "'";
    }
		<?php 
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    session_start();
    if (empty($_POST["query"]) && !empty($_POST["new"])) {
        //new document
        setDocuments();
        addNewDocument($_POST["new"]);
    } else {
        if (!empty($_POST["query"]) && empty($_POST["new"])) {
            //calculate cosine sim
            setDocuments();
            cosineSimilarity($_POST["query"]);
        } else {
            if (empty($_POST["query"]) && !empty($_POST["new"])) {
                //add new document and then calculate cosine
                addNewDocument($_POST["new"]);
                cosineSimilarity($_POST["query"]);
            }
        }
    }
}
function cosineSimilarity($query)
{
    $querySum = 0;
    $termWeights = explode(" ", $query);
    for ($i = 0; $i < count($termWeights); $i++) {
        $querySum += pow($termWeights[$i], 2);
    }
    for ($i = 0; $i < count($_SESSION['documents']); $i++) {
        $numerator = 0;
        $documentSum = 0;
 $acl_allow = acl_check('patients', 'docs', $user);
 if ($acl_allow) {
     $id = 1;
     $type = "file_url";
     $size = '';
     $date = date('Y-m-d H:i:s');
     $url = '';
     $hash = '';
     $image_path = $sitesDir . "{$site}/documents/{$patient_id}";
     if (!file_exists($image_path)) {
         mkdir($image_path);
     }
     $image_date = date('YmdHis');
     $image_root_path = $image_path . "/" . $image_date . "." . $ext;
     file_put_contents($image_root_path, $image_content);
     $res = addNewDocument($image_date . "." . $ext, 'image/png', $image_root_path, 0, filesize($image_root_path), $userId, $patient_id, $cat_id, $higher_level_path = '', $path_depth = '1');
     $lab_report_catid = document_category_to_id("Lab Report");
     if ($cat_id == $lab_report_catid) {
         $device_token_badge = getDeviceTokenBadge($provider_username, 'labreport');
         $badge = $device_token_badge['badge'];
         $deviceToken = $device_token_badge['device_token'];
         if ($deviceToken) {
             $notification_res = notification($deviceToken, $badge, $msg_count = 0, $apt_count = 0, $message = 'New Labreport Notification!');
         }
     }
     if ($res) {
         $xml_array['status'] = "0";
         $xml_array['reason'] = "Document added successfully";
         if ($notification_res) {
             $xml_array['notification'] = 'Add Patient document Notification(' . $notification_res . ')';
         } else {
Ejemplo n.º 5
0
// Fix a nasty html2pdf bug - it ignores document root!
$i = 0;
$wrlen = strlen($web_root);
$wsrlen = strlen($webserver_root);
while (true) {
    $i = stripos($content, " src='/", $i + 1);
    if ($i === false) {
        break;
    }
    if (substr($content, $i + 6, $wrlen) === $web_root && substr($content, $i + 6, $wsrlen) !== $webserver_root) {
        $content = substr($content, 0, $i + 6) . $webserver_root . substr($content, $i + 6 + $wrlen);
    }
}
$temp_filename = '/tmp/' . $filename;
$query = "select id from categories where name like 'Communication'";
$result = sqlStatement($query);
$ID = sqlFetchArray($result);
$category_id = $ID['id'];
$pdf->writeHTML($content, false);
$content_pdf = $pdf->Output($temp_filename, 'F');
$type = "application/pdf";
$size = filesize($temp_filename);
$return = addNewDocument($filename, $type, $temp_filename, 0, $size, $_SESSION['authUserID'], $pid, $category_id);
$doc_id = $return['doc_id'];
$sql = "UPDATE documents set encounter_id=? where id=?";
//link it to this encounter
sqlQuery($sql, array($encounter, $doc_id));
exit;
?>