Skip to content

Instantly share code, notes, and snippets.

@amoore
Created June 1, 2010 15:05
Show Gist options
  • Save amoore/421036 to your computer and use it in GitHub Desktop.
Save amoore/421036 to your computer and use it in GitHub Desktop.
From 00106e46f7906c004badc9e06acd1f8f04925363 Mon Sep 17 00:00:00 2001
From: Andrew Moore <amoore@cpan.org>
Date: Mon, 31 May 2010 12:56:54 -0500
Subject: [PATCH] refactoring common code for facilities drop-down into library
I recently added code to escape HTML characters from several
drop-downs for selecting facilities. Since that code was substantially
the same in several files, this patch refactors those drop-downs out
into a new function in patient.inc.
---
interface/billing/sl_receipts_report.php | 19 +-------------
interface/orders/pending_orders.php | 16 +----------
interface/orders/procedure_stats.php | 16 +----------
interface/reports/appointments_report.php | 19 +-------------
interface/reports/collections_report.php | 16 +----------
interface/reports/encounters_report.php | 19 +-------------
interface/reports/prescriptions_report.php | 19 +-------------
interface/reports/receipts_by_method_report.php | 16 +----------
interface/reports/referrals_report.php | 19 +-------------
interface/reports/sales_by_item.php | 19 +-------------
library/patient.inc | 32 +++++++++++++++++++++++
11 files changed, 42 insertions(+), 168 deletions(-)
diff --git a/interface/billing/sl_receipts_report.php b/interface/billing/sl_receipts_report.php
index f310145..09e32f6 100644
--- a/interface/billing/sl_receipts_report.php
+++ b/interface/billing/sl_receipts_report.php
@@ -106,24 +106,7 @@
<?php xl('Facility','e'); ?>:
</td>
<td>
- <?php
- // Build a drop-down list of facilities.
- //
- $query = "SELECT id, name FROM facility ORDER BY name";
- $fres = sqlStatement($query);
- echo " <select name='form_facility'>\n";
- echo " <option value=''>-- " . xl('All Facilities') . " --\n";
- while ($frow = sqlFetchArray($fres)) {
- $facid = $frow['id'];
- echo " <option value='$facid'";
- if ($facid == $form_facility) echo " selected";
- echo ">" . htmlspecialchars($frow['name']) . "\n";
- }
- echo " <option value='0'";
- if ($form_facility === '0') echo " selected";
- echo ">-- " . xl('Unspecified', 'e') . " --\n";
- echo " </select>\n";
- ?>
+ <?php dropdown_facility( $form_facility, 'form_facility' ) ?>
</td>
<td class='label'>
<?php xl('Provider','e'); ?>:
diff --git a/interface/orders/pending_orders.php b/interface/orders/pending_orders.php
index e0f1ab7..080bd34 100644
--- a/interface/orders/pending_orders.php
+++ b/interface/orders/pending_orders.php
@@ -88,21 +88,7 @@ else { // not export
<tr>
<td>
-<?php
- // Build a drop-down list of facilities.
- //
- $query = "SELECT id, name FROM facility ORDER BY name";
- $fres = sqlStatement($query);
- echo " <select name='form_facility'>\n";
- echo " <option value=''>-- All Facilities --\n";
- while ($frow = sqlFetchArray($fres)) {
- $facid = $frow['id'];
- echo " <option value='$facid'";
- if ($facid == $form_facility) echo " selected";
- echo ">" . htmlspecialchars($frow['name']) . "\n";
- }
- echo " </select>\n";
-?>
+ <?php dropdown_facility( $form_facility, 'form_facility', False ) ?>
&nbsp;<?xl('From:','e')?>
<input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
diff --git a/interface/orders/procedure_stats.php b/interface/orders/procedure_stats.php
index f59b7d3..9f3ebcc 100644
--- a/interface/orders/procedure_stats.php
+++ b/interface/orders/procedure_stats.php
@@ -305,21 +305,7 @@ function process_result_code($row) {
<?php xl('Facility','e'); ?>:
</td>
<td valign='top' class='detail'>
-<?php
- // Build a drop-down list of facilities.
- //
- $query = "SELECT id, name FROM facility ORDER BY name";
- $fres = sqlStatement($query);
- echo " <select name='form_facility'>\n";
- echo " <option value=''>-- All Facilities --\n";
- while ($frow = sqlFetchArray($fres)) {
- $facid = $frow['id'];
- echo " <option value='$facid'";
- if ($facid == $_POST['form_facility']) echo " selected";
- echo ">" . htmlspecialchars($frow['name']) . "\n";
- }
- echo " </select>\n";
-?>
+ <?php dropdown_facility( $_POST['form_facility'], 'form_facility', False ) ?>
</td>
</tr>
<tr>
diff --git a/interface/reports/appointments_report.php b/interface/reports/appointments_report.php
index 82e9351..13be3fc 100644
--- a/interface/reports/appointments_report.php
+++ b/interface/reports/appointments_report.php
@@ -169,24 +169,7 @@ require_once("$srcdir/formatting.inc.php");
<?php xl('Facility','e'); ?>:
</td>
<td>
- <?php
- // Build a drop-down list of facilities.
- //
- $query = "SELECT id, name FROM facility ORDER BY name";
- $fres = sqlStatement($query);
- echo " <select name='form_facility'>\n";
- echo " <option value=''>-- " . xl('All Facilities') . " --\n";
- while ($frow = sqlFetchArray($fres)) {
- $facid = $frow['id'];
- echo " <option value='$facid'";
- if ($facid == $form_facility) echo " selected";
- echo ">" . htmlspecialchars($frow['name']) . "\n";
- }
- echo " <option value='0'";
- if ($form_facility === '0') echo " selected";
- echo ">-- " . xl('Unspecified') . " --\n";
- echo " </select>\n";
- ?>
+ <?php dropdown_facility( $form_facility, 'form_facility' ) ?>
</td>
<td class='label'>
<?php xl('Provider','e'); ?>:
diff --git a/interface/reports/collections_report.php b/interface/reports/collections_report.php
index fb29e48..565f7aa 100644
--- a/interface/reports/collections_report.php
+++ b/interface/reports/collections_report.php
@@ -401,21 +401,7 @@ function checkAll(checked) {
<?php xl('Facility','e'); ?>:
</td>
<td>
- <?php
- // Build a drop-down list of facilities.
- //
- $query = "SELECT id, name FROM facility ORDER BY name";
- $fres = sqlStatement($query);
- echo " <select name='form_facility'>\n";
- echo " <option value=''>-- " . xl('All Facilities') . " --\n";
- while ($frow = sqlFetchArray($fres)) {
- $facid = $frow['id'];
- echo " <option value='$facid'";
- if ($facid == $form_facility) echo " selected";
- echo ">" . htmlspecialchars($frow['name']) . "\n";
- }
- echo " </select>\n";
- ?>
+ <?php dropdown_facility( $form_facility, 'form_facility', False ) ?>
</td>
</tr>
diff --git a/interface/reports/encounters_report.php b/interface/reports/encounters_report.php
index eb01799..e5cf2e0 100644
--- a/interface/reports/encounters_report.php
+++ b/interface/reports/encounters_report.php
@@ -158,24 +158,7 @@ $res = sqlStatement($query);
<?php xl('Facility','e'); ?>:
</td>
<td>
- <?php
- // Build a drop-down list of facilities.
- //
- $query = "SELECT id, name FROM facility ORDER BY name";
- $fres = sqlStatement($query);
- echo " <select name='form_facility'>\n";
- echo " <option value=''>-- " . xl('All Facilities') . " --\n";
- while ($frow = sqlFetchArray($fres)) {
- $facid = $frow['id'];
- echo " <option value='$facid'";
- if ($facid == $form_facility) echo " selected";
- echo ">" . htmlspecialchars($frow['name']) . "\n";
- }
- echo " <option value='0'";
- if ($form_facility === '0') echo " selected";
- echo ">-- " . xl('Unspecified') . " --\n";
- echo " </select>\n";
- ?>
+ <?php dropdown_facility( $form_facility, 'form_facility', True ) ?>
</td>
<td class='label'>
<?php xl('Provider','e'); ?>:
diff --git a/interface/reports/prescriptions_report.php b/interface/reports/prescriptions_report.php
index 44c0cd9..273f42c 100644
--- a/interface/reports/prescriptions_report.php
+++ b/interface/reports/prescriptions_report.php
@@ -101,24 +101,7 @@
<?php xl('Facility','e'); ?>:
</td>
<td>
- <?php
- // Build a drop-down list of facilities.
- //
- $query = "SELECT id, name FROM facility ORDER BY name";
- $fres = sqlStatement($query);
- echo " <select name='form_facility'>\n";
- echo " <option value=''>-- " . xl('All Facilities') . " --\n";
- while ($frow = sqlFetchArray($fres)) {
- $facid = $frow['id'];
- echo " <option value='$facid'";
- if ($facid == $form_facility) echo " selected";
- echo ">" . htmlspecialchars($frow['name']) . "\n";
- }
- echo " <option value='0'";
- if ($form_facility === '0') echo " selected";
- echo ">-- " . xl('Unspecified') . " --\n";
- echo " </select>\n";
- ?>
+ <?php dropdown_facility( $form_facility, 'form_facility', True ) ?>
</td>
<td class='label'>
<?php xl('From','e'); ?>:
diff --git a/interface/reports/receipts_by_method_report.php b/interface/reports/receipts_by_method_report.php
index 1e24e5a..7f1e425 100644
--- a/interface/reports/receipts_by_method_report.php
+++ b/interface/reports/receipts_by_method_report.php
@@ -235,21 +235,7 @@ $form_cptcode = trim($_POST['form_cptcode']);
</td>
<td>
- <?php
- // Build a drop-down list of facilities.
- //
- $query = "SELECT id, name FROM facility ORDER BY name";
- $fres = sqlStatement($query);
- echo " <select name='form_facility'>\n";
- echo " <option value=''>-- " . xl('All Facilities') . " --\n";
- while ($frow = sqlFetchArray($fres)) {
- $facid = $frow['id'];
- echo " <option value='$facid'";
- if ($facid == $form_facility) echo " selected";
- echo ">" . htmlspecialchars($frow['name']) . "\n";
- }
- echo " </select>\n";
- ?>
+ <?php dropdown_facility( $form_facility, 'form_facility', False ) ?>
</td>
<td>
diff --git a/interface/reports/referrals_report.php b/interface/reports/referrals_report.php
index eddd485..ed6ce2b 100644
--- a/interface/reports/referrals_report.php
+++ b/interface/reports/referrals_report.php
@@ -97,24 +97,7 @@
<?php xl('Facility','e'); ?>:
</td>
<td>
- <?php
- // Build a drop-down list of facilities.
- //
- $query = "SELECT id, name FROM facility ORDER BY name";
- $fres = sqlStatement($query);
- echo " <select name='form_facility'>\n";
- echo " <option value=''>-- " . xl('All Facilities') . " --\n";
- while ($frow = sqlFetchArray($fres)) {
- $facid = $frow['id'];
- echo " <option value='$facid'";
- if ($facid == $form_facility) echo " selected";
- echo ">" . htmlspecialchars($frow['name']) . "\n";
- }
- echo " <option value='0'";
- if ($form_facility === '0') echo " selected";
- echo ">-- " . xl('Unspecified') . " --\n";
- echo " </select>\n";
- ?>
+ <?php dropdown_facility( $form_facility, 'form_facility', True ) ?>
</td>
<td class='label'>
<?php xl('From','e'); ?>:
diff --git a/interface/reports/sales_by_item.php b/interface/reports/sales_by_item.php
index 1c6bbde..32f2d31 100644
--- a/interface/reports/sales_by_item.php
+++ b/interface/reports/sales_by_item.php
@@ -231,24 +231,7 @@ function thisLineItem($patient_id, $encounter_id, $rowcat, $description, $transd
<?php xl('Facility','e'); ?>:
</td>
<td>
- <?php
- // Build a drop-down list of facilities.
- //
- $query = "SELECT id, name FROM facility ORDER BY name";
- $fres = sqlStatement($query);
- echo " <select name='form_facility'>\n";
- echo " <option value=''>-- " . xl('All Facilities') . " --\n";
- while ($frow = sqlFetchArray($fres)) {
- $facid = $frow['id'];
- echo " <option value='$facid'";
- if ($facid == $form_facility) echo " selected";
- echo ">" . htmlspecialchars($frow['name']) . "\n";
- }
- echo " <option value='0'";
- if ($form_facility === '0') echo " selected";
- echo ">-- " . xl('Unspecified') . " --\n";
- echo " </select>\n";
- ?>
+ <?php dropdown_facility( $form_facility, 'form_facility', True ) ?>
</td>
<td class='label'>
<?php xl('From','e'); ?>:
diff --git a/library/patient.inc b/library/patient.inc
index 00f4e20..df38bb3 100644
--- a/library/patient.inc
+++ b/library/patient.inc
@@ -1375,4 +1375,36 @@ function get_patient_balance($pid) {
}
return '';
}
+
+/**
+ * DROPDOWN FOR FACILITIES
+ *
+ * build a dropdown with all facilities
+ *
+ * @param string $selected - name of the currently selected facility
+ * @param string $name - the name/id for select form
+ * @param boolean $allow_unspecified - include an option for "unspecified" facility
+ * @return void - just echo the html encoded string
+ */
+function dropdown_facility($selected = '', $name = 'form_facility', $allow_unspecified = True ) {
+ // Build a drop-down list of facilities.
+ //
+ $query = "SELECT id, name FROM facility ORDER BY name";
+ $fres = sqlStatement($query);
+ echo " <select name='form_facility'>\n";
+ echo " <option value=''>-- " . xl('All Facilities') . " --\n";
+ while ($frow = sqlFetchArray($fres)) {
+ $facid = $frow['id'];
+ echo " <option value='$facid'";
+ if ($facid == $selected) echo " selected";
+ echo ">" . htmlspecialchars($frow['name']) . "\n";
+ }
+ if ( $allow_unspecified ) {
+ echo " <option value='0'";
+ if ($selected === '0') echo " selected";
+ echo ">-- " . xl('Unspecified') . " --\n";
+ }
+ echo " </select>\n";
+}
+
?>
--
1.7.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment