How to implement user hierarchy with different levels of roles under different branches, groups etc
Have you looked at Organic Groups.

Im using it for a similar use-case. I would allow you to create content types that can act as 'Departments' and add different roles within those.

You can have for example:


'department' content types with following roles: admin, supervisor
'branch' content type with completely different roles: it programmer, temp


It is very flexible and access control works with views as well. Nice tutorial can be found here.

If you opt to however to write your custom access control module, make sure that you read up on that here

Hope that helps.