A
download class.Authorizations.php
Language: PHP
LOC: 64
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

<?php
	// $Id: class.Authorizations.php,v 1.2 2004/02/23 05:44:34 rufustfirefly Exp $
	// $Author: rufustfirefly $

// Class: FreeMED.Authorizations
//
//	Handle all aspects of authorizations for patient visits. This
//	allows calculation and manipulation of visits by coverages and
//	office visits.
//
class Authorizations {

	// constructor STUB
	function Authorizations ( ) { }

	// Method: find_by_coverage
	//
	//	Find authorizations based on a coverage id
	//
	// Parameters:
	//
	//	$coverage - Coverage id key
	//
	// Returns:
	//
	//	Array of authorization keys, or false if it cannot
	//	find any.
	//
	function find_by_coverage ( $coverage ) {
		// Get insurance company and patient from coverage
		$this_coverage = freemed::get_link_rec($coverage, 'coverage');
		$patient = $this_coverage['covpatient'];
		$insco = $this_coverage['covinsco'];

		// If there is no insurance company link, fail
		if (!$insco) { return false; }

		// Select authorizations that match criteria
		$query = "SELECT id FROM authorizations WHERE ".
			"authinsco = '".addslashes($insco)."' AND ".
			"authpatient = '".addslashes($patient)."'";

		// Loop through all records
		while ( $r = $GLOBALS['sql']->fetch_array ( $result ) ) {
			$return[] = $r['id'];
		} // end while

		// Return array of identifiers
		return $return;
	} // end method find_by_coverage

	// Method: get_authorization
	//
	//	Gets the SQL record associated with an authorization.
	//
	// Parameters:
	//
	//	$auth - Authorization id key
	//
	// Returns:
	//
	//	Associative array of values.
	//
	function get_authorization ( $auth ) {
		return freemed::get_link_rec ( $auth, 'authorizations' );
	} // end method get_authorization

	// Method: replace
	//
	//	Puts an authorization back to pre-appointment status.
	//	This has the exact opposite effect as <use_authorization>,
	//	as it increases the number of visits remaining on an
	//	authorization.
	//
	// Parameters:
	//
	//	$auth - Authorization key id
	//
	// Returns:
	//
	//	Boolean, successful
	//
	// See Also:
	//	<use_authorization>
	//
	function replace_authorization ( $auth ) {
		$query = "UPDATE authorizations ".
			"SET authvisitsused = authvisitsused - 1, ".
			"authvisitsremain = authvisitsremain + 1 ".
			"WHERE id = '".addslashes($auth)."'";
		$result = $GLOBALS['sql']->query ( $query );
		return $result;
	} // end method replace_authorization

	// Method: use_authorization
	//
	//	"Use" an authorization. This computes remaining visits
	//	and other information for the authorization. This has
	//	the exact opposite effect as <replace_authorization>.
	//
	// Parameters:
	//
	//	$auth - Authorization key id
	//
	// Returns:
	//
	//	Boolean, successful
	//
	// See Also:
	//	<replace_authorization>
	//
	function use_authorization ( $auth ) {
		$query = "UPDATE authorizations ".
			"SET authvisitsused = authvisitsused + 1, ".
			"authvisitsremain = authvisitsremain - 1 ".
			"WHERE id = '".addslashes($auth)."'";
		$result = $GLOBALS['sql']->query ( $query );
		return $result;
	} // end method use_authorization

	// Method: valid
	//
	//	Determine if an authorization is valid, based on the
	//	date given.
	//
	// Parameters:
	//
	//	$auth - Authorization id key
	//
	//	$date - (optional) Date for the comparison. Defaults to
	//	the current date if none is provided.
	//
	// Returns:
	//
	//	Boolean, if authorization is currently valid.
	//
	function valid ( $auth, $date = NULL ) {
		// Check for date passed... use current by default
		if ($date = NULL) {
			$search_date = date('Y-m-d');
		} else {
			$search_date = $date;
		} // end date passed or not

		// Get authorization record
		$a = $this->get_authorization($auth);

		// First check dates
		$start = str_replace('-', '', $a['authdtbegin']);
		$end   = str_replace('-', '', $a['authdtend']);
		$curdt = str_replace('-', '', $search_date);
		if ( ($curdt < $start) or ($curdt > $end) ) {
			//print "denied by date range ($startd < $curdt < $end)<br/>\n";
			return false;
		} // end date check

		// Check by visits remaining
		if ($a['visitsremain'] < 1) {
			//print "denied by no visits remaining<br/>\n";
		}

		// If all else fails, this is valid, return pass
		return true;
	} // end method valid

	// Method: valid_set
	//
	//	Find set of valid authorizations from a set of
	//	unvalidated authorization keys.
	//
	// Parameters:
	//
	//	$set - Array of unvalidated authorization keys
	//
	//	$date - (optional) Date to use for range comparison.
	//	Defaults to the current date.
	//
	// Returns:
	//
	//	Array of valid authorization keys, or NULL array if
	//	none exist.
	//
	// See Also:
	//	<valid>
	//
	function valid_set ( $set, $date = NULL ) {
		// Check input
		if (!is_array($set)) { return array ( ); }

		// Start with an empty array in case there are no valids
		$result = array ( );
		foreach ($set AS $authorization) {
			if ($this->valid($authorization, $date)) {
				$result[] = $authorization;
			} // end checking for valid
		} // end foreach auth

		// Return resulting validated set
		return $result;
	} // end method valid_set

} // end class Authorizations

?>

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