DECLARE @GroupId int;
DECLARE @UserId int;
DECLARE @UserId1 int;
DECLARE @UserId2 int;
DECLARE @UserId3 int;
DECLARE @UserId4 int;
DECLARE @UserId5 int;
DEClARE @UserId6 int;
DEClARE @UserId7 int;
DEClARE @UserIdCSKH int;


	-- Admin hệ thống
SET @GroupId = (SELECT TOP 1 Id FROM [dbo].[UserGroup] WHERE Name = N'Admin hệ thống')

IF @GroupId IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroup]
			   ([Name]
			   ,[Desc])
		 VALUES
			   (N'Admin hệ thống', N'Admin hệ thống')

	SET @GroupId = SCOPE_IDENTITY();

	INSERT INTO [dbo].[GroupRole]
			   ([GroupId]
			   ,[RoleId]
			   ,[Modalities])
		 VALUES
			   (@GroupId,13,'x'),
			   (@GroupId,14,'x'),
			   (@GroupId,15,'x'),
			   (@GroupId,17,'x'),
			   (@GroupId,20,'x'),
			   (@GroupId,22,'x'),
			   (@GroupId,99,'x')
END

	-- Add Hứa Đức Lâm
SET @UserId = (SELECT TOP 1 Id FROM [dbo].[Users] WHERE [Username]='huaduclam19900042')

IF @UserId IS NULL
BEGIN
	INSERT INTO [dbo].[Users]
			   ([Fullname]
			   ,[Username]
			   ,[Email]
			   ,[PhoneNo]
			   ,[MSAId]
			   ,[IsAdmin]
			   ,[ApproveConfig]
			   ,[IsDemo]
			   ,[IsManager]
			   ,[StudyEditable]
			   ,[HISCode])
		 VALUES
			   (N'Hứa Đức Lâm', 'huaduclam19900042', NULL, NULL, '5959f72b9ce8d90e4c70f7ce', 1, 0, 0, 0, 0, NULL)

	SET @UserId = SCOPE_IDENTITY();

	INSERT INTO [dbo].[UserRole]
           ([UserId]
           ,[RoleId]
           ,[Modalities])
     VALUES
           (@UserId,1,'x'),
			(@UserId,2,'ALL'),
			(@UserId,3,'ALL'),
			(@UserId,4,'ALL'),
			(@UserId,5,'ALL'),
			(@UserId,13,'x'),
			(@UserId,14,'x'),
			(@UserId,15,'x'),
			(@UserId,16,'x'),
			(@UserId,17,'x'),
			(@UserId,18,'x'),
			(@UserId,19,'x'),
			(@UserId,20,'x'),
			(@UserId,21,'x'),
			(@UserId,22,'x'),
			(@UserId,99,'x')
END

IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId)
END

	-- Add Pham Thu Hien
SET @UserId4 = (SELECT TOP 1 Id FROM [dbo].[Users] WHERE [Username]='hienptt')

IF @UserId4 IS NULL
BEGIN
	INSERT INTO [dbo].[Users]
			   ([Fullname]
			   ,[Username]
			   ,[Email]
			   ,[PhoneNo]
			   ,[MSAId]
			   ,[IsAdmin]
			   ,[ApproveConfig]
			   ,[IsDemo]
			   ,[IsManager]
			   ,[StudyEditable]
			   ,[HISCode])
		 VALUES
			   (N'Phạm Thu Hiền', 'hienptt', NULL, NULL, '5dddf921b85ff19c7c13d441', 1, 0, 0, 0, 0, NULL)

	SET @UserId4 = SCOPE_IDENTITY();

	INSERT INTO [dbo].[UserRole]
           ([UserId]
           ,[RoleId]
           ,[Modalities])
     VALUES
           (@UserId4,1,'x'),
			(@UserId4,2,'ALL'),
			(@UserId4,3,'ALL'),
			(@UserId4,4,'ALL'),
			(@UserId4,5,'ALL'),
			(@UserId4,13,'x'),
			(@UserId4,14,'x'),
			(@UserId4,15,'x'),
			(@UserId4,16,'x'),
			(@UserId4,17,'x'),
			(@UserId4,18,'x'),
			(@UserId4,19,'x'),
			(@UserId4,20,'x'),
			(@UserId4,21,'x'),
			(@UserId4,22,'x'),
			(@UserId4,99,'x')
END

IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId4) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId4)
END

	-- Add Đỗ Hữu Phúc
SET @UserId5 = (SELECT TOP 1 Id FROM [dbo].[Users] WHERE [Username]='phucdh')

IF @UserId5 IS NULL
BEGIN
	INSERT INTO [dbo].[Users]
			   ([Fullname]
			   ,[Username]
			   ,[Email]
			   ,[PhoneNo]
			   ,[MSAId]
			   ,[IsAdmin]
			   ,[ApproveConfig]
			   ,[IsDemo]
			   ,[IsManager]
			   ,[StudyEditable]
			   ,[HISCode])
		 VALUES
			   (N'Đỗ Hữu Phúc', 'phucdh', NULL, NULL, '5bce9d4eb85fbc07b45dd855', 1, 0, 0, 0, 0, NULL)

	SET @UserId5 = SCOPE_IDENTITY();

	INSERT INTO [dbo].[UserRole]
           ([UserId]
           ,[RoleId]
           ,[Modalities])
     VALUES
           (@UserId5,1,'x'),
			(@UserId5,2,'ALL'),
			(@UserId5,3,'ALL'),
			(@UserId5,4,'ALL'),
			(@UserId5,5,'ALL'),
			(@UserId5,13,'x'),
			(@UserId5,14,'x'),
			(@UserId5,15,'x'),
			(@UserId5,16,'x'),
			(@UserId5,17,'x'),
			(@UserId5,18,'x'),
			(@UserId5,19,'x'),
			(@UserId5,20,'x'),
			(@UserId5,21,'x'),
			(@UserId5,22,'x'),
			(@UserId5,99,'x')
END

IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId5) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId5)
END

	-- Add Nguyễn Quang Sáng
SET @UserId6 = (SELECT TOP 1 Id FROM [dbo].[Users] WHERE [Username]='mesoco.alert')

IF @UserId6 IS NULL
BEGIN
	INSERT INTO [dbo].[Users]
			   ([Fullname]
			   ,[Username]
			   ,[Email]
			   ,[PhoneNo]
			   ,[MSAId]
			   ,[IsAdmin]
			   ,[ApproveConfig]
			   ,[IsDemo]
			   ,[IsManager]
			   ,[StudyEditable]
			   ,[HISCode])
		 VALUES
			   (N'Nguyễn Quang Sáng', 'mesoco.alert', NULL, NULL, '5ca709adb85fb882f4c83e40', 1, 0, 0, 0, 0, NULL)

	SET @UserId6 = SCOPE_IDENTITY();

	INSERT INTO [dbo].[UserRole]
           ([UserId]
           ,[RoleId]
           ,[Modalities])
     VALUES
			(@UserId6,1,'x'),
			(@UserId6,2,'ALL'),
			(@UserId6,3,'ALL'),
			(@UserId6,4,'ALL'),
			(@UserId6,5,'ALL'),
			(@UserId6,13,'x'),
			(@UserId6,14,'x'),
			(@UserId6,15,'x'),
			(@UserId6,16,'x'),
			(@UserId6,17,'x'),
			(@UserId6,18,'x'),
			(@UserId6,19,'x'),
			(@UserId6,20,'x'),
			(@UserId6,21,'x'),
			(@UserId6,22,'x'),
			(@UserId6,99,'x')
END

IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId6) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId6)
END

	-- Add Phạm Lê Thanh Sơn
SET @UserId7 = (SELECT TOP 1 Id FROM [dbo].[Users] WHERE [Username]='sonplt')

IF @UserId7 IS NULL
BEGIN
	INSERT INTO [dbo].[Users]
			   ([Fullname]
			   ,[Username]
			   ,[Email]
			   ,[PhoneNo]
			   ,[MSAId]
			   ,[IsAdmin]
			   ,[ApproveConfig]
			   ,[IsDemo]
			   ,[IsManager]
			   ,[StudyEditable]
			   ,[HISCode])
		 VALUES
			   (N'Phạm Lê Thanh Sơn', 'sonplt', 'sonplt@gmail.com', NULL, '5b498a59edcd7555cccf52d7', 1, 0, 0, 0, 0, NULL)

	SET @UserId7 = SCOPE_IDENTITY();

	INSERT INTO [dbo].[UserRole]
           ([UserId]
           ,[RoleId]
           ,[Modalities])
     VALUES
			(@UserId7,1,'x'),
			(@UserId7,2,'ALL'),
			(@UserId7,3,'ALL'),
			(@UserId7,4,'ALL'),
			(@UserId7,5,'ALL'),
			(@UserId7,13,'x'),
			(@UserId7,14,'x'),
			(@UserId7,15,'x'),
			(@UserId7,16,'x'),
			(@UserId7,17,'x'),
			(@UserId7,18,'x'),
			(@UserId7,19,'x'),
			(@UserId7,20,'x'),
			(@UserId7,21,'x'),
			(@UserId7,22,'x'),
			(@UserId7,99,'x')
END

IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId7) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId7)
END

	-- Add CSKH
SET @UserIdCSKH = (SELECT TOP 1 Id FROM [dbo].[Users] WHERE [Username]='cskh')

IF @UserIdCSKH IS NULL
BEGIN
	INSERT INTO [dbo].[Users]
			   ([Fullname]
			   ,[Username]
			   ,[Email]
			   ,[PhoneNo]
			   ,[MSAId]
			   ,[IsAdmin]
			   ,[ApproveConfig]
			   ,[IsDemo]
			   ,[IsManager]
			   ,[StudyEditable]
			   ,[HISCode])
		 VALUES
			   (N'CSKH', 'cskh', 'admincskh@pmr.vn', NULL, '6077ed4e8f618b1358dcb82d', 1, 0, 0, 0, 0, NULL)

	SET @UserIdCSKH = SCOPE_IDENTITY();

	INSERT INTO [dbo].[UserRole]
           ([UserId]
           ,[RoleId]
           ,[Modalities])
     VALUES
			(@UserIdCSKH,1,'x'),
			(@UserIdCSKH,2,'ALL'),
			(@UserIdCSKH,3,'ALL'),
			(@UserIdCSKH,4,'ALL'),
			(@UserIdCSKH,5,'ALL'),
			(@UserIdCSKH,13,'x'),
			(@UserIdCSKH,14,'x'),
			(@UserIdCSKH,15,'x'),
			(@UserIdCSKH,16,'x'),
			(@UserIdCSKH,17,'x'),
			(@UserIdCSKH,18,'x'),
			(@UserIdCSKH,19,'x'),
			(@UserIdCSKH,20,'x'),
			(@UserIdCSKH,21,'x'),
			(@UserIdCSKH,22,'x'),
			(@UserIdCSKH,99,'x')
END

IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserIdCSKH) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserIdCSKH)
END

-- Admin chung
SET @GroupId = (SELECT TOP 1 Id FROM [dbo].[UserGroup] WHERE Name=N'Admin chung')

IF @GroupId IS NULL
BEGIN	
	INSERT INTO [dbo].[UserGroup]
			   ([Name]
			   ,[Desc])
		 VALUES
			   ('Admin chung','ADMIN')

	SET @GroupId = SCOPE_IDENTITY();

	INSERT INTO [dbo].[GroupRole]
			   ([GroupId]
			   ,[RoleId]
			   ,[Modalities])
		 VALUES
			   (@GroupId,1,'x'),
			   (@GroupId,2,'ALL'),
			   (@GroupId,4,'ALL'),
			   (@GroupId,13,'x'),
			   (@GroupId,14,'x'),
			   (@GroupId,15,'x'),
			   (@GroupId,16,'x'),
			   (@GroupId,17,'x'),
			   (@GroupId,18,'x'),
			   (@GroupId,19,'x'),
			   (@GroupId,20,'x'),
			   (@GroupId,99,'x')
END

	-- Add Hứa Thị Du
SET @UserId1 = (SELECT TOP 1 Id FROM [dbo].[Users] WHERE [Username]='duht')

IF @UserId1 IS NULL
BEGIN
	INSERT INTO [dbo].[Users]
			   ([Fullname]
			   ,[Username]
			   ,[Email]
			   ,[PhoneNo]
			   ,[MSAId]
			   ,[IsAdmin]
			   ,[ApproveConfig]
			   ,[IsDemo]
			   ,[IsManager]
			   ,[StudyEditable]
			   ,[HISCode])
		 VALUES
			   (N'Hứa Thị Du', 'duht', NULL, NULL, '5b642407df979325c4213106', 1, 0, 0, 0, 0, NULL)

	SET @UserId1 = SCOPE_IDENTITY();

	INSERT INTO [dbo].[UserGroupMapping]
			   ([GroupId]
			   ,[UserId])
		 VALUES
			   (@GroupId,@UserId1)

	INSERT INTO [dbo].[UserRole]
			   ([UserId]
			   ,[RoleId]
			   ,[Modalities])
		 VALUES
			   (@UserId1,1,'x'),
			   (@UserId1,2,'ALL'),
			   (@UserId1,3,'ALL'),
			   (@UserId1,4,'ALL'),
			   (@UserId1,5,'ALL'),
			   (@UserId1,13,'x'),
			   (@UserId1,14,'x'),
			   (@UserId1,15,'x'),
			   (@UserId1,16,'x'),
			   (@UserId1,17,'x'),
			   (@UserId1,18,'x'),
			   (@UserId1,19,'x'),
			   (@UserId1,20,'x'),
			   (@UserId1,21,'x'),
			   (@UserId1,99,'x')
END

	-- Add Hứa Thị Lê
SET @UserId2 = (SELECT TOP 1 Id FROM [dbo].[Users] WHERE [Username]='lehttn')

IF @UserId2 IS NULL
BEGIN
	INSERT INTO [dbo].[Users]
			   ([Fullname]
			   ,[Username]
			   ,[Email]
			   ,[PhoneNo]
			   ,[MSAId]
			   ,[IsAdmin]
			   ,[ApproveConfig]
			   ,[IsDemo]
			   ,[IsManager]
			   ,[StudyEditable]
			   ,[HISCode])
		 VALUES
			   (N'Hứa Thị Lê', 'lehttn', NULL, NULL, '5adea8520cbdb513d049594f', 1, 0, 0, 0, 0, NULL)

	SET @UserId2 = SCOPE_IDENTITY();

	INSERT INTO [dbo].[UserGroupMapping]
			   ([GroupId]
			   ,[UserId])
		 VALUES
			   (@GroupId,@UserId2)

	INSERT INTO [dbo].[UserRole]
			   ([UserId]
			   ,[RoleId]
			   ,[Modalities])
		 VALUES
			   (@UserId2,1,'x'),
			   (@UserId2,2,'ALL'),
			   (@UserId2,3,'ALL'),
			   (@UserId2,4,'ALL'),
			   (@UserId2,5,'ALL'),
			   (@UserId2,13,'x'),
			   (@UserId2,14,'x'),
			   (@UserId2,15,'x'),
			   (@UserId2,16,'x'),
			   (@UserId2,17,'x'),
			   (@UserId2,18,'x'),
			   (@UserId2,19,'x'),
			   (@UserId2,20,'x'),
			   (@UserId2,21,'x'),
			   (@UserId2,99,'x')
END

-- Add Hứa Đức Lâm
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId)
END

-- Add Pham Thu Hien
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId4) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId4)
END

-- Add Đỗ Hữu Phúc
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId5) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId5)
END

-- Add Nguyễn Quang Sáng
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId6) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId6)
END

-- Add Phạm Lê Thanh Sơn
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId7) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId7)
END

-- Add CSKH
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserIdCSKH) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserIdCSKH)
END

-- IT bệnh viện
SET @GroupId = (SELECT TOP 1 Id FROM [dbo].[UserGroup] WHERE Name=N'IT bệnh viện')

IF @GroupId IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroup]
			   ([Name]
			   ,[Desc])
		 VALUES
			   (N'IT bệnh viện',N'IT bệnh viện')

	SET @GroupId = SCOPE_IDENTITY();

	INSERT INTO [dbo].[GroupRole]
			   ([GroupId]
			   ,[RoleId]
			   ,[Modalities])
		 VALUES
			   (@GroupId,2,'ALL'),
			   (@GroupId,4,'ALL'),
			   (@GroupId,14,'x'),
			   (@GroupId,17,'x'),
			   (@GroupId,99,'x')
END

	-- Bác sĩ chẩn đoán hình ảnh
SET @GroupId = (SELECT TOP 1 Id FROM [dbo].[UserGroup] WHERE Name=N'Bác sĩ CĐHA')

IF @GroupId IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroup]
			   ([Name]
			   ,[Desc])
		 VALUES
			   (N'Bác sĩ CĐHA',N'Bác sĩ chẩn đoán hình ảnh')

	SET @GroupId = SCOPE_IDENTITY();

	INSERT INTO [dbo].[GroupRole]
			   ([GroupId]
			   ,[RoleId]
			   ,[Modalities])
		 VALUES
			   (@GroupId,2,'ALL'),
			   (@GroupId,3,'ALL'),
			   (@GroupId,4,'ALL'),
			   (@GroupId,5,'ALL'),
			   (@GroupId,21,'x')
END

	-- Add Ngô Lê Lâm
SET @UserId3 = (SELECT TOP 1 Id FROM [dbo].[Users] WHERE [Username]='ngolelam')

IF @UserId3 IS NULL
BEGIN
	INSERT INTO [dbo].[Users]
			   ([Fullname]
			   ,[Username]
			   ,[Email]
			   ,[PhoneNo]
			   ,[MSAId]
			   ,[IsAdmin]
			   ,[ApproveConfig]
			   ,[IsDemo]
			   ,[IsManager]
			   ,[StudyEditable]
			   ,[HISCode])
		 VALUES
			   (N'Ngô Lê Lâm', 'ngolelam', NULL, NULL, '591d0ab09ce8d90ec8e46b07', 1, 0, 0, 0, 0, NULL)

	SET @UserId3 = SCOPE_IDENTITY();

	INSERT INTO [dbo].[UserGroupMapping]
			   ([GroupId]
			   ,[UserId])
		 VALUES
			   (@GroupId,@UserId3)

	INSERT INTO [dbo].[UserRole]
			   ([UserId]
			   ,[RoleId]
			   ,[Modalities])
		 VALUES
			   (@UserId3,2,'ALL'),
			   (@UserId3,3,'ALL'),
			   (@UserId3,4,'ALL'),
			   (@UserId3,5,'ALL'),
			   (@UserId3,21,'x')
END

-- Add Hứa Thị Du
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId1) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
			 ([GroupId]
			,[UserId])
		VALUES
			(@GroupId,@UserId1)
END

-- Add Hứa Thị Lê
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId2) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
			 ([GroupId]
			,[UserId])
		VALUES
			(@GroupId,@UserId2)
END

-- Add Hứa Đức Lâm
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId)
END

-- Add Pham Thu Hien
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId4) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId4)
END


-- Add Đỗ Hữu Phúc
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId5) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId5)
END

-- Add Nguyễn Quang Sáng
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId6) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId6)
END

-- Add Phạm Lê Thanh Sơn
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserId7) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserId7)
END

-- Add CSKH
IF (SELECT TOP 1 1 FROM [dbo].[UserGroupMapping] WHERE [GroupId] = @GroupId AND [UserId] = @UserIdCSKH) IS NULL
BEGIN
	INSERT INTO [dbo].[UserGroupMapping]
           ([GroupId]
           ,[UserId])
    VALUES
           (@GroupId,@UserIdCSKH)
END

-- Kĩ thuật viên
SET @GroupId = (SELECT 1 Id FROM [dbo].[UserGroup] WHERE Name = N'Kĩ thuật viên' )
IF @GroupId IS NULL
BEGIN
INSERT INTO [dbo].[UserGroup]
           ([Name]
           ,[Desc])
     VALUES
           (N'Kĩ thuật viên',N'Kĩ thuật viên')

SET @GroupId = SCOPE_IDENTITY();

INSERT INTO [dbo].[GroupRole]
           ([GroupId]
           ,[RoleId]
           ,[Modalities])
     VALUES
           (@GroupId,2,'ALL'),
		   (@GroupId,3,'DR, DRo, DX, CR'),
		   (@GroupId,4,'ALL'),
		   (@GroupId,5,'DR, DRo, DX, CR'),
		   (@GroupId,8,'x'),
		   (@GroupId,10,'x'),
		   (@GroupId,12,'x'),
		   (@GroupId,21,'x'),
		   (@GroupId,23,'x')
END

-- Bác sĩ lâm sàng
SET @GroupId = (SELECT 1 Id FROM [dbo].[UserGroup] WHERE Name = N'Bác sĩ lâm sàng' )
IF @GroupId IS NULL
BEGIN
INSERT INTO [dbo].[UserGroup]
           ([Name]
           ,[Desc])
     VALUES
           (N'Bác sĩ lâm sàng',N'Bác sĩ lâm sàng')

SET @GroupId = SCOPE_IDENTITY();

INSERT INTO [dbo].[GroupRole]
           ([GroupId]
           ,[RoleId]
           ,[Modalities])
     VALUES
           (@GroupId,2,'ALL')
END

-- Quản lý bệnh viện
SET @GroupId = (SELECT 1 Id FROM [dbo].[UserGroup] WHERE Name = N'Quản lý bệnh viện' )
IF @GroupId IS NULL
BEGIN
INSERT INTO [dbo].[UserGroup]
           ([Name]
           ,[Desc])
     VALUES
           (N'Quản lý bệnh viện',N'Quản lý bệnh viện')

SET @GroupId = SCOPE_IDENTITY();

INSERT INTO [dbo].[GroupRole]
           ([GroupId]
           ,[RoleId]
           ,[Modalities])
     VALUES
           (@GroupId,2,'ALL'),
		   (@GroupId,4,'ALL'),
		   (@GroupId,7,'x'),
		   (@GroupId,8,'x'),
		   (@GroupId,12,'x')
END

-- Demo
SET @GroupId = (SELECT 1 Id FROM [dbo].[UserGroup] WHERE Name = 'Demo' )
IF @GroupId IS NULL
BEGIN
INSERT INTO [dbo].[UserGroup]
           ([Name]
           ,[Desc])
     VALUES
           ('Demo','DEMO')

SET @GroupId = SCOPE_IDENTITY();

INSERT INTO [dbo].[GroupRole]
           ([GroupId]
           ,[RoleId]
           ,[Modalities])
     VALUES
           (@GroupId,2,'ALL'),
		   (@GroupId,4,'ALL'),
		   (@GroupId,6,'x')
END

-- Add user vào branch tổng ( thêm vào bảng BranchUser)
INSERT [dbo].[BranchUser]
(
[BranchId],
[UserId],
[Active]
)
VALUES 
(NULL, @UserId, 1),
(NULL, @UserId1, 1),
(NULL, @UserId2, 1),
(NULL, @UserId3, 1),
(NULL, @UserId4, 1),
(NULL, @UserId5, 1),
(NULL, @UserId6, 1),
(NULL, @UserId7, 1),
(NULL, @UserIdCSKH, 1)

GO