

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 產生臨床文件 `$document`
<a name="reference-fhir-operations-document"></a>

AWS HealthLake 現在支援合成資源的 `$document`操作，可讓您將合成與其所有參考的資源綁定到單一的整合套件中，以產生完整的臨床文件。此操作對於需要：
+ 建立標準化臨床文件
+ Exchange 完整患者記錄
+ 存放完整的臨床文件
+ 產生包含所有相關內容的報告

## Usage
<a name="document-usage"></a>

您可以使用 GET 和 POST 方法在合成資源上叫用 `$document`操作：

**受支援的 操作**  


```
GET/POST [base]/Composition/[id]/$document
```

## 支援的參數
<a name="document-parameters"></a>

HealthLake 支援下列 FHIR `$document` 參數：


| 參數 | Type | 必要 | 預設 | Description | 
| --- | --- | --- | --- | --- | 
| persist | 布林值 | 否 | false | 布林值，指出伺服器是否應存放產生的文件套件 | 

## 範例
<a name="document-examples"></a>

**GET 請求**  


```
GET [base]/Composition/180f219f-97a8-486d-99d9-ed631fe4fc57/$document?persist=true
```

**具有參數的 POST 請求**  


```
POST [base]/Composition/180f219f-97a8-486d-99d9-ed631fe4fc57/$document
Content-Type: application/fhir+json

{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "persist",
      "valueBoolean": true
    }
  ]
}
```

**回應範例**  
操作會傳回「文件」類型的套件資源，其中包含合成和所有參考的資源：

```
{
  "resourceType": "Bundle",
  "id": "180f219f-97a8-486d-99d9-ed631fe4fc57",
  "type": "document",
  "identifier": {
    "system": "urn:ietf:rfc:3986",
    "value": "urn:uuid:0c3151bd-1cbf-4d64-b04d-cd9187a4c6e0"
  },
  "timestamp": "2024-06-21T15:30:00Z",
  "entry": [
    {
      "fullUrl": "http://example.org/fhir/Composition/180f219f-97a8-486d-99d9-ed631fe4fc57",
      "resource": {
        "resourceType": "Composition",
        "id": "180f219f-97a8-486d-99d9-ed631fe4fc57",
        "status": "final",
        "type": {
          "coding": [
            {
              "system": "http://loinc.org",
              "code": "34133-9",
              "display": "Summary of Episode Note"
            }
          ]
        },
        "subject": {
          "reference": "Patient/example"
        },
        "section": [
          {
            "title": "Allergies",
            "entry": [
              {
                "reference": "AllergyIntolerance/123"
              }
            ]
          }
        ]
      }
    },
    {
      "fullUrl": "http://example.org/fhir/Patient/example",
      "resource": {
        "resourceType": "Patient",
        "id": "example",
        "name": [
          {
            "family": "Smith",
            "given": ["John"]
          }
        ]
      }
    },
    {
      "fullUrl": "http://example.org/fhir/AllergyIntolerance/123",
      "resource": {
        "resourceType": "AllergyIntolerance",
        "id": "123",
        "patient": {
          "reference": "Patient/example"
        },
        "code": {
          "coding": [
            {
              "system": "http://snomed.info/sct",
              "code": "418689008",
              "display": "Allergy to penicillin"
            }
          ]
        }
      }
    }
  ]
}
```

## Behavior (行為)
<a name="document-behavior"></a>

`$document` 操作：

1. 將指定的合成資源做為文件的基礎

1. 識別和擷取合成直接參考的所有資源

1. 將合成和所有參考的資源封裝到類型為「文件」的套件中

1. 當持久性參數設定為 true 時，將產生的文件套件儲存在資料存放區中

1. 識別和擷取 合成間接參考的資源，以產生全面的文件

`$document` 操作目前支援以下列格式擷取資源參考：

1. 

   ```
   GET https://healthlake.region.amazonaws.com/datastore/datastoreId/r4/Resource/id
   ```

1. 資源/id

合成資源中不支援的資源參考將從產生的文件篩選出。

## 錯誤處理
<a name="document-error-handling"></a>

操作會處理下列錯誤條件：
+ 400 錯誤的請求：無效的`$document`操作 （不符合的請求），或者如果產生的文件在持久性設定為 true 時因篩選掉的參考而失敗 FHIR 驗證
+ 找不到 404：找不到合成資源

如需 `$document`操作規格的詳細資訊，請參閱 [FHIR R4 合成`$document`](https://www.hl7.org/fhir/R4/composition-operation-document.html)文件。