<cfinclude template='/__Security-Block.cfm' />

<cfprocessingdirective suppressWhiteSpace = "yes">
<cfsetting enablecfoutputonly="yes">
	<cfset i = 1 />
	<cfset px = 0 />
	<cfset thelen=#len(CGI.QUERY_STRING)#>
	<cfloop condition = "thelen neq 0">
		<cfset theparam=#GetToken(CGI.QUERY_STRING,i,"?&")#>
		<cfset thekey=#GetToken(theparam,1,"=")#>
		<cfset thevalue=#GetToken(theparam,2,"=")#>
		<cfswitch expression="#thekey#">
		<cfcase value="url">
			<cfset theurl="index.cfm?a=1">
		</cfcase>
		<cfcase value="id">
     <cfquery  name='checkPatientId' datasource='#Application.DataSrc#'>
      SELECT Patient_Id FROM #Request.prefix_db_agency#.pPatients WHERE Patient_Id = '#thevalue#' AND Loc_ID = '#session.AgencyId#'
     </cfquery>
     <cfif checkPatientId.Patient_Id eq thevalue>
			<cfset Session.CS.PatientId = #thevalue#>
     </cfif>
		</cfcase>
		<cfcase value="pid">
     <cfquery  name='checkPatientPid' datasource='#Application.DataSrc#'>
      SELECT Patient_Id FROM #Request.prefix_db_agency#.pPatients WHERE Patient_Id = '#thevalue#' AND Loc_ID = '#session.AgencyId#'
     </cfquery>
     <cfif checkPatientPid.Patient_Id eq thevalue>
			<cfset Session.CS.PatientId = #thevalue#>
		 </cfif>
		</cfcase>
		<cfcase value="phid">
			<cfset Session.CS.PhysicianId = #thevalue#>
		</cfcase>
		<cfcase value="eid">
			<cfset Session.CS.EmployeeId = #thevalue#>
		</cfcase>
		<cfcase value="sid">
			<cfset Session.CS.ScheduleId = #thevalue#>
		</cfcase>
		<cfcase value="ssid">
			<cfset Session.CS.SupplyScheduleId = #thevalue#>
		</cfcase>
		<cfcase value="mid">
			<cfset Session.CS.MedicationId = #thevalue#>
		</cfcase>
		<cfcase value="mpid">
			<cfset Session.CS.PatientMedicationId = #thevalue#>
		</cfcase>
		<cfcase value="aid">
			<cfset Session.CS.AssessmentId = #thevalue#>
		</cfcase>
		<cfcase value="an">
			<cfset Session.CS.AssessmentNumber = #thevalue#>
		</cfcase>
		<cfcase value="atid">
			<cfset Session.CS.AssessmentTrackerId = #thevalue#>
		</cfcase>
		<cfdefaultcase>
		<cfif len(thekey) neq 0>
			<cfset theurl="#theurl#&#thekey#=#thevalue#">
            <cfif px eq 0>
             <cfset theurl = theurl & "&px=y" />
			 <cfset px = px + 1 />
	        </cfif>
		</cfif>
		</cfdefaultcase>
		</cfswitch>
		<cfset thelen=#len(theparam)#>
		<cfset i = i + 1>
	</cfloop>
  <cfoutput>#theurl#;</cfoutput>
<cfsetting enablecfoutputonly="no">
</cfprocessingdirective>
