<!---
This file is Copyright © 1998-2009 by Home Care Business Services. This work may not be reproduced, in whole or in part, 
using any medium, including, but not limited to, electronic transmission, CD-ROM or published in print, without the express 
permission of Home Care Business Services.

$Revision: 1.10 $
$Id: phys_action.cfm,v 1.10 2009/09/08 21:35:59 arlen Exp $
$Date: 2009/09/08 21:35:59 $
--->
<cfif form.Physician_ID EQ 0>

<cftransaction>
	<cfquery name="Insert" datasource="#Application.DataSrc#">
	INSERT INTO #Request.prefix_db_lookup#.Employee
	(EmployeeType,Agency_ID,Last_name,First_Name,Address1,Address2,City,State,Zip,Home_Phone,Cell_Phone,Beeper,Email,status, Record_creation_Date, Record_created_By, Record_Mod_Date, Record_Mod_By)
	VALUES 
	('Physician',#session.agencyid#,'#form.lastname#','#form.firstname#','#form.address1#','#form.address2#','#form.city#','#form.state#','#form.zip#','#form.telephone1#','#form.cell#','#form.beeper#','#form.email#','#form.status#', #now()#, #Session.EmployeeID#, #now()#, #Session.EmployeeID#)
	</cfquery>

	<cfquery name="newvisit" datasource="#Application.DataSrc#">
	SELECT MAX(Employee_ID) as maxid from #Request.prefix_db_lookup#.Employee	
	</cfquery>

<cfoutput>
	<cfquery name="Insert" datasource="#Application.DataSrc#">
	INSERT INTO #Request.prefix_db_lookup#.Physician
	(Employee_ID,Agency_ID,telephone2,natl_provider_id,fax)
	VALUES 
	(#newvisit.maxid#,#session.agencyid#,'#form.telephone2#','#form.natl_provider_id#','#form.fax#')
	</cfquery>

	<cfquery name="doc" datasource="#Application.DataSrc#">
		SELECT MAX(Physician_ID) as maxid from #Request.prefix_db_lookup#.Physician	
	</cfquery>

	<cfquery name="doc2" datasource="#Application.DataSrc#">
	UPDATE #Request.prefix_db_agency#.patient SET
		Primary_ReferringPhys_ID_M0072 = #doc.maxid#					
	WHERE Patient_ID = #session.cs.patientid#
	</cfquery>

</cfoutput>

</cftransaction>

<cfelse>
<cftransaction>
<cfoutput>
	<cfquery name="Update" datasource="#Application.DataSrc#">
	Update #Request.prefix_db_lookup#.Employee
	set Last_name='#form.lastname#',
	First_Name='#form.firstname#',
	Address1='#form.address1#',
	Address2='#form.address2#',
	City='#form.city#',
	State='#form.state#',
	Zip='#form.zip#',
	Home_Phone='#form.telephone1#',
	Cell_Phone='#form.cell#',
	Beeper='#form.beeper#',
	Email='#form.email#',
	status='#form.status#', 
	Record_Mod_Date=#now()#, 
	Record_Mod_By=#Session.EmployeeID#
	WHERE Employee_ID = #form.Employee_ID#
	</cfquery>


	<cfquery name="Update" datasource="#Application.DataSrc#">
	Update #Request.prefix_db_lookup#.Physician
	set telephone2='#form.telephone2#',
	fax='#form.fax#',
	natl_provider_id='#form.natl_provider_id#'
	WHERE Physician_ID = #form.Physician_ID#
	</cfquery>

</cfoutput>

</cftransaction>

</cfif>

<cflocation url="#form.HTTP_REFERER#" addtoken="no" >
<script>
<cfoutput>
secureHREF('index.cfm?page=patient&cat=phys_form&id=#session.cs.patientid#');
</cfoutput>
</script>
