Skip to content

Commit

Permalink
Facility specific user information form via the layout engine.
Browse files Browse the repository at this point in the history
 -Enter in per-facility user information at Administration->Users->View
  Facility Specific User Information->Click on username to edit info
 -Add new entries via Administration->Layouts->Facility Specific User Information
 -TODO: clean up the data entry mechanism
  • Loading branch information
Wakie87 authored and bradymiller committed May 1, 2012
1 parent 50ffc2f commit cb42b47
Show file tree
Hide file tree
Showing 6 changed files with 429 additions and 4 deletions.
9 changes: 5 additions & 4 deletions interface/super/edit_layout.php
Expand Up @@ -15,6 +15,7 @@
'DEM' => xl('Demographics'),
'HIS' => xl('History'),
'REF' => xl('Referrals'),
'FACUSR' => xl('Facility Specific User Information')
);
if ($GLOBALS['ippf_specific']) {
$layouts['GCA'] = xl('Abortion Issues');
Expand Down Expand Up @@ -131,7 +132,7 @@ function nextGroupOrder($order) {
",'" . $listval . "'" .
" )");

if (substr($layout_id,0,3) != 'LBF') {
if (substr($layout_id,0,3) != 'LBF' && $layout_id != "FACUSR") {
// Add the field to the table too (this is critical)
if ($layout_id == "DEM") { $tablename = "patient_data"; }
else if ($layout_id == "HIS") { $tablename = "history_data"; }
Expand Down Expand Up @@ -177,7 +178,7 @@ function nextGroupOrder($order) {
$sqlstmt .= ")";
sqlStatement($sqlstmt);

if (substr($layout_id,0,3) != 'LBF') {
if (substr($layout_id,0,3) != 'LBF' && $layout_id != "FACUSR") {
// drop the field from the table too (this is critical)
if ($layout_id == "DEM") { $tablename = "patient_data"; }
else if ($layout_id == "HIS") { $tablename = "history_data"; }
Expand Down Expand Up @@ -232,7 +233,7 @@ function nextGroupOrder($order) {
",'" . $listval . "'" .
" )");

if (substr($layout_id,0,3) != 'LBF') {
if (substr($layout_id,0,3) != 'LBF' && $layout_id != "FACUSR") {
// Add the field to the table too (this is critical)
if ($layout_id == "DEM") { $tablename = "patient_data"; }
else if ($layout_id == "HIS") { $tablename = "history_data"; }
Expand All @@ -250,7 +251,7 @@ function nextGroupOrder($order) {

else if ($_POST['formaction'] == "deletegroup" && $layout_id) {
// drop the fields from the related table (this is critical)
if (substr($layout_id,0,3) != 'LBF') {
if (substr($layout_id,0,3) != 'LBF' && $layout_id != "FACUSR") {
$res = sqlStatement("SELECT field_id FROM layout_options WHERE " .
" form_id = '".$_POST['layout_id']."' ".
" AND group_name = '".$_POST['deletegroupname']."'"
Expand Down
177 changes: 177 additions & 0 deletions interface/usergroup/facility_user.php
@@ -0,0 +1,177 @@
<?php
// +-----------------------------------------------------------------------------+
// Copyright (C) 2012 NP Clinics <info@npclinics.com.au>
//
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// A copy of the GNU General Public License is included along with this program:
// openemr/interface/login/GnuGPL.html
// For more information write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// Author: Scott Wakefield <scott@npclinics.com.au>
//
// +------------------------------------------------------------------------------+

//SANITIZE ALL ESCAPES
$sanitize_all_escapes=true;


//STOP FAKE REGISTER GLOBALS
$fake_register_globals=false;


require_once("../globals.php");
require_once("$srcdir/sql.inc");
require_once("$srcdir/formdata.inc.php");
require_once("$srcdir/options.inc.php");
require_once("$srcdir/acl.inc");

// Ensure authorized
if (!acl_check('admin', 'users')) {
die(xlt("Unauthorized"));
}

$alertmsg = '';

if ( isset($_POST["mode"]) && $_POST["mode"] == "facility_user_id" && isset($_POST["user_id"]) && isset($_POST["fac_id"]) ) {
// Inserting/Updating new facility specific user information
$fres = sqlStatement("SELECT * FROM `layout_options` " .
"WHERE `form_id` = 'FACUSR' AND `uor` > 0 AND `field_id` != '' " .
"ORDER BY `group_name`, `seq`");
while ($frow = sqlFetchArray($fres)) {
$value = get_layout_form_value($frow);
$entry_id = sqlQuery("SELECT `id` FROM `facility_user_ids` WHERE `uid` = ? AND `facility_id` = ? AND `field_id` =?", array($_POST["user_id"],$_POST["fac_id"],$frow['field_id']) );
if (empty($entry_id)) {
// Insert new entry
sqlInsert("INSERT INTO `facility_user_ids` (`uid`, `facility_id`, `field_id`, `field_value`) VALUES (?,?,?,?)", array($_POST["user_id"],$_POST["fac_id"],$frow['field_id'], $value) );
}
else {
// Update existing entry
sqlStatement("UPDATE `facility_user_ids` SET `field_value` = ? WHERE `id` = ?", array($value,$entry_id['id']) );
}
}
}

?>
<html>
<head>
<link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
<link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
<script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
<script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.1.3.2.js"></script>
<script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script>
<script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
<script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-ui.js"></script>
<script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.easydrag.handler.beta2.js"></script>

<script type="text/javascript">

$(document).ready(function(){

// fancy box
enable_modals();

// special size for
$(".iframe_small").fancybox( {
'overlayOpacity' : 0.0,
'showCloseButton' : true,
'frameHeight' : 300,
'frameWidth' : 500
});

$(function(){
// add drag and drop functionality to fancybox
$("#fancy_outer").easydrag();
});
});

</script>

</head>
<body class="body_top">

<?php
// Collect all users
$u_res = sqlStatement("select * from `users` WHERE `username` != '' AND `active` = 1 order by `username`");

// Collect all facilities and store them in an array
$f_res = sqlStatement("select * from `facility` order by `name`");
$f_arr = array();
for($i=0; $row=sqlFetchArray($f_res); $i++) {
$f_arr[$i]=$row;
}

// Collect layout information and store them in an array
$l_res = sqlStatement("SELECT * FROM layout_options " .
"WHERE form_id = 'FACUSR' AND uor > 0 AND field_id != '' " .
"ORDER BY group_name, seq");
$l_arr = array();
for($i=0; $row=sqlFetchArray($l_res); $i++) {
$l_arr[$i]=$row;
}

?>

<div>
<div>
<table>
<tr >
<td><b><?php echo xlt('Facility Specific User Information'); ?></b></td>
<td><a href="usergroup_admin.php" class="css_button" onclick="top.restoreSession()"><span><?php echo xlt('Back to Users'); ?></span></a>
</td>
</tr>
</table>
</div>

<div style="width:400px;">
<div>

<table cellpadding="1" cellspacing="0" class="showborder">
<tbody><tr height="22" class="showborder_head">
<th width="180px"><b><?php echo xlt('Username'); ?></b></th>
<th width="270px"><b><?php echo xlt('Full Name'); ?></b></th>
<th width="190px"><b><span class="bold"><?php echo xlt('Facility'); ?></span></b></th>
<?php
foreach ($l_arr as $layout_entry) {
echo "<th width='100px'><b><span class='bold'>" . text(xl_layout_label($layout_entry['title'])) . "&nbsp;</span></b></th>";
}
?>
</tr>
<?php
while ($user = sqlFetchArray($u_res)) {
foreach ($f_arr as $facility) {
?>
<tr height="20" class="text" style="border-bottom: 1px dashed;">
<td class="text"><b><a href="facility_user_admin.php?user_id=<?php echo attr($user['id']);?>&fac_id=<?php echo attr($facility['id']);?>" class="iframe_small" onclick="top.restoreSession()"><span><?php echo text($user['username']);?></span></a></b>&nbsp;</td>
<td><span class="text"><?php echo text($user['fname'] . " " . $user['lname']);?></span>&nbsp;</td>
<td><span class="text"><?php echo text($facility['name']);?>&nbsp;</td>
<?php
foreach ($l_arr as $layout_entry) {
$entry_data = sqlQuery("SELECT `field_value` FROM `facility_user_ids` " .
"WHERE `uid` = ? AND `facility_id` = ? AND `field_id` = ?", array($user['id'],$facility['id'],$layout_entry['field_id']) );
echo "<td><span class='text'>" . generate_display_field($layout_entry,$entry_data['field_value']) . "&nbsp;</td>";
}
?>
</tr>
<?php
}}
?>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>

0 comments on commit cb42b47

Please sign in to comment.