1. 必要なツールの概要
FHIR を効果的に実践するには、次のツールを準備する必要があります。
| ツール | 目的 | 必須ですか? |
|---|---|---|
| HAPI FHIR サーバー | 練習用のローカル FHIR サーバー | はい |
| ドッカー | HAPI FHIR サーバーを実行する | はい |
| 郵便配達員/ブルーノ | テストAPI | はい |
| VSコード | FHIR 拡張機能を備えたエディター | はい |
| Node.js | SUSHI (FHIR 短縮コンパイラ) を実行します。 | おすすめ |
| Java 17+ | HAPI FHIR クライアント ライブラリ | オプション |
2. Docker を使用して HAPI FHIR サーバーをインストールする
ハピ・フィル は、Java で書かれた最も人気のあるオープン ソース FHIR サーバーです。これを実行する最も速い方法は、Docker を使用することです。
ステップ 1: docker-compose.yml ファイルを作成する
version: "3.8"
services:
hapi-fhir:
image: hapiproject/hapi:latest
container_name: hapi-fhir-server
ports:
- "8080:8080"
environment:
- hapi.fhir.fhir_version=R5
- hapi.fhir.allow_multiple_delete=true
- hapi.fhir.allow_external_references=true
- hapi.fhir.reuse_cached_search_results_millis=-1
volumes:
- hapi-data:/data/hapi
restart: unless-stopped
volumes:
hapi-data:
ステップ 2: サーバーを起動する
# Tạo thư mục dự án
mkdir fhir-lab && cd fhir-lab
# Tạo docker-compose.yml (nội dung ở trên)
# Khởi chạy
docker compose up -d
# Kiểm tra log
docker compose logs -f hapi-fhir
30 ~ 60 秒ほど待ちます。サーバーの準備が整います。 http://localhost:8080.
ステップ 3: サーバーを確認する
# Lấy CapabilityStatement
curl -s http://localhost:8080/fhir/metadata | jq '.fhirVersion'
# Kết quả: "5.0.0"
# Kiểm tra resource types được hỗ trợ
curl -s http://localhost:8080/fhir/metadata | jq '.rest[0].resource | length'
# Kết quả: 157 (hoặc gần đó)
HAPI FHIR Web UI
アクセス http://localhost:8080 HAPI FHIR Web テスト UI にアクセスします。これは、コードを記述せずにすべての FHIR 操作を実行できる Web インターフェイスです。
3. パブリック FHIR テスト サーバー
ローカル サーバーに加えて、パブリック サーバーを使用して以下をテストできます。
| サーバー | URL | バージョン | 注意事項 |
|---|---|---|---|
| ハピ FHIR R5 | https://hapi.fhir.org/baseR5 | R5 | Public, 無料、定期的にリセット |
| ハピ FHIR R4 | https://hapi.fhir.org/baseR4 | R4 | Public, 無料 |
| Firelyサーバー | https://server.fire.ly | R4 | Sandbox 無料 |
| スマートヘルスIT | https://launch.smarthealthit.org | R4 | SMART FHIR サンドボックス上 |
注: 実際のデータを公開サーバーに投稿しないでください。テスト/合成データのみを使用してください。
4. FHIR 用に Postman を構成する
ステップ 1: コレクションを作成する
Postman で次の変数を使用してコレクション「FHIR Lab」を作成します。
ベースURL=http://localhost:8080/fhir
ステップ 2: 基本的なリクエストを作成する
1. CapabilityStatement (メタデータの取得)
GET {{baseUrl}}/metadata
Accept: application/fhir+json
2. 患者の作成 (POST)
POST {{baseUrl}}/Patient Content-Type: application/fhir+json Accept: application/fhir+json
{ "resourceType": "Patient", "identifier": [{ "system": "http://fhir.vn/sid/cccd", "value": "001085012345" }], "name": [{ "use": "official", "family": "Nguyễn", "given": ["Văn", "A"] }], "gender": "male", "birthDate": "1985-03-15", "address": [{ "use": "home", "line": ["123 Lê Lợi, Quận 1"], "city": "Thành phố Hồ Chí Minh", "country": "VN" }], "telecom": [{ "system": "phone", "value": "+84901234567", "use": "mobile" }] }
3. 患者の読み取り (GET)
GET {{baseUrl}}/Patient/{{patientId}}
Accept: application/fhir+json
4. 患者の検索(GET)
GET {{baseUrl}}/Patient?family=Nguyen&gender=male
Accept: application/fhir+json
5. 患者の更新 (PUT)
PUT {{baseUrl}}/Patient/{{patientId}}
Content-Type: application/fhir+json
Accept: application/fhir+json
5. FHIR 用の VS コード拡張機能
便利な拡張機能をインストールします。
FHIR ツール (推奨)
FHIR 略記法 (SUSHI/HL7) — FSH の構文ハイライト
RESTクライアント (Huachao Mao) — VS Code から HTTP リクエストを直接送信します
JSON パス ファインダー — 大規模な JSON をナビゲートする
VS Code での REST クライアントの使用
ファイルの作成 fhir-test.http:
@baseUrl = http://localhost:8080/fhir
### Metadata
GET {{baseUrl}}/metadata
Accept: application/fhir+json
### Create Patient
POST {{baseUrl}}/Patient
Content-Type: application/fhir+json
{
"resourceType": "Patient",
"name": [{"family": "Trần", "given": ["Thị", "B"]}],
"gender": "female",
"birthDate": "1990-07-20"
}
### Search all patients
GET {{baseUrl}}/Patient?_count=10
Accept: application/fhir+json
各リクエストの上にある「リクエストを送信」をクリックして送信します。
6. FHIR 略記法 (FSH) と SUSHI
FHIR 略記法 (FSH) プロファイル、拡張機能、バリューセットを簡潔に記述するための仕様言語です。 寿司 FSH を FHIR リソースにコンパイルするコンパイラです。
SUSHIをインストールする
# Cài Node.js (nếu chưa có)
# macOS
brew install node
# Cài SUSHI globally
npm install -g fsh-sushi
# Kiểm tra
sushi --version
簡単な FSH の例
Profile: VNPatient
Parent: Patient
Id: vn-patient
Title: "Vietnam Core Patient Profile"
Description: "Profile cho bệnh nhân Việt Nam"
* identifier 1..* MS
* identifier ^slicing.discriminator.type = #pattern
* identifier ^slicing.discriminator.path = "system"
* identifier ^slicing.rules = #open
* identifier contains cccd 0..1 MS
* identifier[cccd].system = "http://fhir.vn/sid/cccd"
* identifier[cccd].value 1..1
* name 1..* MS
* gender 1..1 MS
* birthDate 1..1 MS
FSH は、レッスン 13 (プロファイル) とレッスン 20 (実装ガイド) で広範囲に使用されます。
7. 実践: 最初の CRUD 操作
それでは、HAPI FHIR サーバーの基本的な操作を練習してみましょう。
7.1.患者の作成 (CREATE)
curl -X POST http://localhost:8080/fhir/Patient \
-H "Content-Type: application/fhir+json" \
-d '{
"resourceType": "Patient",
"identifier": [{
"system": "http://fhir.vn/sid/cccd",
"value": "001085012345"
}],
"name": [{
"use": "official",
"family": "Nguyễn",
"given": ["Văn", "A"]
}],
"gender": "male",
"birthDate": "1985-03-15",
"address": [{
"line": ["123 Lê Lợi"],
"city": "Hồ Chí Minh",
"country": "VN"
}]
}'
サーバーが戻ります 201 件が作成されました ヘッダー付き 場所: 患者/{id}/_history/1。
7.2.患者の読み取り (READ)
# Thay {id} bằng id thực tế được trả về
curl -s http://localhost:8080/fhir/Patient/{id} | jq '.name[0]'
7.3.患者の検索 (SEARCH)
# Tìm theo họ
curl -s "http://localhost:8080/fhir/Patient?family=Nguyen" | jq '.total'
# Tìm theo giới tính
curl -s "http://localhost:8080/fhir/Patient?gender=male" | jq '.entry | length'
# Tìm theo identifier (số CCCD)
curl -s "http://localhost:8080/fhir/Patient?identifier=http://fhir.vn/sid/cccd|001085012345" | jq '.entry[0].resource.name'
7.4.患者の更新 (UPDATE)
curl -X PUT http://localhost:8080/fhir/Patient/{id} \
-H "Content-Type: application/fhir+json" \
-d '{
"resourceType": "Patient",
"id": "{id}",
"identifier": [{
"system": "http://fhir.vn/sid/cccd",
"value": "001085012345"
}],
"name": [{
"use": "official",
"family": "Nguyễn",
"given": ["Văn", "A"]
}],
"gender": "male",
"birthDate": "1985-03-15",
"telecom": [{
"system": "phone",
"value": "+84901234567",
"use": "mobile"
}],
"address": [{
"line": ["456 Nguyễn Huệ"],
"city": "Hồ Chí Minh",
"country": "VN"
}]
}'
7.5。患者の削除 (DELETE)
curl -X DELETE http://localhost:8080/fhir/Patient/{id}
# Trả về 200 OK hoặc 204 No Content
7.6.履歴を見る(HISTORY)
# Lịch sử một resource cụ thể
curl -s http://localhost:8080/fhir/Patient/{id}/_history | jq '.entry | length'
# Lịch sử toàn bộ Patient type
curl -s "http://localhost:8080/fhir/Patient/_history?_count=5" | jq '.entry[].request.method'
8. バッチテストデータの作成
豊富な実践データを得るには、次を使用します。 シンテア — 合成患者データを作成するツール:
# Cài Synthea (cần Java 11+)
git clone https://github.com/synthetichealth/synthea.git
cd synthea
# Tạo 10 bệnh nhân
./run_synthea -p 10 --exporter.fhir.export=true
# Output sẽ nằm trong output/fhir/
ls output/fhir/
出力ファイルは FHIR バンドル (トランザクション) であり、サーバーに直接 POST できます。
# Upload một bundle lên server
curl -X POST http://localhost:8080/fhir \
-H "Content-Type: application/fhir+json" \
-d @output/fhir/hospitalInformation1234.json
9. 推奨されるプロジェクト構造
fhir-lab/
├── docker-compose.yml # HAPI FHIR Server
├── http/ # REST Client files
│ ├── patient.http
│ ├── observation.http
│ └── search.http
├── fsh/ # FHIR Shorthand files
│ ├── input/
│ │ └── fsh/
│ │ ├── profiles/
│ │ ├── extensions/
│ │ └── valuesets/
│ └── sushi-config.yaml
├── sample-data/ # Dữ liệu mẫu
│ ├── patients/
│ ├── observations/
│ └── bundles/
└── scripts/ # Scripts tiện ích
├── load-data.sh
└── cleanup.sh
10. まとめ
この記事では、次の内容を説明します。
インストール HAPI FHIR サーバー Docker (ポート 8080) を使用する
を知る FHIR テストサーバー パブリック (hapi.fhir.org)
構成 郵便屋さん そして VS コード REST クライアント FHIR用
インストール 寿司 (FHIR 短縮コンパイラ)
練習する CRUD操作: 作成、読み取り、検索、更新、削除、履歴
使用する シンテア 合成テストデータを作成する
次の記事ではさらに深く掘り下げていきます FHIR リソース — 患者、医師、組織、管理リソースから始めます。