{
  "openapi": "3.0.3",
  "info": {
    "title": "QuireKit OFD 工作站接入接口",
    "version": "1.2.0",
    "description": "用模板版本和标准填写 JSON 生成 OFD，按业务文书 ID 续写，并按模板版本共享列映射。演示主机仅在本机运行。正式部署由宿主先鉴权，再提供调用者可见的目录。"
  },
  "servers": [
    {
      "url": "http://127.0.0.1:8998/ofd",
      "description": "本机模拟业务系统"
    }
  ],
  "paths": {
    "/templates": {
      "get": {
        "summary": "列出可见模板",
        "operationId": "listTemplates",
        "responses": {
          "200": {
            "description": "可选版本",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Entry"
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Http404"
          },
          "502": {
            "$ref": "#/components/responses/Http502"
          }
        }
      }
    },
    "/templates/{id}/fields": {
      "get": {
        "summary": "读取模板字段与 v3 示例",
        "operationId": "getTemplateFields",
        "responses": {
          "200": {
            "description": "原生绑定与标准填写示例",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Catalog"
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                },
                "description": "带双引号的强版本标识，更新时原样传回 If-Match。"
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Http404"
          },
          "412": {
            "$ref": "#/components/responses/Http412"
          },
          "428": {
            "$ref": "#/components/responses/Http428"
          },
          "502": {
            "$ref": "#/components/responses/Http502"
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "description": "已授权的机构内标识。",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "已选模板版本的强 ETag，例如 \"1\"。",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/templates/{id}/preflight": {
      "post": {
        "summary": "预检标准填写 JSON",
        "operationId": "preflightTemplate",
        "responses": {
          "200": {
            "description": "完整性与逐项冲突",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Review"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Http404"
          },
          "412": {
            "$ref": "#/components/responses/Http412"
          },
          "428": {
            "$ref": "#/components/responses/Http428"
          },
          "502": {
            "$ref": "#/components/responses/Http502"
          },
          "400": {
            "$ref": "#/components/responses/Http400"
          },
          "415": {
            "$ref": "#/components/responses/Http415"
          },
          "422": {
            "description": "输入未通过模板校验",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Review"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "description": "已授权的机构内标识。",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "已选模板版本的强 ETag，例如 \"1\"。",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FillData"
              }
            }
          }
        }
      }
    },
    "/templates/{id}/draft": {
      "post": {
        "summary": "生成独立工作文档",
        "operationId": "generateDraft",
        "responses": {
          "201": {
            "description": "独立的可编辑 OFD",
            "content": {
              "application/ofd": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Http404"
          },
          "412": {
            "$ref": "#/components/responses/Http412"
          },
          "428": {
            "$ref": "#/components/responses/Http428"
          },
          "502": {
            "$ref": "#/components/responses/Http502"
          },
          "400": {
            "$ref": "#/components/responses/Http400"
          },
          "415": {
            "$ref": "#/components/responses/Http415"
          },
          "422": {
            "description": "输入未通过模板校验",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Review"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "description": "已授权的机构内标识。",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "已选模板版本的强 ETag，例如 \"1\"。",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FillData"
              }
            }
          }
        }
      }
    },
    "/drafts": {
      "get": {
        "summary": "列出可见业务草稿",
        "operationId": "listDrafts",
        "responses": {
          "200": {
            "description": "业务文书目录",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Entry"
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Http404"
          },
          "502": {
            "$ref": "#/components/responses/Http502"
          }
        }
      }
    },
    "/drafts/{id}": {
      "get": {
        "summary": "重开业务草稿",
        "operationId": "getDraft",
        "responses": {
          "200": {
            "description": "已保存的当前版本",
            "content": {
              "application/ofd": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                },
                "description": "带双引号的强版本标识，更新时原样传回 If-Match。"
              },
              "OFD-Draft-Name": {
                "schema": {
                  "type": "string"
                },
                "description": "UTF-8 百分号编码的文档名。"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Http400"
          },
          "404": {
            "$ref": "#/components/responses/Http404"
          },
          "502": {
            "$ref": "#/components/responses/Http502"
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "description": "已授权的机构内标识。",
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "put": {
        "summary": "登记或回写业务草稿",
        "operationId": "putDraft",
        "responses": {
          "200": {
            "description": "已更新或已确认的相同内容重试",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Entry"
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                },
                "description": "带双引号的强版本标识，更新时原样传回 If-Match。"
              }
            }
          },
          "201": {
            "description": "首次登记",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Entry"
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                },
                "description": "带双引号的强版本标识，更新时原样传回 If-Match。"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Http400"
          },
          "404": {
            "$ref": "#/components/responses/Http404"
          },
          "412": {
            "$ref": "#/components/responses/Http412"
          },
          "415": {
            "$ref": "#/components/responses/Http415"
          },
          "422": {
            "$ref": "#/components/responses/Http422"
          },
          "428": {
            "$ref": "#/components/responses/Http428"
          },
          "502": {
            "$ref": "#/components/responses/Http502"
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "description": "已授权的机构内标识。",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "name",
            "required": true,
            "description": "文档显示名称（含 .ofd）。",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "If-None-Match",
            "required": false,
            "description": "首次登记传 *。与 If-Match 二选一。",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "If-Match",
            "required": false,
            "description": "更新时传打开的版本，例如 \"1\"。与 If-None-Match 二选一。",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/ofd": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        }
      }
    },
    "/sheet-mappings/{key}": {
      "get": {
        "summary": "读取已发布的列映射",
        "operationId": "getMapping",
        "responses": {
          "200": {
            "description": "已保存的当前版本",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StoredMapping"
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                },
                "description": "带双引号的强版本标识，更新时原样传回 If-Match。"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Http400"
          },
          "404": {
            "$ref": "#/components/responses/Http404"
          },
          "502": {
            "$ref": "#/components/responses/Http502"
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "key",
            "required": true,
            "description": "ofdMappingKey(template, headers) 计算的 64 位十六进制摘要。",
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "put": {
        "summary": "登记或发布共享列映射",
        "operationId": "putMapping",
        "responses": {
          "200": {
            "description": "已更新或已确认的相同内容重试",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StoredMapping"
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                },
                "description": "带双引号的强版本标识，更新时原样传回 If-Match。"
              }
            }
          },
          "201": {
            "description": "首次登记",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StoredMapping"
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                },
                "description": "带双引号的强版本标识，更新时原样传回 If-Match。"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Http400"
          },
          "404": {
            "$ref": "#/components/responses/Http404"
          },
          "412": {
            "$ref": "#/components/responses/Http412"
          },
          "415": {
            "$ref": "#/components/responses/Http415"
          },
          "422": {
            "$ref": "#/components/responses/Http422"
          },
          "428": {
            "$ref": "#/components/responses/Http428"
          },
          "502": {
            "$ref": "#/components/responses/Http502"
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "key",
            "required": true,
            "description": "ofdMappingKey(template, headers) 计算的 64 位十六进制摘要。",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "If-None-Match",
            "required": false,
            "description": "首次登记传 *。与 If-Match 二选一。",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "If-Match",
            "required": false,
            "description": "更新时传打开的版本，例如 \"1\"。与 If-None-Match 二选一。",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Profile"
              }
            }
          }
        }
      }
    },
    "/sheet-mappings/lookup": {
      "post": {
        "summary": "用模板版本及有序表头查询映射和发布键",
        "operationId": "lookupMapping",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MappingLookup"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "目录键和当前配置",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MappingResult"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Http400"
          },
          "415": {
            "$ref": "#/components/responses/Http415"
          },
          "502": {
            "$ref": "#/components/responses/Http502"
          }
        }
      }
    },
    "/templates/{id}/batch-preflight": {
      "post": {
        "summary": "按业务文书号逐份预检",
        "description": "使用指定版本的模板检查每份 v3 数据，返回已有草稿、可生成项和逐项错误。预检不会写入。",
        "operationId": "preflightBatchDrafts",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "description": "已授权的机构内标识。",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "已选模板版本的强 ETag，例如 \"1\"。",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BatchRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "逐份返回结果及待补项",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BatchResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Http404"
          },
          "412": {
            "$ref": "#/components/responses/Http412"
          },
          "428": {
            "$ref": "#/components/responses/Http428"
          },
          "502": {
            "$ref": "#/components/responses/Http502"
          },
          "400": {
            "$ref": "#/components/responses/Http400"
          },
          "415": {
            "$ref": "#/components/responses/Http415"
          }
        }
      }
    },
    "/templates/{id}/batch-drafts": {
      "post": {
        "summary": "生成独立业务草稿",
        "description": "逐份创建。相同文书号和创建输入重放返回现存版本。其他数据占用同一文书号时返回该项失败，已生成或人工修改的文书保留。",
        "operationId": "createBatchDrafts",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "description": "已授权的机构内标识。",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "已选模板版本的强 ETag，例如 \"1\"。",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BatchRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "逐份返回结果及待补项",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BatchResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Http404"
          },
          "412": {
            "$ref": "#/components/responses/Http412"
          },
          "428": {
            "$ref": "#/components/responses/Http428"
          },
          "502": {
            "$ref": "#/components/responses/Http502"
          },
          "400": {
            "$ref": "#/components/responses/Http400"
          },
          "415": {
            "$ref": "#/components/responses/Http415"
          }
        }
      }
    },
    "/drafts/{id}/preflight": {
      "post": {
        "summary": "预检现有草稿的填写和更正",
        "description": "绑定指定业务草稿的当前版本，返回确切差异及确认令牌。",
        "operationId": "preflightWorkingDraft",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "description": "已授权的机构内标识。",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "当前业务草稿的强 ETag，例如 \"1\"。",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FillData"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "当次填写结果和对应的业务草稿版本",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DraftFillReview"
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                },
                "description": "带双引号的强版本标识，更新时原样传回 If-Match。"
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Http404"
          },
          "412": {
            "$ref": "#/components/responses/Http412"
          },
          "428": {
            "$ref": "#/components/responses/Http428"
          },
          "502": {
            "$ref": "#/components/responses/Http502"
          },
          "400": {
            "$ref": "#/components/responses/Http400"
          },
          "415": {
            "$ref": "#/components/responses/Http415"
          },
          "422": {
            "description": "输入未通过模板校验",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/Review"
                    },
                    {
                      "$ref": "#/components/schemas/Problem"
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/drafts/{id}/fill": {
      "post": {
        "summary": "向已有业务草稿应用确认的更改",
        "description": "一次应用新增值及逐项确认的覆盖、清空和撤回。未确认项保留，旧草稿版本返回 412。",
        "operationId": "fillWorkingDraft",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "description": "已授权的机构内标识。",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "当前业务草稿的强 ETag，例如 \"1\"。",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FillData"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "当次填写结果和对应的业务草稿版本",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DraftFillReview"
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                },
                "description": "带双引号的强版本标识，更新时原样传回 If-Match。"
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Http404"
          },
          "412": {
            "$ref": "#/components/responses/Http412"
          },
          "428": {
            "$ref": "#/components/responses/Http428"
          },
          "502": {
            "$ref": "#/components/responses/Http502"
          },
          "400": {
            "$ref": "#/components/responses/Http400"
          },
          "415": {
            "$ref": "#/components/responses/Http415"
          },
          "422": {
            "description": "输入未通过模板校验",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/Review"
                    },
                    {
                      "$ref": "#/components/schemas/Problem"
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/templates/{id}/cda-profile": {
      "get": {
        "summary": "查询选定模板的 WS/T 500 分册、章节及条目约束",
        "operationId": "getMedicalCdaProfile",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "description": "已授权的机构内标识。",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "已选模板版本的强 ETag，例如 \"1\"。",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "2016 版分册结构及官方原文页码。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CdaProfile"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Http404"
          },
          "412": {
            "$ref": "#/components/responses/Http412"
          },
          "422": {
            "$ref": "#/components/responses/Http422"
          },
          "428": {
            "$ref": "#/components/responses/Http428"
          },
          "502": {
            "$ref": "#/components/responses/Http502"
          }
        }
      }
    },
    "/templates/{id}/cda-check": {
      "post": {
        "summary": "按选定分册检查 UTF-8 CDA 文档",
        "operationId": "checkMedicalCda",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "description": "已授权的机构内标识。",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "已选模板版本的强 ETag，例如 \"1\"。",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/xml": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "通过当前结构和值域检查。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CdaCheck"
                }
              }
            }
          },
          "422": {
            "description": "XML 核对结果或模板不支持 CDA。",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/CdaCheck"
                    },
                    {
                      "$ref": "#/components/schemas/Problem"
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Http404"
          },
          "412": {
            "$ref": "#/components/responses/Http412"
          },
          "415": {
            "$ref": "#/components/responses/Http415"
          },
          "428": {
            "$ref": "#/components/responses/Http428"
          },
          "502": {
            "$ref": "#/components/responses/Http502"
          }
        }
      }
    },
    "/drafts/{id}/cda": {
      "get": {
        "operationId": "exportDraftCda",
        "summary": "从医院批准的草稿修订直接导出共享文档 XML",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "description": "已授权的机构内标识。",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "当前业务草稿的强 ETag，例如 \"1\"。",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "从指定草稿修订导出经核验的共享文档。",
            "content": {
              "application/xml": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            },
            "headers": {
              "X-Content-SM3": {
                "schema": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                },
                "description": "返回 XML 字节的 SM3 摘要。"
              }
            }
          },
          "403": {
            "description": "医院未授权导出本次修订。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "XML 核对结果或模板不支持 CDA。",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/CdaCheck"
                    },
                    {
                      "$ref": "#/components/schemas/Problem"
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Http404"
          },
          "412": {
            "$ref": "#/components/responses/Http412"
          },
          "428": {
            "$ref": "#/components/responses/Http428"
          },
          "502": {
            "$ref": "#/components/responses/Http502"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Entry": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "revision": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "name",
          "revision"
        ],
        "additionalProperties": false
      },
      "Template": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "revision": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "revision"
        ],
        "additionalProperties": false
      },
      "Problem": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string"
          }
        },
        "required": [
          "message"
        ]
      },
      "FillData": {
        "type": "object",
        "properties": {
          "version": {
            "type": "integer",
            "enum": [
              3
            ]
          },
          "context": {
            "type": "object",
            "properties": {
              "patientId": {
                "type": "string"
              },
              "encounterId": {
                "type": "string"
              }
            },
            "required": [
              "patientId",
              "encounterId"
            ],
            "additionalProperties": false
          },
          "values": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/FormValue"
            }
          },
          "repeats": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": {
                  "$ref": "#/components/schemas/FormValue"
                }
              }
            }
          },
          "rowKeys": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assets": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "approved": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            }
          },
          "corrections": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Correction"
            },
            "maxItems": 1000
          }
        },
        "required": [
          "version",
          "values"
        ],
        "additionalProperties": false,
        "example": {
          "version": 3,
          "context": {
            "patientId": "SYN-P001",
            "encounterId": "0007"
          },
          "values": {
            "patientNames": "演示患者"
          }
        }
      },
      "Mapping": {
        "type": "object",
        "properties": {
          "fields": {
            "type": "object",
            "additionalProperties": {
              "type": "integer",
              "minimum": 0
            }
          },
          "columns": {
            "type": "object",
            "additionalProperties": {
              "type": "integer",
              "minimum": 0
            }
          },
          "group": {
            "type": "string"
          },
          "rowKey": {
            "type": "string"
          },
          "patientColumn": {
            "type": "integer",
            "minimum": 0
          },
          "encounterColumn": {
            "type": "integer",
            "minimum": 0
          }
        },
        "required": [
          "fields",
          "columns"
        ],
        "additionalProperties": false
      },
      "Profile": {
        "type": "object",
        "properties": {
          "version": {
            "type": "integer",
            "enum": [
              1
            ]
          },
          "template": {
            "$ref": "#/components/schemas/Template"
          },
          "headers": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "mapping": {
            "$ref": "#/components/schemas/Mapping"
          }
        },
        "required": [
          "version",
          "template",
          "headers",
          "mapping"
        ],
        "additionalProperties": false
      },
      "StoredMapping": {
        "type": "object",
        "properties": {
          "revision": {
            "type": "string"
          },
          "profile": {
            "$ref": "#/components/schemas/Profile"
          }
        },
        "required": [
          "revision",
          "profile"
        ],
        "additionalProperties": false
      },
      "Field": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "kind": {
            "type": "string"
          },
          "required": {
            "type": "boolean"
          },
          "multiline": {
            "type": "boolean"
          },
          "maxLength": {
            "type": "integer",
            "minimum": 0
          },
          "format": {
            "type": "string"
          },
          "element": {
            "type": "string"
          }
        }
      },
      "Group": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "capacity": {
            "type": "integer",
            "minimum": 0
          },
          "fields": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Field"
            }
          }
        }
      },
      "Catalog": {
        "type": "object",
        "properties": {
          "fields": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Field"
            }
          },
          "groups": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Group"
            }
          },
          "schema": {
            "type": "object"
          },
          "example": {
            "$ref": "#/components/schemas/FillData"
          }
        },
        "required": [
          "fields",
          "groups",
          "schema",
          "example"
        ]
      },
      "Review": {
        "type": "object",
        "properties": {
          "canFill": {
            "type": "boolean"
          },
          "complete": {
            "type": "boolean"
          },
          "issues": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FieldIssue"
            }
          },
          "conflicts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FieldChange"
            }
          }
        },
        "required": [
          "canFill",
          "complete",
          "issues"
        ]
      },
      "MappingLookup": {
        "type": "object",
        "properties": {
          "template": {
            "$ref": "#/components/schemas/Template"
          },
          "headers": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "template",
          "headers"
        ],
        "additionalProperties": false
      },
      "MappingResult": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "stored": {
            "type": "object",
            "nullable": true,
            "description": "已发布映射及修订，初次使用时为 null。",
            "properties": {
              "revision": {
                "type": "string"
              },
              "profile": {
                "$ref": "#/components/schemas/Profile"
              }
            },
            "required": [
              "revision",
              "profile"
            ]
          }
        },
        "required": [
          "key",
          "stored"
        ]
      },
      "Correction": {
        "description": "明细以 rowKeys 对应的业务字段匹配 id。清空或撤回已有值需逐项确认。",
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "op": {
                "type": "string",
                "enum": [
                  "clear"
                ]
              },
              "field": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              }
            },
            "required": [
              "op",
              "field"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "op": {
                "type": "string",
                "enum": [
                  "clear"
                ]
              },
              "group": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "id": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "field": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              }
            },
            "required": [
              "op",
              "group",
              "id",
              "field"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "op": {
                "type": "string",
                "enum": [
                  "retract"
                ]
              },
              "group": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "id": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              }
            },
            "required": [
              "op",
              "group",
              "id"
            ],
            "additionalProperties": false
          }
        ]
      },
      "FieldIssue": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string"
          },
          "group": {
            "type": "string"
          },
          "field": {
            "type": "string"
          },
          "row": {
            "type": "integer",
            "minimum": 1
          }
        },
        "required": [
          "message"
        ]
      },
      "FieldChange": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "field": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "group": {
            "type": "string"
          },
          "row": {
            "type": "integer"
          },
          "index": {
            "type": "integer"
          },
          "before": {
            "$ref": "#/components/schemas/FormValue"
          },
          "after": {
            "$ref": "#/components/schemas/FormValue"
          },
          "conflict": {
            "type": "boolean"
          },
          "operation": {
            "type": "string",
            "enum": [
              "clear",
              "retract"
            ]
          },
          "businessId": {
            "type": "string"
          },
          "removedValues": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/FormValue"
            }
          }
        },
        "required": [
          "id",
          "field",
          "label",
          "before",
          "after",
          "conflict"
        ]
      },
      "DraftFillReview": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Review"
          },
          {
            "type": "object",
            "properties": {
              "entry": {
                "$ref": "#/components/schemas/Entry"
              },
              "accepted": {
                "type": "integer",
                "minimum": 0
              }
            },
            "required": [
              "entry",
              "accepted"
            ]
          }
        ]
      },
      "BatchItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 160
          },
          "data": {
            "$ref": "#/components/schemas/FillData"
          }
        },
        "required": [
          "id",
          "data"
        ],
        "additionalProperties": false
      },
      "BatchRequest": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BatchItem"
            },
            "minItems": 1,
            "maxItems": 100
          }
        },
        "required": [
          "items"
        ],
        "additionalProperties": false,
        "example": {
          "items": [
            {
              "id": "SYN-L01",
              "data": {
                "version": 3,
                "context": {
                  "patientId": "SYN-P001",
                  "encounterId": "0007"
                },
                "values": {
                  "patientNames": "合成患者"
                }
              }
            }
          ]
        }
      },
      "BatchResult": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "status": {
            "type": "string",
            "enum": [
              "ready",
              "created",
              "existing",
              "failed"
            ]
          },
          "entry": {
            "$ref": "#/components/schemas/Entry"
          },
          "issues": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FieldIssue"
            }
          },
          "conflicts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FieldChange"
            }
          }
        },
        "required": [
          "id",
          "status",
          "issues"
        ],
        "additionalProperties": false
      },
      "BatchResponse": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BatchResult"
            }
          }
        },
        "required": [
          "items"
        ],
        "additionalProperties": false
      },
      "FormValue": {
        "oneOf": [
          {
            "type": "string"
          },
          {
            "type": "boolean"
          },
          {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "picture"
                ]
              },
              "asset": {
                "type": "string",
                "nullable": true
              }
            },
            "required": [
              "type",
              "asset"
            ],
            "additionalProperties": false
          }
        ]
      },
      "CdaNodeRule": {
        "type": "object",
        "required": [
          "path",
          "required",
          "attributes"
        ],
        "properties": {
          "path": {
            "type": "string"
          },
          "required": {
            "type": "boolean"
          },
          "attributes": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          }
        }
      },
      "CdaObservationType": {
        "type": "object",
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "ST",
              "CD",
              "BL",
              "INT",
              "REAL",
              "TS",
              "PQ",
              "MO"
            ]
          },
          "codeSystem": {
            "type": "string"
          },
          "unit": {
            "type": "string"
          }
        }
      },
      "CdaEntry": {
        "type": "object",
        "required": [
          "number",
          "act",
          "elements",
          "rules",
          "components"
        ],
        "properties": {
          "number": {
            "type": "integer"
          },
          "label": {
            "type": "string"
          },
          "reviewNote": {
            "type": "string"
          },
          "act": {
            "type": "string",
            "enum": [
              "observation",
              "organizer",
              "procedure",
              "substanceAdministration",
              "act",
              "encounter"
            ]
          },
          "code": {
            "type": "string"
          },
          "elements": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "min": {
            "type": "integer"
          },
          "max": {
            "type": "integer"
          },
          "observation": {
            "$ref": "#/components/schemas/CdaObservationType"
          },
          "rules": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CdaNodeRule"
            }
          },
          "components": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "code"
              ],
              "properties": {
                "code": {
                  "type": "string"
                },
                "type": {
                  "type": "string"
                },
                "codeSystem": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "CdaSection": {
        "type": "object",
        "required": [
          "name",
          "min",
          "max",
          "displayName",
          "sourcePage",
          "entries"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "min": {
            "type": "integer"
          },
          "max": {
            "type": "integer"
          },
          "code": {
            "type": "string"
          },
          "codeSystem": {
            "type": "string"
          },
          "displayName": {
            "type": "string"
          },
          "sourcePage": {
            "type": "integer"
          },
          "entries": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CdaEntry"
            }
          }
        }
      },
      "CdaProfile": {
        "type": "object",
        "required": [
          "part",
          "code",
          "templateRoot",
          "requiresExtension",
          "standard",
          "sourceSha256",
          "source",
          "patientIdRoot",
          "patientRoleIds",
          "header",
          "sections",
          "patientElements"
        ],
        "properties": {
          "part": {
            "type": "integer"
          },
          "code": {
            "type": "string"
          },
          "templateRoot": {
            "type": "string"
          },
          "requiresExtension": {
            "type": "boolean"
          },
          "standard": {
            "type": "string"
          },
          "sourceSha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "source": {
            "type": "string",
            "format": "uri"
          },
          "patientIdRoot": {
            "type": "string"
          },
          "patientRoleIds": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "root"
              ],
              "properties": {
                "root": {
                  "type": "string"
                },
                "element": {
                  "type": "string"
                },
                "min": {
                  "type": "integer"
                },
                "max": {
                  "type": "integer"
                }
              }
            }
          },
          "header": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "minItems": 2,
              "maxItems": 2,
              "description": "最小和最大出现次数，最大值为 null 表示无上限。",
              "items": {
                "type": "integer",
                "nullable": true
              }
            }
          },
          "sections": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CdaSection"
            }
          },
          "patientElements": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "name"
              ],
              "properties": {
                "name": {
                  "type": "string"
                },
                "min": {
                  "type": "integer"
                },
                "max": {
                  "type": "integer"
                },
                "codeSystem": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "CdaCheck": {
        "type": "object",
        "required": [
          "valid",
          "issues"
        ],
        "properties": {
          "valid": {
            "type": "boolean"
          },
          "issues": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "path",
                "message"
              ],
              "properties": {
                "path": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "responses": {
      "Http404": {
        "description": "资源未配置或不可见",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Problem"
            }
          }
        }
      },
      "Http502": {
        "description": "宿主未确认请求",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Problem"
            }
          }
        }
      },
      "Http412": {
        "description": "版本过期或标识已被占用",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Problem"
            }
          }
        }
      },
      "Http428": {
        "description": "缺少唯一的写入前置条件",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Problem"
            }
          }
        }
      },
      "Http400": {
        "description": "请求格式错误",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Problem"
            }
          }
        }
      },
      "Http415": {
        "description": "请求体类型不受支持",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Problem"
            }
          }
        }
      },
      "Http422": {
        "description": "文档、映射或业务身份校验失败",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Problem"
            }
          }
        }
      }
    }
  }
}
