Below is information about the hospital's operating hours, the patient's required tests, and the test devices including their currently occupied schedules.
Place every required test that can feasibly be booked into an available device slot, respecting all dependencies and constraints, and following the patient's scheduling preference.
Respond in JSON format only, as shown in the examples below.


## Hospital time information:
* Start_hour: {START_HOUR}
* End_hour: {END_HOUR}
* Time unit: {TIME_UNIT}
* Current time: {CURRENT_TIME}


## Patient information:
* Department: {DEPARTMENT}
* Patient utterance expressing scheduling preference: {PREFERENCE}
    * This is the patient's natural utterance, not a preference label. Infer which of the cases below it matches, and optimize accordingly. An utterance that expresses no particular preference (e.g., "I don't mind", "whatever works", "up to you") is the `indifferent` case.
* Tips:
    * `throughput_max` case: All required tests must finish (including the time required for results to be ready) as early as possible, even if the patient must visit the hospital on multiple distinct days.
    * `indifferent` case: The patient has no preference, so apply the hospital's default policy and schedule exactly as in the `throughput_max` case (all required tests finish, including result-ready time, as early as possible, even across multiple visit days).
    * `visit_min` case: Minimize the number of distinct visit dates by clustering tests on as few days as possible. Among feasible groupings, prefer the one whose final test result becomes available the earliest.
    * `stay_min` case: Minimize the patient's total idle waiting time between consecutive tests taken on the same date (the gaps during which the patient just sits and waits at the hospital). A test taken alone on its own date adds no waiting, so separating tests across more dates is preferred whenever it removes a same-day gap. Neither completion speed nor visit-date count is optimized.
* When the patient CANNOT attend: {UNAVAILABLE}
    * This is a hard constraint, not a preference: no test may be placed on a date the patient cannot attend, nor inside the half of a date they cannot attend (the morning runs from the opening hour until 12:00, the afternoon from 12:00 until the closing hour).
    * It never changes which preference case above applies — optimize exactly as that case says, but only over the slots the patient can actually attend.
    * If a test can only be placed in a window the patient cannot attend, omit that test (see "Partial scheduling is allowed" below) rather than booking it anyway.


## Required tests (each entry includes duration_hour, result_hours, priority, depends_on, avoid_same_day):
NOTE: ``priority`` is a hard time-ordering constraint. If priority(A) < priority(B), then A.end <= B.start.
``depends_on`` lists tests that must complete (including their result-ready time) before this test can start.
``avoid_same_day`` lists tests that must NOT share a date with this test.
```json
{TESTS}
```


## How to read the device availability tables below (READ CAREFULLY):
For each device you are given a table whose rows are dates and whose cell lists that date's **FREE (bookable) windows** as ``start-end`` ranges — these are the times that are OPEN (already excluding everything occupied), computed within operating hours. You may place a test only inside one of these free windows.
* ``9-19`` means the whole operating day is open; ``9-9.1, 9.25-19`` means only those two ranges are free and everything else that day is taken.
* ``— (fully booked)`` means the device has no free window that day.
* Only dates shown in a device's table are bookable. Never invent a date that is not listed.
* A free window is a capacity bound only — you must still satisfy Current time, duration, grid alignment, priority, dependencies, avoid_same_day, and patient availability when choosing a slot inside it.


## Test device availability ({DAY}-day horizon), per device:
{TEST_DEVICES}

## Test scheduling constraints (what makes a schedule valid):
A predicted test slot ``{{date, start, end}}`` on device ``D`` for test ``T`` is valid only if **all** of the following hold:
1. **Single placement.** Each required test appears at most once across the output list, on exactly one of its supporting devices listed under ``T.devices``.
2. **Operating hours.** ``start < end``, ``Start_hour <= start``, and ``end <= End_hour``.
3. **Later than current time.** The ISO timestamp built from ``date`` + ``start`` must be strictly later than ``Current time``. Past dates and earlier-on-today slots are invalid even if they are not occupied.
4. **Exact duration and grid alignment.** ``end - start`` (in the hospital's ``Time unit``) must equal ``T.duration_hour`` exactly. No rounding, no overrun, no shortening. Both ``start`` and ``end`` must also be exact integer multiples of ``Time unit`` — off-grid values (e.g. 9.13 when ``Time unit`` is 0.05) are invalid even if they appear not to overlap any occupied interval, since segment-level conflict checks quantize the values and a hidden conflict may collapse in.
5. **Device availability.** The chosen ``[start, end]`` interval must lie entirely within one of device ``D``'s FREE windows for that date (from D's availability table) — it may not spill outside a free window by even a single time unit.
6. **Priority is a hard time-order constraint.** For any two tests A and B with priority(A) < priority(B), A's end time must be at or before B's start time (using ISO timestamps so this holds across dates).
7. **Dependencies.** For every predecessor P listed in ``T.depends_on``, T's start ISO timestamp must be at or after ``P.end + P.result_hours`` (the moment P's result is ready).
8. **Avoid-same-day.** For every test ``X`` listed in ``T.avoid_same_day``, ``T.date`` must differ from ``X.date``.
9. **List ordering — non-decreasing priority.** The output list must be sorted so that priorities are non-decreasing along the list (i.e., item i's priority <= item i+1's priority).
10. **List ordering — global chronological.** The output list must also be sorted by ISO start timestamp, globally across all dates (i.e., item i's end ISO <= item i+1's start ISO). This is a strict, hard requirement enforced by the downstream validator.
11. **Patient availability.** ``date`` must not be one the patient cannot attend, and ``[start, end]`` must not overlap the half of the day they cannot attend (see "When the patient CANNOT attend" above). A slot the patient cannot attend is invalid even when the device is free.
12. **Patient single-occupancy across devices.** A single patient cannot be at two devices simultaneously. On any given date, the placed ``[start, end]`` intervals of all tests in the output — regardless of which device each test uses — must be mutually non-overlapping. (This is the same constraint that rule #10's global chronological ordering enforces once the list is correctly sorted, but you must respect it while choosing candidates, not only at the end.)

## Partial scheduling is allowed (and expected when needed):
Schedule as many of the required tests as you can while satisfying every constraint above. If a particular test cannot be placed anywhere in the provided horizon (e.g., its only supporting devices are fully booked, or no slot satisfies its ``depends_on`` window), **omit that test entirely from the output list**. Do NOT invent a slot, do NOT shrink ``duration_hour``, do NOT use a date that is not in the schedule. Omitted tests will be re-scheduled by a later process. (An empty ``test_schedule`` list is acceptable only if no test at all could be placed.)


## Optimization based on the patient's preference:
* **`throughput_max`**: minimize the latest ``end + result_hours`` across the placed tests (i.e., make the slowest result-ready time as early as possible). Multiple visit dates are acceptable.
* **`indifferent`**: apply the hospital's default policy — optimize identically to **`throughput_max`** (minimize the latest ``end + result_hours`` across the placed tests; multiple visit dates are acceptable).
* **`visit_min`**: minimize the number of distinct visit dates first; among feasible groupings, prefer the one whose final ``end + result_hours`` is earliest.
* **`stay_min`**: minimize the total idle waiting time between consecutive same-day tests — i.e., the sum, over each visit date, of every gap between one test's ``end`` and the next test's ``start`` on that date. Tests on different dates contribute no waiting, so prefer separating tests across dates over leaving long same-day gaps. Visit-date count and overall completion speed are not optimized.


## Step-by-step procedure (follow this when reasoning):
1. **Topologically order the tests.** Sort the required tests by ``priority`` ascending; within the same priority, place predecessors (anything listed in another test's ``depends_on``) before their dependents.
2. **Place each test in that order.** For the current test T:
   a. Walk through each supporting device ``D`` in ``T.devices``.
   b. Walk through D's listed dates in chronological order. For each date, use its FREE windows from the availability table; any sub-interval of length ``T.duration_hour`` that fits inside a free window is a candidate.
   c. Reject any candidate slot that (i) starts at or before ``Current time``, (ii) is not fully contained in one of D's free windows for that date, (iii) starts before any already-placed test of strictly lower priority ends, (iv) starts before ``predecessor.end + predecessor.result_hours`` for any predecessor in ``depends_on``, (v) lands on a date that conflicts with ``avoid_same_day``, (vi) overlaps in time with any already-placed test of this patient on another device on the same date (single patient, single location at a time), (vii) has ``start`` or ``end`` that is not an exact integer multiple of ``Time unit``, or (viii) falls on a date — or in the half of a date — the patient cannot attend.
   d. Among the remaining candidates, pick:
      * For **`throughput_max`**: the earliest start ISO timestamp overall.
      * For **`indifferent`**: the earliest start ISO timestamp overall (same as **`throughput_max`**).
      * For **`visit_min`**: a slot on a date already used by another placed test if such a slot exists and is valid; otherwise the earliest start ISO timestamp.
      * For **`stay_min`**: a slot that abuts an already-placed test on the same date — starting exactly when that test ends, or ending exactly when it starts, so no idle gap is created. If no such back-to-back slot exists on any already-used date, prefer a slot on a date not yet used (a visit of its own, which adds no waiting) over a same-date slot that would open an idle gap.
   e. If no candidate exists for T after scanning all devices and dates, OMIT T (do not place it).
3. **Sort the final list** by ISO start timestamp ascending. Because step 1 ordered by priority and step 2c forbids out-of-priority placements, this will automatically satisfy both ordering rules (#9, #10).


## Output format:
Respond with ONE JSON object containing only the key ``test_schedule``. Its value is a list. Each list item is an object with exactly one key (the **device code**, one of the keys under ``T.devices``); the value is ``{{"date", "start", "end"}}`` with ``start`` and ``end`` expressed in float hours.

Do NOT include ``fu_schedule``, ``test_visit_dates``, ``all_results_ready_at``, or any other top-level field. Do NOT wrap the JSON in commentary.


## Answer format examples:
Example 1 (`throughput_max` / `indifferent`, all tests scheduled as early as possible):
```json
{{"test_schedule": [{{"IMCAR-T02-1": {{"date": "2025-06-13", "start": 9.0, "end": 9.5}}}}, {{"IMCAR-T03-0": {{"date": "2025-06-13", "start": 10.0, "end": 10.5}}}}]}}
```

Example 2 (`visit_min`, multiple tests on the same date):
```json
{{"test_schedule": [{{"IMGAS-T01-2": {{"date": "2025-06-14", "start": 13.0, "end": 14.0}}}}, {{"IMALL-T01-1": {{"date": "2025-06-14", "start": 14.5, "end": 15.0}}}}]}}
```

Example 3 (`stay_min`, same-day tests placed back-to-back so there is no idle waiting between them):
```json
{{"test_schedule": [{{"IMGAS-T01-2": {{"date": "2025-06-14", "start": 13.0, "end": 14.0}}}}, {{"IMALL-T01-1": {{"date": "2025-06-14", "start": 14.0, "end": 14.5}}}}]}}
```

Example 4 (partial — one test could not be placed within the horizon and is omitted):
```json
{{"test_schedule": [{{"IMPUL-T04-0": {{"date": "2025-06-20", "start": 16.0, "end": 17.0}}}}]}}
```
