Functional contract
Organization structure
Tenants are Organizations. Physical clinics are Locations. Fiscal identity is a Legal Entity, independent of Location. Location Groups (Elite) are an optional operational cluster. Founder register provisions placeholders; Settings CRUD for Legal Entities, Locations, and Location Groups ships.
Hierarchy
Operational grouping is a separate, optional axis (Elite):
| Level | What it is | Owns |
|---|---|---|
| Organization | Customer account and brand umbrella | Staff memberships, master catalog, pricing groups, clients and pets, plan, Location grants, default logos and brand colors |
| Legal Entity | Tax/legal person (EIN / tax ID) | Invoices, merchant account, POs, tax config, accounting export, currency |
| Location Group | Optional cluster of Locations (region, brand, franchise network) | Group catalog grants; catalog, price, patient group, and tax overrides and locks; group patient groups, taxes, tax groups, and commission groups |
| Location | Physical site | Hours, rooms and equipment, appointments, on-hand stock, cash drawer, card terminals, optional logo/color overrides |
| Staff | Membership of a User in an Organization | Role assignments; founder gets org-wide Organization administrator |
Location Groups
- Elite only (
Organization#allows_location_groups?, featuresettings.location_groups). Downgrading from Elite is blocked while any group exists. - A Location belongs to zero or one group (
locations.location_group_id). New Locations start without a group. A group is independent of Legal Entity and may mix entities. - Organization administrators manage groups at Settings → Location groups (
/app/settings?tab=location_groups; API/api/v1/location_groups), picking members on the group form or the group on the Location form. - A group cannot be removed while it has Locations, catalog grants, or owned patient groups, taxes, tax groups, or commission groups. Removing it deletes its overrides and role assignments.
- Location group administrator (RBAC): administers every member Location and edits group settings (profile; catalog, price, patient group, and tax overrides and locks; catalog grants; group-owned patient groups, taxes, tax groups, and commission groups). Only Organization administrators change membership or create and remove groups.
- No group workspace: Organization administrators manage group data from any workspace; group administrators from a member Location.
- Location group page (
/app/location_groups/:id, from the group name in Settings or a record's All sites tab): member Locations and every value and lock the group overrides, by area (catalog and prices, taxes, commissions, appointment types), each linking to the record with Change. Empty: “This group uses the organization's values everywhere.” Organization admins and that group's admins.LocationGroups::OverridesSummary. - Inheritance: a Location sees Organization records, its group's records, and its own. Applies to catalog items (Catalog and pricing), patient groups, taxes, tax groups, and commission groups (Commissions), owned by Organization, group, or Location (
HierarchyOwned). Pricing groups are Organization-owned; their prices take Location and group overrides.
Rules
- An Organization has
1..NLegal Entities and1..NLocations. Every Location belongs to exactly one Organization and one Legal Entity. - A
Useris a login identity. Clinic membership is aStaffrecord; a User may have several in different Organizations. SuperUsers are platform operators, not staff. - Staff are granted Locations by role assignment, including per-Location-Group grants (Staff access, RBAC). Organization-scoped roles imply every Location.
- Founder
/registercallsOrganization.provision!: Organization, Legal Entity, Location (UTC, empty address), Staff, org-wide Organization administrator, and a default “General” pricing group. - Elite: Legal Entities CRUD (
legal_name,tax_id,currencydefaultUSD) at/app/settings?tab=legal_entities. Starter/Business edit the sole entity on Settings → Organization. Locations inherit the entity's currency. - Settings → Locations lists sites; the name opens the site ficha (
/app/locations/:id) for site fields, hours, and resources. The last Legal Entity and last Location cannot be destroyed. - Branding: Organization logos (horizontal, vertical) and primary / accent / secondary colors on Settings → Organization. Locations may override on the ficha; blanks inherit Organization then platform defaults (
#577590,#f3ca40,#f2a541). Client emails resolve Location → Organization → platform. - Location administrators edit site fields, hours, and resources at granted Locations; they cannot create or destroy Locations or change Legal Entity or group.
Same-EIN groups, independent-EIN franchises, and mixed MSO / post-acquisition groups are all valid. A newly acquired clinic is a new Location, plus a new Legal Entity only when it keeps its own tax identity.
Data domains
| Domain | Level | Behavior |
|---|---|---|
| Clients and pets | Organization | One medical chart per patient, visible from every Location |
| Master catalog | Organization | One list; groups and Locations inherit and may override as allowed |
| Inventory on hand | Location | A sale at A decrements A, never B |
| Purchase orders | Legal Entity | POs in the name of the EIN; one PO may supply several Locations of that entity |
| Appointments | Location | Slots depend on rooms, equipment, and staff at that site |
| Invoices | Hybrid | Fiscal header from Location's Legal Entity; sale attributed to the Location |
| Cash drawer / terminals | Location | Each site closes its own drawer |
| Merchant account / payouts | Legal Entity | Card proceeds settle to that entity's bank |
| Financial reports | All three | Org view, tax view per entity, operational view per Location |
Workspace context
Staff work inside one Organization and one current Location, stored in the Rails session.
- One granted Location: always current; no switcher.
- Several grants: sidebar switcher (Organization plus each granted site). Group roles surface as their member Locations.
- Default: the only Location, else the last one used (
session[:workspace_location_id]). - Organization scope (
session[:workspace_scope] = "organization") shows Home and Schedule as placeholders. - Times, “today”, and grids use the current Location's
time_zone.
A SuperUser may select any Organization, then any Location in it.
Clients and pets
Client and pet records are Organization-scoped (Patients). A pet that visits A and later C keeps one chart. Financial balances are not global:
- Receivables belong to the Location (and Legal Entity) that originated the invoice.
- An open balance at C shows an alert at A. Do not auto-apply it or net across Legal Entities.
- A payment is attributed to the Location and Legal Entity where it was taken.
Plan implications
| Plan | Legal Entities | Locations UX | Location Groups |
|---|---|---|---|
| Starter / Business (and trial without Elite) | Exactly one; edited on Settings → Organization; tab hidden | Listed under the Organization; no Legal Entity picker | Not available |
| Elite | Unlimited; Settings → Legal Entities CRUD | May assign Locations to a Legal Entity; structure map Org → Legal Entity → Locations | Settings → Location groups |
Downgrading from Elite is blocked while extra Legal Entities or any Location Group remain.
Opening hours
Each Location has weekly hours and date exceptions, edited on the ficha (and /app/locations/new) by staff who may_manage_location?. Appointments are not rejected outside hours.
| Record | What it is |
|---|---|
LocationHour | Weekly open interval. weekday ISO 1–7 (Monday = 1); times in Location time_zone. Several per day allowed; no overnight |
LocationHourException | A date that replaces weekly hours: closed, or custom intervals |
LocationHourExceptionInterval | Custom interval on a non-closed exception |
- No hours and no exceptions = unconfigured: calendar stays clear, no confirm.
provision!seeds no hours. - Schedule Day/Week grey closed spans; fully closed Month cells and Year days are muted.
- Saving an appointment outside configured hours asks for confirmation (“This appointment is outside opening hours.”). The server does not validate.
- API:
/api/v1/locationsincludeshoursandhour_exceptions(nestedlocation_hours_attributes,location_hour_exceptions_attributes).
Rooms and equipment
Each Location has LocationResource rows (kind room or equipment), edited on the ficha. Appointments may book zero or more (Appointments).
| Field / rule | Behavior |
|---|---|
name | Required; unique within the Location, including the waiting room name |
available | Default true; mark false when out of service |
occupancy_limit | Positive integer (default 1) |
| Waiting room | Location#waiting_room_name (“Waiting Room” / “Sala de espera”), not a resource; first row, renamable, not removable |
| Booking | Unavailable resource or over occupancy limit confirms and still saves |
| Whiteboard Floor | Columns are rooms plus the waiting room; equipment never (Visits) |
| Schedule | /app/schedule?view=resource: one swimlane per room or equipment; waiting room excluded |
- The ficha shows Location Group on Elite (changed only by Organization administrators). Settings readers see the ficha without inputs.
- API:
POST/PATCH/DELETE /api/v1/locations/:location_id/resources[/:id](may_manage_location?). Duplicates, unknown kinds, non-positive limits →422; cross-organization ids →404. - Destroying a Location removes its resources. The ficha ends with a Change history timeline including hours and resources.
Acceptance
Organization.provision!creates at least one Legal Entity, one Location, and a “General” pricing group. Shipped.- A Location cannot exist without a Legal Entity. The last Legal Entity and last Location cannot be destroyed. Shipped.
- Moving a Location to another Legal Entity is an Elite Organization administrator action. Shipped. Issued invoices keep the original entity (
invoices.legal_entity_id). - Staff with grants to A and B switch in one session and see each site's schedule and stock. Staff granted only A cannot select B. Shipped.
- A Location group administrator operates every Location in the group, including Locations added later.
- A pet treated at two Locations shows one medical history.
- An invoice at Location C shows Legal Entity 2's legal name and tax ID.
- A Location administrator sets Monday 09:00–13:00 and 16:00–20:00, closes Sunday, adds 25 December closed; Day/Week grey those spans; a 21:00 appointment saves after confirming.
Out of scope: payment-processor onboarding, accounting-export field maps, rejecting appointments outside hours, overnight intervals, staff-specific hours, mobile editors.