# One fill-data contract

Use the same versioned JSON to fill scalar fields and detail rows from a spreadsheet or a business system.

## Select the target template first

Open 文件 → 导入 → 填写数据 for the current document. An integration selects a template revision and calls `GET /ofd/templates/{id}/fields` for its scalar fields, detail groups and column keys. Display labels can change by organization. Use the stable keys for writing. If a template has no form controls, add and bind them in the editor first.

## An ordinary office form

For an incoming-mail register, bind the reference number and subject controls to `incomingNumber` and `subject`. Two spreadsheet columns or two properties from an office system can produce the same request.

```json
{ "version": 3, "values": { "incomingNumber": "OA-0024", "subject": "Quarterly meeting" } }
```

## A record with detail rows

This synthetic lab record matches the downloads below. `values` holds document-wide values. `repeats` contains ordered detail rows. `rowKeys` identifies an existing row on subsequent imports. Medical records use `context` for patient and encounter identity. Ordinary business forms can omit medical context.

```json
{
  "version": 3,
  "context": { "patientId": "SYN-P001", "encounterId": "0007" },
  "values": { "patientNames": "合成甲", "reportNumber": "SYN-L01" },
  "rowKeys": { "labItems": "sourceResultId" },
  "repeats": {
    "labItems": [
      { "sourceResultId": "R001", "itemCode": "LAB-A", "numericResult": "0", "resultUnit": "mmol/L" },
      { "sourceResultId": "R002", "itemCode": "LAB-B", "numericResult": "3", "resultUnit": "mmol/L" }
    ]
  }
}
```

<a href="/downloads/laboratory-sample.xlsx" download="laboratory-sample.xlsx">Download the synthetic workbook</a> · <a href="/downloads/laboratory-record.json" download="laboratory-record.json">Download the matching JSON</a>

## Two sources, one workflow

- **Excel**　Open the matching blank laboratory template. Select the worksheet, header row, patient and encounter columns. Map results to a detail group, select one record and review the proposed changes. Export the resulting JSON to test the same data through an API.
- **Business system**　Build v3 JSON from the same field keys. Submit it to the template's `preflight` endpoint, then create a draft against the same revision. To update an existing draft, use its own preflight and fill endpoints with the draft revision.

Keep identifiers such as `"0007"` as strings and retain zero-valued results such as `"0"`. Review unmapped fields, row identities and conflicts before applying a change. [HTTP and revision handling](/en/integration/http)
