{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.kodemed.ch/his_rest/SessionCreate-1.0.schema.json",
  "title": "KodeMed HIS REST — Create Coding Session Request",
  "description": "Request body for `POST /api/v1/coding/session`. Partner HIS submits a case for coder review. The server returns a redirect URL (see SessionResponse-1.0). On the wire format-drift front: this schema composes `_common/CaseData` (data + format + dataHash + schemaVersion) via `allOf` — the field shape lives in one place across every flow that carries case data (#640).",
  "type": "object",
  "allOf": [
    { "$ref": "../_common/CaseData.schema.json" }
  ],
  "required": ["data", "instanceId"],
  "properties": {
    "instanceId": {
      "$ref": "../_common/OpaqueIdentifier.schema.json",
      "description": "HIS-side correlator for this submission. ONE value per POST, regardless of how many `<Fall>` cases ride inside `data`. MUST be unique across the HIS's active sessions: a second POST with an instanceId still in use returns 409 with the existing sessionId. Echoed back in the webhook as `instanceId`."
    },
    "source": {
      "type": "string",
      "enum": ["API", "DLL", "BROWSER"],
      "description": "Channel that initiated the session. HIS REST integrations send `API` (triggers strict validation, including the format-required gate on the server). DLL / UI callers may omit (server defaults to `DLL`)."
    },
    "targetUserId": {
      "$ref": "../_common/OpaqueIdentifier.schema.json",
      "description": "Optional delegation target — when set, the session is created on behalf of this user (not the authenticated caller). The server pushes a CODING_SESSION_LAUNCH event to the target user's connected CodingClient."
    },
    "forceClose": {
      "type": "boolean",
      "description": "If true, force-close any existing DLL session for the (target) user before creating this one. If false (default) and a session exists, the server returns conflict information."
    }
  },
  "unevaluatedProperties": false,
  "examples": [
    {
      "data": "<?xml version=\"1.0\"?><spiges><Fall fall_id=\"F001\">…</Fall></spiges>",
      "format": "spiges",
      "instanceId": "his-2026-06-01-12345",
      "source": "API"
    }
  ]
}
