IF EXISTS(SELECT * FROM	sys.columns 
		WHERE	Name = N'generalSymptoms'
				AND Object_ID = Object_ID(N'pal_MedicalPatientHistory'))
BEGIN
	ALTER TABLE pal_MedicalPatientHistory DROP COLUMN generalSymptoms;
END

IF EXISTS(SELECT * FROM	sys.columns 
		WHERE	Name = N'drugsTaken'
				AND Object_ID = Object_ID(N'pal_MedicalPatientHistory'))
BEGIN
	ALTER TABLE pal_MedicalPatientHistory DROP COLUMN drugsTaken;
END

IF EXISTS(SELECT * FROM	sys.columns 
		WHERE	Name = N'compaintId'
				AND Object_ID = Object_ID(N'pal_MedicalPatientSubjectivesLog'))
BEGIN
	EXEC sp_RENAME 'pal_MedicalPatientSubjectivesLog.compaintId', 'complaintId', 'COLUMN'
END

IF EXISTS(SELECT * FROM	sys.columns 
		WHERE	Name = N'surfaceItemId'
				AND Object_ID = Object_ID(N'pal_MedicalPatientVisitLog'))
BEGIN
	EXEC sp_RENAME 'pal_MedicalPatientVisitLog.surfaceItemId', 'userId', 'COLUMN'
END

IF NOT EXISTS(SELECT * FROM	sys.columns 
		WHERE	Name = N'note'
				AND Object_ID = Object_ID(N'pal_MedicalPatientVisitLog'))
BEGIN
	ALTER TABLE pal_MedicalPatientVisitLog
			ADD note VARCHAR(500);
END

IF NOT EXISTS(SELECT * FROM	sys.columns 
		WHERE	Name = N'userDisplay'
				AND Object_ID = Object_ID(N'pal_User'))
BEGIN
	ALTER TABLE pal_User
			ADD userDisplay AS ((name + ' ') + surname);
END

IF  NOT EXISTS (SELECT * FROM sys.objects 
WHERE object_id = OBJECT_ID(N'[dbo].[pal_MedicalPatientSymptom]') AND type in (N'U'))
BEGIN
	CREATE TABLE [dbo].[pal_MedicalPatientSymptom] (
		[recId]         INT           IDENTITY (1, 1) NOT NULL,
		[surfaceItemId] INT           NULL,
		[symptoms]      VARCHAR (500) NULL,
		[drugsTaken]    VARCHAR (500) NULL,
		CONSTRAINT [PK_pal_MedicalPatientSymptom] PRIMARY KEY CLUSTERED ([recId] ASC)
	);
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_GetSurfaceData]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_GetSurfaceData]
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_GetSurfaceDataAll]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_GetSurfaceDataAll]
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_GetSurfaceItemData]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_GetSurfaceItemData]
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_GetSurfaceItemGridData]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_GetSurfaceItemGridData]
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_GetSubjectivesAndNotesBySurfaceItemId]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_GetSubjectivesAndNotesBySurfaceItemId]
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_GetSubjectivesBySurfaceItemId]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_GetSubjectivesBySurfaceItemId]
END

IF EXISTS (SELECT * FROM sys.views WHERE name = 'v_MedicalPatientSubjectiveDetails')
BEGIN
	DROP VIEW v_MedicalPatientSubjectiveDetails
END