Hi all @dev5,
@ibacher @jdick and I have been brainstorming on Slack (here) about the least expensive way to implement access levels for cohorts. This post is an early proposal, please fire and let’s find a working consensus.
First of all there are 4 access levels that we have identified:
- View
- Edit (Ability to add/remove patients to/from the cohort.)
- Share (Ability to add/remove managing users of the cohort.)
- Delete (Ability to void the cohort.)
The question is how do we associate a cohort with its managing users?
We have come up with two separate cases that would be handled differently:
- Associating a single user;
- Associating a collection of users.
1. Associating a single user with a cohort - Through user properties
We are suggesting to do this through specially named user properties.
Example: user jdoe
can edit and share cohort ID’d f4bca462-76d1-446b-8369-f8dab42e19b3
because the following user property exists for jdoe
:
{
key: "org.openmrs.cohort.f4bca462-76d1-446b-8369-f8dab42e19b3",
value: "E+S"
}
2. Associating a collection of users with a cohort - Through cohort attributes
Let’s take the user role example. Imagine the use case that all users sharing the role Covid-19 Contact Tracer
can edit and delete the cohort ID’d f4bca462-76d1-446b-8369-f8dab42e19b3
.
This would be done through a cohort attribute whose value would be structured like this:
{
strategy: "org.openmrs.cohort.RoleMappingStrategy",
entity: "a3265110-b90b-474e-8f4b-c5a8fdf4e3d1",
access: "E+D"
}
This delegates the work to a strategy bean that takes an entity UUID argument. RoleMappingStrategy
will assume that the provided UUID is that of a role, and would fetch and return all the users with that role.
If the use case was that all users logged at a certain location should view the above cohort, then we would have to come up with something like:
{
strategy: "org.openmrs.cohort.SessionLocationMappingStrategy",
entity: "9a377cba-dfbb-443f-887e-9f5bb04fd4ef",
access: "V"
}
… and so on and so forth. There would be an interface to implement that would return a list of users from a UUID:
public interface MappingStrategy {
List<User> getUsers(String uuid);
}
Both the user properties and the cohort attributes would contain all the necessary information to implement a service layer and REST API that can answer two sets of basic requests and their variations:
- Given a user, return all the cohorts and the user’s access levels for those cohorts.
- Given a cohort, return all the users and their access levels for that cohort.