
declare @RoleAuthorizationActions table(
	actionid int NOT NULL,
	groupid int not NULL
)

--Read organization unit
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='572D45DE-1302-4940-AD3F-1F6556BC5F19' and a.guid in ('641087C9-A7EE-45FE-AA93-893707FD8A18')

--'CUD organization unit'
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='6E0A37F5-58FD-43D0-AC97-4FBC19FE664D' and a.guid in ('49A6B509-9C5F-409A-9469-176496E9C80A','31D95CBB-B341-410A-B8B7-FD7A9685273E','1AC1C216-7403-4657-B968-E96FC5D0D53A')

--'CRUD device (CP)'
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='ED65F06B-4DE4-4B3B-9E7B-AA3849362A16' and a.guid in ('12BB55A5-EE3D-4759-8147-93C1F6130367','214A539A-2C0E-4761-8551-866D95DDC85A','8A5D98C8-9494-4701-A4B0-7B25E36B0E19')

--'Read device',						
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='B47D02CF-F595-4652-80C4-8F8C34DE8C2E' and a.guid in ('C77E1B9C-C59C-4003-AC35-31C1E3E4FED2')

--'Edit device configuration',		
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='BC6EAC6C-0C91-4169-A2C2-33AE54902E60' and a.guid in ('51051E8D-64E9-43DE-8A8B-E94D21F26943','7941180F-A491-4A04-8589-55E565BC317E')

--'Send command',						
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='80F67FCE-680C-4FD5-BA74-C91A4EBFFAD8' and a.guid in ('81F0E2D1-C469-4A55-AF24-1A4BB61C5B6F','BBA77A57-7B06-4503-8838-A48692A4EF4D','19D4B799-274B-449C-9172-570663382D68','7345D7FE-850B-4002-B960-202131CD7ECE')

--'Upload Template ',					
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='80EA898F-4712-48BF-A7BA-82FFA2905AA1' and a.guid in ('27850967-76A7-455B-AF03-7FE02D1580F8')

--'Perform batch',					
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='1DB93246-E71B-4004-ACAA-F0DC4EF94690' and a.guid in ('96639387-41E7-4D17-97D8-F5B71277201B')

--'CRUD staff',						
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='5A0FBC1D-C7DD-4C5B-801D-BCE7A0E276A1' and a.guid in ('E956D023-A3AB-47A2-B3BC-6BFF99337B10','27061901-5A98-4754-90E5-2D46243E5050','BC09021F-6411-45D1-8BB2-752BC8D0495F','0C9D3EA6-DF44-4ACD-A854-06EC8EE6A2E9')

--'Create user (resident)',			
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='44E26B50-C07B-4480-9CBD-7C3576D7D014' and a.guid in ('27061901-5A98-4754-90E5-2D46243E5050')

--'Read user (resident)',				
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='6ADC970A-7319-45DF-82C9-CF6AAAC5449C' and a.guid in ('E956D023-A3AB-47A2-B3BC-6BFF99337B10')

--'Update user (resident)',			
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='C2E85DBA-D1EB-4FFE-89AF-01D07A4BD56D' and a.guid in ('BC09021F-6411-45D1-8BB2-752BC8D0495F')

--'Delete user (resident)',			
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='6BDC7B82-1142-4327-97F0-40FCCAF795F1' and a.guid in ('0C9D3EA6-DF44-4ACD-A854-06EC8EE6A2E9')

--'Export CV reports ',				
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='E4E43600-DA93-435F-8EE9-49DF3BEB89C7' and a.guid in ('C216EC25-4665-48D3-83CC-ED85FF3AFE95')

--'Monitoring ',						
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='BEBDA7CF-A6BF-4621-9E7A-0BEDDE55526C' and a.guid in ('86EAECDA-918A-48EC-B3EC-49D3FEB3F492')

--'Clinical monitoring',				
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='519B59BD-5E6A-4688-8159-E80AC7932A36' and a.guid in ('28DEAEA4-895D-4C48-A2D5-0C0E49126739')

--'Edit thresholds ',					
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='5323738B-E3AB-4F1B-8832-4DB062FDED08' and a.guid in ('37D22628-42ED-40F2-A531-116CA46BD1FA')

--'FIT',								
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='F6CA26B0-BA14-4681-8B15-EC1CC9804386' and a.guid in ('1EBA1260-C867-47C0-90AD-E1F1372E4878')

--'Family/Pro Rules',					
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='FBF64DE8-BE89-40D4-9A3F-30567186AB36' and a.guid in ('47D32A00-EE97-44C5-957F-45654C8A27CD','B525BA9B-7A94-4B69-B03C-A6D61BFE133A')

--'Save Template',								
insert into @RoleAuthorizationActions (actionid,groupid)
select a.id,g.id from roleactiontypes a , RoleAuthorizationGroupTypes g where g.guid ='2CAE9C2D-802A-42B9-9ADA-45A1C5433A36' and a.guid in ('76086A65-F1F4-4E09-A5BC-F0C915B2A608')


MERGE INTO [dbo].RoleAuthorizationActions AS TARGET
USING @RoleAuthorizationActions AS SOURCE
	ON TARGET.actionid = SOURCE.actionid and TARGET.groupid = SOURCE.groupid
	WHEN NOT MATCHED BY TARGET THEN   
			INSERT ( actionid,groupid) VALUES (Source.actionid, SOURCE.groupid)  
OUTPUT $action, SOURCE.*;

