Skip to content

Commit

Permalink
initial support for layout-based encounter forms
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsetsystems committed Jul 24, 2009
1 parent daadaa2 commit 5aac1d1
Show file tree
Hide file tree
Showing 17 changed files with 624 additions and 248 deletions.
277 changes: 277 additions & 0 deletions interface/forms/LBF/new.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
<?php
// Copyright (C) 2009 Rod Roark <[email protected]>
//
// 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.

require_once("../../globals.php");
require_once("$srcdir/api.inc");
require_once("$srcdir/forms.inc");
require_once("$srcdir/options.inc.php");
require_once("$srcdir/patient.inc");
require_once("$srcdir/formdata.inc.php");

$CPR = 4; // cells per row

$pprow = array();

if (! $encounter) { // comes from globals.php
die("Internal error: we do not seem to be in an encounter!");
}

function end_cell() {
global $item_count, $cell_count;
if ($item_count > 0) {
echo "</td>";
$item_count = 0;
}
}

function end_row() {
global $cell_count, $CPR;
end_cell();
if ($cell_count > 0) {
for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
echo "</tr>\n";
$cell_count = 0;
}
}

function end_group() {
global $last_group;
if (strlen($last_group) > 0) {
end_row();
echo " </table>\n";
echo "</div>\n";
}
}

$formname = formData('formname', 'G');
$formid = 0 + formData('id', 'G');

$tmp = sqlQuery("SELECT title FROM list_options WHERE list_id = 'lbfnames'");
$formtitle = $tmp['title'];

$newid = 0;

// If Save was clicked, save the info.
//
if ($_POST['bn_save']) {
$sets = "";
$fres = sqlStatement("SELECT * FROM layout_options " .
"WHERE form_id = '$formname' AND uor > 0 AND field_id != '' AND " .
"edit_options != 'H' " .
"ORDER BY group_name, seq");
while ($frow = sqlFetchArray($fres)) {
$field_id = $frow['field_id'];
$value = get_layout_form_value($frow);
if ($formid) { // existing form
if ($value === '') {
$query = "DELETE FROM lbf_data WHERE " .
"form_id = '$formid' AND field_id = '$field_id'";
}
else {
$query = "REPLACE INTO lbf_data SET field_value = '$value', " .
"form_id = '$formid', field_id = '$field_id'";
}
sqlStatement($query);
}
else { // new form
if ($value !== '') {
if ($newid) {
sqlStatement("INSERT INTO lbf_data " .
"( form_id, field_id, field_value ) " .
" VALUES ( '$newid', '$field_id', '$value' )");
}
else {
$newid = sqlInsert("INSERT INTO lbf_data " .
"( field_id, field_value ) " .
" VALUES ( '$field_id', '$value' )");
}
}
// Note that a completely empty form will not be created at all!
}
}

if (!$formid && $newid) {
addForm($encounter, $formtitle, $newid, $formname, $pid, $userauthorized);
}

formHeader("Redirecting....");
formJump();
formFooter();
exit;
}

$enrow = sqlQuery("SELECT p.fname, p.mname, p.lname, fe.date FROM " .
"form_encounter AS fe, forms AS f, patient_data AS p WHERE " .
"p.pid = '$pid' AND f.pid = '$pid' AND f.encounter = '$encounter' AND " .
"f.formdir = 'newpatient' AND f.deleted = 0 AND " .
"fe.id = f.form_id LIMIT 1");

// if ($formid) {
// $pprow = sqlQuery("SELECT * FROM lbf_data WHERE " .
// "form_id = '$formid'");
// }
?>
<html>
<head>
<?php html_header_show();?>
<link rel=stylesheet href="<?echo $css_header;?>" type="text/css">
<style>

td, input, select, textarea {
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
}

div.section {
border: solid;
border-width: 1px;
border-color: #0000ff;
margin: 0 0 0 10pt;
padding: 5pt;
}

</style>

<script type="text/javascript" src="../../../library/dialog.js"></script>

<script language="JavaScript">

// Supports customizable forms (currently just for IPPF).
function divclick(cb, divid) {
var divstyle = document.getElementById(divid).style;
if (cb.checked) {
divstyle.display = 'block';
} else {
divstyle.display = 'none';
}
return true;
}

</script>
</head>

<body <?php echo $top_bg_line; ?> topmargin="0" rightmargin="0" leftmargin="2" bottommargin="0" marginwidth="2" marginheight="0">
<form method="post" action="<?php echo $rootdir ?>/forms/LBF/new.php?formname=<?php echo $formname ?>&id=<?php echo $formid ?>"
onsubmit="return top.restoreSession()">

<p class='title' style='margin-top:8px;margin-bottom:8px;text-align:center'>
<?php
echo "$formtitle " . xl('for') . ' ';
echo $enrow['fname'] . ' ' . $enrow['mname'] . ' ' . $enrow['lname'];
echo ' ' . xl('on') . ' ' . substr($enrow['date'], 0, 10);
?>
</p>

<?php
$shrow = getHistoryData($pid);

// echo "<div id='ippf_srh' style='display:none'>\n";

$fres = sqlStatement("SELECT * FROM layout_options " .
"WHERE form_id = '$formname' AND uor > 0 " .
"ORDER BY group_name, seq");
$last_group = '';
$cell_count = 0;
$item_count = 0;
$display_style = 'block';

while ($frow = sqlFetchArray($fres)) {
$this_group = $frow['group_name'];
$titlecols = $frow['titlecols'];
$datacols = $frow['datacols'];
$data_type = $frow['data_type'];
$field_id = $frow['field_id'];
$list_id = $frow['list_id'];

$currvalue = '';

if ($frow['edit_options'] == 'H') {
// This data comes from static history
if (isset($shrow[$field_id])) $currvalue = $shrow[$field_id];
} else {
if ($formid) {
$pprow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
"form_id = '$formid' AND field_id = '$field_id'");
if (!empty($pprow)) $currvalue = $pprow['field_value'];
}
}

// Handle a data category (group) change.
if (strcmp($this_group, $last_group) != 0) {
end_group();
$group_seq = 'lbf' . substr($this_group, 0, 1);
$group_name = substr($this_group, 1);
$last_group = $this_group;
echo "<br /><span class='bold'><input type='checkbox' name='form_cb_$group_seq' value='1' " .
"onclick='return divclick(this,\"div_$group_seq\");'";
if ($display_style == 'block') echo " checked";
echo " /><b>$group_name</b></span>\n";
echo "<div id='div_$group_seq' class='section' style='display:$display_style;'>\n";
echo " <table border='0' cellpadding='0' width='100%'>\n";
$display_style = 'none';
}

// Handle starting of a new row.
if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
end_row();
echo " <tr>";
}

if ($item_count == 0 && $titlecols == 0) $titlecols = 1;

// Handle starting of a new label cell.
if ($titlecols > 0) {
end_cell();
echo "<td valign='top' colspan='$titlecols' width='1%' nowrap";
echo ($frow['uor'] == 2) ? " class='required'" : " class='bold'";
if ($cell_count == 2) echo " style='padding-left:10pt'";
echo ">";
$cell_count += $titlecols;
}
++$item_count;

echo "<b>";
if ($frow['title']) echo $frow['title'] . ":"; else echo "&nbsp;";
echo "</b>";

// Handle starting of a new data cell.
if ($datacols > 0) {
end_cell();
echo "<td valign='top' colspan='$datacols' class='text'";
if ($cell_count > 0) echo " style='padding-left:5pt'";
echo ">";
$cell_count += $datacols;
}

++$item_count;

if ($frow['edit_options'] == 'H')
echo generate_display_field($frow, $currvalue);
else
generate_form_field($frow, $currvalue);
}

end_group();
// echo "</div>\n";
?>

<p style='text-align:center'>
<input type='submit' name='bn_save' value='Save' />
&nbsp;
<input type='button' value='Cancel' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" />
&nbsp;
</p>

</form>
<?php

// TBD: If $alertmsg, display it with a JavaScript alert().

?>
</body>
</html>
29 changes: 29 additions & 0 deletions interface/forms/LBF/report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
// Copyright (C) 2009 Rod Roark <[email protected]>
//
// 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.

include_once("../../globals.php");
include_once($GLOBALS["srcdir"] . "/api.inc");

// This function is invoked from printPatientForms in report.inc
// when viewing a "comprehensive patient report". Also from
// interface/patient_file/encounter/forms.php.
//
function lbf_report($pid, $encounter, $cols, $id, $formname) {
require_once($GLOBALS["srcdir"] . "/options.inc.php");
echo "<table>\n";

$arr = array();
$fres = sqlStatement("SELECT field_id, field_value FROM lbf_data WHERE form_id = '$id'");
while ($frow = sqlFetchArray($fres)) {
$arr[$frow['field_id']] = $frow['field_value'];
}
display_layout_rows($formname, $arr);

echo "</table>\n";
}
?>
3 changes: 3 additions & 0 deletions interface/forms/LBF/view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
require("new.php");
?>
11 changes: 9 additions & 2 deletions interface/forms_admin/forms_admin.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
// 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.

//INCLUDES, DO ANY ACTIONS, THEN GET OUR DATA
include_once("../globals.php");
include_once("$srcdir/registry.inc");
Expand Down Expand Up @@ -129,7 +134,6 @@
</table>
<hr>


<?php //UNREGISTERED SECTION ?>
<span class=bold><?php xl('Unregistered','e');?></span><br>
<table border=0 cellpadding=1 cellspacing=2 width="500">
Expand All @@ -138,7 +142,10 @@
$dp = opendir($dpath);
$color="#CCCCCC";
for ($i=0; false != ($fname = readdir($dp)); $i++)
if ($fname != "." && $fname != ".." && $fname != "CVS" && (is_dir($dpath.$fname) || stristr($fname, ".tar.gz") || stristr($fname, ".tar") || stristr($fname, ".zip") || stristr($fname, ".gz")))
if ($fname != "." && $fname != ".." && $fname != "CVS" && $fname != "LBF" &&
(is_dir($dpath.$fname) || stristr($fname, ".tar.gz") ||
stristr($fname, ".tar") || stristr($fname, ".zip") ||
stristr($fname, ".gz")))
$inDir[$i] = $fname;

// ballards 11/05/2005 fixed bug in removing registered form from the list
Expand Down
19 changes: 13 additions & 6 deletions interface/patient_file/deleter.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ function decorateString($fmt, $str) {
return $res;
}

// Delete a form's data from its form-specific table.
//
function form_delete($formdir, $formid) {
$formdir = ($formdir == 'newpatient') ? 'encounter' : $formdir;
if (substr($formdir,0,3) == 'LBF')
row_delete("lbf_data", "form_id = '$formid'");
else
row_delete("form_$formdir", "id = '$formid'");
}

?>
<html>
<head>
Expand Down Expand Up @@ -115,8 +125,7 @@ function decorateString($fmt, $str) {

$res = sqlStatement("SELECT * FROM forms WHERE pid = '$patient'");
while ($row = sqlFetchArray($res)) {
$formdir = ($row['formdir'] == 'newpatient') ? 'encounter' : $row['formdir'];
row_delete("form_$formdir", "id = '" . $row['form_id'] . "'");
form_delete($row['formdir'], $row['form_id'])
}
row_delete("forms", "pid = '$patient'");

Expand All @@ -132,8 +141,7 @@ function decorateString($fmt, $str) {
row_delete("issue_encounter", "encounter = '$encounterid'");
$res = sqlStatement("SELECT * FROM forms WHERE encounter = '$encounterid'");
while ($row = sqlFetchArray($res)) {
$formdir = ($row['formdir'] == 'newpatient') ? 'encounter' : $row['formdir'];
row_delete("form_$formdir", "id = '" . $row['form_id'] . "'");
form_delete($row['formdir'], $row['form_id'])
}
row_delete("forms", "encounter = '$encounterid'");
}
Expand All @@ -142,8 +150,7 @@ function decorateString($fmt, $str) {
$row = sqlQuery("SELECT * FROM forms WHERE id = '$formid'");
$formdir = $row['formdir'];
if (! $formdir) die("There is no form with id '$formid'");
$formname = ($formdir == 'newpatient') ? 'encounter' : $formdir;
row_delete("form_$formname", "id = '" . $row['form_id'] . "'");
form_delete($formdir, $row['form_id'])
row_delete("forms", "id = '$formid'");
}
else if ($issue) {
Expand Down
Loading

0 comments on commit 5aac1d1

Please sign in to comment.