Skip to content

Commit

Permalink
CDR module to add per patient gui for plan:
Browse files Browse the repository at this point in the history
At patient summary screen for edit button of clinical
reminders widget. Can set per patient plans off/on/default
in Admin tab. These settings are used to create the plans
output in the Plans tab of this same script.
  • Loading branch information
bradymiller committed Feb 13, 2011
1 parent bd8e23a commit 816cf8b
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 4 deletions.
62 changes: 61 additions & 1 deletion interface/patient_file/reminder/clinical_reminders.php
Expand Up @@ -60,7 +60,8 @@
<br>

<?php
// collect the pertinent rules
// collect the pertinent plans and rules
$plans_default = resolve_plans_sql('','0',TRUE);
$rules_default = resolve_rules_sql('','0',TRUE);
?>

Expand All @@ -85,6 +86,55 @@

<div class="tab" style="height:auto;width:97%;">
<div id='report_results'>
<table>
<tr>
<th rowspan="2"><?php echo htmlspecialchars( xl('Plan'), ENT_NOQUOTES); ?></th>
<th colspan="2"><?php echo htmlspecialchars( xl('Show'), ENT_NOQUOTES); ?></th>
</tr>
<tr>
<th><?php echo htmlspecialchars( xl('Patient Setting'), ENT_NOQUOTES); ?></th>
<th style="left-margin:1em;"><?php echo htmlspecialchars( xl('Practice Default Setting'), ENT_NOQUOTES); ?></th>
</tr>
<?php foreach ($plans_default as $plan) { ?>
<tr>
<td style="border-right:1px solid black;"><?php echo generate_display_field(array('data_type'=>'1','list_id'=>'clinical_plans'), $plan['id']); ?></td>
<td align="center">
<?php
$patient_plan = collect_plan($plan['id'],$patient_id);
// Set the patient specific setting for gui
if (empty($patient_plan)) {
$select = "default";
}
else {
if ($patient_plan['normal_flag'] == "1") {
$select = "on";
}
else if ($patient_plan['normal_flag'] == "0"){
$select = "off";
}
else { // $patient_rule['normal_flag'] == NULL
$select = "default";
}
} ?>
<select class="plan_show" name="<?php echo htmlspecialchars( $plan['id'], ENT_NOQUOTES); ?>">
<option value="default" <?php if ($select == "default") echo "selected"; ?>><?php echo htmlspecialchars( xl('Default'), ENT_NOQUOTES); ?></option>
<option value="on" <?php if ($select == "on") echo "selected"; ?>><?php echo htmlspecialchars( xl('On'), ENT_NOQUOTES); ?></option>
<option value="off" <?php if ($select == "off") echo "selected"; ?>><?php echo htmlspecialchars( xl('Off'), ENT_NOQUOTES); ?></option>
</select>
</td>
<td align="center" style="border-right:1px solid black;">
<?php if ($plan['normal_flag'] == "1") {
echo htmlspecialchars( xl('On'), ENT_NOQUOTES);
}
else {
echo htmlspecialchars( xl('Off'), ENT_NOQUOTES);
} ?>
</td>
</tr>
<?php } ?>
</table>
<br>
<br>
<table>
<tr>
<th rowspan="2"><?php echo htmlspecialchars( xl('Rule'), ENT_NOQUOTES); ?></th>
Expand Down Expand Up @@ -197,6 +247,16 @@
});
});

$(".plan_show").change(function() {
top.restoreSession();
$.post( "../../../library/ajax/plan_setting.php", {
plan: this.name,
type: 'normal',
setting: this.value,
patient_id: '<?php echo htmlspecialchars($patient_id, ENT_QUOTES); ?>'
});
});

$(".medium_modal").fancybox( {
'overlayOpacity' : 0.0,
'showCloseButton' : true,
Expand Down
30 changes: 30 additions & 0 deletions library/ajax/plan_setting.php
@@ -0,0 +1,30 @@
<?php
// Copyright (C) 2011 Brady Miller <brady@sparmy.com>
//
// 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 file contains functions that manage custom user
// settings
//

//SANITIZE ALL ESCAPES
$sanitize_all_escapes=true;
//

//STOP FAKE REGISTER GLOBALS
$fake_register_globals=false;
//

require_once(dirname(__FILE__) . "/../../interface/globals.php");
require_once(dirname(__FILE__) . "/../clinical_rules.php");

//set the rule setting for patient (ensure all variables exist)
if ($_POST['plan'] && $_POST['type'] && $_POST['setting'] && $_POST['patient_id']) {
set_plan_activity_patient($_POST['plan'], $_POST['type'], $_POST['setting'], $_POST['patient_id']);
}

?>
57 changes: 54 additions & 3 deletions library/clinical_rules.php
Expand Up @@ -641,7 +641,7 @@ function resolve_plans_sql($type='',$patient_id='0',$configurableOnly=FALSE) {
if ($configurableOnly) {
// Collect all default, configurable (per patient) plans into an array
// (ie. ignore the cqm rules)
$sql = sqlStatement("SELECT * FROM `clinical_plans` WHERE `pid`=0 AND `cqm` !=1 ORDER BY `id`");
$sql = sqlStatement("SELECT * FROM `clinical_plans` WHERE `pid`=0 AND `cqm_flag` !=1 ORDER BY `id`");
}
else {
// Collect all default plans into an array
Expand Down Expand Up @@ -705,6 +705,59 @@ function resolve_plans_sql($type='',$patient_id='0',$configurableOnly=FALSE) {
return $returnArray;
}

// Function to return a specific plan
// Parameters:
// $plan - id(string) of plan
// $patient_id - pid of selected patient. (if set to 0, then will return
// the default rule).
// Return: array containing a rule
function collect_plan($plan,$patient_id='0') {

return sqlQuery("SELECT * FROM `clinical_plans` WHERE `id`=? AND `pid`=?", array($plan,$patient_id) );

}

// Function to set a specific plan activity for a specific patient
// Parameters:
// $plan - id(string) of plan
// $type - plan filter (normal,cqm)
// $setting - activity of plan (yes,no,default)
// $patient_id - pid of selected patient.
// Return: nothing
function set_plan_activity_patient($plan,$type,$setting,$patient_id) {

// Don't allow messing with the default plans here
if ($patient_id == "0") {
return;
}

// Convert setting
if ($setting == "on") {
$setting = 1;
}
else if ($setting == "off") {
$setting = 0;
}
else { // $setting == "default"
$setting = NULL;
}

// Collect patient specific plan, if already exists.
$query = "SELECT * FROM `clinical_plans` WHERE `id` = ? AND `pid` = ?";
$patient_plan = sqlQuery($query, array($plan,$patient_id) );

if (empty($patient_plan)) {
// Create a new patient specific plan with flags all set to default
$query = "INSERT into `clinical_plans` (`id`, `pid`) VALUES (?,?)";
sqlStatement($query, array($plan, $patient_id) );
}

// Update patient specific row
$query = "UPDATE `clinical_plans` SET `" . add_escape_custom($type) . "_flag`= ? WHERE id = ? AND pid = ?";
sqlStatement($query, array($setting,$plan,$patient_id) );

}

// Function to return active rules
// Parameters:
// $type - rule filter (active_alert,passive_alert,cqm,amc,patient_reminder)
Expand Down Expand Up @@ -840,8 +893,6 @@ function set_rule_activity_patient($rule,$type,$setting,$patient_id) {
$query = "SELECT * FROM `clinical_rules` WHERE `id` = ? AND `pid` = ?";
$patient_rule = sqlQuery($query, array($rule,$patient_id) );

error_log("DEBUG :".$rule.$type.$setting.$patient_id,0);

if (empty($patient_rule)) {
// Create a new patient specific rule with flags all set to default
$query = "INSERT into `clinical_rules` (`id`, `pid`) VALUES (?,?)";
Expand Down

0 comments on commit 816cf8b

Please sign in to comment.