A
download class.Patient.php
Language: PHP
LOC: 160
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
<?php
 // $Id: class.Patient.php,v 1.12 2005/07/16 09:24:15 rufustfirefly Exp $
 // $Author: rufustfirefly $

// class: FreeMED.Patient
//
//	Patient object container.
//
class Patient {
	var $local_record;                // stores basic patient record
	var $ptlname, $ptfname, $ptmname; // name variables
	var $ptdob;                       // date of birth
	var $ptdep;                       // patient dependencies
	var $ptsex;                       // gender
	var $ptmarital;                   // marital status
	var $ptreldep;                    // relation to guarantor
	var $id;                          // ID number
	var $ptempl;
	var $is_callin;                   // flag for call ins
	var $ptid;			  // local practice ID (chart num)

	// method: Patient constructor
	//
	// Parameters:
	//
	//	$patient_number - Database table identifier for the
	//	specified patient.
	//
	//	$is_callin - (optional) Boolean flag to specify if the
	//	patient is a "call-in" patient. Defaults to false.
	//
	function Patient ($_patient_number, $is_callin = false) { // constructor
		if (is_array($_patient_number)) {
			$patient_number = $_patient_number['id'];
		} else {
			$patient_number = $_patient_number;
		}

		// if the patient number is an error
		if ($patient_number<1) return false;

		// Check for cached record
		$_callin = ($is_callin ? "callin" : "patient");
		if (!isset($GLOBALS['__freemed']['cache'][$_callin][$patient_number])) {
			// Get new record ...
			if (is_array($_patient_number)) {
				$this->local_record = $_patient_number;
			} else {
				$this->local_record = freemed::get_link_rec ( $patient_number, $_callin );
			}

			// ... and store in the cache
			$GLOBALS['__freemed']['cache'][$_callin][$patient_number] = $this->local_record;
		} else {
			// Retrieve from cache
			$this->local_record = $GLOBALS['__freemed']['cache'][$_callin][$patient_number];
		}

		// Check if this is supposed to be a call-in
		if (!$is_callin) {
			// Check for null ID, then trigger error
			if (!isset($this->local_record['id']))
				trigger_error ("Patient container: ".
					"invalid patient ID specified!",
					E_USER_ERROR
				);

		
			// pull records
			$this->ptlname      = $this->local_record["ptlname"  ];
			$this->ptfname      = $this->local_record["ptfname"  ];
			$this->ptmname      = $this->local_record["ptmname"  ];
			$this->ptdob        = $this->local_record["ptdob"    ];
			$this->ptsex        = $this->local_record["ptsex"    ];
			$this->ptmarital    = $this->local_record["ptmarital"];
			$this->ptid         = $this->local_record["ptid"     ];
			$this->id           = $this->local_record["id"       ];
			$this->ptempl       = $this->local_record["ptempl"   ];
     
			// callin set as false
			$this->is_callin    = false;
		} else {
			// pull records (limited for callins)
			$this->ptlname      = $this->local_record["cilname"];
			$this->ptfname      = $this->local_record["cifname"];
			$this->ptmname      = $this->local_record["cimname"];
			$this->ptdob        = $this->local_record["cidob"  ];
			$this->id           = $this->local_record["id"     ];
			$this->is_callin    = true;
		} // end if/else for is_callin
	} // end constructor Patient

	// Method: Patient->age
	//
	//	Produces a user-friendly age description.
	//
	// Parameters:
	//
	//	$date_to - (optional) Date to which the age is being
	//	calculated. Defaults to today.
	//
	// Returns:
	//
	//	Text string describing the patient's age.
	//
	function age ($date_to="") {
		return date_diff_display ($this->local_record["ptdob"],
		( ($date_to=="") ? date("Y-m-d") : $date_to ),
		__("year(s)"), __("month(s)"), __("day(s)"), __("ago"), __("ahead"));
	} // end function Patient->age

	// Method: Patient->date_of_last_procedure
	//
	//	Determine last procedure date for this patient object.
	//
	// Returns:
	//
	//	SQL date formatted string, or NULL if there is no previous
	//	procedure date.
	//
	function date_of_last_procedure ( ) {
		$query = "SELECT procdt FROM procrec ".
			"WHERE procpatient = '".addslashes($this->id)."' ".
			"ORDER BY procdt DESC";
		$res = $GLOBALS['sql']->query ( $query );
		$r = $GLOBALS['sql']->fetch_array ( $res );
		return $r['procdt'];
	} // end method date_of_last_procedure

	// Method: Patient->fullName
	//
	//	Get the patient's full name.
	//
	// Parameters:
	//
	//	$with_dob - (optional) Boolean flag to determine if date
	//	of birth is included in the output. Defaults to false.
	//
	// Returns:
	//
	//	Text string containing patient's full name.
	//
	function fullName ($with_dob = false) {
		if (!$with_dob) {
			return $this->_fixcaps($this->ptfname)." ".
				$this->_fixcaps($this->ptmname).
				( strlen($this->ptmname) == 1 ? ". " : " " ).
				$this->_fixcaps($this->ptlname);
		} else {
			return $this->_fixcaps($this->ptlname).", ".
				$this->_fixcaps($this->ptfname)." ".
				$this->_fixcaps($this->ptmname).
				" [ ".$this->ptdob." ] ";
		} // end if for checking for date of birth
	} // end function Patient->fullName

	// Method: to_text
	//
	//	Convert record into textual representation.
	//
	// Returns:
	//
	//	Textual representation of record.
	//
	function to_text ( ) {
		return $this->_fixcaps($this->ptlname).", ".
			$this->_fixcaps($this->ptfname)." ".
			$this->_fixcaps($this->ptmname).
			" [ ".$this->ptdob." ] ".
			$this->ptid;
	} // end method to_text

	// Method: Patient->dateOfBirth
	//
	//	Determine patient's date of birth.
	//
	// Returns:
	//
	//	String representation of patient's date of birth, using
	//	<fm_date_print> format.
	//
	function dateOfBirth ($no_parameters = "") {
		return fm_date_print ($this->ptdob);
	} // end function Patient->dateOfBirth

	// Method: Patient->idNumber
	//
	//	Determine patient's database table id number.
	//
	// Returns:
	//
	//	SQL table id number for this patient object.
	//
	function idNumber ($no_parameters = "") {
		return ($this->ptid);
	} // end func idNumber

	// Method: Patient->isEmployed
	//
	//	Determine patient's employment status.
	//
	// Returns:
	//
	//	Boolean value, whether patient is employed.
	//
	function isEmployed ($no_parameters = "") {
		return ($this->ptempl == "y");
	} // end function Patient->isEmployed

	// Method: Patient->isFemale
	//
	//	Determine whether patient is female.
	//
	// Returns:
	//
	//	Boolean value, whether patient is female.
	//
	function isFemale ($no_parameters = "") {
		return ($this->ptsex == "f");
	} // end function Patient->isFemale

	// Method: Patient->isMale
	//
	//	Determine whether patient is male.
	//
	// Returns:
	//
	//	Boolean value, whether patient is male.
	//
	function isMale ($no_parameters = "") {
		return ($this->ptsex == "m");
	} // end function Patient->isMale

	// Method: phoneNumber
	//
	// Returns:
	//
	//	Formatted phone number string
	//
	function phoneNumber ( ) {
		if (!$this->local_record['pthphone']) {
			return __("No Phone Number");
		}
		// TODO: Fix non-US formatting...
		return '('.
			substr($this->local_record['pthphone'], 0, 3).
			') '.
			substr($this->local_record['pthphone'], 3, 3).
			'-'.
			substr($this->local_record['pthphone'], 6, 4);
	} // end method phoneNumber

	// Method: get_list_by_name
	//
	//	Get list of patient id keys based on first and
	//	last name provided
	//
	// Parameters:
	//
	//	$last - Last name substring
	//
	//	$first - First name substring
	//
	// Returns:
	//
	//	Array of patient id keys
	//
	function get_list_by_name ( $last, $first ) {
		$query = "SELECT ptlname, ptfname, ptmname, id ".
			"FROM patient WHERE ".
			"ptlname LIKE '%".addslashes($last)."%' AND ".
			"ptfname LIKE '%".addslashes($first)."%' ".
			"ORDER BY ptlname,ptfname,ptmname";
		$result = $GLOBALS['sql']->query ( $query );
		while ( $r = $GLOBALS['sql']->fetch_array ( $result ) ) {
			$patients[] = $r['id'];
		} // end while loop
		return $patients;
	} // end method get_list_name

	// Method: get_procedures_to_bill
	//
	//	Get list of procedures to bill by patient
	//
	// Parameters:
	//
	//	$by_patient - (optional) Boolean. If this is false,
	//	all procedures which are billable in the system will
	//	be returned. Defaults to true.
	//
	// Returns:
	//
	//	Array of procedure ids.
	//
	function get_procedures_to_bill ( $by_patient = true ) {
		$s = "SELECT proc.id AS p ".
			"FROM patient AS pat, procrec AS proc ".
			"WHERE proc.procpatient = pat.id ".
			"AND proc.procbalcurrent > 0 ".
			"AND proc.proccurcovtp = '0' ".
			( $by_patient ? "AND pat.id = '".addslashes($this->id)."'" : "" );

		$q = $GLOBALS['sql']->query($s);
		while ($res = $GLOBALS['sql']->fetch_array($q)) {
			$procs[] = $res['p'];
		}

		return $procs;
	} // end method get_procedures_to_bill

	// Method: _fixcaps
	//
	//	Produce proper capitalization of a string.
	//
	// Parameters:
	//
	//	$string - Original string.
	//
	// Returns:
	//
	//	Properly capitalized string.
	//
	function _fixcaps ( $string ) {
		$subs = array (
			'Ii' => 'II',
			'Iii' => 'III',
			'Iv' => 'IV'
		);
		$a = explode (' ', $string);
		foreach ($a AS $k => $v) {
			$a[$k] = ucfirst(strtolower($v));
			foreach ($subs AS $s_k => $s_v) {
				if ($a[$k] == $s_k) { $a[$k] = $s_v; }
				if (substr($a[$k], 0, 2) == 'Mc') {
					$a[$k] = 'Mc'.ucfirst(strtolower(substr($a[$k], -(strlen($a[$k])-2))));
				}
			}
		} // end foreach
		return join(' ', $a);
	} // end method _fixcaps

} // end class Patient

?>

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