# Update location

Canonical page: https://docs.ovok.com/api/slim/location/update-location

`PUT /v1/slim/location/{id}`

Updates a location: its name, floor, room, bed and zone, the devices at it, and the resident on those devices.

**Auth:** Bearer token. The caller must be a practitioner, an admin, a super admin, or hold the "System Owner" access policy. The access policy must grant `Location:update` and `Device:update` (an admin or super admin who holds no access policy skips this check).
**Scope:** The location must belong to the caller's project (from the token). Devices and residents you attach must be in your project or one of its sub-projects. The zone must be in your project, a sub-project, or the parent project.

## Behaviour

- `name` is required and must be unique among the locations your token can search, not counting this one.
- `floor`, `room`, `bed`: an omitted field keeps its current value. If the zone, floor, room or bed changes, the new combination must not match another location's.
- `organizationId`:
  - omitted: the zone is unchanged.
  - `null`: the zone is removed from the location and from every device at it.
  - an id: the location and every device at it move to that zone. Residents on those devices move too.
- `deviceId` (one id or a list):
  - omitted: the devices at the location are unchanged.
  - a list: it becomes the full set of devices at the location. Devices not in the list are detached; new ones are attached. `null` or `[]` detaches all devices.
  - Devices that hold a discharged resident cannot be attached.
- `patientId`:
  - an id: that resident is assigned to the devices in `deviceId`, or, when `deviceId` is omitted or empty, to the single device at the location. The resident is first removed from any other device. A resident already on a target device is replaced. A discharged resident is refused.
  - **omitted: every resident is removed from every device at the location and every device in `deviceId`.** To keep the current resident, send their `patientId`.
- A resident who loses a device has their active out-of-bed notification revoked in the same write, and the device's live telemetry state is cleared afterwards.
- Device use history is updated for every device whose resident changes.
- The write is atomic and takes a short write lock. A concurrent write to the same resources, or a device reassigned by someone else while this request ran, gets a 409.
- Every save adds a location-updated entry to the change history. Residents who move into a new zone, or lose a device, also get an entry in their own change history.
- The response is the location after the update, in the same shape as `GET /v1/slim/location/{id}`.
- If another location has the same zone, floor, room and bed, the request is refused with 409 and the body carries `existingLocationId` and `existingLocationName`.

## Example

```bash
curl -X PUT 'https://api.sandbox.ovok.com/v1/slim/location/c3499c27-2973-0a7f-807e-fb8676a92dcb' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NjcyNjg4MDAsImV4cCI6MTc2NzI3MjQwMH0.Ql3B_ztDvctlyZ2z0vp4sl3ExXRQGkzmxdmTAqxNzZk' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "Room 201",
    "floor": "2",
    "room": "201",
    "bed": "A",
    "organizationId": "87ea5dfc-8b8e-384d-8489-79496e706390",
    "deviceId": ["c3499c27-2973-0a7f-807e-fb8676a92dcb"],
    "patientId": "c3499c27-2973-0a7f-807e-fb8676a92dcb"
  }'
```
