- Python 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .env.sample | ||
| .gitignore | ||
| import_casebooks.py | ||
| README.md | ||
| test_import.json | ||
CPOMS → TargetConnect Casebook Sync
Imports student case data from a CPOMS JSON export into TargetConnect casebooks.
How it works
For each student in the export file the script will:
- Look up the student in TargetConnect by student number
- Create a casebook for them if one does not already exist
- Create a case issue for each CPOMS case linked to that student
- Create case items (notes) within each case issue for linked incidents and case notes
- Create top-level case items against the casebook for any incidents not linked to a case
Staff attribution is preserved as a line at the end of each note in the format Recorded by: Name, since legacy CPOMS staff accounts cannot be reliably matched to TargetConnect operators.
Student matching uses the mis_id field in the CPOMS export, which should contain the Unit-e student number. This is matched against the student number (usercode) in TargetConnect.
Setup
1. Prerequisites
Python 3 with the following packages:
pip install requests python-dotenv
2. Environment variables
Copy .env.sample to .env and fill in the values:
CLIENT_ID=your_client_id
CLIENT_SECRET=your_client_secret
BASE_URL=your-instance.targetconnect.net
SCOPE=service-400200
CLIENT_ID / CLIENT_SECRET — obtain these from your TargetConnect administrator. The service account will need casebook read/write permissions.
BASE_URL — the hostname of your TargetConnect instance, without https://.
SCOPE — this must match the service ID for your TargetConnect partition. It is usually service-400200 for single-partition instances. If your institution has multiple partitions you will need to confirm the correct service ID with your TargetConnect administrator.
3. Create a case item type in TargetConnect
Before running the import, create a new case item type in the TargetConnect admin panel called Legacy CPOMS note. This allows imported notes to be clearly distinguished from notes created natively in the system.
Once created, retrieve its ID by calling:
GET https://{your-instance}/api/global/lookup/caseitemtype
Update the DEFAULT_ITEM_TYPE_ID value at the top of import_casebooks.py with the ID returned for the new type.
4. Set the default casebook status
When a casebook is created during import it is assigned a status. You need to decide which status is appropriate for imported casebooks in your instance (for example, a status indicating the record is historic or under review).
To see the available statuses, retrieve an existing casebook via the API and check the status.code field in the response:
GET https://{your-instance}/api/v1/casebooks/casebook/user/STUDENT_NUMBER/{studentNumber}
Update the DEFAULT_CASEBOOK_STATUS value at the top of import_casebooks.py with the exact status code string from your instance.
Running the import
Dry run (recommended first step)
Checks that students in the export can be found in TargetConnect without writing anything:
python import_casebooks.py path/to/export.json --dry-run
Full import
python import_casebooks.py path/to/export.json
Progress and any errors are logged to stdout.