Details
Description
Rationale
========
When cases are related to each other it is critical for staff to be aware of the linkages. For example an intervention case may have an existing case where a co-worker called in and now the problem person themselves has called in. Later, another staffer is covering the primary staffer on these cases and is required to perform an activity for the second case and needs to know this linkage.
Implementation
============
1. Data Model
We'll use a new 'special' type of Activity => 'Link Cases' - which has it's own class file to extend the activity form (same approach as Open Case and Change Case Status) - to register these linkages. Each 'linkage' will be represented as two entries in the case_activity table.
EXAMPLE:
Link Cases activity created with activity.id = 50 to link case.id = 12 to case.id = 25
The case_activity table will have two inserts:
- activity_id = 50, case_id = 12
- activitiy_id = 50, case_id = 25
To retrieve related cases for case_id 25, we would retrieve any activity for that case with activity type = 'Link Cases' (and where is_deleted = 0), and then find instances of those activities in case_activity where case_id != this case_id.
2. Recording a linkage to another case
This will happen via new 'special' type of Activity => 'Link Cases' - which has it's own class file to extend the activity form (same approach as Open Case and Change Case Status).
- add the new activity type - 'Link Cases'
- create class file for this new activity type which adds the following form element above the Subject field:
- Link To Case: - autocomplete select of 'unclosed cases' (see
CRM-5761which also needs an autocomplete lookup on client + case type)
- Link To Case: - autocomplete select of 'unclosed cases' (see
- When the user selects the linked case, prepopulate the activity Subject field with this string:
"Create link between $clientSortName_a - $caseType_a (CaseID: $id_a) AND $clientSortName_b - $caseType_b (CaseID: $id_a)"
- post process inserts TWO civicrm_case_activity records, one points to current case, one to linked case (in addition to inserting this activity record)
3. Displaying linked cases on Manage Case screen
- If this case has 1 or more linked cases WHICH THE USER HAS ACCESS TO, add a clickable link to Case Summary fieldset - 'Related Cases' (above the new 'Merge Case' and 'Assign to Another Client' links).
- Clicking this link displays a pop-up dialog (title = 'Related Cases') with a table listing the related case(s). Table columns are 'Client Name', 'Case Type'. Client name hyperlinks to contact/view.
- For each row there is also a 'View Case' action link to the manage case screen for linked case
4. Removing case links
Users with 'delete activity' permission can 'remove' a case link by deleting (moving to trash) the corresponding 'Link Cases' activity. Since this activity is now marked is_deleted, it won't be returned by the query which checks for related cases.