> ## Documentation Index
> Fetch the complete documentation index at: https://docs.solvice.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Healthcare Scheduling

> Schedule nurses and caregivers with skill matching, certifications, and labor compliance

## Overview

This example demonstrates hospital nursing schedules where staff must be matched to shifts based on certifications, unit experience, and labor regulations. The solution ensures proper skill coverage while respecting mandatory rest periods and fair workload distribution.

<Info>
  This example showcases skill-level matching, consecutive day limits, rest period enforcement, and fairness balancing across a nursing team.
</Info>

## Business Scenario

A hospital unit manages:

* 12 nurses with different certifications (RN, LPN, charge nurse)
* 3-week rotating schedule with day, evening, and night shifts
* Mandatory 11-hour rest between shifts
* Maximum 5 consecutive working days
* At least 2 weekends off per month
* Charge nurse coverage on every shift

## Complete Implementation

<Tabs>
  <Tab title="Request">
    ```json theme={null}
    {
      "employees": [
        {
          "name": "Sarah-RN",
          "skills": [
            { "name": "RN", "level": 5 },
            { "name": "charge", "level": 3 },
            { "name": "ICU", "level": 4 }
          ],
          "availability": [
            "2024-04-01T00:00:00/2024-04-21T23:59:59"
          ],
          "preference": ["day-ICU-1", "day-ICU-2"],
          "wage": 45
        },
        {
          "name": "Michael-RN",
          "skills": [
            { "name": "RN", "level": 4 },
            { "name": "charge", "level": 5 },
            { "name": "ER", "level": 5 }
          ],
          "availability": [
            "2024-04-01T00:00:00/2024-04-21T23:59:59"
          ],
          "wage": 48
        },
        {
          "name": "Jennifer-LPN",
          "skills": [
            { "name": "LPN", "level": 4 },
            { "name": "med-surg", "level": 5 }
          ],
          "availability": [
            "2024-04-01T06:00:00/2024-04-01T22:00:00",
            "2024-04-02T06:00:00/2024-04-02T22:00:00",
            "2024-04-03T06:00:00/2024-04-03T22:00:00",
            "2024-04-04T06:00:00/2024-04-04T22:00:00",
            "2024-04-05T06:00:00/2024-04-05T22:00:00"
          ],
          "wage": 32
        },
        {
          "name": "David-RN",
          "skills": [
            { "name": "RN", "level": 3 },
            { "name": "ICU", "level": 2 }
          ],
          "availability": [
            "2024-04-01T00:00:00/2024-04-21T23:59:59"
          ],
          "wage": 42
        },
        {
          "name": "Emily-RN",
          "skills": [
            { "name": "RN", "level": 5 },
            { "name": "charge", "level": 4 },
            { "name": "pediatrics", "level": 5 }
          ],
          "availability": [
            "2024-04-01T00:00:00/2024-04-21T23:59:59"
          ],
          "preference": ["evening-peds-1"],
          "wage": 46
        }
      ],
      "shifts": [
        {
          "name": "day-ICU-1",
          "from": "2024-04-01T07:00:00",
          "to": "2024-04-01T19:00:00",
          "skills": [{ "name": "RN" }, { "name": "ICU" }],
          "min": 2,
          "max": 3,
          "tags": [{ "name": "DAY" }, { "name": "ICU" }],
          "priority": 1
        },
        {
          "name": "night-ICU-1",
          "from": "2024-04-01T19:00:00",
          "to": "2024-04-02T07:00:00",
          "skills": [{ "name": "RN" }, { "name": "ICU" }],
          "min": 2,
          "max": 2,
          "tags": [{ "name": "NIGHT" }, { "name": "ICU" }],
          "priority": 1
        },
        {
          "name": "day-charge-1",
          "from": "2024-04-01T07:00:00",
          "to": "2024-04-01T19:00:00",
          "skills": [{ "name": "RN" }, { "name": "charge" }],
          "min": 1,
          "max": 1,
          "tags": [{ "name": "DAY" }, { "name": "CHARGE" }],
          "priority": 1
        },
        {
          "name": "evening-peds-1",
          "from": "2024-04-01T15:00:00",
          "to": "2024-04-01T23:00:00",
          "skills": [{ "name": "RN" }, { "name": "pediatrics" }],
          "min": 1,
          "max": 2,
          "tags": [{ "name": "EVENING" }, { "name": "PEDS" }],
          "priority": 2
        }
      ],
      "rules": [
        {
          "constraint": "SEQUENCE",
          "type": "WORKING_DAYS",
          "max": 5
        },
        {
          "constraint": "COUNTER",
          "type": "WEEKENDS_IDLE",
          "min": 2,
          "period": {
            "from": "2024-04-01",
            "to": "2024-04-30"
          }
        },
        {
          "constraint": "COUNTER",
          "type": "WORKING_SHIFT_TYPE",
          "shifts": ["NIGHT"],
          "max": 4,
          "period": {
            "duration": "P14D"
          }
        },
        {
          "constraint": "COUNTER",
          "type": "HOURS_WORKED",
          "min": 72,
          "max": 84,
          "period": {
            "duration": "P14D"
          }
        }
      ],
      "rests": [
        {
          "tags": ["NIGHT"],
          "sequence": "AFTER",
          "min": "PT11H"
        },
        {
          "tags": ["DAY", "EVENING"],
          "sequence": "AFTER",
          "min": "PT10H"
        }
      ],
      "patterns": [
        {
          "type": "MULTI_DAY",
          "satisfy": "PROHIBITED",
          "elements": [
            { "type": "ON", "tags": ["NIGHT"] },
            { "type": "ON", "tags": ["DAY"] }
          ]
        },
        {
          "type": "MULTI_DAY",
          "satisfy": "PROHIBITED",
          "elements": [
            { "type": "ON", "tags": ["EVENING"] },
            { "type": "ON", "tags": ["DAY"] }
          ]
        }
      ],
      "requirements": [
        {
          "shifts": ["day-ICU-1", "day-ICU-2", "day-ICU-3"],
          "skill": "charge",
          "value": 1
        }
      ],
      "fairnessBuckets": [
        {
          "employees": ["Sarah-RN", "Michael-RN", "David-RN", "Emily-RN"],
          "shifts": ["night-ICU-1", "night-ICU-2", "night-ICU-3"],
          "period": {
            "from": "2024-04-01",
            "to": "2024-04-14"
          },
          "target": "PT36H"
        }
      ],
      "options": {
        "hardAvailability": true,
        "hardSkill": true,
        "idleWeekend": {
          "fromDayOfWeek": "FRIDAY",
          "fromTime": "19:00:00",
          "toDayOfWeek": "SUNDAY",
          "toTime": "23:00:00"
        }
      },
      "weights": {
        "skills": "100hard",
        "minRest": "50hard",
        "maxConsecutive": "30hard",
        "wages": "5soft",
        "pref": "10medium"
      }
    }
    ```
  </Tab>

  <Tab title="Solution">
    ```json theme={null}
    {
      "id": "healthcare-schedule-001",
      "status": "SOLVED",
      "score": {
        "hardScore": 0,
        "mediumScore": -2,
        "softScore": -1250,
        "feasible": true
      },
      "assignments": [
        {
          "shift": "day-ICU-1",
          "from": "2024-04-01T07:00:00",
          "to": "2024-04-01T19:00:00",
          "skills": ["RN", "ICU"],
          "employee": "Sarah-RN"
        },
        {
          "shift": "day-ICU-1",
          "from": "2024-04-01T07:00:00",
          "to": "2024-04-01T19:00:00",
          "skills": ["RN", "ICU"],
          "employee": "David-RN"
        },
        {
          "shift": "day-charge-1",
          "from": "2024-04-01T07:00:00",
          "to": "2024-04-01T19:00:00",
          "skills": ["RN", "charge"],
          "employee": "Michael-RN"
        },
        {
          "shift": "evening-peds-1",
          "from": "2024-04-01T15:00:00",
          "to": "2024-04-01T23:00:00",
          "skills": ["RN", "pediatrics"],
          "employee": "Emily-RN"
        }
      ],
      "unassigned": [],
      "violations": [
        {
          "name": "Shift Preference",
          "value": 2,
          "level": "MEDIUM"
        },
        {
          "name": "Wage Costs",
          "value": 1250,
          "level": "SOFT"
        }
      ]
    }
    ```
  </Tab>

  <Tab title="Analysis">
    The solution demonstrates several key healthcare scheduling optimizations:

    1. **Skill Matching**: ICU shifts assigned only to ICU-certified nurses
    2. **Charge Coverage**: Every shift has at least one charge-certified nurse
    3. **Rest Compliance**: 11-hour minimum rest after night shifts enforced
    4. **Pattern Prevention**: No night→day transitions that cause fatigue
    5. **Fair Night Distribution**: Night shifts balanced across RN staff

    <Check>
      All hard constraints satisfied with feasible solution. Medium score reflects 2 unmet preferences.
    </Check>
  </Tab>
</Tabs>

## Key Healthcare Features

### Certification-Based Skill Matching

Match nurses to units based on certifications:

```json theme={null}
{
  "employees": [{
    "name": "Sarah-RN",
    "skills": [
      { "name": "RN", "level": 5 },
      { "name": "ICU", "level": 4 },
      { "name": "ACLS", "level": 5 }
    ]
  }],
  "shifts": [{
    "name": "ICU-day",
    "skills": [
      { "name": "RN" },
      { "name": "ICU" }
    ]
  }]
}
```

### Mandatory Rest Periods

Enforce labor law rest requirements:

```json theme={null}
{
  "rests": [
    {
      "tags": ["NIGHT"],
      "sequence": "AFTER",
      "min": "PT11H"
    }
  ]
}
```

<Warning>
  Many jurisdictions require 11 hours minimum rest between shifts. Configure rest rules to match local regulations.
</Warning>

### Charge Nurse Requirements

Ensure leadership coverage on every shift:

```json theme={null}
{
  "requirements": [
    {
      "shifts": ["day-1", "day-2", "day-3"],
      "skill": "charge",
      "value": 1
    }
  ]
}
```

### Night Shift Limits

Restrict consecutive nights and total night shifts:

```json theme={null}
{
  "rules": [
    {
      "constraint": "COUNTER",
      "type": "WORKING_SHIFT_TYPE",
      "shifts": ["NIGHT"],
      "max": 4,
      "period": { "duration": "P14D" }
    }
  ]
}
```

## Common Healthcare Patterns

<AccordionGroup>
  <Accordion title="12-hour shift rotation">
    ```json theme={null}
    {
      "shifts": [
        { "name": "day", "from": "07:00", "to": "19:00" },
        { "name": "night", "from": "19:00", "to": "07:00" }
      ],
      "rules": [
        { "constraint": "SEQUENCE", "type": "WORKING_DAYS", "max": 3 }
      ]
    }
    ```
  </Accordion>

  <Accordion title="Weekend rotation (every other weekend)">
    ```json theme={null}
    {
      "rules": [
        {
          "constraint": "COUNTER",
          "type": "WEEKENDS_IDLE",
          "min": 2,
          "period": { "from": "2024-04-01", "to": "2024-04-30" }
        }
      ]
    }
    ```
  </Accordion>

  <Accordion title="Float pool nurses">
    ```json theme={null}
    {
      "employees": [{
        "name": "Float-Nurse",
        "skills": [
          { "name": "RN" },
          { "name": "ICU", "level": 2 },
          { "name": "ER", "level": 2 },
          { "name": "med-surg", "level": 3 }
        ]
      }]
    }
    ```
  </Accordion>

  <Accordion title="On-call scheduling">
    ```json theme={null}
    {
      "shifts": [{
        "name": "on-call-weekend",
        "from": "2024-04-06T19:00:00",
        "to": "2024-04-07T07:00:00",
        "tags": [{ "name": "ON_CALL" }],
        "cost": 100
      }],
      "options": { "partialPlanning": true }
    }
    ```
  </Accordion>
</AccordionGroup>

## Related Examples

<CardGroup cols={2}>
  <Card title="Rest Requirements" icon="bed" href="/guides/fill/examples/rest">
    Configure rest periods and recovery time
  </Card>

  <Card title="Rules and Constraints" icon="scale-balanced" href="/guides/fill/examples/rule">
    Working hour limits and consecutive days
  </Card>

  <Card title="Fairness Buckets" icon="balance-scale" href="/guides/fill/examples/fairness">
    Balance workload across staff
  </Card>

  <Card title="Shift Patterns" icon="calendar-days" href="/guides/fill/examples/pattern">
    Prevent undesirable shift sequences
  </Card>
</CardGroup>
