Skip to content

Commit

Permalink
improved logging of alerts in CDR engine
Browse files Browse the repository at this point in the history
  • Loading branch information
bradymiller committed Dec 23, 2015
1 parent 624049a commit 0d8e88e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
36 changes: 32 additions & 4 deletions interface/reports/cdr_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@
</th>

<th align='center'>
<?php echo xlt('Alerts'); ?>
<?php echo xlt('All Alerts'); ?>
</th>

<th align='center'>
<?php echo xlt('New Alerts'); ?>
</th>

</thead>
Expand All @@ -195,7 +199,10 @@
$category_title = $row['category'];
}
//Prepare the targets
$alerts = json_decode($row['value'], true);
$all_alerts = json_decode($row['value'], true);
if (!empty($row['new_value'])) {
$new_alerts = json_decode($row['new_value'], true);
}
?>
<tr>
<td><?php echo text($row['date']); ?></td>
Expand All @@ -204,8 +211,8 @@
<td><?php echo text($category_title); ?></td>
<td>
<?php
//list off targets with rule information shown when hover
foreach ($alerts as $targetInfo => $alert) {
//list off all targets with rule information shown when hover
foreach ($all_alerts as $targetInfo => $alert) {
$rule_title = getListItemTitle("clinical_rules",$alert['rule_id']);
$catAndTarget = explode(':',$targetInfo);
$category = $catAndTarget[0];
Expand All @@ -218,6 +225,27 @@
}
?>
</td>
<td>
<?php
if (!empty($row['new_value'])) {
//list new targets with rule information shown when hover
foreach ($new_alerts as $targetInfo => $alert) {
$rule_title = getListItemTitle("clinical_rules",$alert['rule_id']);
$catAndTarget = explode(':',$targetInfo);
$category = $catAndTarget[0];
$target = $catAndTarget[1];
echo "<span title='" .attr($rule_title) . "'>" .
generate_display_field(array('data_type'=>'1','list_id'=>'rule_action_category'),$category) .
": " . generate_display_field(array('data_type'=>'1','list_id'=>'rule_action'),$target) .
" (" . generate_display_field(array('data_type'=>'1','list_id'=>'rule_reminder_due_opt'),$alert['due_status']) . ")" .
"<span><br>";
}
}
else {
echo "&nbsp;";
}
?>
</td>
</tr>

<?php
Expand Down
18 changes: 11 additions & 7 deletions library/clinical_rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function listingCDRReminderLog($begin_date='',$end_date='') {
}

$sqlArray = array();
$sql = "SELECT `date`, `pid`, `uid`, `category`, `value` FROM `clinical_rules_log` WHERE `date` <= ?";
$sql = "SELECT `date`, `pid`, `uid`, `category`, `value`, `new_value` FROM `clinical_rules_log` WHERE `date` <= ?";
array_push($sqlArray,$end_date);
if (!empty($begin_date)) {
$sql .= " AND `date` >= ?";
Expand Down Expand Up @@ -334,15 +334,19 @@ function compare_log_alerts($patient_id,$current_targets,$category='clinical_rem
$prior_targets = json_decode($prior_targets_sql['value'], true);
}

// Store current action_log
$current_targets_json = json_encode($current_targets);
sqlInsert("INSERT INTO `clinical_rules_log` " .
"(`date`,`pid`,`uid`,`category`,`value`) " .
"VALUES (NOW(),?,?,?,?)", array($patient_id,$userid,$category,$current_targets_json) );

// Compare the current with most recent action log
$new_targets = array_diff_key($current_targets,$prior_targets);

// Store current action_log and the new items
$current_targets_json = json_encode($current_targets);
$new_targets_json = '';
if (!empty($new_targets)) {
$new_targets_json = json_encode($new_targets);
}
sqlInsert("INSERT INTO `clinical_rules_log` " .
"(`date`,`pid`,`uid`,`category`,`value`,`new_value`) " .
"VALUES (NOW(),?,?,?,?,?)", array($patient_id,$userid,$category,$current_targets_json,$new_targets_json) );

// Return news actions (if there are any)
return $new_targets;
}
Expand Down
4 changes: 4 additions & 0 deletions sql/4_2_0-to-4_2_1_upgrade.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12628,3 +12628,7 @@ INSERT INTO `rule_target` ( `id`, `group_id`, `include_flag`, `required_flag`, `
INSERT INTO `rule_target` ( `id`, `group_id`, `include_flag`, `required_flag`, `method`, `value`, `interval` ) VALUES ('rule_penicillin_allergy', 1, 1, 1, 'target_database', 'CUSTOM::act_cat_assess::act_penicillin_allergy::YES::ge::1', 0);
#EndIf

#IfMissingColumn clinical_rules_log new_value
ALTER TABLE `clinical_rules_log` ADD `new_value` TEXT NOT NULL;
#EndIf

1 change: 1 addition & 0 deletions sql/database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ CREATE TABLE `clinical_rules_log` (
`uid` bigint(20) NOT NULL DEFAULT '0',
`category` VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'An example category is clinical_reminder_widget',
`value` TEXT NOT NULL,
`new_value` TEXT NOT NULL,
PRIMARY KEY (`id`),
KEY `pid` (`pid`),
KEY `uid` (`uid`),
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// is a database change in the course of development. It is used
// internally to determine when a database upgrade is needed.
//
$v_database = 151;
$v_database = 152;

// Access control version identifier, this is to be incremented whenever there
// is a access control change in the course of development. It is used
Expand Down

0 comments on commit 0d8e88e

Please sign in to comment.