Database schema
labFeatures.b2b_collection flag and trip_management tables for B2B Collection in crelio-app
Database schema
B2B Collection touches two areas in crelio-app:
- Feature gate β
labFeatures.b2b_collection(per lab) toggles the product in session / UI. - Logistics data β
admin.trip_managementtables (Trip, stops, routes, samples) behindapi-v3/trip-management/b2b-logistics/β¦.
B2B logistics trips are rows in Trip with trip_type = 2 (B2B_TRIP) and the optional visit-link column home_collection_id IS NULL (B2BTrip / B2BTripManager in models/core/trip.py).
labFeatures β b2b_collection
Table: labFeatures
Model: admin.account.models.lab_features.LabFeatures
Meta: db_table = "labFeatures"
One row (conceptually) per lab via the lab foreign key. The B2B Collection product is enabled when this column is true for that labβs features row.
| Column | Type | Notes |
|---|---|---|
id | PK | Auto |
labForId | FK β account.Labs | Lab this feature row belongs to (labForId on model) |
b2b_collection | boolean | True = B2B Collection enabled (Registration β B2B Collection, session.b2b_collection) |
| (other columns) | various | Many other lab flags on the same table; see lab_features.py for the full schema |
Source: admin/account/models/lab_features.py (field b2b_collection).
Entity overview (trip management)
Trip
Table: Trip
Model: admin.trip_management.models.core.trip.Trip
Proxy (B2B): B2BTrip β same table; default Trip.objects manager is phlebotomist-only; use B2BTrip.objects or Trip.all_objects for B2B rows.
| Column | Type | Notes |
|---|---|---|
id | PK | Auto |
created_at, updated_at | datetime | Auto-maintained |
phlebotomist_id | FK β account.LabUser | Pickup person (lab_user on model, db_column="phlebotomist_id") |
device_id | varchar(100) | Device identifier |
lab_id | FK β account.Labs | Lab |
home_collection_id | FK nullable (patient app) | NULL for B2B logistics (trip_type = 2); may be set for trip_type = 1 rows on the same table |
total_distance | float, nullable | Filled when distance is calculated |
start_point, end_point | text | Coordinates / serialized points |
status | varchar(20) | NOT_STARTED, STARTED, ENDED, CANCELLED, PAUSED |
scheduled_at, started_at, stopped_at, ended_at, cancelled_at | datetime, nullable | Lifecycle timestamps |
reason, comment | text, nullable | |
is_distance_calculated | boolean | Default false |
name | varchar(50), nullable | Trip name |
trip_type | smallint | 1 = phlebotomist, 2 = B2B |
cancelled_by | int, nullable | LabUser id who cancelled |
schedule_group | varchar(50), nullable | Recurring / series grouping |
Index: (lab_id, started_at, trip_type, status).
trip_location
Table: trip_location
Model: TripLocation
Stops on a trip (sequence, status, distances, notes).
| Column | Type | Notes |
|---|---|---|
id | PK | |
lab_id | FK β account.Labs | PROTECT |
trip_id | FK β Trip | PROTECT |
location_id | FK β location | PROTECT |
sequence | smallint | Stop order |
end_point, start_point | varchar(40) | Coordinates |
location_distance | int | Segment distance (meters, default 0) |
traveled_distance | int | Default 0 |
status | smallint | 1β6: NOT_STARTED, IN_PROGRESS, PAUSED, REACHED, COMPLETED, CANCELLED |
started_at, ended_at | bigint, nullable | Epoch ms UTC |
note, remark, comment | text |
Index: (lab_id, trip_id, location_id, status).
trip_location_sample
Table: trip_location_sample
Model: TripLocationSample
Sample counts captured per stop (optional link to accession sample).
| Column | Type | Notes |
|---|---|---|
id | PK | |
lab_id | FK β account.Labs | PROTECT |
trip_location_id | FK β trip_location | PROTECT |
sample_id | FK β accession.sample, nullable | Null = βunknownβ sample row |
count | int | 0 β¦ 10_000 (check constraint) |
created_at, updated_at | bigint | Epoch ms |
Unique: (lab_id, trip_location_id, sample_id) (nullable sample_id handled per DB semantics).
Index: (lab_id, trip_location_id).
location
Table: location
Model: Location
UI term: Stop.
| Column | Type | Notes |
|---|---|---|
id | PK | |
organization_id | FK β organization.Organization | PROTECT |
created_by_id | FK β account.LabUser | PROTECT |
name | varchar(50) | |
coordinates | varchar(40) | |
address | JSON | e.g. { "full_address": "..." } |
email | varchar(50), nullable | |
country_code | varchar(5), nullable | |
contact | varchar(15), nullable | |
created_at, updated_at | bigint | Epoch ms |
note | varchar(255), nullable | |
is_active | boolean | Default true |
Index: (organization_id, name).
route
Table: route
Model: Route
| Column | Type | Notes |
|---|---|---|
id | PK | |
lab_id | FK β account.Labs | PROTECT |
created_by_id | FK β account.LabUser | PROTECT |
name | varchar(50) | |
distance | int | Total / aggregate distance (meters, default 0) |
created_at, updated_at | bigint | Epoch ms |
is_active | boolean | Default true |
route_location
Table: route_location
Model: RouteLocation
Ordered stops belonging to a route template.
| Column | Type | Notes |
|---|---|---|
id | PK | |
route_id | FK β route | PROTECT |
location_id | FK β location | PROTECT |
sequence | smallint | Order in route |
distance | int | Meters from previous stop to this one |
Index: (route_id, location_id).
Source locations
| Model | Path |
|---|---|
LabFeatures | admin/account/models/lab_features.py |
Trip, B2BTrip | admin/trip_management/models/core/trip.py |
TripLocation | admin/trip_management/models/core/trip_location.py |
TripLocationSample | admin/trip_management/models/core/trip_location_sample.py |
Location | admin/trip_management/models/core/location.py |
Route | admin/trip_management/models/core/route.py |
RouteLocation | admin/trip_management/models/core/route_location.py |
Related
- Data model β conceptual overview and proxies
- API reference β HTTP routes