<?xml version="1.0" encoding="utf-8" ?>

<dbscripts>
	<!--<script>
		<name>Alter Delete MasterDelete Procedure</name>
		<sql>
			ALTER Procedure [dbo].[DeleteMasterData]
			/*
			(
			@parameter1 int = 5,
			@parameter2 datatype OUTPUT
			)

			*/
			AS

			Begin Tran
			delete from dbo.mActivityInfo
			delete from dbo.mAssessmentInfo
			delete from dbo.mATCInfo
			delete from dbo.mBodyAreaInfo
			delete from dbo.mBodyPartInfo
			delete from dbo.MedRefOrthoFacilityTable
			delete from dbo.MedRefSourceAPTable
			delete from dbo.mInjuryInfo
			delete from dbo.mLocationInfo
			delete from dbo.mMedicalRef_Location
			delete from dbo.mOnsetInfo
			delete from dbo.mPhyscianInfo
			delete from dbo.mSiteInfo
			delete from dbo.PlanRecActivityLevelTable
			delete from dbo.PlanRecLimitRestrictions
			delete from dbo.PlanRecLimitRestrictionsTable
			delete from dbo.PlanRecMgmtRecommendationsTable
			delete from dbo.PlanRecMgmtRecTable
			delete from dbo.StudentGradeTable
			delete from dbo.SurgicalProcHospitalTable
			delete from dbo.SurgicalProcRehabTable
			delete from dbo.SurgicalProcTable
			DELETE FROM dbo.MedRefTypeTable
			DELETE FROM dbo.mOnsetInfo
			DELETE FROM dbo.mEvalInjuryTypeClassification
			Commit

		</sql>
	   </script>
	<script>
		<name>Create  [HBE_spPopulateCoachesReportPriorEval]</name>
		<sql>
			Create     Proc [dbo].[HBE_spPopulateCoachesReportPriorEval]
			(@EvalDate DATETIME, @SchoolName VARCHAR(50), @Sport VARCHAR(50), @EvalID UNIQUEIDENTIFIER )

			AS
			set nocount on

			truncate table dbo.RptCouchesTable


			insert into dbo.RptCouchesTable

			/* Changed per request 4/15/2005'
			select
			ie.ATCID, atc.FullName, atc.PhoneNumber, atc.EmailAddr,
			ie.SchoolList, ie.Sport, ie.EvaluationDate,
			ie.FName  + ' ' + ie.LName as FullName, left(ie.LRB,1), ie.BodyPart,
			ie.Classification, ie.Assessment, pr.ManagementRecommendations,
			pr.ActivityLevel, pr.Limit_Restrictions, pr.Limit_RestrictionDesc,
			pr.TreatmentTherapy,
			pr.Protection_Tape + ' ' + pr.Protection_Brace + ' '+ pr.Protection_Pad + ' ' + pr.Protection_Splint + ' ' AS ProtectionSupport,
			pr.Comments, 'sa'
			from
			dbo.uInjuryEvaluation ie inner join  dbo.mATCInfo atc on ie.ATCID = atc.ATCID inner join dbo.uPlanRecommendations pr on ie.evaluationid = pr.evaluationid
			where
			ie.EvaluationDate = @EvalDate and ie.SchoolList = @SchoolName and ie.Sport = @Sport
			*/
			select distinct
			ie.ATCID, atc.FullName, atc.PhoneNumber, atc.EmailAddr,
			ie.SchoolList, sp.InjuryName, ie.EvaluationDate,
			ie.FName  + ' ' + ie.LName as FullName, left(ie.LRB,1), ie.BodyPart,
			ie.Classification, ie.Assessment, pr.ManagementRecommendations,
			pr.ActivityLevel, pr.Limit_Restrictions, pr.Limit_RestrictionDesc,
			pr.TreatmentTherapy,
			pr.Protection_Tape + ' ' + pr.Protection_Brace + ' '+ pr.Protection_Pad + ' ' + pr.Protection_Splint + ' ' AS ProtectionSupport,
			pr.Comments, 'sa',
			ie.evaluationid,
			ie.Site
			from
			dbo.uInjuryEvaluation ie inner join  dbo.mATCInfo atc on ie.ATCID = atc.ATCID inner join dbo.uPlanRecommendations pr on ie.evaluationid = pr.evaluationid inner join dbo.mInjuryInfo sp on ie.sport = sp.injuryid AND sp.Gender = ie.Gender
			where
			ie.EvaluationDate = @EvalDate and ie.SchoolList = @SchoolName and ie.Sport = @Sport
			AND ie.EvaluationID = @EvalID
			order by fullname
		</sql>
	   </script>
		  <script>
		<name>Alter RptAthleticDirectorTable </name>
			<sql>
				ALTER TABLE dbo.RptAthleticDirectorTable
				ADD Limit_RestrictionDesc VARCHAR(255) NULL
			</sql>			  
	   </script>
	<script>
		<name>Alter Procedure qproc_InsertDirectorReport</name>
		<sql>
			ALTER Proc [dbo].[qproc_InsertDirectorReport]
			(@BegDate DateTime, @EndDate DateTime, @SchoolName Varchar(50))

			AS
			Declare @ReportDate DateTime
			Set @ReportDate = GetDate()

			Truncate Table dbo.RptAthleticDirectorTable
			
			Insert Into dbo.RptAthleticDirectorTable
			(
			ReportDate,
			ATCInfo,
			ATCCell,
			StudentFirstName,
			StudentLastName,
			StudentName,
			SchoolName,
			SportID,
			Body,
			BodyPart,
			Site,
			Assessment,
			InjuryTypeClassification,
			MedicalReferral,
			EvulationDate,
			ManagementRecommendations,
			ActivityLevel,
			LimitAndRestrictions,
			Limit_RestrictionDesc,
			RecordID
			)
			Select distinct
			GetDate() as ReportDate,
			a.FullName as ATCInfo,
			a.PhoneNumber as ATCCell,
			fe.FName as StudentFirstName,
			fe.LName as StudentLastName,
			fe.FName + ' ' + fe.LName as StudentName,
			fe.SchoolList as SchoolName,
			fe.Sport as SportID,
			left(fe.LRB,1) as Body,
			fe.BodyPart as BodyPart,
			fe.Site as Site,
			fe.Assessment as Assessment,
			fe.Classification as InjuryTypeClassification,
			case
			when len(fe.SourceAP) > 0 then 'X'
			else ' '
			end
			as MedicalReferral,
			fe.EvaluationDate as EvaluationDate,
			fe.ManagementRecommendations,
			fe.ActivityLevel,
			fe.Limit_Restrictions,
			fe.Limit_RestrictionDesc,
			fe.RecordID as RecordID
			from
			dbo.vFullEvaluation fe
			join dbo.mATCInfo a on fe.ATCID = a.ATCID
			join (select max(recordID) as RecordID, studentID, injuryID from dbo.uInjuryEvaluation where EvalComplete = 1 group by StudentID, InjuryID) e on fe.RecordID = e.RecordID
			Where
			EvaluationDate Between @BegDate and @EndDate
			and fe.SchoolList = @SchoolName
			Order by SchoolName, StudentLastName, fe.EvaluationDate
		</sql>
	   </script>-->
	<!--	<script>
		<name>Create Prior Eval List Proc</name>
		<sql>
			CREATE PROC [dbo].[fnd_pPriorEvalListSelect]
			(@student_id AS UNIQUEIDENTIFIER, @injury_id AS UNIQUEIDENTIFIER)
			AS
			SELECT
			EvaluationDate,SchoolList, Sport,EvaluationID
			FROM
			dbo.uInjuryEvaluation
			WHERE
			StudentID = @student_id
			AND InjuryID = @injury_id
			AND EvalComplete =1
			ORDER BY
			EvaluationDate DESC
		</sql>
	   </script>
	<script>
		<name>Update DeleteMasterData store procedure</name>
		<sql>
			ALTER Procedure [dbo].[DeleteMasterData]
			/*
			(
			@parameter1 int = 5,
			@parameter2 datatype OUTPUT
			)

			*/
			AS

			Begin Tran
			delete from dbo.mActivityInfo
			delete from dbo.mAssessmentInfo
			delete from dbo.mATCInfo
			delete from dbo.mBodyAreaInfo
			delete from dbo.mBodyPartInfo
			delete from dbo.MedRefOrthoFacilityTable
			delete from dbo.MedRefSourceAPTable
			delete from dbo.mInjuryInfo
			delete from dbo.mLocationInfo
			delete from dbo.mMedicalRef_Location
			delete from dbo.mOnsetInfo
			delete from dbo.mPhyscianInfo
			delete from dbo.mSiteInfo
			delete from dbo.PlanRecActivityLevelTable
			delete from dbo.PlanRecLimitRestrictions
			delete from dbo.PlanRecLimitRestrictionsTable
			delete from dbo.PlanRecMgmtRecommendationsTable
			delete from dbo.PlanRecMgmtRecTable
			delete from dbo.StudentGradeTable
			delete from dbo.SurgicalProcHospitalTable
			delete from dbo.SurgicalProcRehabTable
			delete from dbo.SurgicalProcTable
			DELETE FROM dbo.MedRefTypeTable
			Commit
		</sql>
	   </script>
	<script>
		<name>Alter Tables</name>
		<sql>
			ALTER TABLE dbo.uInjuryEvaluation
			ADD ModifiedDate DATETIME NOT NULL DEFAULT GETDATE()

			ALTER TABLE dbo.mStudentInfo
			ADD ModifiedDate DATETIME NOT NULL DEFAULT GETDATE()


			ALTER TABLE dbo.StudentInjuryTable
			ADD ModifiedDate DATETIME NOT NULL DEFAULT GETDATE()
		</sql>
	</script>
	SCRIPT UPDATE 9/16/2014 to Handle Remote Sync Version 2014.09.15.03
		<script>
			<name>Alter mStudentInfo</name>
			<sql>
				alter table dbo.mStudentInfo
				add LastSyncDate DateTime not null default getdate()
			</sql>
		</script>
		<script>
			<name>Alter uInjuryEvaluation</name>
			<sql>
				alter table dbo.uInjuryEvaluation
				add LastSyncDate DateTime not null default getdate()
			</sql>
		</script>
		<script>
			<name>Alter StudentInjuryTable</name>
			<sql>
				alter table dbo.StudentInjuryTable
				add LastSyncDate DateTime not null default getdate()
			</sql>
		</script>
		<script>
			<name>Update mStudentInfo</name>
			<sql>
				update dbo.mStudentInfo set LastSyncDate = ModifiedDate
			</sql>
		</script>
		<script>
			<name>Update uInjuryEvaluation</name>
			<sql>
				update dbo.uInjuryEvaluation set LastSyncDate = ModifiedDate
			</sql>
		</script>
		<script>
			<name>Update StudentInjuryTable</name>
			<sql>
				update dbo.StudentInjuryTable set LastSyncDate = ModifiedDate
			</sql>
		</script>
		<script>
			<name>Update Delete Data Stored Procedure</name>
			<sql>
				ALTER Procedure [dbo].[DeleteMasterData]
				/*
				(
				@parameter1 int = 5,
				@parameter2 datatype OUTPUT
				)

				*/
				AS

				Begin Tran
				delete from dbo.mActivityInfo
				delete from dbo.mAssessmentInfo
				delete from dbo.mATCInfo
				delete from dbo.mBodyAreaInfo
				delete from dbo.mBodyPartInfo
				delete from dbo.MedRefOrthoFacilityTable
				delete from dbo.MedRefSourceAPTable
				delete from dbo.mInjuryInfo
				delete from dbo.mLocationInfo
				delete from dbo.mMedicalRef_Location
				delete from dbo.mOnsetInfo
				delete from dbo.mPhyscianInfo
				delete from dbo.mSiteInfo
				delete from dbo.PlanRecActivityLevelTable
				delete from dbo.PlanRecLimitRestrictions
				delete from dbo.PlanRecLimitRestrictionsTable
				delete from dbo.PlanRecMgmtRecommendationsTable
				delete from dbo.PlanRecMgmtRecTable
				delete from dbo.StudentGradeTable
				delete from dbo.SurgicalProcHospitalTable
				delete from dbo.SurgicalProcRehabTable
				delete from dbo.SurgicalProcTable
				DELETE FROM dbo.MedRefTypeTable
				DELETE FROM dbo.mEvalInjuryTypeClassification
				Commit
			</sql>
		</script>-->

	<!--<script>
		<name>Alter Student Injury</name>
		<sql>
			ALTER Proc [dbo].[HBE_spCreateInjuryRecord]

			(
			@StudentID UNIQUEIDENTIFIER,
			@Assessment VARCHAR(255),
			@TypeClassification VARCHAR(255),
			@InjuryID UniqueIdentifier
			)

			AS
			if (Select Count(*) from dbo.StudentInjuryTable Where InjuryID = @InjuryID) >0

			BEGIN
			Update dbo.StudentInjuryTable
			Set Assessment = @Assessment, TypeClassification = @TypeClassification, ModifiedDate = GETDATE()
			Where StudentID = @StudentID and InjuryID = @InjuryID

			UPDATE dbo.mStudentInfo
			SET ModifiedDate = GETDATE()
			WHERE StudentID = @StudentId
			END
			else
			BEGIN
			Insert Into dbo.StudentInjuryTable
			(StudentID, Assessment, TypeClassification, InjuryID, ModifiedDate)
			VALUES
			(@StudentID, @Assessment, @TypeClassification, @InjuryID, GETDATE())


			UPDATE dbo.mStudentInfo
			SET ModifiedDate = GETDATE()
			WHERE StudentID = @StudentId
			END
		</sql>
	</script>
	<script>
		<name>Alter Student Record</name>
		<sql>
			ALTER   PROCEDURE [dbo].[HBE_pInsertStudentInfo]
			@StudentID UNIQUEIDENTIFIER ,
			@FName VARCHAR(255) ,
			@LName VARCHAR(255) ,
			@FullName VARCHAR(510) ,
			@Age INT ,
			@Grade VARCHAR(50) ,
			@Gender CHAR(1) ,
			@DateOfBirth DATETIME ,
			@SchoolName VARCHAR(255)
			AS /* $Revision $ */

			DECLARE
			@intRetCode INT ,
			@intRowcount INT ,
			@intIdentity INT ,
			@intError INT

			SELECT
			@intRetCode = 0


			DECLARE @SchoolID UNIQUEIDENTIFIER

			SELECT TOP 1
			@SchoolID = SCHOOLID
			FROM
			dbo.mSchoolInfo
			WHERE
			SchoolName = @SchoolName

			IF ( SELECT
			COUNT(*)
			FROM
			dbo.mStudentInfo
			WHERE
			StudentID = @StudentID
			) > 0
			BEGIN

			UPDATE
			dbo.mStudentInfo
			SET
			FName = @FName ,
			LName = @LName ,
			FullName = @FullName ,
			Age = @Age ,
			Grade = @Grade ,
			Gender = @Gender ,
			DateOfBirth = @DateOfBirth ,
			SchoolID = @SchoolID ,
			RecUpdated = 1,
			ModifiedDate = GETDATE()
			WHERE
			StudentID = @StudentID

			END

			ELSE
			BEGIN
			INSERT  mStudentInfo
			( StudentID ,
			FName ,
			LName ,
			FullName ,
			Age ,
			Grade ,
			Gender ,
			DateOfBirth ,
			SchoolID ,
			RecUpdated,
			ModifiedDate
			)
			SELECT
			@StudentID ,
			@FName ,
			@LName ,
			@FullName ,
			@Age ,
			@Grade ,
			@Gender ,
			@DateOfBirth ,
			@SchoolID ,
			1,
			GETDATE()
			END
		</sql>
	</script>
	<script>
		<name>Create Split Function</name>
		<sql>
			CREATE FUNCTION [dbo].[fnSplit]
			(
			@List VARCHAR(MAX) ,
			@SplitOn VARCHAR(5)
			)
			RETURNS @RtnValue TABLE
			(
			Id INT IDENTITY(1, 1) ,
			Value NVARCHAR(256)
			)
			AS
			BEGIN
			WHILE ( CHARINDEX(@SplitOn, @List) > 0 )
			BEGIN
			INSERT  INTO @RtnValue
			( value
			)
			SELECT  Value = LTRIM(RTRIM(SUBSTRING(@List, 1,
			CHARINDEX(@SplitOn,
			@List) - 1)))
			SET @List = SUBSTRING(@List,
			CHARINDEX(@SplitOn, @List)
			+ LEN(@SplitOn), LEN(@List))
			END

			INSERT  INTO @RtnValue
			( Value )
			SELECT  Value = LTRIM(RTRIM(@List))

			RETURN
			END
		</sql>
	</script>
	<script>
		<name>Create Missing Plan Recommendations</name>
		<sql>
			CREATE PROC dbo.pInsertMissingPlanRecommendations_TreatmentThrapy
			(@EvalID UNIQUEIDENTIFIER, @StudentID UNIQUEIDENTIFIER, @InjuryID UNIQUEIDENTIFIER,@TreatmentTherapyValues VARCHAR(MAX))
			AS

			INSERT INTO dbo.uPlanRecommendations_TreatmentThrapy
			( EvaluationID ,
			TreatmentTherapy ,
			StudentID ,
			InjuryID ,
			RecUpdated
			)

			SELECT
			@EvalId,
			Value,
			@StudentID,
			@InjuryId,
			1

			FROM
			[dbo].[fnSplit](@TreatmentTherapyValues,';')
			WHERE
			Value != ''
		</sql>
	</script>-->
	<!--<script>
		<name></name>
		<sql></sql>
	</script>-->
	
	<!--VERSION 2015.05.01 
	<script>
		<name>Update LRB values "R"</name>
		<sql>
			UPDATE DBO.uInjuryEvaluation
			SET LRB = 'R'
			WHERE LRB = 'R-Right'
		</sql>
	</script>
	<script>
		<name>Update LRB values "L"</name>
		<sql>
			UPDATE DBO.uInjuryEvaluation
			SET LRB = 'L'
			WHERE LRB = 'L-Left'
		</sql>
	</script>
	<script>
		<name>Update LRB values "B"</name>
		<sql>
			UPDATE DBO.uInjuryEvaluation
			SET LRB = 'B'
			WHERE LRB = 'B-Bilateral'
		</sql>
	</script>
	<script>
		<name>Update LRB values "NA" Head</name>
		<sql>
			UPDATE dbo.uInjuryEvaluation
			SET LRB = 'NA'
			where BodyPart = 'Head'
		</sql>
	</script>
	<script>
		<name>Update LRB values "NA" Brain</name>
		<sql>
			UPDATE dbo.uInjuryEvaluation
			SET LRB = 'NA'
			where BodyPart = 'Brain'
		</sql>
	</script>
	<script>
		<name>Add New Fields to Injury Evaluation</name>
		<sql>
			Alter Table dbo.uInjuryEvaluation
			add
			[ActivityType_InSeason] bit default 0
			,[ActivityType_PEClass] bit default 0
			,[ActivityType_ClubSport] bit default 0
		</sql>
	   </script>
	<script>
		<name>Update PEClass/ClubSport/InSeason - Eval2</name>
		<sql>
			ALTER Procedure [dbo].[uproc_SelectInjuryEval2]
			
			(
			@StudentID UniqueIdentifier,
			@InjuryID UniqueIdentifier,
			@EvalID UniqueIdentifier
			)
			AS

			/**
			File: Name: uproc_SelectInjuryEval
			Desc:
			This template can be customized:
			Return values:
			Called by:
			Parameters: Input Output

			Auth:
			** Date:

			** Change History

			** Date: Author: Description:


			*/

			SELECT TOP 1
			[EvaluationID],
			[EvaluationDate],
			[ATCID],
			[Episode],
			[OnSetDate],
			[OnsetOther],
			[NatureOfOnset],
			[PriorHistory],
			[ActivityType_Practice],
			[ActivityType_Competition],
			[ActivityType_Conditioning],
			[ActivityType_WeightLifting],
			[ActivityType_Recreational],
			[ActivityType_NonAthletic],
			[ActivityType_OffSeason],
			[ActivityType_InSeason],
			[ActivityType_ClubSport] ,
			[ActivityType_PEClass] ,
			[Location],
			[SubComments],
			[FName],
			[LName],
			[Age],
			[Gender],
			[Grade],
			[ParentEmailAddr],
			[SchoolList],
			[Sport],
			[LRB],
			[BodyArea],
			[BodyPart],
			[Site],
			[Classification],
			[Assessment],
			[ObjComments],
			[RecordDate],
			[RecordID],
			[InjuryID],
			[StudentID],
			[EvalComplete]
			FROM
			[dbo].[uInjuryEvaluation]
			WHERE
			StudentID = @StudentID AND
			InjuryID = @InjuryID AND
			EvaluationID = @EvalID
		</sql>
	</script>
	<script>
		<name>Update PEClass/ClubSport/InSeason - Eval</name>
		<sql>
			ALTER Procedure [dbo].[uproc_SelectInjuryEval]			
			(
			@StudentID UniqueIdentifier,
			@InjuryID UniqueIdentifier
			)
			AS

			SELECT TOP 1
			[EvaluationID],
			[EvaluationDate],
			[ATCID],
			[Episode],
			[OnSetDate],
			[OnsetOther],
			[NatureOfOnset],
			[PriorHistory],
			[ActivityType_Practice],
			[ActivityType_Competition],
			[ActivityType_Conditioning],
			[ActivityType_WeightLifting],
			[ActivityType_Recreational],
			[ActivityType_NonAthletic],
			[ActivityType_OffSeason],
			[ActivityType_InSeason],
			[ActivityType_ClubSport] ,
			[ActivityType_PEClass] ,
			[Location],
			[SubComments],
			ms.[FName],
			ms.[LName],
			ms.[Age],
			ms.[Gender],
			ms.[Grade],
			si.[ParentEmailAddr],
			si.[SchoolList],
			[Sport],
			[LRB],
			[BodyArea],
			[BodyPart],
			[Site],
			[Classification],
			[Assessment],
			[ObjComments],
			[RecordDate],
			[RecordID],
			[InjuryID],
			si.[StudentID],
			[EvalComplete],
			OnsetOtherCheck
			FROM
			[dbo].[uInjuryEvaluation] si inner join dbo.mStudentInfo ms on si.StudentID = ms.StudentID
			WHERE
			si.StudentID = @StudentID AND
			si.InjuryID = @InjuryID
			ORDER BY
			RECORDID DESC
		</sql>
		<name> Update NULL Values </name>
		<sql>
			update dbo.uInjuryEvaluation
			set ActivityType_ClubSport = 0, ActivityType_PEClass = 0, ActivityType_InSeason = 0
			where ActivityType_ClubSport is null and ActivityType_InSeason is null and ActivityType_PEClass is null
		</sql>
	   </script>
	-->
	<!--VERSION 2015.07.31 -->
	<script>
		<name>Alter pInsert Injury Eval Procedure</name>
		<sql>
			ALTER Procedure [dbo].[HBE_pInsertInjuryEval]
			(
			@EvaluationID                      uniqueidentifier ,
			@EvaluationDate                    datetime ,
			@ATCID                             varchar(50) ,
			@Episode                           varchar(255) ,
			@OnSetDate                         datetime ,
			@OnsetOther                        varchar(50) ,
			@OnsetOtherCheck				   bit,
			@NatureOfOnset                     varchar(255) ,
			@PriorHistory                      bit ,
			@ActivityType_Practice             bit ,
			@ActivityType_Competition          bit,
			@ActivityType_Conditioning         bit,
			@ActivityType_WeightLifting        bit,
			@ActivityType_Recreational         bit,
			@ActivityType_NonAthletic          bit,
			@ActivityType_OffSeason            bit ,
			@ActivityType_InSeason			   bit,
			@ActivityType_PEClass			   bit,
			@ActivityType_ClubSport			   bit,
			@Location                          varchar(255) ,
			@SubComments                       varchar(1000) ,
			@FName                             varchar(50) ,
			@LName                             varchar(50) ,
			@Age                               smallint ,
			@Gender                            char(1) ,
			@Grade                             varchar(25) ,
			@ParentEmailAddr                   varchar(50) ,
			@SchoolList                        varchar(255) ,
			@Sport                             varchar(50) ,
			@LRB                               varchar(50) ,
			@BodyArea                          varchar(50) ,
			@BodyPart                          varchar(50) ,
			@Site                              varchar(50) ,
			@Classification                    varchar(50) ,
			@Assessment                        varchar(50) ,
			@ObjComments                       varchar(1000),
			@StudentID						   uniqueidentifier,
			@InjuryID						   uniqueidentifier
			)
			AS

			/******************************************************************************
			**		File:
			**		Name: dbo.HBE_pInsertInjuryEval
			**		Desc:
			**
			**		This template can be customized:
			**
			**		Return values:
			**
			**		Called by:
			**
			**		Parameters:
			**		Input							Output
			**     ----------							-----------
			**
			**		Auth:
			**		Date:
			*******************************************************************************
			**		Change History
			*******************************************************************************
			**		Date:		Author:				Description:
			**		--------		--------				-------------------------------------------
			**
			*******************************************************************************/

			IF (SELECT COUNT(*) FROM dbo.uInjuryEvaluation WHERE EvaluationID = @EvaluationID) > 0
			-- Update Record
			BEGIN
			UPDATE    dbo.uInjuryEvaluation
			SET
			EvaluationID                      = @EvaluationID ,
			EvaluationDate                    = @EvaluationDate ,
			ATCID                             = @ATCID ,
			Episode                           = @Episode ,
			OnSetDate                         = @OnSetDate ,
			OnsetOther                        = @OnsetOther ,
			OnsetOtherCheck					= @OnsetOtherCheck,
			NatureOfOnset                     = @NatureOfOnset ,
			PriorHistory                      = @PriorHistory ,
			ActivityType_Practice             = @ActivityType_Practice ,
			ActivityType_Competition          = @ActivityType_Competition ,
			ActivityType_Conditioning         = @ActivityType_Conditioning ,
			ActivityType_WeightLifting        = @ActivityType_WeightLifting ,
			ActivityType_Recreational         = @ActivityType_Recreational ,
			ActivityType_NonAthletic          = @ActivityType_NonAthletic ,
			ActivityType_OffSeason            = @ActivityType_OffSeason ,
			ActivityType_InSeason			  = @ActivityType_InSeason,
			ActivityType_ClubSport			  = @ActivityType_ClubSport ,
			ActivityType_PEClass			  = @ActivityType_PEClass ,
			Location                          = @Location ,
			SubComments                       = @SubComments ,
			FName                             = @FName ,
			LName                             = @LName ,
			Age                               = @Age ,
			Gender                            = @Gender ,
			Grade                             = @Grade ,
			ParentEmailAddr                   = @ParentEmailAddr ,
			SchoolList                        = @SchoolList ,
			Sport                             = @Sport ,
			LRB                               = @LRB ,
			BodyArea                          = @BodyArea ,
			BodyPart                          = @BodyPart ,
			Site                              = @Site ,
			Classification                    = @Classification ,
			Assessment                        = @Assessment ,
			ObjComments                       = @ObjComments,
			StudentID 						= @StudentID,
			InjuryID                          = @InjuryID,
			RecUpdated						= 1,
			ModifiedDate						= GETDATE(),
			EvalComplete						= 1
			WHERE
			EvaluationID                      = @EvaluationID


			UPDATE dbo.mStudentInfo SET ModifiedDate = GETDATE()
			WHERE StudentID = @StudentId

			UPDATE dbo.StudentInjuryTable SET ModifiedDate = GETDATE()
			WHERE StudentID = @StudentId AND InjuryID = @InjuryId


			END
			ELSE
			-- Insert New Record
			BEGIN
			INSERT INTO   dbo.uInjuryEvaluation (
			EvaluationID ,
			EvaluationDate ,
			ATCID ,
			Episode ,
			OnSetDate ,
			OnsetOther ,
			OnsetOtherCheck,
			NatureOfOnset ,
			PriorHistory ,
			ActivityType_Practice ,
			ActivityType_Competition ,
			ActivityType_Conditioning ,
			ActivityType_WeightLifting ,
			ActivityType_Recreational ,
			ActivityType_NonAthletic ,
			ActivityType_OffSeason ,
			ActivityType_InSeason,
			ActivityType_ClubSport ,
			ActivityType_PEClass ,
			Location ,
			SubComments ,
			FName ,
			LName ,
			Age ,
			Gender ,
			Grade ,
			ParentEmailAddr ,
			SchoolList ,
			Sport ,
			LRB ,
			BodyArea ,
			BodyPart ,
			Site ,
			Classification ,
			Assessment ,
			ObjComments,
			StudentID,
			InjuryID,
			RecUpdated,
			ModifiedDate,
			EvalComplete
			)
			SELECT
			@EvaluationID ,
			@EvaluationDate ,
			@ATCID ,
			@Episode ,
			@OnSetDate ,
			@OnsetOther ,
			@OnsetOtherCheck,
			@NatureOfOnset ,
			@PriorHistory ,
			@ActivityType_Practice ,
			@ActivityType_Competition ,
			@ActivityType_Conditioning ,
			@ActivityType_WeightLifting ,
			@ActivityType_Recreational ,
			@ActivityType_NonAthletic ,
			@ActivityType_OffSeason ,
			@ActivityType_InSeason ,
			@ActivityType_ClubSport ,
			@ActivityType_PEClass ,
			@Location ,
			@SubComments ,
			@FName ,
			@LName ,
			@Age ,
			@Gender ,
			@Grade ,
			@ParentEmailAddr ,
			@SchoolList ,
			@Sport ,
			ISNULL(@LRB,'') ,
			@BodyArea ,
			@BodyPart ,
			@Site ,
			@Classification ,
			@Assessment ,
			@ObjComments,
			@StudentID,
			@InjuryID,
			1,
			GETDATE(),
			1



			UPDATE dbo.mStudentInfo SET ModifiedDate = GETDATE()
			WHERE StudentID = @StudentId

			UPDATE dbo.StudentInjuryTable SET ModifiedDate = GETDATE()
			WHERE StudentID = @StudentId AND InjuryID = @InjuryId

			END

		</sql>
	</script>
		<script>
			<name>Alter View vFullEvaluation</name>
			<sql>
				ALTER VIEW [dbo].[vFullEvaluation]
				AS
				SELECT     dbo.uInjuryEvaluation.EvaluationID, dbo.uInjuryEvaluation.EvaluationDate, dbo.uInjuryEvaluation.ATCID, dbo.uInjuryEvaluation.Episode,
				dbo.uInjuryEvaluation.OnSetDate, dbo.uInjuryEvaluation.OnsetOther, dbo.uInjuryEvaluation.NatureOfOnset, dbo.uInjuryEvaluation.PriorHistory,
				dbo.uInjuryEvaluation.ActivityType_Practice, dbo.uInjuryEvaluation.ActivityType_Competition, dbo.uInjuryEvaluation.ActivityType_Conditioning,
				dbo.uInjuryEvaluation.ActivityType_WeightLifting, dbo.uInjuryEvaluation.ActivityType_Recreational, dbo.uInjuryEvaluation.ActivityType_NonAthletic,
				dbo.uInjuryEvaluation.ActivityType_OffSeason, dbo.uInjuryEvaluation.ActivityType_InSeason, dbo.uInjuryEvaluation.ActivityType_PEClass, dbo.uInjuryEvaluation.ActivityType_ClubSport, dbo.uInjuryEvaluation.Location, dbo.uInjuryEvaluation.SubComments, dbo.uInjuryEvaluation.FName,
				dbo.uInjuryEvaluation.LName, dbo.uInjuryEvaluation.Age, dbo.uInjuryEvaluation.Gender, dbo.uInjuryEvaluation.Grade,
				dbo.uInjuryEvaluation.ParentEmailAddr, dbo.uInjuryEvaluation.SchoolList, dbo.uInjuryEvaluation.Sport, dbo.uInjuryEvaluation.LRB,
				dbo.uInjuryEvaluation.BodyArea, dbo.uInjuryEvaluation.BodyPart, dbo.uInjuryEvaluation.Site, dbo.uInjuryEvaluation.Classification,
				dbo.uInjuryEvaluation.Assessment, dbo.uInjuryEvaluation.ObjComments, dbo.uInjuryEvaluation.InjuryID, dbo.uInjuryEvaluation.StudentID,
				dbo.uInjuryEvaluation.OnsetOtherCheck, dbo.uInjuryEvaluation.RecordDate, dbo.uMedicalReferrals.SourceAP, dbo.uMedicalReferrals.Type,
				dbo.uMedicalReferrals.OVAppt, dbo.uMedicalReferrals.Location1, dbo.uMedicalReferrals.Physician1, dbo.uMedicalReferrals.Location2,
				dbo.uMedicalReferrals.Physician2, dbo.uMedicalReferrals.Location3, dbo.uMedicalReferrals.Physician3, dbo.uMedicalReferrals.Notes,
				dbo.uPlanRecommendations.ManagementRecommendations, dbo.uPlanRecommendations.ActivityLevel,
				dbo.uPlanRecommendations.Limit_Restrictions, dbo.uPlanRecommendations.Limit_RestrictionDesc, dbo.uPlanRecommendations.TreatmentTherapy,
				dbo.uPlanRecommendations.Protection_Tape, dbo.uPlanRecommendations.Protection_Brace, dbo.uPlanRecommendations.Protection_Pad,
				dbo.uPlanRecommendations.Protection_Splint, dbo.uPlanRecommendations.Comments, dbo.uSurgicalProcedures.SurgicalProcedure,
				dbo.uSurgicalProcedures.Hospital, dbo.uSurgicalProcedures.Rehab, dbo.uSurgicalProcedures.Notes AS Expr1, dbo.uRevenueTracking.AmountBilled,
				dbo.uRevenueTracking.AmountCollected, dbo.uInjuryEvaluation.RecordID
				FROM         dbo.uInjuryEvaluation INNER JOIN
				dbo.uMedicalReferrals ON dbo.uInjuryEvaluation.EvaluationID = dbo.uMedicalReferrals.EvaluationID INNER JOIN
				dbo.uPlanRecommendations ON dbo.uInjuryEvaluation.EvaluationID = dbo.uPlanRecommendations.EvaluationID INNER JOIN
				dbo.uRevenueTracking ON dbo.uInjuryEvaluation.EvaluationID = dbo.uRevenueTracking.EvaluationID INNER JOIN
				dbo.uSurgicalProcedures ON dbo.uInjuryEvaluation.EvaluationID = dbo.uSurgicalProcedures.EvaluationID
			</sql>
	</script>
	<script>
		<!-- Added 2/19/2016 for new release to address issue #4 on service tickets -->
		<name>Alter HBE_spUpdateExisitingInjuryEval</name>
		<sql>			
			ALTER     Procedure [dbo].[HBE_spUpdateExisitingInjuryEval]
			/* Param List */
			(
			@InjuryID uniqueidentifier,
			@StudentID uniqueidentifier,
			@EvaluationID uniqueidentifier
			)

			AS

			/******************************************************************************
			**		File:
			**		Name: dbo.HBE_spUpdateExisitingInjuryEval
			**		Desc:
			**
			**		This template can be customized:
			**
			**		Return values:
			**
			**		Called by:
			**
			**		Parameters:
			**		Input							Output
			**     ----------							-----------
			**
			**		Auth:
			**		Date:
			*******************************************************************************
			**		Change History
			*******************************************************************************
			**		Date:		Author:				Description:
			**		--------		--------				-------------------------------------------
			**
			*******************************************************************************/
			SET NOCOUNT ON

			DECLARE @NewestInjuryRecID INT
			DECLARE @NewestMRRecID INT
			DECLARE @NewestPRRecID INT
			DECLARE @NewestRTRecID INT
			DECLARE @NewestSPRecID INT
			DECLARE @NewestMultiplePlanSelectionID INT

			-- if Student and Injury Record Exisit then copy information over
			BEGIN
			-- Get the highest/newest record from the db and copy it
			SELECT TOP 1 @NewestInjuryRecID = RecordID FROM dbo.uInjuryEvaluation WHERE StudentID = @StudentID AND InjuryID = @InjuryID ORDER BY RecordID DESC, RecordDate DESC
			SELECT TOP 1 @NewestMRRecID = RecordID FROM dbo.[uMedicalReferrals] WHERE StudentID = @StudentID AND InjuryID = @InjuryID ORDER BY RecordID DESC, RecordDate DESC
			SELECT TOP 1 @NewestPRRecID = RecordID FROM dbo.[uPlanRecommendations] WHERE StudentID = @StudentID AND InjuryID = @InjuryID ORDER BY RecordID DESC, RecordDate DESC
			SELECT TOP 1 @NewestRTRecID = RecordID FROM dbo.[uRevenueTracking] WHERE StudentID = @StudentID AND InjuryID = @InjuryID ORDER BY RecordID DESC, RecordDate DESC
			SELECT TOP 1 @NewestSPRecID = RecordID FROM dbo.[uSurgicalProcedures] WHERE StudentID = @StudentID AND InjuryID = @InjuryID ORDER BY RecordID DESC, RecordDate DESC

			/*-- Removed Per Change Request 4.15.2005
			Insert INTO dbo.uInjuryEvaluation ([EvaluationID], [EvaluationDate], [ATCID], [Episode], [OnSetDate], [OnsetOther], [NatureOfOnset], [PriorHistory], [ActivityType_Practice], [ActivityType_Competition], [ActivityType_Conditioning], [ActivityType_WeightLifting], [ActivityType_Recreational], [ActivityType_NonAthletic], [ActivityType_OffSeason], [Location], [SubComments], [FName], [LName], [Age], [Gender], [Grade], [ParentEmailAddr], [SchoolList], [Sport], [LRB], [BodyArea], [BodyPart], [Site], [Classification], [Assessment], [ObjComments], [InjuryID], [StudentID])
			SELECT @EvaluationID, [EvaluationDate], [ATCID], [Episode], [OnSetDate], [OnsetOther], [NatureOfOnset], [PriorHistory], [ActivityType_Practice], [ActivityType_Competition], [ActivityType_Conditioning], [ActivityType_WeightLifting], [ActivityType_Recreational], [ActivityType_NonAthletic], [ActivityType_OffSeason], [Location], [SubComments], [FName], [LName], [Age], [Gender], [Grade], [ParentEmailAddr], [SchoolList], [Sport], [LRB], [BodyArea], [BodyPart], [Site], [Classification], [Assessment], [ObjComments], [InjuryID], [StudentID] from dbo.uInjuryEvaluation WHERE RecordID = @NewestInjuryRecID
			*/
			-- Insert Injury Evaluation
			Insert INTO dbo.uInjuryEvaluation ([EvaluationID], [EvaluationDate], [ATCID], [Episode], [OnSetDate], [OnsetOther], [NatureOfOnset], [PriorHistory], [ActivityType_Practice], [ActivityType_Competition], [ActivityType_Conditioning], [ActivityType_WeightLifting], [ActivityType_Recreational], [ActivityType_NonAthletic], [ActivityType_OffSeason], [Location], [SubComments], [FName], [LName], [Age], [Gender], [Grade], [ParentEmailAddr], [SchoolList], [Sport], [LRB], [BodyArea], [BodyPart], [Site], [Classification], [Assessment], [ObjComments], [InjuryID], [StudentID], [OnsetOtherCheck],  [ActivityType_InSeason])
			SELECT @EvaluationID, '1/1/1900' AS [EvaluationDate], [ATCID], [Episode], [OnSetDate], [OnsetOther], [NatureOfOnset], [PriorHistory], [ActivityType_Practice], [ActivityType_Competition], [ActivityType_Conditioning], [ActivityType_WeightLifting], [ActivityType_Recreational], [ActivityType_NonAthletic], [ActivityType_OffSeason], [Location], '' as [SubComments], s.[FName], s.[LName], s.[Age], s.[Gender], s.[Grade], [ParentEmailAddr], sc.SchoolName, [Sport], [LRB], [BodyArea], [BodyPart], [Site], [Classification], [Assessment], '' as [ObjComments], [InjuryID], s.[StudentID], ie.OnsetOtherCheck, ie. [ActivityType_InSeason]
			from dbo.uInjuryEvaluation ie
			join dbo.mStudentInfo s on ie.StudentID = s.StudentID
			join dbo.mSchoolInfo sc on s.SchoolID = sc.SchoolID
			WHERE RecordID = @NewestInjuryRecID
			--SELECT @EvaluationID, '1/1/1900' AS [EvaluationDate], [ATCID], [Episode], [OnSetDate], [OnsetOther], [NatureOfOnset], [PriorHistory], [ActivityType_Practice], [ActivityType_Competition], [ActivityType_Conditioning], [ActivityType_WeightLifting], [ActivityType_Recreational], [ActivityType_NonAthletic], [ActivityType_OffSeason], [Location], '' as [SubComments], [FName], [LName], [Age], [Gender], [Grade], [ParentEmailAddr], [SchoolList], [Sport], [LRB], [BodyArea], [BodyPart], [Site], [Classification], [Assessment], '' as [ObjComments], [InjuryID], [StudentID] from dbo.uInjuryEvaluation WHERE RecordID = @NewestInjuryRecID

			-- Insert Medical Referals
			INSERT INTO [dbo].[uMedicalReferrals]([EvaluationID], [EvaluationDate], [SourceAP], [Type], [OVAppt], [Location1], [Physician1], [Location2], [Physician2], [Location3], [Physician3], [Notes], [InjuryID], [StudentID])
			SELECT @EvaluationID, [EvaluationDate], [SourceAP], [Type], [OVAppt], [Location1], [Physician1], [Location2], [Physician2], [Location3], [Physician3], [Notes], [InjuryID], [StudentID] FROM dbo.[uMedicalReferrals] WHERE RecordID = @NewestMRRecID

			-- Insert Plan Recommendations
			/** Updated per request Beta3 Doc**/
			INSERT INTO [dbo].[uPlanRecommendations]([EvaluationID], [EvaluationDate], [ManagementRecommendations], [ActivityLevel], [Limit_Restrictions], [Limit_RestrictionDesc], [TreatmentTherapy], [Protection_Tape], [Protection_Brace], [Protection_Pad], [Protection_Splint], [Comments], [InjuryID], [StudentID])
			SELECT @EvaluationID, [EvaluationDate], '', '', '', '', '', '', '', '', '', '', [InjuryID], [StudentID] FROM dbo.[uPlanRecommendations] WHERE RecordID = @NewestPRRecID


			-- Insert Revenue Tracking
			INSERT INTO [dbo].[uRevenueTracking]([EvaluationID], [EvaluationDate], [AmountBilled], [AmountCollected], [InjuryID], [StudentID])
			SELECT @EvaluationID, [EvaluationDate], [AmountBilled], [AmountCollected], [InjuryID], [StudentID] FROM dbo.[uRevenueTracking] WHERE RecordID = @NewestRTRecID

			-- Insert Surgical Procedures
			INSERT INTO [dbo].[uSurgicalProcedures]([EvaluationID], [EvaluationDate], [SurgicalProcedure], [Hospital], [Rehab], [Notes], [InjuryID], [StudentID])
			SELECT @EvaluationID, [EvaluationDate], [SurgicalProcedure], [Hospital], [Rehab], [Notes], [InjuryID], [StudentID] FROM dbo.[uSurgicalProcedures] WHERE RecordID = @NewestSPRecID

			END

		</sql>
	   </script>
	<script>
		   <!--Added 2/19/2016 for new release to address issue #5 on service tickets-->
		<name>Alter [HBE_spPopulateCoachesReport]</name>
		<sql>
			ALTER     Proc [dbo].[HBE_spPopulateCoachesReport]
			(@EvalDate DATETIME, @SchoolName VARCHAR(50), @Sport VARCHAR(50))

			AS
			set nocount on

			truncate table dbo.RptCouchesTable


			insert into dbo.RptCouchesTable

			/* Changed per request 4/15/2005'
			select
			ie.ATCID, atc.FullName, atc.PhoneNumber, atc.EmailAddr,
			ie.SchoolList, ie.Sport, ie.EvaluationDate,
			ie.FName  + ' ' + ie.LName as FullName, left(ie.LRB,1), ie.BodyPart,
			ie.Classification, ie.Assessment, pr.ManagementRecommendations,
			pr.ActivityLevel, pr.Limit_Restrictions, pr.Limit_RestrictionDesc,
			pr.TreatmentTherapy,
			pr.Protection_Tape + ' ' + pr.Protection_Brace + ' '+ pr.Protection_Pad + ' ' + pr.Protection_Splint + ' ' AS ProtectionSupport,
			pr.Comments, 'sa'
			from
			dbo.uInjuryEvaluation ie inner join  dbo.mATCInfo atc on ie.ATCID = atc.ATCID inner join dbo.uPlanRecommendations pr on ie.evaluationid = pr.evaluationid
			where
			ie.EvaluationDate = @EvalDate and ie.SchoolList = @SchoolName and ie.Sport = @Sport
			*/
			select distinct
			ie.ATCID, atc.FullName, atc.PhoneNumber, atc.EmailAddr,
			ie.SchoolList, sp.InjuryName, ie.EvaluationDate,
			ie.FName  + ' ' + ie.LName as FullName, case when ie.LRB = 'NA' then '' else left(ie.LRB,1) end, ie.BodyPart,
			ie.Classification, ie.Assessment, pr.ManagementRecommendations,
			pr.ActivityLevel, pr.Limit_Restrictions, pr.Limit_RestrictionDesc,
			pr.TreatmentTherapy,
			pr.Protection_Tape + ' ' + pr.Protection_Brace + ' '+ pr.Protection_Pad + ' ' + pr.Protection_Splint + ' ' AS ProtectionSupport,
			pr.Comments, 'sa',
			ie.evaluationid,
			ie.Site
			from
			dbo.uInjuryEvaluation ie inner join  dbo.mATCInfo atc on ie.ATCID = atc.ATCID inner join dbo.uPlanRecommendations pr on ie.evaluationid = pr.evaluationid inner join dbo.mInjuryInfo sp on ie.sport = sp.injuryid AND sp.Gender = ie.Gender
			where
			ie.EvaluationDate = @EvalDate and ie.SchoolList = @SchoolName and ie.Sport = @Sport
			-- 	and
			-- 	ie.recordid in (
			-- 		select max(recordid) from dbo.uInjuryEvaluation
			-- 		where EvaluationDate = @EvalDate and SchoolList = @SchoolName and Sport = @Sport
			-- 		group by studentid
			-- 		)

			order by fullname
		</sql>
	   </script>
	<script>
		<!--Added 2/19/2016 for new release to address issue #5 on service tickets-->
		<name>Alter [HBE_spPopulateCoachesReportPriorEval]</name>
		<sql>
			ALTER     Proc [dbo].[HBE_spPopulateCoachesReportPriorEval]
			(@EvalDate DATETIME, @SchoolName VARCHAR(50), @Sport VARCHAR(50), @EvalID UNIQUEIDENTIFIER )

			AS
			set nocount on

			truncate table dbo.RptCouchesTable


			insert into dbo.RptCouchesTable

			/* Changed per request 4/15/2005'
			select
			ie.ATCID, atc.FullName, atc.PhoneNumber, atc.EmailAddr,
			ie.SchoolList, ie.Sport, ie.EvaluationDate,
			ie.FName  + ' ' + ie.LName as FullName, left(ie.LRB,1), ie.BodyPart,
			ie.Classification, ie.Assessment, pr.ManagementRecommendations,
			pr.ActivityLevel, pr.Limit_Restrictions, pr.Limit_RestrictionDesc,
			pr.TreatmentTherapy,
			pr.Protection_Tape + ' ' + pr.Protection_Brace + ' '+ pr.Protection_Pad + ' ' + pr.Protection_Splint + ' ' AS ProtectionSupport,
			pr.Comments, 'sa'
			from
			dbo.uInjuryEvaluation ie inner join  dbo.mATCInfo atc on ie.ATCID = atc.ATCID inner join dbo.uPlanRecommendations pr on ie.evaluationid = pr.evaluationid
			where
			ie.EvaluationDate = @EvalDate and ie.SchoolList = @SchoolName and ie.Sport = @Sport
			*/
			select distinct
			ie.ATCID, atc.FullName, atc.PhoneNumber, atc.EmailAddr,
			ie.SchoolList, sp.InjuryName, ie.EvaluationDate,
			ie.FName  + ' ' + ie.LName as FullName, case when ie.LRB = 'NA' then '' else left(ie.LRB,1) end, ie.BodyPart,
			ie.Classification, ie.Assessment, pr.ManagementRecommendations,
			pr.ActivityLevel, pr.Limit_Restrictions, pr.Limit_RestrictionDesc,
			pr.TreatmentTherapy,
			pr.Protection_Tape + ' ' + pr.Protection_Brace + ' '+ pr.Protection_Pad + ' ' + pr.Protection_Splint + ' ' AS ProtectionSupport,
			pr.Comments, 'sa',
			ie.evaluationid,
			ie.Site
			from
			dbo.uInjuryEvaluation ie inner join  dbo.mATCInfo atc on ie.ATCID = atc.ATCID inner join dbo.uPlanRecommendations pr on ie.evaluationid = pr.evaluationid inner join dbo.mInjuryInfo sp on ie.sport = sp.injuryid AND sp.Gender = ie.Gender
			where
			ie.EvaluationDate = @EvalDate and ie.SchoolList = @SchoolName and ie.Sport = @Sport
			AND ie.EvaluationID = @EvalID
			-- 	and
			-- 	ie.recordid in (
			-- 		select max(recordid) from dbo.uInjuryEvaluation
			-- 		where EvaluationDate = @EvalDate and SchoolList = @SchoolName and Sport = @Sport
			-- 		group by studentid
			-- 		)

			order by fullname
		</sql>
	   </script>
	<script>
		<!--Added 2/19/2016 for new release to address issue #5 on service tickets-->
		<name>Alter [qproc_InsertDirectorReport]</name>
		<sql>
			ALTER Proc [dbo].[qproc_InsertDirectorReport]
			(@BegDate DateTime, @EndDate DateTime, @SchoolName Varchar(50))

			AS
			Declare @ReportDate DateTime
			Set @ReportDate = GetDate()

			Truncate Table dbo.RptAthleticDirectorTable
			--
			Insert Into dbo.RptAthleticDirectorTable
			(
			ReportDate,
			ATCInfo,
			ATCCell,
			StudentFirstName,
			StudentLastName,
			StudentName,
			SchoolName,
			SportID,
			Body,
			BodyPart,
			Site,
			Assessment,
			InjuryTypeClassification,
			MedicalReferral,
			EvulationDate,
			ManagementRecommendations,
			ActivityLevel,
			LimitAndRestrictions,
			Limit_RestrictionDesc,
			RecordID
			)
			Select distinct
			GetDate() as ReportDate,
			a.FullName as ATCInfo,
			a.PhoneNumber as ATCCell,
			fe.FName as StudentFirstName,
			fe.LName as StudentLastName,
			fe.FName + ' ' + fe.LName as StudentName,
			fe.SchoolList as SchoolName,
			fe.Sport as SportID,
			case when fe.LRB='NA' then '' else left(fe.LRB,1) end as Body,
			fe.BodyPart as BodyPart,
			fe.Site as Site,
			fe.Assessment as Assessment,
			fe.Classification as InjuryTypeClassification,
			case
			when len(fe.SourceAP) > 0 then 'X'
			else ' '
			end
			as MedicalReferral,
			fe.EvaluationDate as EvaluationDate,
			fe.ManagementRecommendations,
			fe.ActivityLevel,
			fe.Limit_Restrictions,
			fe.Limit_RestrictionDesc,
			fe.RecordID as RecordID
			from
			dbo.vFullEvaluation fe
			join dbo.mATCInfo a on fe.ATCID = a.ATCID
			join (select max(recordID) as RecordID, studentID, injuryID from dbo.uInjuryEvaluation where EvalComplete = 1 group by StudentID, InjuryID) e on fe.RecordID = e.RecordID
			Where
			EvaluationDate Between @BegDate and @EndDate
			and fe.SchoolList = @SchoolName
			Order by SchoolName, StudentLastName, fe.EvaluationDate
		</sql>
	   </script>
	<script>
		<!--Added 2/19/2016 for new release to address issue #5 on service tickets-->
		<name>Alter View dbo.vStudentInfo</name>
		<sql>
			ALTER    VIEW [dbo].[vStudentInfo]
			AS
			SELECT DISTINCT
			sc.SchoolName,
			st.FName,
			st.LName,
			st.Age AS AGE,
			st.GRADE AS GRADE,
			case when ie.LRB = 'NA' then '' else LEFT(ie.LRB,1) end AS [L/R/B],
			ie.BodyPart,
			ie.Classification,
			ie.Assessment,
			mr.SourceAP AS MedicalRefFlag,
			sp.SurgicalProcedure AS SurgicalProcFlag,
			ISNULL(ie.Sport, 'NONE') AS SPORT,
			ISNULL(ie.EvaluationDate,'1/1/1900') AS [EVAL DATE],
			ie.recordid AS recordid,
			st.StudentID AS STUDENTID,
			st.Archive

			from
			dbo.mStudentInfo st inner join dbo.mSchoolInfo sc on st.schoolid = sc.schoolid
			left outer join dbo.uInjuryEvaluation ie on st.studentid = ie.studentid
			inner join dbo.uMedicalReferrals mr on ie.studentid = mr.studentid and ie.EvaluationID = mr.EvaluationID
			inner join dbo.uPlanRecommendations pr on ie.studentid = pr.studentid and ie.EvaluationID = pr.EvaluationID
			inner join dbo.uSurgicalProcedures sp on ie.studentid = sp.studentid and ie.EvaluationID = sp.EvaluationID
			--FROM
			--	dbo.mStudentInfo st INNER JOIN dbo.mSchoolInfo sc
			--	ON st.schoolid = sc.schoolid
			--	INNER JOIN (SELECT MAX(recordID) AS RecordID, studentID, injuryID FROM dbo.uInjuryEvaluation WHERE EvalComplete = 1 GROUP BY StudentID, InjuryID) e
			--	ON st.studentID = e.StudentiD
			--	LEFT JOIN dbo.uInjuryEvaluation ie
			--	ON st.studentid = ie.studentid AND ie.RecordID = e.RecordID
			--	INNER JOIN dbo.uMedicalReferrals mr
			--	ON ie.studentid = mr.studentid AND ie.EvaluationID = mr.EvaluationID
			--	INNER JOIN dbo.uPlanRecommendations pr
			--	ON ie.studentid = pr.studentid AND ie.EvaluationID = pr.EvaluationID
			--	INNER JOIN dbo.uSurgicalProcedures sp
			--	ON ie.studentid = sp.studentid AND ie.EvaluationID = sp.EvaluationID


			/*
			SELECT     dbo.mStudentInfo.FName, dbo.mStudentInfo.LName, dbo.mStudentInfo.FullName, dbo.mStudentInfo.Age, dbo.mStudentInfo.Grade,
			dbo.mStudentInfo.DateOfBirth, dbo.mSchoolInfo.SchoolName, dbo.mStudentInfo.StudentID
			FROM         dbo.mStudentInfo INNER JOIN
			dbo.mSchoolInfo ON dbo.mStudentInfo.SchoolID = dbo.mSchoolInfo.SchoolID
			*/

		</sql>
	</script>
	<script>
		<!--Added 2/26/2016 for new release to address issue #7 on service tickets-->
		<name>Alter [fnd_pPriorEvalListSelect]</name>
		<sql>
			ALTER PROC [dbo].[fnd_pPriorEvalListSelect]
			(@student_id AS UNIQUEIDENTIFIER, @injury_id AS UNIQUEIDENTIFIER)
			AS
			SELECT
			EvaluationDate,SchoolList, Sport,EvaluationID, FName + ' '  + LName as StudentName
			FROM
			dbo.uInjuryEvaluation
			WHERE
			StudentID = @student_id
			AND InjuryID = @injury_id
			AND EvalComplete =1
			ORDER BY
			EvaluationDate DESC
		</sql>
		
	</script>
	<script>
		<!--Added 4/27/2016 for new release to directors report being filtered by prior eval full report-->
		<name>Create vFullEvaluationDirectorsReport</name>
		<sql>
			CREATE VIEW [dbo].[vFullEvaluationDirectorsReport] AS
			SELECT dbo.uInjuryEvaluation.EvaluationID,
			dbo.uInjuryEvaluation.EvaluationDate,
			dbo.uInjuryEvaluation.ATCID,
			dbo.uInjuryEvaluation.Episode,
			dbo.uInjuryEvaluation.OnSetDate,
			dbo.uInjuryEvaluation.OnsetOther,
			dbo.uInjuryEvaluation.NatureOfOnset,
			dbo.uInjuryEvaluation.PriorHistory,
			dbo.uInjuryEvaluation.ActivityType_Practice,
			dbo.uInjuryEvaluation.ActivityType_Competition,
			dbo.uInjuryEvaluation.ActivityType_Conditioning,
			dbo.uInjuryEvaluation.ActivityType_WeightLifting,
			dbo.uInjuryEvaluation.ActivityType_Recreational,
			dbo.uInjuryEvaluation.ActivityType_NonAthletic,
			dbo.uInjuryEvaluation.ActivityType_OffSeason,
			dbo.uInjuryEvaluation.ActivityType_InSeason,
			dbo.uInjuryEvaluation.ActivityType_PEClass,
			dbo.uInjuryEvaluation.ActivityType_ClubSport,
			dbo.uInjuryEvaluation.Location,
			dbo.uInjuryEvaluation.SubComments,
			dbo.uInjuryEvaluation.FName,
			dbo.uInjuryEvaluation.LName,
			dbo.uInjuryEvaluation.Age,
			dbo.uInjuryEvaluation.Gender,
			dbo.uInjuryEvaluation.Grade,
			dbo.uInjuryEvaluation.ParentEmailAddr,
			dbo.uInjuryEvaluation.SchoolList,
			dbo.uInjuryEvaluation.Sport,
			dbo.uInjuryEvaluation.LRB,
			dbo.uInjuryEvaluation.BodyArea,
			dbo.uInjuryEvaluation.BodyPart,
			dbo.uInjuryEvaluation.Site,
			dbo.uInjuryEvaluation.Classification,
			dbo.uInjuryEvaluation.Assessment,
			dbo.uInjuryEvaluation.ObjComments,
			dbo.uInjuryEvaluation.InjuryID,
			dbo.uInjuryEvaluation.StudentID,
			dbo.uInjuryEvaluation.OnsetOtherCheck,
			dbo.uInjuryEvaluation.RecordDate,
			dbo.uMedicalReferrals.SourceAP,
			dbo.uMedicalReferrals.Type,
			dbo.uMedicalReferrals.OVAppt,
			dbo.uMedicalReferrals.Location1,
			dbo.uMedicalReferrals.Physician1,
			dbo.uMedicalReferrals.Location2,
			dbo.uMedicalReferrals.Physician2,
			dbo.uMedicalReferrals.Location3,
			dbo.uMedicalReferrals.Physician3,
			dbo.uMedicalReferrals.Notes,
			dbo.uPlanRecommendations.ManagementRecommendations,
			dbo.uPlanRecommendations.ActivityLevel,
			dbo.uPlanRecommendations.Limit_Restrictions,
			dbo.uPlanRecommendations.Limit_RestrictionDesc,
			dbo.uPlanRecommendations.TreatmentTherapy,
			dbo.uPlanRecommendations.Protection_Tape,
			dbo.uPlanRecommendations.Protection_Brace,
			dbo.uPlanRecommendations.Protection_Pad,
			dbo.uPlanRecommendations.Protection_Splint,
			dbo.uPlanRecommendations.Comments,
			dbo.uSurgicalProcedures.SurgicalProcedure,
			dbo.uSurgicalProcedures.Hospital,
			dbo.uSurgicalProcedures.Rehab,
			dbo.uSurgicalProcedures.Notes AS Expr1,
			dbo.uRevenueTracking.AmountBilled,
			dbo.uRevenueTracking.AmountCollected,
			dbo.uInjuryEvaluation.RecordID
			FROM dbo.uInjuryEvaluation
			INNER JOIN dbo.uMedicalReferrals ON dbo.uInjuryEvaluation.EvaluationID = dbo.uMedicalReferrals.EvaluationID
			INNER JOIN dbo.uPlanRecommendations ON dbo.uInjuryEvaluation.EvaluationID = dbo.uPlanRecommendations.EvaluationID
			INNER JOIN dbo.uRevenueTracking ON dbo.uInjuryEvaluation.EvaluationID = dbo.uRevenueTracking.EvaluationID
			INNER JOIN dbo.uSurgicalProcedures ON dbo.uInjuryEvaluation.EvaluationID = dbo.uSurgicalProcedures.EvaluationID
		</sql>
	   </script>
	<script>
		<name>Alter Proc qproc_InsertDirectorReport</name>
		<sql>
			ALTER Proc [dbo].[qproc_InsertDirectorReport]
			(@BegDate DateTime, @EndDate DateTime, @SchoolName Varchar(50))

			AS
			Declare @ReportDate DateTime
			Set @ReportDate = GetDate()


			Truncate Table dbo.RptAthleticDirectorTable
			--
			Insert Into dbo.RptAthleticDirectorTable
			(
			ReportDate,
			ATCInfo,
			ATCCell,
			StudentFirstName,
			StudentLastName,
			StudentName,
			SchoolName,
			SportID,
			Body,
			BodyPart,
			Site,
			Assessment,
			InjuryTypeClassification,
			MedicalReferral,
			EvulationDate,
			ManagementRecommendations,
			ActivityLevel,
			LimitAndRestrictions,
			Limit_RestrictionDesc,
			RecordID
			)
			Select distinct
			GetDate() as ReportDate,
			a.FullName as ATCInfo,
			a.PhoneNumber as ATCCell,
			fe.FName as StudentFirstName,
			fe.LName as StudentLastName,
			fe.FName + ' ' + fe.LName as StudentName,
			fe.SchoolList as SchoolName,
			fe.Sport as SportID,
			case when fe.LRB='NA' then '' else left(fe.LRB,1) end as Body,
			fe.BodyPart as BodyPart,
			fe.Site as Site,
			fe.Assessment as Assessment,
			fe.Classification as InjuryTypeClassification,
			case
			when len(fe.SourceAP) > 0 then 'X'
			else ' '
			end
			as MedicalReferral,
			fe.EvaluationDate as EvaluationDate,
			fe.ManagementRecommendations,
			fe.ActivityLevel,
			fe.Limit_Restrictions,
			fe.Limit_RestrictionDesc,
			fe.RecordID as RecordID
			from
			dbo.vFullEvaluationDirectorsReport fe
			join dbo.mATCInfo a on fe.ATCID = a.ATCID
			join (select max(recordID) as RecordID, studentID, injuryID from dbo.uInjuryEvaluation where EvalComplete = 1 group by StudentID, InjuryID) e on fe.RecordID = e.RecordID
			Where
			EvaluationDate Between @BegDate and @EndDate
			and fe.SchoolList = @SchoolName
			Order by SchoolName, StudentLastName, fe.EvaluationDate
		</sql>
	   </script>

	<script>	
		<name>create RptAthleticInjuryTable</name>
		<sql>
			CREATE TABLE [dbo].[RptAthleticInjuryTable](
			[EvaluationID] [uniqueidentifier] NOT NULL,
			[EvaluationDate] [datetime] NULL,
			[ATCID] [varchar](50) NULL,
			[Episode] [varchar](255) NULL,
			[OnSetDate] [datetime] NULL,
			[OnsetOther] [varchar](50) NULL,
			[NatureOfOnset] [varchar](255) NULL,
			[PriorHistory] [bit] NOT NULL,
			[ActivityType_Practice] [bit] NOT NULL,
			[ActivityType_Competition] [bit] NOT NULL,
			[ActivityType_Conditioning] [bit] NOT NULL,
			[ActivityType_WeightLifting] [bit] NOT NULL,
			[ActivityType_Recreational] [bit] NOT NULL,
			[ActivityType_NonAthletic] [bit] NOT NULL,
			[ActivityType_OffSeason] [bit] NOT NULL,
			[ActivityType_InSeason] [bit] NULL,
			[ActivityType_PEClass] [bit] NULL,
			[ActivityType_ClubSport] [bit] NULL,
			[Location] [varchar](255) NULL,
			[SubComments] [varchar](1000) NULL,
			[FName] [varchar](50) NULL,
			[LName] [varchar](50) NULL,
			[Age] [smallint] NULL,
			[Gender] [char](1) NULL,
			[Grade] [varchar](25) NULL,
			[ParentEmailAddr] [varchar](50) NULL,
			[SchoolList] [varchar](255) NULL,
			[Sport] [varchar](50) NULL,
			[LRB] [varchar](50) NULL,
			[BodyArea] [varchar](50) NULL,
			[BodyPart] [varchar](50) NULL,
			[Site] [varchar](50) NULL,
			[Classification] [varchar](50) NULL,
			[Assessment] [varchar](50) NULL,
			[ObjComments] [varchar](1000) NULL,
			[InjuryID] [uniqueidentifier] NULL,
			[StudentID] [uniqueidentifier] NULL,
			[OnsetOtherCheck] [bit] NOT NULL,
			[RecordDate] [datetime] NOT NULL,
			[SourceAP] [varchar](50) NULL,
			[Type] [varchar](50) NULL,
			[OVAppt] [varchar](50) NULL,
			[Location1] [varchar](255) NULL,
			[Physician1] [varchar](255) NULL,
			[Location2] [varchar](255) NULL,
			[Physician2] [varchar](255) NULL,
			[Location3] [varchar](255) NULL,
			[Physician3] [varchar](255) NULL,
			[Notes] [varchar](2000) NULL,
			[ManagementRecommendations] [varchar](255) NULL,
			[ActivityLevel] [varchar](255) NULL,
			[Limit_Restrictions] [varchar](50) NULL,
			[Limit_RestrictionDesc] [varchar](255) NULL,
			[TreatmentTherapy] [varchar](255) NULL,
			[Protection_Tape] [varchar](255) NULL,
			[Protection_Brace] [varchar](255) NULL,
			[Protection_Pad] [varchar](255) NULL,
			[Protection_Splint] [varchar](255) NULL,
			[Comments] [varchar](2000) NULL,
			[SurgicalProcedure] [varchar](255) NULL,
			[Hospital] [varchar](255) NULL,
			[Rehab] [varchar](255) NULL,
			[Expr1] [varchar](2000) NULL,
			[AmountBilled] [numeric](19, 5) NULL,
			[AmountCollected] [numeric](19, 5) NULL,
			[RecordID] [int] NOT NULL
			) ON [PRIMARY]
		</sql>
	</script>
	<script>
		<name>Create Proc dbo.qproc_InsertFullEvaluationReport</name>
		<sql>
			Alter Proc dbo.[qproc_InsertFullEvaluationReport]
			(@BegDate DateTime, @EndDate DateTime, @SchoolName Varchar(50), @EvalID Uniqueidentifier)

			AS

			delete from dbo.RptAthleticInjuryTable

			Insert into dbo.RptAthleticInjuryTable
			(
			EvaluationID,
			EvaluationDate,
			ATCID,
			Episode,
			OnSetDate,
			OnsetOther,
			NatureOfOnset,
			PriorHistory,
			ActivityType_Practice,
			ActivityType_Competition,
			ActivityType_Conditioning,
			ActivityType_WeightLifting,
			ActivityType_Recreational,
			ActivityType_NonAthletic,
			ActivityType_OffSeason,
			ActivityType_InSeason,
			ActivityType_PEClass,
			ActivityType_ClubSport,
			Location,
			SubComments,
			FName,
			LName,
			Age,
			Gender,
			Grade,
			ParentEmailAddr,
			SchoolList,
			Sport,
			LRB,
			BodyArea,
			BodyPart,
			Site,
			Classification,
			Assessment,
			ObjComments,
			InjuryID,
			StudentID,
			OnsetOtherCheck,
			RecordDate,
			SourceAP,
			Type,
			OVAppt,
			Location1,
			Physician1,
			Location2,
			Physician2,
			Location3,
			Physician3,
			Notes,
			ManagementRecommendations,
			ActivityLevel,
			Limit_Restrictions,
			Limit_RestrictionDesc,
			TreatmentTherapy,
			Protection_Tape,
			Protection_Brace,
			Protection_Pad,
			Protection_Splint,
			Comments,
			SurgicalProcedure,
			Hospital,
			Rehab,
			Expr1,
			dbo.uRevenueTracking.AmountBilled,
			dbo.uRevenueTracking.AmountCollected,
			dbo.uInjuryEvaluation.RecordID

			)


			SELECT dbo.uInjuryEvaluation.EvaluationID,
			dbo.uInjuryEvaluation.EvaluationDate,
			dbo.uInjuryEvaluation.ATCID,
			dbo.uInjuryEvaluation.Episode,
			dbo.uInjuryEvaluation.OnSetDate,
			dbo.uInjuryEvaluation.OnsetOther,
			dbo.uInjuryEvaluation.NatureOfOnset,
			dbo.uInjuryEvaluation.PriorHistory,
			dbo.uInjuryEvaluation.ActivityType_Practice,
			dbo.uInjuryEvaluation.ActivityType_Competition,
			dbo.uInjuryEvaluation.ActivityType_Conditioning,
			dbo.uInjuryEvaluation.ActivityType_WeightLifting,
			dbo.uInjuryEvaluation.ActivityType_Recreational,
			dbo.uInjuryEvaluation.ActivityType_NonAthletic,
			dbo.uInjuryEvaluation.ActivityType_OffSeason,
			dbo.uInjuryEvaluation.ActivityType_InSeason,
			dbo.uInjuryEvaluation.ActivityType_PEClass,
			dbo.uInjuryEvaluation.ActivityType_ClubSport,
			dbo.uInjuryEvaluation.Location,
			dbo.uInjuryEvaluation.SubComments,
			dbo.uInjuryEvaluation.FName,
			dbo.uInjuryEvaluation.LName,
			dbo.uInjuryEvaluation.Age,
			dbo.uInjuryEvaluation.Gender,
			dbo.uInjuryEvaluation.Grade,
			dbo.uInjuryEvaluation.ParentEmailAddr,
			dbo.uInjuryEvaluation.SchoolList,
			dbo.uInjuryEvaluation.Sport,
			dbo.uInjuryEvaluation.LRB,
			dbo.uInjuryEvaluation.BodyArea,
			dbo.uInjuryEvaluation.BodyPart,
			dbo.uInjuryEvaluation.Site,
			dbo.uInjuryEvaluation.Classification,
			dbo.uInjuryEvaluation.Assessment,
			dbo.uInjuryEvaluation.ObjComments,
			dbo.uInjuryEvaluation.InjuryID,
			dbo.uInjuryEvaluation.StudentID,
			dbo.uInjuryEvaluation.OnsetOtherCheck,
			dbo.uInjuryEvaluation.RecordDate,
			dbo.uMedicalReferrals.SourceAP,
			dbo.uMedicalReferrals.Type,
			dbo.uMedicalReferrals.OVAppt,
			dbo.uMedicalReferrals.Location1,
			dbo.uMedicalReferrals.Physician1,
			dbo.uMedicalReferrals.Location2,
			dbo.uMedicalReferrals.Physician2,
			dbo.uMedicalReferrals.Location3,
			dbo.uMedicalReferrals.Physician3,
			dbo.uMedicalReferrals.Notes,
			dbo.uPlanRecommendations.ManagementRecommendations,
			dbo.uPlanRecommendations.ActivityLevel,
			dbo.uPlanRecommendations.Limit_Restrictions,
			dbo.uPlanRecommendations.Limit_RestrictionDesc,
			dbo.uPlanRecommendations.TreatmentTherapy,
			dbo.uPlanRecommendations.Protection_Tape,
			dbo.uPlanRecommendations.Protection_Brace,
			dbo.uPlanRecommendations.Protection_Pad,
			dbo.uPlanRecommendations.Protection_Splint,
			dbo.uPlanRecommendations.Comments,
			dbo.uSurgicalProcedures.SurgicalProcedure,
			dbo.uSurgicalProcedures.Hospital,
			dbo.uSurgicalProcedures.Rehab,
			dbo.uSurgicalProcedures.Notes AS Expr1,
			dbo.uRevenueTracking.AmountBilled,
			dbo.uRevenueTracking.AmountCollected,
			dbo.uInjuryEvaluation.RecordID
			--INTO dbo.RptAthleticInjuryTable
			FROM dbo.uInjuryEvaluation
			INNER JOIN dbo.uMedicalReferrals ON dbo.uInjuryEvaluation.EvaluationID = dbo.uMedicalReferrals.EvaluationID
			INNER JOIN dbo.uPlanRecommendations ON dbo.uInjuryEvaluation.EvaluationID = dbo.uPlanRecommendations.EvaluationID
			INNER JOIN dbo.uRevenueTracking ON dbo.uInjuryEvaluation.EvaluationID = dbo.uRevenueTracking.EvaluationID
			INNER JOIN dbo.uSurgicalProcedures ON dbo.uInjuryEvaluation.EvaluationID = dbo.uSurgicalProcedures.EvaluationID
			WHERE dbo.uInjuryEvaluation.EvaluationDate between @BegDate and DateAdd(dd, 1,@EndDate)
			AND dbo.uInjuryEvaluation.SchoolList = @SchoolName
			AND dbo.uInjuryEvaluation.EvaluationID = @EvalID
		</sql>
	   </script>
	<script>
		<name>Create Proc InsertFullEvaluationReport</name>
		<sql>
			ALTER Proc [dbo].[qproc_InsertFullEvaluationReport]
			(@BegDate DateTime, @EndDate DateTime, @SchoolName Varchar(50), @EvalID Uniqueidentifier)

			AS

			delete from dbo.RptAthleticInjuryTable

			Insert into dbo.RptAthleticInjuryTable
			(
			EvaluationID,
			EvaluationDate,
			ATCID,
			Episode,
			OnSetDate,
			OnsetOther,
			NatureOfOnset,
			PriorHistory,
			ActivityType_Practice,
			ActivityType_Competition,
			ActivityType_Conditioning,
			ActivityType_WeightLifting,
			ActivityType_Recreational,
			ActivityType_NonAthletic,
			ActivityType_OffSeason,
			ActivityType_InSeason,
			ActivityType_PEClass,
			ActivityType_ClubSport,
			Location,
			SubComments,
			FName,
			LName,
			Age,
			Gender,
			Grade,
			ParentEmailAddr,
			SchoolList,
			Sport,
			LRB,
			BodyArea,
			BodyPart,
			Site,
			Classification,
			Assessment,
			ObjComments,
			InjuryID,
			StudentID,
			OnsetOtherCheck,
			RecordDate,
			SourceAP,
			Type,
			OVAppt,
			Location1,
			Physician1,
			Location2,
			Physician2,
			Location3,
			Physician3,
			Notes,
			ManagementRecommendations,
			ActivityLevel,
			Limit_Restrictions,
			Limit_RestrictionDesc,
			TreatmentTherapy,
			Protection_Tape,
			Protection_Brace,
			Protection_Pad,
			Protection_Splint,
			Comments,
			SurgicalProcedure,
			Hospital,
			Rehab,
			Expr1,
			dbo.uRevenueTracking.AmountBilled,
			dbo.uRevenueTracking.AmountCollected,
			dbo.uInjuryEvaluation.RecordID

			)


			SELECT dbo.uInjuryEvaluation.EvaluationID,
			dbo.uInjuryEvaluation.EvaluationDate,
			dbo.uInjuryEvaluation.ATCID,
			dbo.uInjuryEvaluation.Episode,
			dbo.uInjuryEvaluation.OnSetDate,
			dbo.uInjuryEvaluation.OnsetOther,
			dbo.uInjuryEvaluation.NatureOfOnset,
			dbo.uInjuryEvaluation.PriorHistory,
			dbo.uInjuryEvaluation.ActivityType_Practice,
			dbo.uInjuryEvaluation.ActivityType_Competition,
			dbo.uInjuryEvaluation.ActivityType_Conditioning,
			dbo.uInjuryEvaluation.ActivityType_WeightLifting,
			dbo.uInjuryEvaluation.ActivityType_Recreational,
			dbo.uInjuryEvaluation.ActivityType_NonAthletic,
			dbo.uInjuryEvaluation.ActivityType_OffSeason,
			dbo.uInjuryEvaluation.ActivityType_InSeason,
			dbo.uInjuryEvaluation.ActivityType_PEClass,
			dbo.uInjuryEvaluation.ActivityType_ClubSport,
			dbo.uInjuryEvaluation.Location,
			dbo.uInjuryEvaluation.SubComments,
			dbo.uInjuryEvaluation.FName,
			dbo.uInjuryEvaluation.LName,
			dbo.uInjuryEvaluation.Age,
			dbo.uInjuryEvaluation.Gender,
			dbo.uInjuryEvaluation.Grade,
			dbo.uInjuryEvaluation.ParentEmailAddr,
			dbo.uInjuryEvaluation.SchoolList,
			dbo.uInjuryEvaluation.Sport,
			dbo.uInjuryEvaluation.LRB,
			dbo.uInjuryEvaluation.BodyArea,
			dbo.uInjuryEvaluation.BodyPart,
			dbo.uInjuryEvaluation.Site,
			dbo.uInjuryEvaluation.Classification,
			dbo.uInjuryEvaluation.Assessment,
			dbo.uInjuryEvaluation.ObjComments,
			dbo.uInjuryEvaluation.InjuryID,
			dbo.uInjuryEvaluation.StudentID,
			dbo.uInjuryEvaluation.OnsetOtherCheck,
			dbo.uInjuryEvaluation.RecordDate,
			dbo.uMedicalReferrals.SourceAP,
			dbo.uMedicalReferrals.Type,
			dbo.uMedicalReferrals.OVAppt,
			dbo.uMedicalReferrals.Location1,
			dbo.uMedicalReferrals.Physician1,
			dbo.uMedicalReferrals.Location2,
			dbo.uMedicalReferrals.Physician2,
			dbo.uMedicalReferrals.Location3,
			dbo.uMedicalReferrals.Physician3,
			dbo.uMedicalReferrals.Notes,
			dbo.uPlanRecommendations.ManagementRecommendations,
			dbo.uPlanRecommendations.ActivityLevel,
			dbo.uPlanRecommendations.Limit_Restrictions,
			dbo.uPlanRecommendations.Limit_RestrictionDesc,
			dbo.uPlanRecommendations.TreatmentTherapy,
			dbo.uPlanRecommendations.Protection_Tape,
			dbo.uPlanRecommendations.Protection_Brace,
			dbo.uPlanRecommendations.Protection_Pad,
			dbo.uPlanRecommendations.Protection_Splint,
			dbo.uPlanRecommendations.Comments,
			dbo.uSurgicalProcedures.SurgicalProcedure,
			dbo.uSurgicalProcedures.Hospital,
			dbo.uSurgicalProcedures.Rehab,
			dbo.uSurgicalProcedures.Notes AS Expr1,
			dbo.uRevenueTracking.AmountBilled,
			dbo.uRevenueTracking.AmountCollected,
			dbo.uInjuryEvaluation.RecordID
			--INTO dbo.RptAthleticInjuryTable
			FROM dbo.uInjuryEvaluation
			INNER JOIN dbo.uMedicalReferrals ON dbo.uInjuryEvaluation.EvaluationID = dbo.uMedicalReferrals.EvaluationID
			INNER JOIN dbo.uPlanRecommendations ON dbo.uInjuryEvaluation.EvaluationID = dbo.uPlanRecommendations.EvaluationID
			INNER JOIN dbo.uRevenueTracking ON dbo.uInjuryEvaluation.EvaluationID = dbo.uRevenueTracking.EvaluationID
			INNER JOIN dbo.uSurgicalProcedures ON dbo.uInjuryEvaluation.EvaluationID = dbo.uSurgicalProcedures.EvaluationID
			WHERE dbo.uInjuryEvaluation.EvaluationDate between @BegDate and DateAdd(dd, 1,@EndDate)
			AND dbo.uInjuryEvaluation.SchoolList = @SchoolName
			AND dbo.uInjuryEvaluation.EvaluationID = @EvalID
		</sql>
	   </script>
	
</dbscripts>
