Case Sharing
Case Sharing allows your field team to share responsibilities of a case load.
Overview
In the default CommCare model, each CommCare user has their own list of cases, comprised of the cases he/she has created. When a mobile worker registers a pregnant mother on CommCare Mobile, let's call her 'Monica' in this example, the 'Monica' case will only appear in this specific mobile worker's case list (What's a case list is? See https://dimagi.atlassian.net/wiki/x/8xrKfw). The 'Monica' case will not be show in anyone else's case list, meaning no other mobile worker can perform a follow-up visit with Monica.
Case Sharing changes this model by allowing mobile workers to share cases with other CommCare users.
To do so, you'll create a case sharing group, then add mobile users to that group. All mobile users within a single case sharing group have access to the cases other members of the group have created. These Case Sharing Groups allow multiple mobile workers to share responsibility for a group of cases, by making it seamless for different workers to conduct different pieces of overall project services for a single case.Â
Some common use cases:
David works with another community health worker, Maria, who has the same CommCare application on her phone.  David and Maria visit the same community members. Sometimes David will register a new pregnancy, and Maria will follow up with her later.
David refers sick clients to a local clinic. Â A nurse at the clinic has a phone with a different CommCare application for sick community members. Â The nurse will want to see why David referred the patient, as well as all the data that David has collected about the patient in the past. Â David will want to know the outcome of the visit.
How to enable case sharing
Make sure any CommCare applications that you want to have share cases with one another are located in the same project space.
Turn on case sharing for your application(s), by doing the following for each app:
Go to app settings (by clicking the gear icon next to the app name).
Select the "Advanced Settings" tab.
Check the "Case Sharing" checkbox.
Add your mobile users to case sharing groups, by doing the following:
Go to the "Users" page.
Click on "Groups".
Enter a name for the group and then click on the "+ Create Group" button.
On the new page that loads, click "Edit Settings" and then turn on Case Sharing.
Under the "Group Membership" tab, add all users who you wish to have share cases with each other in this group, by entering each username one at a time and then clicking "Update".
If you're sharing cases between two or more different CommCare applications, make sure that the case type matches between all the menus you want to have share case lists.
It is important to note that by default case sharing assumes all users are in exactly one case sharing group (or location). If a user is not in a group, or is in more than one group, apps will throw an error for any form that creates a new case unless additional configuration is provided to clarify the owner of the case.
To configure case sharing for users in multiple groups, you can read the following guides depending on what features you are using.
Advanced
You can structure your case sharing groups such that a "supervisor" user is in multiple case sharing groups. If you are on the Advanced plan or higher, this is easy to set up through Organizations Overview | [hardBreak]Case Sharing using Organizations
Errors
Often if you have an error in case management (i.e. you did not follow one of the steps above), you will see a message indicating that your user is not in a case sharing group or is in more than one case sharing group. If you see this, go back and check your case sharing settings. It is likely that 1 of your users is not in exactly one case sharing group.
Assigning cases to one of multiple groups
Let's suppose that you have nurses who see patients at health centres, and each health centre draws patients from several surrounding villages. Each village then has a worker who performs checkups in the village at the patients' houses.Â
Alternative Option
This page describes manually configuring case sharing groups. You can also use the Organizations (Locations) feature to more easily configure this setup.
What needs to exist for the above to happen (without having all the workers see all the other workers' cases) is one case-sharing group per village containing the worker and each nurse that could potentially assign a case to that worker. If the worker registers a new case, the case will be shared in the village's case-sharing group which includes the nurse. When the nurse registers a case, they will have to select which village's case sharing group will own the new case. This means that the nurses will be in several different case sharing groups.
Â
Step 1: Setup the Case Sharing Groups
You need to setup one Case Sharing group for each set of cases you want shared. Â In the example above, the project needs one group for Village 1 Worker, one group for Village 2 worker, one group for Village 3 worker. Â You would then assign the nurse to all three groups, and the worker to their own groups.
To setup the Case Sharing groups, go to Users -> Groups. Â Then create the case sharing groups required, and make sure you turn on "Case Sharing" for each group. To do so, select the group you want to enable case sharing for to proceed to the edit groups page. On this page, select Edit Settings to open a pop out window where you can turn case sharing on.Â
Step 2: Turn on the Feature Preview
When a nurse is registering a patient, you want to display a list of the case sharing groups so that they can assign the case to the appropriate village worker.  To do this, you need to turn on a Feature Preview called "Custom Single and Multiple Answer Questions".  This allows you to display custom choice lists in forms (i.e. a list of case sharing groups) instead of just items from a Lookup Table.
Proceed to the Application Settings by selecting the Gear in the top left hand corner. Then select the 'Add-ons' tab:
Select the button with three lines on on the right hand side of the screen. Select 'Calculations' from this drop-down.
Turn on the "Custom Single and Multiple Answer Questions" feature preview and then click 'Save'.
Step 3: Configure Your Application
In the application, you need to setup your Registration form so that it displays the list of case sharing groups in a single or multiple select question. Â
Go to your form that is used to register a new case. Â Add a new Checkbox Lookup table question to the form:
Set the question ID toÂ
village (or whatever makes sense)Â and the display text to "What village do you come from?"
Choose the "Lookup Table Data" item in the left tree, and then choose the "..." button to configure the list of choices.
Set the Query Expression to
instance('group')/groups/group . This will display the list of case sharing groups.  Set the Instance ID to group and the Instance URI to jr://fixture/user-groups .  Then click on the Save button.Â
Back on the Lookup Table Data page, set the Value field toÂ
@id and the Label field to name. Â Note that the Lookup Table dropdown should say "Lookup table not found in project"
Save your form, and then go to the Case Management section of the form and save the question to the case property calledÂ
owner_id.
Separate worker and nurse apps
If the workers and the nurses use the same app, the workers will see the question 'what village do you come from?' with only one possible answer corresponding to the one village which they work in. To avoid this, you can have the workers use a separate app to register cases. Make sure the worker app has case sharing Enabled so that the nurses can see the cases they register. Remember that only forms with the above code can be accessed by users in more than one group.
Multiple workers in the same village
If each village has more than one worker, make sure that they are all the workers are in the village's group, that the group has case sharing enabled, and that the workers' app also has case sharing enabled (see above).
Case Sharing FAQs
If a case was created before case sharing was turned on and the case sharing group was created, does that case get reassigned automatically to that group's owner id, or does the case retain its original owner id?
The case should retain the original case owner ID
What is the difference between user id and owner id?
The owner ID is the id of the user or group who owns the case (the case will appear on their application's case list). User id is the id of the user who last submitted a form to the case.
What happens if two mobile users are sharing a case, are both working offline, and both make changes to the case?
Once the forms are submitted they will update the case in the order in which they are received (according to the server received time). If one of the forms closed a case and a subsequent form attempts to update that case, the case will not be reopened but the (now closed) case will be updated.
Is there a way to specify case sharing for different groups by menu or a specific case type?
Unfortunately this use case is not currently supported in the app builder. However, you can configure this manually by specifying the "owner_id" property for new cases which you don't want to share to be set to the id of the current user (defined in the form as a hidden value) in the normal case property configuration screen. That will result in those cases not being shared.