# SDK

> Dart / Flutter (anpheros_sdk) および TypeScript (@anpheros/sdk) クライアント: 同じ形状、冪等な作成、リトライ、トークンリフレッシュ、および同意フロー。

Source: https://developers.anpheros.com/ja/guides/sdks

> FHIR R4 ヘルスケア API 用の公式クライアントライブラリ。無料の FHIR サンドボックスを備え、患者、観察結果、検査結果、病状、投薬、International Patient Summary、患者の同意、AI コンテキストを TypeScript および Dart / Flutter で利用できます。

**Anpheros は、ヘルスケアアプリケーション、医療ソフトウェア、AI サービスを構築するための相互運用可能な医療データインフラストラクチャです。** 各患者は、自身が管理する 1 つの HL7 FHIR R4 レコードを持ちます。アプリケーション、クリニック、ラボ、AI エージェントは、患者の同意 (OAuth 2.1 / SMART on FHIR)、すべての書き込みに対する来歴、および患者が確認できるアクセスログを通じて、Anpheros Platform API を介してそれを読み書きします。このリポジトリには、公式クライアントライブラリと実行可能なサンプルが含まれています。

| 言語 | パッケージ | インストール | ソース |
|---|---|---|---|
| Dart / Flutter | [`anpheros_sdk`](https://pub.dev/packages/anpheros_sdk) | `dart pub add anpheros_sdk` | [`dart/anpheros_sdk`](https://github.com/anpheros/anpheros-sdk/tree/main/dart/anpheros_sdk) |
| TypeScript (Node 18+, ブラウザ, Deno, Bun) | [`@anpheros/sdk`](https://www.npmjs.com/package/@anpheros/sdk) | `npm install @anpheros/sdk` | [`ts`](https://github.com/anpheros/anpheros-sdk/tree/main/ts) |

## 2分でクイックスタート

1.  **無料のサンドボックスキーを取得する:** [ダッシュボード](https://platform.anpheros.com/dashboard/)にサインインし、**サンドボックスキーを取得** (`sk_test_…`) をクリックします。サンドボックスには 30 人の合成患者が含まれています。
2.  **動作確認:**

    ```bash
   curl -H "Authorization: Bearer $ANPHEROS_KEY" "https://platform.anpheros.com/fhir/R4/Patient?_count=3"
   ```

3.  **SDK をインストールしてレコードを読む:** `npm install @anpheros/sdk` または `dart pub add anpheros_sdk` を選択し、[Connect](#connect) の下のコードを実行するか、[quickstart-ts](https://github.com/anpheros/anpheros-sdk/tree/main/examples/quickstart-ts) をクローンします。

## 対象者

患者や家族向けのヘルスケアアプリ、医療アプリのバックエンド、クリニックや検査室との連携、患者の構造化された医療コンテキストを必要とするAIアシスタントやエージェントを開発する開発者。これらの開発者は、医療データベース、同意システム、監査証跡を一から設計する必要がありません。

## Sandboxキーの取得

サンドボックスは無料でセルフサービスでご利用いただけます。[ダッシュボード](https://platform.anpheros.com/dashboard/)でGoogleでサインインし、「**Sandboxキーを取得**」ボタンを押してください。これにより、サンドボックスプロジェクトとキーが即座に発行されます。各サンドボックスプロジェクトには、30人の合成患者（6ヶ月分の病状、処方薬、アレルギー、検査結果、バイタルサイン）が含まれており、自由に編集したり、いつでもリセットしたりできます。サンドボックスキー（`sk_test_…`）は、実際の患者データにアクセスすることはありません。

本番環境への移行時には、データ処理契約を締結済みの認証済み組織が対象となります。本番環境は月額€99からで、初月は無料です（[料金](https://developers.anpheros.com/ja/guides/pricing)）。

## 接続

```ts
import { Anpheros, apiKey } from '@anpheros/sdk';

const anpheros = new Anpheros({ auth: apiKey(process.env.ANPHEROS_KEY!) });   // sk_test_… in the sandbox
const { data: patients } = await anpheros.patients.list();
const labs = await anpheros.observations.list(patients[0].id, { category: 'laboratory', limit: 10 });
const ctx = await anpheros.context.build({ patient: patients[0].id, task: 'weekly check-in', budget_tokens: 1500, format: 'text' });
```

```dart
import 'package:anpheros_sdk/anpheros_sdk.dart';

final anpheros = Anpheros(auth: AnpherosAuth.apiKey('sk_test_…'));
final patients = await anpheros.patients.list();
final labs = await anpheros.observations.list(patients.data.first.id, category: 'laboratory', limit: 10);
```

APIキーはサーバー上に配置します。個人に代わって動作するアプリは、代わりにOAuthを使用します。SDKはどちらも同意フロー（認可コード + PKCE）を実装し、リフレッシュトークンを自動的に処理します。

## SDK のカバー範囲

どちらの SDK も、パブリックサーフェス全体（`/v1`、`/fhir/R4`、`/oauth/token`、`/oauth/revoke`）を同じ形式でカバーしています。具体的には、`patients`、`observations`、`conditions`、`medications`、`documents`、`timeline`、`provenance`、`context`、`grants`、`terminology`、および生の `fhir` です。パブリックルートがいずれかの SDK に存在しない場合、または SDK がサーバーに存在しないルートを呼び出した場合、テストはビルドで失敗します。

両方の SDK に共通する機能：
* 作成時の自動 `Idempotency-Key`
* 429/5xx エラー時のバックオフ付きリトライ
* 401 エラー時のトークンリフレッシュ（1回）
* リクエスト ID を含む型指定されたエラー
* PKCE ヘルパー
* 同意フロー

## 医療データとFHIR

レコードは標準的なFHIR R4リソースで構成されています — `Observation`、`Condition`、`MedicationStatement`、`DocumentReference`、`Immunization`、`AllergyIntolerance` を含む26種類のリソースが、LOINC、ICD-10、ATC、UCUMでコード化されています。REST API (`/v1`) とFHIR API (`/fhir/R4`) は、同じIDで同じリソースを読み書きします。両方のSDKの`fhir`は、生のFHIRアクセス（検索、トランザクション、`$everything`、`$summary`、`$validate`）を提供します。

## 例

| 例 | 内容 |
|---|---|
| [quickstart-ts](https://github.com/anpheros/anpheros-sdk/tree/main/examples/quickstart-ts) | レコードの書き込みと読み取り: 測定値、検査結果、診断、投薬、タイムライン、FHIR検索、IPS、AIコンテキスト |
| [quickstart-dart](https://github.com/anpheros/anpheros-sdk/tree/main/examples/quickstart-dart) | Dart / Flutter からの同様の例 |
| [consent-app-ts](https://github.com/anpheros/anpheros-sdk/tree/main/examples/consent-app-ts) | 同意を求めるWebアプリ (OAuth 2.1 + PKCE) と個人のレコードの読み取り |
| [ai-context-llm](https://github.com/anpheros/anpheros-sdk/tree/main/examples/ai-context-llm) | 選択したモデル (ローカルまたはホスト) によって回答されるレコードに関する質問 |
| [fhir-transaction](https://github.com/anpheros/anpheros-sdk/tree/main/examples/fhir-transaction) | FHIR R4 トランザクションバンドルと、それによって生成される International Patient Summary |

これらの例は無料のサンドボックスで実行されます。各サンドボックスプロジェクトには、それぞれ30人の合成患者が用意されています。詳細は[サンドボックスキーの取得](#get-a-sandbox-key)を参照してください。

## 関連リポジトリ

| リポジトリ | 内容 |
|---|---|
| [fhir-api-openapi](https://github.com/anpheros/fhir-api-openapi) | API の OpenAPI 3.1 仕様および Postman コレクション |
| [mcp-server](https://github.com/anpheros/mcp-server) | AI エージェント向けのホスト済み FHIR MCP サーバー: Claude, Cursor, VS Code 用の設定 |
| [agent-skills](https://github.com/anpheros/agent-skills) | Agent Skill, Claude Code プラグイン, Cursor ルールおよび AGENTS.md |
| [fhir-synthetic-patients](https://github.com/anpheros/fhir-synthetic-patients) | 30 件の合成患者データ (FHIR R4 Bundles および NDJSON 形式) |
| [ips-examples](https://github.com/anpheros/ips-examples) | 国際患者サマリー (IPS) ドキュメント (FHIR R4 形式) |
| [fhir-validate-action](https://github.com/anpheros/fhir-validate-action) | CI で FHIR R4 JSON を検証する GitHub Action |
| [lab-results-to-fhir](https://github.com/anpheros/lab-results-to-fhir) | CLI: CSV / HL7 v2 の検査レポート → FHIR Observations |
| [healthcare-app-starters](https://github.com/anpheros/healthcare-app-starters) | Next.js および Flutter のヘルスケアアプリテンプレート |

## 適合性

生のテスト結果は、確認できるように公開されています（認定ではなく、テスト結果です）：[conformance/](https://github.com/anpheros/anpheros-sdk/tree/main/conformance)。2026年9月28日、Inferno SMART App Launch STU2 テストキット（v1.0.3）の Standalone Launch グループは、プラットフォームに対して 22 件中 22 件のテストに合格しました。EHR 起動はサポートされていません。

## ドキュメント

- [開発者ガイド](https://developers.anpheros.com/guides/)
- [はじめに](https://developers.anpheros.com/ja/guides/getting-started)
- [FHIRサンドボックス](https://developers.anpheros.com/ja/guides/fhir-sandbox)
- [ヘルスケアAPI](https://developers.anpheros.com/ja/guides/healthcare-api)
- [ヘルスケアAPIプラットフォーム](https://developers.anpheros.com/ja/guides/healthcare-api-platform)
- [FHIRプラットフォーム](https://developers.anpheros.com/ja/guides/fhir)
- [SDKガイド](https://developers.anpheros.com/ja/guides/sdks)
- [APIリファレンス (OpenAPI)](https://developers.anpheros.com/docs)
- [AIアシスタント向け](https://developers.anpheros.com/llms.txt)
- [Anpheros](https://anpheros.com/)

## 問題とセキュリティ

バグは、このリポジトリのイシューで報告してください。イシューにAPIキー、トークン、または患者データを絶対に入れないでください。セキュリティに関する報告は、contact@anpheros.com までご連絡ください。

## ライセンス

Apache License 2.0 — 各パッケージの`LICENSE`ファイルを参照してください。Copyright 2026 Anpheros。

## @anpheros/sdk

**Anpheros Platform** 用 TypeScript クライアント。このプラットフォームは、患者ごとの FHIR R4 ヘルスレコード、プロジェクト分離、患者同意 (OAuth 2.1 / SMART on FHIR)、すべての書き込みに対するプロベナンス、および AI コンテキスト API を提供します。`fetch` が存在するあらゆる場所 (Node 18 以降、ブラウザ、Deno、Bun) で実行できます。

```ts
import { Anpheros, apiKey } from '@anpheros/sdk';

const anpheros = new Anpheros({ auth: apiKey(process.env.ANPHEROS_KEY!) });
const { data: patients } = await anpheros.patients.list();
const labs = await anpheros.observations.list(patients[0].id, { category: 'laboratory', limit: 10 });
const ctx = await anpheros.context.build({ patient: patients[0].id, task: 'weekly check-in', budget_tokens: 1500, format: 'text' });
```

代理で操作する場合:

```ts
import { OAuthFlow, OAuthAuth, generatePkce } from '@anpheros/sdk';

const flow = new OAuthFlow({ baseUrl: BASE, clientId: 'client_…', redirectUri: 'https://myapp.example/callback' });
const pkce = await generatePkce();
location.href = flow.authorizeUrl({ scopes: ['patient/Observation.rs?category=laboratory', 'offline_access'], state, pkce, lang: 'ro' });
// on the callback:
const tokens = await flow.exchange(code, pkce);
const anpheros = new Anpheros({ auth: new OAuthAuth({ tokens, onRefresh: flow.refresh, onTokens: persist }) });
```

エラーは `AnpherosError` です (`status`、`type`、`message`、`field`、`requestId`)。送信されたリクエストは `Idempotency-Key` を生成します。429/5xx エラーはリトライされます。期限切れのトークンは一度だけリフレッシュされ、呼び出しがリトライされます。

## anpheros_sdk

**Anpheros Platform** 用の Dart / Flutter クライアント。Anpheros Platform は、患者ごとの FHIR R4 レコード、プロジェクト分離、患者同意 (OAuth 2.1 / SMART on FHIR)、すべての書き込みに対する来歴、および AI コンテキスト API を備えたヘルスデータバックエンドです。

```dart
import 'package:anpheros_sdk/anpheros_sdk.dart';

final anpheros = Anpheros(auth: AnpherosAuth.apiKey('sk_test_…'));      // server / sandbox

final patients = await anpheros.patients.list();
final elena = patients.data.first;
final labs = await anpheros.observations.list(elena.id, category: 'laboratory', limit: 10);
final ctx = await anpheros.context.build(ContextRequest(patient: elena.id, task: 'weekly check-in', budgetTokens: 1500));
```

## 個人として行動する（アプリ）

```dart
final flow = OAuthFlow(baseUrl: 'https://…', clientId: 'client_…', redirectUri: 'myapp://callback');
final pkce = Pkce.generate();
final url = flow.authorizeUrl(scopes: ['patient/Observation.rs?category=laboratory', 'patient/MedicationStatement.r', 'offline_access'],
                              state: 'abc', pkce: pkce, lang: 'ro');
// open `url`; on return with ?code=…:
final tokens = await flow.exchange(code: code, pkce: pkce);
final anpheros = Anpheros(auth: AnpherosAuth.oauth(
  accessToken: tokens.accessToken, refreshToken: tokens.refreshToken, expiresAt: tokens.expiresAt,
  onRefresh: flow.refresh, onTokens: persist));
final meds = await anpheros.medications.listMedications(tokens.patient!);
```

すべてのオブジェクトには、`fhir`（その`/fhir/R4`参照）が付属しています。`anpheros.fhir`は生のFHIRアクセス（read, search, create, transaction, `$everything`, `$summary`, `$validate`）を提供します。

エラーは、`AnpherosException`、`status`、`type`、`message`、`field`、`requestId`とともに返されます。
Createリクエストは自動的に`Idempotency-Key`を送信します。429/5xxエラーはバックオフ付きでリトライされます。期限切れのOAuthトークンは一度リフレッシュされ、呼び出しがリトライされます。
