

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

# 使用 STOW-RS 存放執行個體
<a name="dicomweb-storing"></a>

AWS HealthImaging 提供用於匯入資料的 [https://www.dicomstandard.org/using/dicomweb/store-stow-rs](https://www.dicomstandard.org/using/dicomweb/store-stow-rs) APIs表示法。使用這些 APIs 將 DICOM 資料同步儲存到您的 HealthImaging 資料存放區。

下表說明可用於匯入資料的 DICOMweb STOW-RS APIs 的 HealthImaging 表示法。


**HealthImaging 表示 DICOMweb STOW-RS APIs**  

| 名稱 | 描述 | 
| --- | --- | 
| StoreDICOM | 將一或多個執行個體儲存到 HealthImaging 資料存放區。 | 
| StoreDICOMStudy | 將一個或多個對應至指定試驗執行個體 UID 的執行個體儲存至 HealthImaging 資料存放區。 | 

使用 `StoreDICOM`和 `StoreDICOMStudy`動作匯入的資料將組織為新的主要影像集，或新增至現有的主要影像集，使用與非同步[匯入任務](https://docs.aws.amazon.com/healthimaging/latest/devguide/understanding-import-jobs.html)相同的邏輯。如果新匯入的 DICOM P10 資料的中繼資料元素與現有的主要[影像集](https://docs.aws.amazon.com/healthimaging/latest/devguide/getting-started-concepts.html#concept-image-set)衝突，則新資料將新增至非主要[影像集](https://docs.aws.amazon.com/healthimaging/latest/devguide/getting-started-concepts.html#concept-image-set)。

**注意**  
這些動作支援每個請求上傳最多 1GB 的 DICOM 資料。
API 回應將採用 JSON 格式，符合 DICOMweb STOW-RS 標準。

**啟動 StoreDICOM 請求**  


1. 收集您的 AWS 區域、HealthImaging `datastoreId`和 DICOM P10 檔案名稱。

1. 建構表單請求的 URL： `https://dicom-medical-imaging.{{region}}.amazonaws.com/datastore/{{datastore-id}}/studies`

1. 使用您偏好的命令判斷 DICOM P10 檔案的內容長度，例如 `$(stat -f %z $FILENAME)`。

1. 準備並傳送您的請求。 `StoreDICOM`使用 HTTP POST 請求搭配 [AWS Signature 第 4 版](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv.html)簽署通訊協定。

 

**Example 範例 1：使用 `StoreDICOM`動作存放 DICOM P10 檔案**  

```
curl -X POST -v \
  'https://dicom-medical-imaging.us-east-1.amazonaws.com/datastore/d9a2a515ab294163a2d2f4069eed584c/studies' \
  --aws-sigv4 "aws:amz:$AWS_REGION:medical-imaging" \
  --user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \
  --header "x-amz-security-token:$AWS_SESSION_TOKEN" \
  --header "x-amz-content-sha256: STREAMING-AWS4-HMAC-SHA256-PAYLOAD" \
  --header "x-amz-decoded-content-length: $CONTENT_LENGTH" \
  --header 'Accept: application/dicom+json' \
  --header "Content-Type: application/dicom" \
  --upload-file $FILENAME
```

**Example 範例 2：使用 `StoreDICOMStudy`動作存放 DICOM P10 檔案**  
StoreDICOM 和 StoreDICOMStudy 之間的唯一區別是，將研究執行個體 UID 作為參數傳遞給 StoreDICOMStudy，且上傳的執行個體必須是指定研究的成員。  

```
curl -X POST -v \
  'https://dicom-medical-imaging.us-east-1.amazonaws.com/datastore/d9a2a515ab294163a2d2f4069eed584c/studies/1.3.6.1.4.1.5962.1.2.4.20040826285059.5457' \
  --aws-sigv4 "aws:amz:$AWS_REGION:medical-imaging" \
  --user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \
  --header "x-amz-security-token:$AWS_SESSION_TOKEN" \
  --header "x-amz-content-sha256: STREAMING-AWS4-HMAC-SHA256-PAYLOAD" \
  --header "x-amz-decoded-content-length: $CONTENT_LENGTH" \
  --header 'Accept: application/dicom+json' \
  --header "Content-Type: application/dicom" \
  --upload-file $FILENAME
```

**Example 範例 3：使用分段 HTTP 承載存放 DICOM P10 檔案**  
您可以使用單一分段上傳動作來上傳多個 P10 檔案。下列 shell 命令示範如何組合包含兩個 P10 檔案的分段承載，並使用 `StoreDICOM`動作將其上傳。  

```
#!/bin/sh
FILENAME=multipart.payload
BOUNDARY=2a8a02b9-0ed3-c8a7-7ebd-232427531940
boundary_str="--$BOUNDARY\r\n"
mp_header="${boundary_str}Content-Type: application/dicom\r\n\r\n"

##Encapsulate the binary DICOM file 1.
printf '%b' "$mp_header" > $FILENAME
cat file1.dcm >> $FILENAME

##Encapsulate the binary DICOM file 2 (note the additional CRLF before the part header).
printf '%b' "\r\n$mp_header" >> $FILENAME
cat file2.dcm >> $FILENAME

## Add the closing boundary.
printf '%b' "\r\n--$BOUNDARY--" >> $FILENAME

## Obain the payload size in bytes.
multipart_payload_size=$(stat -f%z "$FILENAME")

# Execute CURL POST request with AWS SIGv4
curl -X POST -v \
  'https://iad-dicom.external-healthlake-imaging.ai.aws.dev/datastore/b5f34e91ca734b39a54ac11ea42416cf/studies' \
  --aws-sigv4 "aws:amz:us-east-1:medical-imaging" \
  --user "AKIAIOSFODNN7EXAMPLE:wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" \
  --header "x-amz-content-sha256: STREAMING-AWS4-HMAC-SHA256-PAYLOAD" \
  --header "x-amz-decoded-content-length: ${multipart_payload_size}" \
  --header 'Accept: application/dicom+json' \
  --header "Content-Type: multipart/related; type=\"application/dicom\"; boundary=\"${BOUNDARY}\"" \
  --data-binary "@$FILENAME"

# Delete the payload file
rm $FILENAME
```