truncate table RoleActions;


declare @RoleActions table(
	[RoleId] [int] NOT NULL,
	actionid [int] NOT NULL,
	[Scope] [nvarchar](500) NULL
)

/*,Warehouse technician',*/ insert into @RoleActions (roleid,ActionId,scope) select r.id,g.id,null from roles r , RoleActionTypes g where r.guid='F1C4B065-85CF-46C3-B262-E4FE26D9BA58' and g.guid in (
'12BB55A5-EE3D-4759-8147-93C1F6130367',
'154260C0-7EAE-4CA6-8D37-0BD9B687419D',
'214A539A-2C0E-4761-8551-866D95DDC85A',
'8A5D98C8-9494-4701-A4B0-7B25E36B0E19',
'C77E1B9C-C59C-4003-AC35-31C1E3E4FED2',
'87EC56A0-AAB1-41B5-AB64-3C6A6D5D89E7',
'81F0E2D1-C469-4A55-AF24-1A4BB61C5B6F',
'BBA77A57-7B06-4503-8838-A48692A4EF4D',
'19D4B799-274B-449C-9172-570663382D68',
'7345D7FE-850B-4002-B960-202131CD7ECE',
'51051E8D-64E9-43DE-8A8B-E94D21F26943',
'7941180F-A491-4A04-8589-55E565BC317E',
'27850967-76A7-455B-AF03-7FE02D1580F8',
'76086A65-F1F4-4E09-A5BC-F0C915B2A608',
'86EAECDA-918A-48EC-B3EC-49D3FEB3F492',
'47D32A00-EE97-44C5-957F-45654C8A27CD',
'B525BA9B-7A94-4B69-B03C-A6D61BFE133A')

/*,Technician',*/ insert into @RoleActions (roleid,ActionId,scope) select r.id,g.id,null from roles r , RoleActionTypes g where r.guid='A508E668-94BC-4076-A8EE-972ADAD06E64' and g.guid in (
'12BB55A5-EE3D-4759-8147-93C1F6130367',
'214A539A-2C0E-4761-8551-866D95DDC85A',
'8A5D98C8-9494-4701-A4B0-7B25E36B0E19',
'C77E1B9C-C59C-4003-AC35-31C1E3E4FED2',
'87EC56A0-AAB1-41B5-AB64-3C6A6D5D89E7',
'51051E8D-64E9-43DE-8A8B-E94D21F26943',
'86EAECDA-918A-48EC-B3EC-49D3FEB3F492',
'1EBA1260-C867-47C0-90AD-E1F1372E4878',
'47D32A00-EE97-44C5-957F-45654C8A27CD',
'B525BA9B-7A94-4B69-B03C-A6D61BFE133A')

/*,Support',*/ insert into @RoleActions (roleid,ActionId,scope) select r.id,g.id,null from roles r , RoleActionTypes g where r.guid='14665214-632A-4729-B22B-892CC31B1894' and g.guid in (
'12BB55A5-EE3D-4759-8147-93C1F6130367',
'154260C0-7EAE-4CA6-8D37-0BD9B687419D',
'214A539A-2C0E-4761-8551-866D95DDC85A',
'8A5D98C8-9494-4701-A4B0-7B25E36B0E19',
'C77E1B9C-C59C-4003-AC35-31C1E3E4FED2',
'87EC56A0-AAB1-41B5-AB64-3C6A6D5D89E7',
'81F0E2D1-C469-4A55-AF24-1A4BB61C5B6F',
'BBA77A57-7B06-4503-8838-A48692A4EF4D',
'19D4B799-274B-449C-9172-570663382D68',
'7345D7FE-850B-4002-B960-202131CD7ECE',
'51051E8D-64E9-43DE-8A8B-E94D21F26943',
'7941180F-A491-4A04-8589-55E565BC317E',
'27850967-76A7-455B-AF03-7FE02D1580F8',
'96639387-41E7-4D17-97D8-F5B71277201B',
'76086A65-F1F4-4E09-A5BC-F0C915B2A608',
'E956D023-A3AB-47A2-B3BC-6BFF99337B10',
'27061901-5A98-4754-90E5-2D46243E5050',
'BC09021F-6411-45D1-8BB2-752BC8D0495F',
'0C9D3EA6-DF44-4ACD-A854-06EC8EE6A2E9',
'C216EC25-4665-48D3-83CC-ED85FF3AFE95',
'86EAECDA-918A-48EC-B3EC-49D3FEB3F492',
'1EBA1260-C867-47C0-90AD-E1F1372E4878',
'47D32A00-EE97-44C5-957F-45654C8A27CD',
'B525BA9B-7A94-4B69-B03C-A6D61BFE133A')

/*,Admin',*/ insert into @RoleActions (roleid,ActionId,scope) select r.id,g.id,null from roles r , RoleActionTypes g where r.guid='62FD0F19-43D8-4F1E-B7C7-57A8D17A0131' and g.guid in (
'641087C9-A7EE-45FE-AA93-893707FD8A18',
'31D95CBB-B341-410A-B8B7-FD7A9685273E',
'12BB55A5-EE3D-4759-8147-93C1F6130367',
'154260C0-7EAE-4CA6-8D37-0BD9B687419D',
'214A539A-2C0E-4761-8551-866D95DDC85A',
'8A5D98C8-9494-4701-A4B0-7B25E36B0E19',
'C77E1B9C-C59C-4003-AC35-31C1E3E4FED2',
'87EC56A0-AAB1-41B5-AB64-3C6A6D5D89E7',
'81F0E2D1-C469-4A55-AF24-1A4BB61C5B6F',
'BBA77A57-7B06-4503-8838-A48692A4EF4D',
'19D4B799-274B-449C-9172-570663382D68',
'7345D7FE-850B-4002-B960-202131CD7ECE',
'51051E8D-64E9-43DE-8A8B-E94D21F26943',
'7941180F-A491-4A04-8589-55E565BC317E',
'27850967-76A7-455B-AF03-7FE02D1580F8',
'96639387-41E7-4D17-97D8-F5B71277201B',
'76086A65-F1F4-4E09-A5BC-F0C915B2A608',
'E956D023-A3AB-47A2-B3BC-6BFF99337B10',
'27061901-5A98-4754-90E5-2D46243E5050',
'BC09021F-6411-45D1-8BB2-752BC8D0495F',
'0C9D3EA6-DF44-4ACD-A854-06EC8EE6A2E9',
'1EBA1260-C867-47C0-90AD-E1F1372E4878',
'47D32A00-EE97-44C5-957F-45654C8A27CD',
'B525BA9B-7A94-4B69-B03C-A6D61BFE133A')


/*,Organization Admin',*/ insert into @RoleActions (roleid,ActionId,scope) select r.id,g.id,null from roles r , RoleActionTypes g where r.guid='1BF4E983-EC11-4A4C-B02B-8F2F7631DAA9' and g.guid in (
'641087C9-A7EE-45FE-AA93-893707FD8A18',
'49A6B509-9C5F-409A-9469-176496E9C80A',
'31D95CBB-B341-410A-B8B7-FD7A9685273E',
'1AC1C216-7403-4657-B968-E96FC5D0D53A',
'12BB55A5-EE3D-4759-8147-93C1F6130367',
'154260C0-7EAE-4CA6-8D37-0BD9B687419D',
'214A539A-2C0E-4761-8551-866D95DDC85A',
'8A5D98C8-9494-4701-A4B0-7B25E36B0E19',
'C77E1B9C-C59C-4003-AC35-31C1E3E4FED2',
'87EC56A0-AAB1-41B5-AB64-3C6A6D5D89E7',
'81F0E2D1-C469-4A55-AF24-1A4BB61C5B6F',
'BBA77A57-7B06-4503-8838-A48692A4EF4D',
'19D4B799-274B-449C-9172-570663382D68',
'7345D7FE-850B-4002-B960-202131CD7ECE',
'51051E8D-64E9-43DE-8A8B-E94D21F26943',
'7941180F-A491-4A04-8589-55E565BC317E',
'27850967-76A7-455B-AF03-7FE02D1580F8',
'96639387-41E7-4D17-97D8-F5B71277201B',
'76086A65-F1F4-4E09-A5BC-F0C915B2A608',
'E956D023-A3AB-47A2-B3BC-6BFF99337B10',
'27061901-5A98-4754-90E5-2D46243E5050',
'BC09021F-6411-45D1-8BB2-752BC8D0495F',
'0C9D3EA6-DF44-4ACD-A854-06EC8EE6A2E9',
'1EBA1260-C867-47C0-90AD-E1F1372E4878',
'47D32A00-EE97-44C5-957F-45654C8A27CD',
'B525BA9B-7A94-4B69-B03C-A6D61BFE133A')


/*,System admin',*/ insert into @RoleActions (roleid,ActionId,scope) select r.id,g.id,null from roles r , RoleActionTypes g where r.guid='0E9CB844-06B6-4AEA-A0DC-0FC17EE71BE2' and g.guid in (
'641087C9-A7EE-45FE-AA93-893707FD8A18',
'49A6B509-9C5F-409A-9469-176496E9C80A',
'31D95CBB-B341-410A-B8B7-FD7A9685273E',
'1AC1C216-7403-4657-B968-E96FC5D0D53A',
'12BB55A5-EE3D-4759-8147-93C1F6130367',
'154260C0-7EAE-4CA6-8D37-0BD9B687419D',
'214A539A-2C0E-4761-8551-866D95DDC85A',
'8A5D98C8-9494-4701-A4B0-7B25E36B0E19',
'C77E1B9C-C59C-4003-AC35-31C1E3E4FED2',
'87EC56A0-AAB1-41B5-AB64-3C6A6D5D89E7',
'81F0E2D1-C469-4A55-AF24-1A4BB61C5B6F',
'BBA77A57-7B06-4503-8838-A48692A4EF4D',
'19D4B799-274B-449C-9172-570663382D68',
'7345D7FE-850B-4002-B960-202131CD7ECE',
'51051E8D-64E9-43DE-8A8B-E94D21F26943',
'7941180F-A491-4A04-8589-55E565BC317E',
'27850967-76A7-455B-AF03-7FE02D1580F8',
'96639387-41E7-4D17-97D8-F5B71277201B',
'76086A65-F1F4-4E09-A5BC-F0C915B2A608',
'E956D023-A3AB-47A2-B3BC-6BFF99337B10',
'27061901-5A98-4754-90E5-2D46243E5050',
'BC09021F-6411-45D1-8BB2-752BC8D0495F',
'0C9D3EA6-DF44-4ACD-A854-06EC8EE6A2E9',
'C216EC25-4665-48D3-83CC-ED85FF3AFE95',
'86EAECDA-918A-48EC-B3EC-49D3FEB3F492',
'28DEAEA4-895D-4C48-A2D5-0C0E49126739',
'37D22628-42ED-40F2-A531-116CA46BD1FA',
'1EBA1260-C867-47C0-90AD-E1F1372E4878',
'47D32A00-EE97-44C5-957F-45654C8A27CD',
'B525BA9B-7A94-4B69-B03C-A6D61BFE133A')


/*,Caregiver',*/ insert into @RoleActions (roleid,ActionId,scope) select r.id,g.id,'AssociatedAccounts' from roles r , RoleActionTypes g where r.guid='D0275602-E7DF-420F-9E29-77AF67A7B844' and g.guid in (
'214A539A-2C0E-4761-8551-866D95DDC85A',
'C77E1B9C-C59C-4003-AC35-31C1E3E4FED2',
'86EAECDA-918A-48EC-B3EC-49D3FEB3F492')
/*,Caregiver',*/ insert into @RoleActions (roleid,ActionId,scope) select r.id,g.id,null from roles r , RoleActionTypes g where r.guid='D0275602-E7DF-420F-9E29-77AF67A7B844' and g.guid in (
'1EBA1260-C867-47C0-90AD-E1F1372E4878',
'47D32A00-EE97-44C5-957F-45654C8A27CD',
'B525BA9B-7A94-4B69-B03C-A6D61BFE133A')


/*,Health proffesional',*/ insert into @RoleActions (roleid,ActionId,scope) select r.id,g.id,'AssociatedAccounts' from roles r , RoleActionTypes g where r.guid='B7B24D8B-3ACE-4B6B-8581-6ABD4375470A' and g.guid in (
'C77E1B9C-C59C-4003-AC35-31C1E3E4FED2',
'28DEAEA4-895D-4C48-A2D5-0C0E49126739')


/*,Physician',*/ insert into @RoleActions (roleid,ActionId,scope) select r.id,g.id,'AssociatedAccounts' from roles r , RoleActionTypes g where r.guid='D4F9CE6E-C39F-4179-B2FB-A02F2E4C86B6' and g.guid in (
'12BB55A5-EE3D-4759-8147-93C1F6130367',
'214A539A-2C0E-4761-8551-866D95DDC85A',
'C77E1B9C-C59C-4003-AC35-31C1E3E4FED2',
'28DEAEA4-895D-4C48-A2D5-0C0E49126739',
'37D22628-42ED-40F2-A531-116CA46BD1FA')


/*,Medical admin',*/ insert into @RoleActions (roleid,ActionId,scope) select r.id,g.id,null from roles r , RoleActionTypes g where r.guid='A6B2BFC3-D2E0-4496-81D0-224F77085DA5' and g.guid in (
'12BB55A5-EE3D-4759-8147-93C1F6130367',
'214A539A-2C0E-4761-8551-866D95DDC85A',
'C77E1B9C-C59C-4003-AC35-31C1E3E4FED2',
'E956D023-A3AB-47A2-B3BC-6BFF99337B10',
'27061901-5A98-4754-90E5-2D46243E5050',
'BC09021F-6411-45D1-8BB2-752BC8D0495F',
'C216EC25-4665-48D3-83CC-ED85FF3AFE95',
'86EAECDA-918A-48EC-B3EC-49D3FEB3F492',
'28DEAEA4-895D-4C48-A2D5-0C0E49126739',
'37D22628-42ED-40F2-A531-116CA46BD1FA')






MERGE INTO [dbo].RoleActions AS TARGET
USING @RoleActions AS SOURCE
	ON TARGET.roleid = SOURCE.roleid
	and TARGET.ActionId= SOURCE.ActionId
	WHEN MATCHED THEN    
			UPDATE SET scope=source.scope
	WHEN NOT MATCHED BY TARGET THEN   
			INSERT ( roleid,ActionId,scope) VALUES (Source.roleid,Source.ActionId,Source.scope)  
OUTPUT $action, SOURCE.*;
