<?xml version="1.0" encoding="utf-8" ?>

<dbscripts>
	<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>
	</script>
	<script>
		<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>
		<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>
</dbscripts>
