A
download class.User.php
Language: PHP
LOC: 176
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
<?php
	// $Id: class.User.php,v 1.19 2005/06/14 21:35:40 rufustfirefly Exp $
	// $Author: rufustfirefly $

// TODO migrate all password setting to use setPassword
//	write checkPassword
//	migrate all password checking to use checkPassword 
// 	verify that there are no md5 calls outside of this class!!


// class: FreeMED.User
//
//	Class container for FreeMED user information.
//
class User {
	var $local_record;                 // local record
	var $user_number;                  // user number (id)
	var $user_level;                   // user level (0..9)
	var $user_name;                    // name of the user
	var $user_descrip;                 // user description
	var $user_phy;                     // number of physician 
	var $manage_config; // configuration for patient management
	var $perms_fac, $perms_phy, $perms_phygrp;

	// Method: User constructor
	//
	// Parameters:
	//
	//	$param - (optional) Specify user identification number.
	//	If not specified, the system will default to using
	//	cookie session data to supply it.
	//
	function User ($param=NULL) {
		if ($param == NULL) {
			// Check to see if XML-RPC or session data
			if ($_SESSION['authdata']['user']) {
				$this->user_number = $_SESSION['authdata']['user']; 
			} else {
				$this->user_number = $GLOBALS['__freemed']['basic_auth_id'];
			}
		} else {
			$this->user_number = $param;
		}

		// Check for cached copy
		if (!isset($GLOBALS['__freemed']['cache']['user'][$this->user_number])) {
			// Retrieve copy
			$this->local_record = freemed::get_link_rec (
				$this->user_number, "user"
			);

			// Store in the cache
			$GLOBALS['__freemed']['cache']['user'][$this->user_number] = $this->local_record;
		} else {
			// Pull copy from the cache
			$this->local_record = $GLOBALS['__freemed']['cache']['user'][$this->user_number];
		}

		$this->user_name    = stripslashes($this->local_record["username"]);
		$this->user_descrip = stripslashes($this->local_record["userdescrip"]);
		$this->user_level   = $this->local_record["userlevel"  ];
		$this->user_phy     = $this->local_record["userrealphy"];
		$this->perms_fac    = $this->local_record["userfac"    ]; 
		$this->perms_phy    = $this->local_record["userphy"    ];
		$this->perms_phygrp = $this->local_record["userphygrp" ];

		// special root stuff
		if ($this->user_number == 1) $this->user_level = 9;

		// Map configuration vars
		$this->manage_config = unserialize($this->local_record['usermanageopt']);
	} // end function User

	// method: getDescription
	//
	//	Retrieve description of current user. (Usually their name)
	//
	// Returns:
	//
	//	Description of the current user object.
	//
	function getDescription ($no_parameters = "") {
		if (empty($this->user_descrip)) return __("(no description)");
		return ($this->user_descrip);
	} // end function getDescription

	function getLevel ($no_parameters = "") {
		return ($this->user_level)+0;
	} // end function getLevel

	function getPhysician ($no_parameters = "") {
		return ($this->user_phy)+0;
	} // end function getPhysician

	// Method: getFaxesInQueue
	//
	//	Get list of faxes in queue to check
	//
	// Returns:
	//
	//	Array of fax ids, or NULL if there are none
	function getFaxesInQueue ( ) {
		if (is_array($_SESSION['fax_queue'])) {
			foreach ($_SESSION['fax_queue'] AS $k => $v) {
				if ($k and $v['id']) { $r[$k] = $v['id']; }
			}
			if (is_array($r)) { return $r; }
		}
		return NULL;
	} // end method getFaxesInQueue

	// Method: getFaxDescription
	//
	//	Gives stored description of fax in queue by id number.
	//
	// Parameters:
	//
	//	$fid - Fax ID
	//
	// Returns:
	//
	//	String containing description
	//
	function getFaxDescription ( $fid ) {
		return $_SESSION['fax_queue'][$fid]['info'];
	} // end method getFaxDescription

	// Method: setFaxInQueue
	//
	//	Set a fax to be in the queue to check.
	//
	// Parameters:
	//
	//	$fid - Fax id
	//
	//	$info - (optional) Textual description of fax to be stored in queue.
	//
	function setFaxInQueue ( $fid, $info = NULL ) {
		$_SESSION['fax_queue'][$fid]['id'] = $fid;
		$_SESSION['fax_queue'][$fid]['info'] = $info;
	} // end method setFaxInQueue

	// Method: faxNotify
	//
	//	Create Javascript alerts for finished faxes.
	//
	// Returns:
	//
	//	Javascript code (in SCRIPT tags) or NULL if nothing.
	//
	function faxNotify ( ) {
		if (!($fax = $this->getFaxesInQueue())) { return ''; }
		$f = CreateObject('_FreeMED.Fax');
		foreach ($fax AS $k => $v) {
			$st = $f->State($k);
			if ($st == 1) {
				$messages[] = sprintf(
					__("Fax job %d to %s (%s) finished."),
					$k, $f->GetNumberFromId($k),
					$this->getFaxDescription($k)
					);
				unset($_SESSION['fax_queue'][$k]);
			} elseif (is_array($st) and $st[0] == -1) {
				$messages[] = sprintf(
					__("Fax job %d (%s) failed with '%s'."),
					$k, $f->GetNumberFromId($k), $st[1]
					);
				unset($_SESSION['fax_queue'][$k]);
			}
		}

		// Create Javascript notification if there is any
		if (is_array($messages)) {
			$final = join('\n', $messages);
			return "<script language=\"javascript\">\n".
				"alert('".addslashes($final)."');\n".
				"</script>\n";
		}
	} // end method faxNotify

	// Method: getName
	//
	//	Retrieves the user name. This is their login name.
	//
	// Returns:
	//
	//	User name for user.
	//
	function getName ($no_parameters = "") {
		return ($this->user_name);
	} // end function getName

	// method: isPhysician
	//
	//	Determines if the user is classified as a physician/provider.
	//
	// Returns:
	//
	//	Boolean, true if they are a physician/provider.
	//
	function isPhysician ($no_parameters = "") {
		return ($this->user_phy != 0);
	} // end function isPhysician

	// Method: setPassword
	//
	//	Set password for specified user id
	//
	// Parameters:
	//
	//	$password - New password
	//
	//	$user_id - Id of user record
	//
	function setPassword ($password, $user_id) {
		global $sql;

		if ($user_id == "") {
			if((LOGLEVEL<1)||LOG_ERRORS){syslog(LOG_INFO,"class.User.php|setPassword| no user id!!");}
			return false;
		}

		$md5_password=md5($password);
		
		$my_query = $sql->update_query(
			"user",
			array (
				"userpassword" => $md5_password
			), array ("id" => $user_id)
		);
		if((LOGLEVEL<1)||LOG_SQL){syslog(LOG_INFO,"setPassword query=$my_query");}	

		$result = $sql->query($my_query);
	} // end function setPassword

	// Method: getManageConfig
	//
	//	Retrieve a user configuration variable by key.
	//
	// Parameters:
	//
	//	$key - Configuration key to retrieve.
	//
	// Returns:
	//
	//	Value of the specified key.
	//
	function getManageConfig ($key) {
		return $this->manage_config["$key"];
	} // end function getManageConfig

	// Method: getManageConfig
	//
	//	Set a user configuration variable by key to a particular
	//	value.
	//
	// Parameters:
	//
	//	$key - Configuration key to set.
	//
	//	$val - Configuration value to set.
	//
	function setManageConfig ($new_key, $new_val) {
		// Now, set extra value(s)
		$this->manage_config["$new_key"] = $new_val;

		// Set part of record
		$query = $GLOBALS['sql']->update_query(
			'user',
			array(
				'usermanageopt' => serialize($this->manage_config)
			), array ('id' => $this->user_number)
		);
		$result = $GLOBALS['sql']->query($query);
	} // end function setManageConfig

	// Method: newMessages
	//
	//	Determines how many new unread messages exist in the system
	//	for this user.
	//
	// Returns:
	//
	//	Number of unread messages in the system for this user.
	//
	function newMessages () {
		global $sql;
		$result = $sql->query("SELECT * FROM messages WHERE ".
			"msgfor='".addslashes($this->user_number)."' AND ".
			"msgread='0'");
		if (!$sql->results($result)) return false;
		return $sql->num_rows($result);
	} // end function newMessages

	// Method: init
	//
	//	Creates user database table and populates it with
	//	required data. This is not "default" or "useful
	//	starting" data, it is the data that is required
	//	to run FreeMED.
	//
	// Parameters:
	//
	//	$adminpassword - New administrative password.
	//
	function init($adminpassword) {
		global $sql;

		// Database Clean
		$result=$sql->query("DROP TABLE user"); 

		// Database Rebuild
		$result = $sql->query($sql->create_table_query(
			'user',
			array(
				'username' => SQL__NOT_NULL(SQL__VARCHAR(16)),
				'userpassword' => SQL__NOT_NULL(SQL__VARCHAR(32)),
				'userdescrip' => SQL__VARCHAR(50),
				'userlevel' => SQL__BLOB,
				'usertype' => SQL__ENUM (array(
					"phy",
					"misc",
					"super"
				)),
				'userfac' => SQL__BLOB,
				'userphy' => SQL__BLOB,
				'userphygrp' => SQL__BLOB,
				'userrealphy' => SQL__INT_UNSIGNED(0),
				'usermanageopt' => SQL__BLOB,
				'id' => SQL__SERIAL
			), array ('id', 'username')
		));

		// Required Data!!

		$result = $sql->query($sql->insert_query(
			"user",
			array (
	    			"username" => "admin",
				"userpassword" => $adminpassword,
				"userdescrip" => __("Administrator"),
				"userlevel" => "admin",
				"usertype" => "misc",
				"userfac" => "-1",
				"userphy" => "-1",
				"userphygrp" => "-1",
				"userrealphy" => "0",
				"usermanageopt" => 'a:6:{s:1:" ";N;s:22:"automatic_refresh_time";s:0:"";s:15:"display_columns";s:1:"3";s:17:"num_summary_items";s:1:"1";s:17:"static_components";a:6:{s:12:"appointments";a:2:{s:6:"static";s:12:"appointments";s:5:"order";i:5;}s:14:"custom_reports";a:2:{s:6:"static";s:14:"custom_reports";s:5:"order";i:5;}s:19:"medical_information";a:2:{s:6:"static";s:19:"medical_information";s:5:"order";i:5;}s:9:" messages";a:2:{s:6:"static";s:9:" messages";s:5:"order";i:5;}s:19:"patient_information";a:2:{s:6:"static";s:19:"patient_information";s:5:"order";i:5;}s:21:"photo_id__action_last";a:2:{s:6:"static";s:21:"photo_id__action_last";s:5:"order";i:5;}}s:18:"modular_components";a:20:{s:12:"appointments";a:2:{s:6:"static";s:12:"appointments";s:5:"order";i:5;}s:14:"custom_reports";a:2:{s:6:"static";s:14:"custom_reports";s:5:"order";i:5;}s:19:"medical_information";a:2:{s:6:"static";s:19:"medical_information";s:5:"order";i:5;}s:9:" messages";a:2:{s:6:"static";s:9:" messages";s:5:"order";i:5;}s:19:"patient_information";a:2:{s:6:"static";s:19:"patient_information";s:5:"order";i:5;}s:21:"photo_id__action_last";a:2:{s:6:"static";s:21:"photo_id__action_last";s:5:"order";i:5;}s:15:"AllergiesModule";a:2:{s:6:"module";s:15:"AllergiesModule";s:5:"order";i:5;}s:21:"ChronicProblemsModule";a:2:{s:6:"module";s:21:"ChronicProblemsModule";s:5:"order";i:5;}s:21:"CurrentProblemsModule";a:2:{s:6:"module";s:21:"CurrentProblemsModule";s:5:"order";i:5;}s:13:"EpisodeOfCare";a:2:{s:6:"module";s:13:"EpisodeOfCare";s:5:"order";i:5;}s:20:"AuthorizationsModule";a:2:{s:6:"module";s:20:"AuthorizationsModule";s:5:"order";i:5;}s:13:"LettersModule";a:2:{s:6:"module";s:13:"LettersModule";s:5:"order";i:5;}s:15:"QuickmedsModule";a:2:{s:6:"module";s:15:"QuickmedsModule";s:5:"order";i:5;}s:22:"PatientCoveragesModule";a:2:{s:6:"module";s:22:"PatientCoveragesModule";s:5:"order";i:5;}s:13:"PatientImages";a:2:{s:6:"module";s:13:"PatientImages";s:5:"order";i:5;}s:13:"PaymentModule";a:2:{s:6:"module";s:13:"PaymentModule";s:5:"order";i:5;}s:18:"PrescriptionModule";a:2:{s:6:"module";s:18:"PrescriptionModule";s:5:"order";i:5;}s:24:"PreviousOperationsModule";a:2:{s:6:"module";s:24:"PreviousOperationsModule";s:5:"order";i:5;}s:15:"ProcedureModule";a:2:{s:6:"module";s:15:"ProcedureModule";s:5:"order";i:5;}s:13:"ProgressNotes";a:2:{s:6:"module";s:13:"ProgressNotes";s:5:"order";i:5;}}}'
	    		)
	    	));

		return $result;
	} // end method init

} // end class User

?>

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