Skip to content

Healthcare Service Unit Setup

Overview

Healthcare Service Units represent the physical locations in a hospital — buildings, floors, wards, consultation rooms, labs, operation theaters. They form a tree structure (parent-child hierarchy) and control appointment scheduling, inpatient bed management, and stock warehouse linking.

Tree Structure

Service units use Frappe's nested set model (lft/rgt fields) for hierarchical organization:

Hospital (is_group=1)
├── Outpatient Block (is_group=1)
│   ├── Consultation Room 1 (allow_appointments=1)
│   ├── Consultation Room 2 (allow_appointments=1, overlap=1, capacity=3)
│   └── Minor Procedure Room (allow_appointments=1)
├── Inpatient Block (is_group=1)
│   ├── General Ward (is_group=1)
│   │   ├── Bed GW-001 (inpatient_occupancy=1)
│   │   ├── Bed GW-002 (inpatient_occupancy=1)
│   │   └── Bed GW-003 (inpatient_occupancy=1)
│   └── ICU (is_group=1)
│       ├── Bed ICU-001 (inpatient_occupancy=1)
│       └── Bed ICU-002 (inpatient_occupancy=1)
└── Laboratory (allow_appointments=1)

Healthcare Service Unit Fields

FieldTypeDescription
healthcare_service_unit_nameDataRequired, display name
is_groupCheckIf checked, this is a container (floor, wing, ward) — not bookable
service_unit_typeLink → Healthcare Service Unit TypeRequired if not a group. Defines behavior.
allow_appointmentsCheckFetched from service_unit_type, read-only
overlap_appointmentsCheckFetched from service_unit_type, read-only
service_unit_capacityIntMax concurrent appointments. Required if overlap_appointments=1
inpatient_occupancyCheckFetched from service_unit_type, read-only. Marks as a bed.
occupancy_statusSelectVacant / Occupied (auto-managed, read-only)
companyLink → CompanyRequired. Limits visibility to company users.
warehouseLink → WarehouseERPNext warehouse for stock consumption (e.g., procedure consumables)
parent_healthcare_service_unitLinkParent in the tree

Constraints: healthcare_service_unit_name + company must be unique (enforced at database level, line 141).

Healthcare Service Unit Type

Defines the behavior template for service units. Create types first, then assign to units.

FieldTypeDescription
service_unit_typeDataUnique name (e.g., "Consultation Room", "Ward Bed", "Lab")
allow_appointmentsCheckUnits of this type accept appointments
overlap_appointmentsCheckAllow multiple simultaneous appointments (visible if allow_appointments=1)
inpatient_occupancyCheckUnits of this type are beds/rooms for inpatients (visible if allow_appointments=0)
is_billableCheckWhether occupancy in this unit type generates charges (visible if inpatient_occupancy=1)
disabledCheckDeactivate this type

If billable (inpatient rooms that charge per stay):

FieldTypeDescription
itemLink → ItemAuto-created ERPNext Item (read-only)
item_codeDataItem code (read-only)
item_groupLink → Item GroupRequired
uomLink → UOMRequired (usually "Hour" or "Day")
no_of_hoursIntHours per UOM unit (for rate calculation)
rateCurrencyCharge rate per UOM
descriptionDataFetched from Item

Capacity & Overlap Rules

No Overlap (default)

  • overlap_appointments = 0
  • Only one appointment per time slot
  • Standard for consultation rooms

Overlap with Capacity

  • overlap_appointments = 1
  • service_unit_capacity = N (required, must be > 0)
  • Up to N appointments in the same time slot
  • Used for: multi-chair dental clinics, physiotherapy rooms, group consultation
  • The slot selection UI shows a badge with remaining capacity and disables the slot when full

Validation (healthcare_service_unit.py)

set_service_unit_properties() (line 42):

  • Copies allow_appointments, overlap_appointments, inpatient_occupancy from the service unit type
  • Validates: if overlap_appointments=1, then service_unit_capacity must be > 0

Bulk Creation

For wards with many beds, use the bulk creation API:

python
frappe.call(
    "healthcare.healthcare.doctype.healthcare_service_unit.healthcare_service_unit.add_multiple_service_units",
    {
        "parent": "General Ward",
        "service_unit_type": "Ward Bed",
        "company": "Your Hospital",
        "count": 20,            # number of units to create
        "prefix": "GW-Bed"     # naming prefix (generates GW-Bed-0001 through GW-Bed-0020)
    }
)

This whitelist method (line 73) creates units with auto-incrementing names under the specified parent.

  • Service Unit: healthcare/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py
    • set_service_unit_properties() — line 42
    • add_multiple_service_units() — line 73 (whitelisted)
    • on_doctype_update() — line 141 (unique constraint)
  • Service Unit Type: healthcare/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.json