A
download class.BaseModule.php
Language: PHP
LOC: 313
Project Info
FreeMED Project(freemed)
Server: SourceForge
Type: cvs
...reemed\freemed\freemed\lib\
   acl.php
   API.php
   bcadd.php
   calendar-functions.php
   class.AdminModule.php
   class.Agata.php
   class.Authorizations.php
   class.BaseModule.php
   class.BillingModule.php
   class.CalendarModule.php
   class.ClaimLog.php
   class.Coverage.php
   class.Debug.php
   class.diagnosis_set.php
   class.Djvu.php
   class.EMRModule.php
   class.Fax.php
   class.FixedFormEntry.php
   ...s.FixedFormRenderer.php
   class.FormRenderer.php
   class.FreeMEDSelfTest.php
   class.GeneralConfig.php
   class.GraphModule.php
   class.Guarantor.php
   class.Handler_HL7v2.php
   ...s.Handler_HL7v2_A04.php
   ...s.Handler_HL7v2_A08.php
   ...s.Handler_HL7v2_S12.php
   ...s.Handler_HL7v2_S15.php
   class.InsuranceCompany.php
   class.LanguageRegistry.php
   class.Ledger.php
   ...s.MaintenanceModule.php
   class.Messages.php
   class.OMBS_Patient.php
   class.OMBS_Wrapper.php
   class.Parser_HL7v2.php
   class.Patient.php
   class.Payer.php
   class.PHPlot.php
   class.Physician.php
   class.Procedure.php
   class.RecordLock.php
   class.Remitt.php
   class.ReportsModule.php
   class.rxlist.php
   class.Scheduler.php
   class.TeX.php
   class.User.php
   class.UtilityModule.php
   class.vCalendar.php
   class.vCalendarEvent.php
   error_handler.php
   freemed.php
   i18n.php
   iso-set.php
   macros.php
   mail-functions.php
   settings.php
   settings.php.tmpl
   xml.php
   xmlrpc_services.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
<?php
	// $Id: class.BaseModule.php,v 1.28 2005/06/15 00:26:42 rufustfirefly Exp $
	// lic : GPL, v2

LoadObjectDependency('PHP.module');

// Class: FreeMED.BaseModule
//
//	Basic FreeMED module class. All modules in FreeMED inheirit methods
//	from this class. It extends the phpwebtools module class.
//
class BaseModule extends module {

	// override variables
	var $PACKAGE_NAME = PACKAGENAME;
	var $MODULE_AUTHOR = "jeff b (jeff@ourexchange.net)";
	var $MODULE_DESCRIPTION = "No description.";
	var $MODULE_VENDOR = "Stock Module";

	// Set package versioning information
	var $PACKAGE_VERSION = VERSION;

	// All FreeMED modules use this one loader
	var $page_name = "module_loader.php";

	// Variable: print_template
	//
	//	Sets the print template to be used for this EMR
	//	segment. Templates are given as files in lib/tex without
	//	the .tex extension. If this is not definied, FreeMED
	//	will default to using the internal renderer.
	//
	// Example:
	//
	//	$this->print_template = '_template';
	//
	var $print_template = '';

	// Method: BaseModule constructor
	function BaseModule () {
		// Call parent constructor
		$this->module();
		// Call setup
		$this->setup();
		// Load language files, if necessary
		GettextXML::textdomain(strtolower(get_class($this)));
		// Push acl information, if there is any
		if ($this->acl) { $this->_SetMetaInformation('acl', $this->acl); }
	} // end constructor BaseModule

	// Method: BaseModule->check_vars
	function check_vars ($nullvar = "") {
		global $module;
		if (!isset($module))
		{
			 trigger_error("No Module Defined",E_ERROR);
		}
		return true;
	} // end function check_vars

	// Method: BaseModule->_header
	function _header ($nullvar = "") {
		global $display_buffer, $page_name;
		freemed::connect ();
		$page_name = __($this->MODULE_NAME);

		// Check for existance of separate "record_name"
		if (!isset($this->record_name)) {
			$this->record_name = __($this->MODULE_NAME);
		}

		// Globalize record_name and page_title
		if (page_name() == $this->page_name) {
			$GLOBALS['record_name'] = $this->record_name;
			$GLOBALS['page_title'] = $this->record_name;
		}
	} // end function _header
	function header ( ) { $this->_header(); }

	// Method: BaseModule->_footer
	function footer ($nullvar = "") {
	} // end function footer

	// Method: fax_widget
	//
	//	Callback to allow custom fax controls (for addressbook,
	//	et cetera). By default, this is disabled, and a standard
	//	text entry is used.
	//
	// Parameters:
	//
	//	$varname - Name of the variable
	//
	//	$id - Record id that is being printed
	//
	// Returns:
	//
	//	XHTML widget.
	//
	function fax_widget ( $varname, $id ) {
		return html_form::text_widget('fax_number',
			array( 'length' => '16' )
		);
	} // end method fax_widget

	// Method: printaction
	//
	//	Basic printing functionality
	//
	function printaction ( ) { $this->_print(); }

	// Method: _print
	//
	//	Provides basic printing interface
	//
	function _print ( ) {
		// Turn off the template
		global $display_buffer;
		$GLOBALS['__freemed']['no_template_display'] = true;

		// Deal with faxstatus
		if (isset($_REQUEST['faxstatus'])) {
			$fax = CreateObject('_FreeMED.Fax', '/dev/null');
			$status = $fax->State($_REQUEST['faxstatus']);
			$display_buffer .= "<b>".$output."</b>\n";
			if ($status == 1) {
				$display_buffer .= "<div align=\"center\"><b>".__("Fax sent successfully.")."</b></div>\n";
				$display_buffer .= "<div align=\"center\"><a onClick=\"javascript:close();\" class=\"button\">".__("Close")."</div>\n";
			} else {
				$display_buffer .= "<b>".__("Fax is attempting to send: ")."</b>".$status."\n";
				$GLOBALS['__freemed']['automatic_refresh'] = 10;
			}
			return true;
			break;
		}

		// Check for selected printer
		if (!freemed::config_value('printnoselect') and !isset($_REQUEST['printer'])) {
			// select printer form
			global $display_buffer;
			$display_buffer .= "
			<form action=\"".$this->page_name."\" method=\"post\"
			 name=\"myform\">
			<div class=\"PrintContainer\">
			<input type=\"hidden\" name=\"module\" value=\"".prepare($_REQUEST['module'])."\"/>
			<input type=\"hidden\" name=\"type\" value=\"".prepare($_REQUEST['type'])."\"/>
			<input type=\"hidden\" name=\"action\" value=\"".prepare($_REQUEST['action'])."\"/>
			<input type=\"hidden\" name=\"id\" value=\"".prepare($_REQUEST['id'])."\"/>
			<input type=\"hidden\" name=\"patient\" value=\"".prepare($_REQUEST['patient'])."\"/>
			";
			if ($_REQUEST['print_template']) {
				$display_buffer .= "<input type=\"hidden\" name=\"print_template\" value=\"".prepare($_REQUEST['print_template'])."\"/>\n";
			}
			$display_buffer .= "
			<table border=\"0\" width=\"98%\" cellspacing=\"0\">
			<tr class=\"PrintContainerItem\"
			 	 onMouseOver=\"this.className='PrintContainerItemSelected'; return true;\"
				 onMouseOut=\"this.className='PrintContainerItem'; return true;\"
				 onClick=\"document.getElementById('print_method_printer').click(); return true;\">

				<td width=\"50\">
				<input type=\"radio\" 
				 name=\"print_method\"
				 value=\"printer\" checked
				 id=\"print_method_printer\" /></td>
				<td
				>".__("Printer")."</td>
				<td>".freemed::printers_widget('printer')."</td>
			</tr>
			<tr class=\"PrintContainerItem\"
			 	 onMouseOver=\"this.className='PrintContainerItemSelected'; return true;\"
				 onMouseOut=\"this.className='PrintContainerItem'; return true;\"
				 onClick=\"document.getElementById('print_method_fax').click(); return true;\">
				<td width=\"50\">
				<input type=\"radio\"
				 name=\"print_method\"
				 value=\"fax\"
				 id=\"print_method_fax\" /></td>
				<td>".__("Fax")."</td>
				<td>".$this->fax_widget('fax_number', $_REQUEST['id'])."</td>
			</tr>
			<tr class=\"PrintContainerItem\"
			 	 onMouseOver=\"this.className='PrintContainerItemSelected'; return true;\"
				 onMouseOut=\"this.className='PrintContainerItem'; return true;\"
				 onClick=\"document.getElementById('print_method_browser').click(); return true;\">
				 <td width=\"50\">
				 <input type=\"radio\"
				  name=\"print_method\"
				  value=\"browser\"
				  checked=\"checked\" 
				  id=\"print_method_browser\" /></td>
				 <td colspan=\"2\">".__("Browser-Based")."</td>
			</tr>
			</table>
			<script language=\"javascript\">
			function isValid(parm) {
				var val = '0123456789';
				if (parm == '') return false;
				if (parm.length < 7) return false;
				for (i=0; i<parm.length; i++) {
					if (val.indexOf(parm.charAt(i),0) == -1) return false;
				}
				return true;
			}
			</script>
			<div align=\"center\">
			<input onClick=\"if(document.getElementById('print_method_fax').checked) { if (!isValid(document.getElementById('fax_number').value)) { alert('Invalid fax number.'); return false; } } else { this.form.submit(); }\" type=\"submit\" value=\"".__("Print")."\"
			 class=\"button\" />
			</div>
			</div>
			</form>
			";
			return true;
		}

		// Handle render
		if ($render = $this->print_override($_REQUEST['id'])) {
			// Handle this elsewhere
		} else {
			list ($title, $heading, $physician) = $this->_TeX_Information();

			// Create TeX object for patient
			$TeX = CreateObject('FreeMED.TeX', array (
				'title' => $title,
				'heading' => $heading,
				'physician' => $physician
			));

			// Actual renderer for formatting array
			if ($this->table_name) {
				if ($this->summary_query) {
					// If this is an EMR module with additional
					// fields, import them
					$query = "SELECT *".
						( (count($this->summary_query)>0) ? 
						",".join(",", $this->summary_query)." " : " " ).
						"FROM ".$this->table_name." ".
						"WHERE id='".addslashes($_REQUEST['id'])."'";
						$result = $GLOBALS['sql']->query($query);
						$rec = $GLOBALS['sql']->fetch_array($result);
				} else {
					$rec = freemed::get_link_rec($_REQUEST['id'], $this->table_name);
				} // end checking for summary_query
			} else {
				$rec = array ( 'id' => $_REQUEST['id'] );
			}

			// Check for overridden template
			if (file_exists('lib/tex/'.freemed::secure_filename($_REQUEST['print_template']).'.tex')) {
				$this_template = freemed::secure_filename($_REQUEST['print_template']);
			} else {
				$this_template = $this->print_template;
			}

			$TeX->_buffer = $TeX->RenderFromTemplate(
				$this_template,
				$rec
			);
		}

		global $display_buffer;

		// Get appropriate printer from user settings
		global $this_user;
		if (!is_object($this_user)) {
			$this_user = CreateObject('FreeMED.User');
		}
		$printer = CreateObject('PHP.PrinterWrapper');

		$display_buffer .= __("Printing")." ... <br/>\n";

		// Figure out print method
		$_pm = $_REQUEST['print_method'];
		switch ($_pm) {
			// Handle direct to browser
			case 'browser':
			if ($render) {
				$file = $render;
			} else {
				$file = $TeX->RenderToPDF(!empty($this->print_template));
			}
			ob_start();
			readfile($file);
			$contents = ob_get_contents();
			ob_end_clean();

			Header('Content-Type: application/x-freemed-print-pdf');
			Header('Content-Length: '.strlen($contents));
			Header('Content-Disposition: inline; filename="'.mktime().'.pdf"');
			print $contents;
			flush();
			//print "file = $file<br/>\n";
			unlink($file);
			die();
			break;

			case 'fax':
			if ($render) {
				$file = $render;
			} else {
				$file = $TeX->RenderToPDF(!empty($this->print_template));
			}
			$fax = CreateObject('_FreeMED.Fax', $file, array (
				'sender' => $this_user->user_descrip,
				'comments' => __("HIPPA Compliance Notice: This transmission contains confidential medical information which is protected by the patient/physician privilege. The enclosed message is being communicated to the intended recipient for the purposes of facilitating healthcare. If you have received this transmission in error, please notify the sender immediately, return the fax message and delete the message from your system.")
				));
			//print ($_REQUEST['fax_number']);
			$output = $fax->Send($_REQUEST['fax_number']);
			//$display_buffer .= "<b>".$output."</b>\n";
			// TODO : Descrip call back
			if ($this->patient_field) {
				$_r = freemed::get_link_rec($_REQUEST['id'], $this->table_name);
				$_p = CreateObject('_FreeMED.Patient', $_r[$this->patient_field]);
				$descrip = $this->record_name.' for '.$_p->fullName();
			}
			$this_user->setFaxInQueue($output, $descrip);
			$display_buffer .= "<b>".__("Refreshing")."... </b>\n";
			//$GLOBALS['refresh'] = $this->page_name."?".
			//	"module=".urlencode($_REQUEST['module'])."&".
			//	"type=".urlencode($_REQUEST['type'])."&".
			//	"action=print&".
			//	"faxstatus=".urlencode($output);
			$GLOBALS['__freemed']['close_on_load'] = true;
			break;

			// Handle actual printer
			case 'printer': 
			if ($render) {
				$_p = CreateObject('PHP.PrinterWrapper');
				$_p->PrintFile($_REQUEST['printer'], $render);
				unlink($render);
			} else {
				// DEBUG:
				//$display_buffer .= "<pre>\n".
				//	$TeX->RenderDebug().
				//	"</pre>\n(You must disable this to print)";
				//template_display();
				$TeX->SetPrinter(
					CreateObject('PHP.PrinterWrapper'),
					//$user->getManageConfig('default_printer')
					$_REQUEST['printer']
				);
				// TODO: Handle direct PDF generation and return here
				$TeX->PrintTeX(1, !empty($this->print_template));
			}
			$GLOBALS['__freemed']['close_on_load'] = true;
			break;

			default:
			print "print_method = ".$_pm."<br/>\n";
			break;
		}
	} // end function print

	// Method: _print_mapping
	//
	//	Callback to provide a macro mapping for TeX templating.
	//
	// Parameters:
	//
	//	$TeX - TeX rendering object of type <FreeMED.TeX>
	//
	//	$id - Record id of the target record.
	//
	// Returns:
	//
	//	Associative array containing mapping information.
	//
	function _print_mapping ( $TeX, $id ) {
		// By default superclass returns nothing
		return array ( );
	} // end method _print_mapping

	// Method: _TeX_Information
	//
	//	Callback to provide information to the TeX renderer about
	//	formatting. (Should be depreciated)
	//
	// Returns:
	//
	//	Array ( title, heading, physician )
	//
	function _TeX_Information ( ) {
		// abstract
		$rec = freemed::get_link_rec($_REQUEST['id'], $this->table_name);
		$patient = CreateObject('FreeMED.Patient', $_REQUEST['patient']);
		$user = CreateObject('FreeMED.User');
		if ($user->isPhysician()) {
			$phy = $user->getPhysician();
		} else {
			$phy = $patient->local_record['patphy'];
		}
		$physician_object = CreateObject('FreeMED.Physician', $phy);
		$title = __($this->record_name);
		$heading = $patient->fullName().' ('.$patient->local_record['ptid'].')';
		$physician = $physician_object->fullName();
		return array ($title, $heading, $physician);
	} // end method _TeX_Information

	// Method: BaseModule->setup
	//
	//	Overrides the internal phpwebtools setup method. This causes
	//	FreeMED to run either _setup() on first run, or _update()
	//	if the module has an older version installed.
	//
	function setup () {
		global $display_buffer;
		if (!freemed::module_check($this->MODULE_NAME,$this->MODULE_VERSION)) {
			// check if it is installed *AT ALL*
			if (!freemed::module_check($this->MODULE_NAME, "0.0001")) {
				// run internal setup routine
				$val = $this->_setup();
			} else {
				// run internal update routine
				$val = $this->_update();
			} // end checking to see if installed at all

			// register module
			freemed::module_register($this->MODULE_NAME, $this->MODULE_VERSION);

			return $val;
		} // end checking for module
	} // end function setup

	// _setup (in this case, wrapped in classes...)
	function _setup () { return true; }

	// _update (in this case, wrapped in classes...)
	function _update () { return true; }

	// Method: BaseModule->init
	//
	//	Initializes the module table in the database. This should
	//	only be called by the setup routines in FreeMED, otherwise
	//	it poses a major system risk.
	//
	function init($test) {
		global $sql;
	
		$result = $sql->query("DROP TABLE module"); 

		$result = $sql->query($sql->create_table_query(
			'module',
			array(
				'module_name' => SQL__VARCHAR(100),
				'module_version' => SQL__VARCHAR(50),
				'id' => SQL__SERIAL
			), array('id')
		));
		return $result;
	} // end method BaseModule->init

	//----- Internal module functions

	// Method: print_override
	//
	//	Use this to replace the default printing behavior of the
	//	system.
	//
	// Parameters:
	//
	//	$id - Record ID to be "printed" as a PDF.
	//
	// Returns:
	//
	//	Filename of PDF file containing render.
	//
	function print_override ( $id ) {
		return false; // STUB, so we don't use it most of the time
	} // end method print_override

	// Method: BaseModule->_GetAssociations
	//
	//	Get a list of associations for the current module.
	//
	// Returns:
	//
	//	Array of associations made to this module.
	//
	function _GetAssociations () {
		if (!is_array($GLOBALS['__phpwebtools']['GLOBAL_MODULES'])) {
			$modules = CreateObject(
				'PHP.module_list',
				PACKAGENAME,
				array(
					'cache_file' => 'data/cache/modules'
				)
			);
		}
		$associations = array();
		foreach ($GLOBALS['__phpwebtools']['GLOBAL_MODULES'] AS $__crap => $v) {
			$a = $v['META_INFORMATION']['__associations'];
			foreach ($a as $_k => $_v) {
				if (strtolower($_k) == strtolower($this->MODULE_CLASS)) {
					$associations[] = $_v;
				}
			}
		}
		return $associations;
	} // end method BaseModule->_GetAssociations

	// Method: BaseModule->_SetAssociation
	//
	//	Creates an association with another module.
	//
	// Parameters:
	//
	//	$with - Module name (class name) of module to associate with.
	//
	function _SetAssociation ($with) {
		$this->META_INFORMATION['__associations']["$with"] = get_class($this);
	} // end method BaseModule->_SetAssociation

	// Method: BaseModule->_SetHandler
	//
	//	Attaches the current module to the specified system
	//	handler.
	//
	// Parameters:
	//
	//	$handler - Name of the system handler. Please note that
	//	this is case sensitive.
	//
	//	$method - Method that will be called by the specified handler.
	//	This is 'handler' by default.
	//
	function _SetHandler ($handler, $method = 'handler') {
		$this->META_INFORMATION['__handler']["$handler"] = $method;
	} // end method BaseModule->_SetHandler

} // end class BaseModule

?>

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us