Overview
Backend implementation overview for Task Manager in crelio-app.
Task Manager — Backend
All server-side logic lives in crelio-app/services/task_manager. The feature provides a comprehensive task management system with different task types, assignment capabilities, attachments, logging, and references to various entities.
What this section covers
| Page | Covers |
|---|---|
| Data Model | Migration files, Task, TaskType, TaskAttachment, TaskLog, TaskReference models |
| API Reference | Task creation, listing, updates, assignments, attachments, and comments endpoints |
| Comments & Mentions | Centralized comment creation, task comment fetching, attachments, and mention support |
Architecture
Proxy architecture
The Task Manager uses Django proxy models to implement task-type-specific behavior while keeping a single Task database table.
services/task_manager/utils/constants.pymaps task type IDs to proxy classes:TaskType.TASK_TYPE_PERSONAL_TASK→PersonalTaskTaskType.TASK_TYPE_REPORT_EXCEPTION→ReportExceptionTaskTaskType.TASK_TYPE_SAMPLE_EXCEPTION→SampleExceptionTask
TaskCreateViewresolves the proxy viaget_task_type_child_class(task_type_id).TaskUpdateViewandTaskResolveViewrestore proxy behavior on existing tasks withcast_to_task_type_child(task).
Each proxy class implements specialized task creation behavior through:
validate_initialize(context)prepare_title()prepare_description()prepare_default_reporter_and_assignee()prepare_references()
Shared lifecycle behavior lives in services/task_manager/proxies/abstract_task.py, including create_task(), open(), close(), and add_references().
Task lifecycle
The Task Manager lifecycle is generic at the Task model level and customizable through proxy classes.
- Create
TaskCreateViewreceivestask_type_idandcontext- It resolves the right proxy and calls
create_task(context) AbstractTask.create_task()validates inputs, initializes metadata, saves theTask, and persists references
- Update / Assign
TaskUpdateViewloads the task, casts it to the proxy class, applies field updates, and saves- Supports
title,description,assignee_id,org_id,status, and reference add/remove operations self-assignroutes the current session user as assignee
- Resolve
TaskResolveViewusesclose(updated_by_lab_user_id)to setstatus = RESOLVED, recordresolved_at, and store who closed it
- Reopen
AbstractTask.open()resetsstatus = OPENand clearsresolved_at
Status transitions follow the expected workflow: OPEN → IN_PROGRESS → RESOLVED.
Key files
| File | Role |
|---|---|
services/task_manager/migrations/0001_initial.py | Initial schema — Task, TaskType, TaskAttachment, TaskLog, TaskReference models |
services/task_manager/migrations/0002_task_updated_by_doctor_task_updated_by_lab_user_and_more.py | Added updated_by fields and task log enhancements |
services/task_manager/models/task.py | Main Task model with statuses, assignees, reporters |
services/task_manager/proxies/ | Task type proxies for different task categories |
services/task_manager/views/ | API endpoints for task operations |
services/task_manager/serializers/ | Data serialization for API responses |