AnpherosAnpheros PlatformDevelopers

Try it free in the sandbox · first FHIR call in 5 minutesFree · 30 synthetic patients · no card

构建医疗应用

教程:将 Anpheros 用作医疗应用的数据后端 — 患者、测量值、病情、药物、文件、实验室、同意、Webhook 和 SDK。

本教程展示了医疗健康或医疗应用如何使用 Anpheros Platform 作为其医疗数据后端:存储患者记录、如何读写这些记录、如何连接其他系统以及患者如何保持控制权。下方每个调用都是公共 API 的一部分(参考)。

您正在构建的内容

典型的面向患者的应用——例如慢性病追踪器、家庭健康应用、远程监控伴侣——需要:

  1. 为每位患者维护一份记录:包括测量值、病情、用药、文档;
  2. 以列表和时间轴的形式展示该记录;
  3. 接受来自其他来源(设备、实验室、诊所)的数据;
  4. 在获得患者同意的情况下,共享记录的某些部分;
  5. 在发生变化时做出响应。

通过 Anpheros,您的应用可以保留自己的用户、界面和业务逻辑,并将医疗记录委托给平台:

Mobile / web app ──► your backend ──► Anpheros Platform API ──► FHIR R4 record of each patient
                         ▲                                              │
                         └──────────── signed webhooks ◄────────────────┘

您的后端持有 API 密钥;应用与您的后端通信。(代表已有 Anpheros 记录的患者而运行的应用则使用 OAuth——请参阅第 7 步。)

1. 获取沙盒密钥

沙盒是自助服务:在仪表板 (https://platform.anpheros.com/dashboard/) 上使用 Google 登录,然后按 获取沙盒密钥。沙盒密钥以 sk_test_ 开头,只能访问沙盒数据库,您的项目在该数据库中已拥有 30 名合成患者的副本。

export BASE=https://platform.anpheros.com
export KEY=sk_test_…
curl $BASE/v1/patients -H "Authorization: Bearer $KEY"

2. 创建患者

您的应用中的每个用户都会获得一个由您的项目拥有的患者记录。

curl -X POST $BASE/v1/patients -H "Authorization: Bearer $KEY" -H 'content-type: application/json' \
     -H "Idempotency-Key: $(uuidgen)" \
     -d '{"given": "Elena", "family": "Ionescu", "birth_date": "1985-09-03", "gender": "female"}'

响应包含患者 id(您为该个人指定的标识符——其他项目会看到不同的标识符)及其 fhir 引用。

3. 写入测量值、诊断和药物

使用 author_type: patient, practitioner, device, import 或 ai 来声明数据的来源。如果省略,平台将记录 import,绝不会默认记录 patient。

# a blood-pressure reading from a connected device (LOINC panel with two components)
curl -X POST $BASE/v1/patients/$PID/observations -H "Authorization: Bearer $KEY" -H 'content-type: application/json' \
     -H "Idempotency-Key: $(uuidgen)" -d '{
  "code": "85354-9", "display": "Blood pressure panel", "category": "vital-signs",
  "effective_at": "2026-09-28T08:00:00Z", "author_type": "device",
  "components": [
    {"code": "8480-6", "display": "Systolic", "value": 128, "unit": "mm[Hg]"},
    {"code": "8462-4", "display": "Diastolic", "value": 82, "unit": "mm[Hg]"}
  ]}'

# a diagnosis (ICD-10 by default)
curl -X POST $BASE/v1/patients/$PID/conditions -H "Authorization: Bearer $KEY" -H 'content-type: application/json' \
     -d '{"code": "I10", "display": "Essential hypertension", "onset": "2024-03-01", "author_type": "practitioner"}'

# a medication (ATC by default)
curl -X POST $BASE/v1/patients/$PID/medications -H "Authorization: Bearer $KEY" -H 'content-type: application/json' \
     -d '{"display": "Amlodipine 5 mg", "code": "C08CA01", "dosage": "1 tablet in the morning", "start": "2024-03-01", "author_type": "patient"}'

Observation 类别:vital-signs, laboratory, symptom, activity, survey, exam, imaging, social-history。每次写入都会存储为 FHIR 资源,并自动获得一个 Provenance 条目。

4. 存储文档

# create the document, then upload the bytes
curl -X POST $BASE/v1/patients/$PID/documents -H "Authorization: Bearer $KEY" -H 'content-type: application/json' \
     -d '{"title": "Blood tests 2026-09-14", "kind": "lab_report", "content_type": "application/pdf", "date": "2026-09-14"}'
curl -X PUT $BASE/v1/documents/$DOC/content -H "Authorization: Bearer $KEY" -H 'content-type: application/pdf' --data-binary @report.pdf

上传后,原始文档不可变;您可以从中提取的值可以指向它,使用 derived_from。

5. 读回记录

curl "$BASE/v1/patients/$PID/observations?category=vital-signs&limit=20" -H "Authorization: Bearer $KEY"
curl "$BASE/v1/patients/$PID/medications?status=active" -H "Authorization: Bearer $KEY"
curl "$BASE/v1/patients/$PID/timeline?from=2026-06-01" -H "Authorization: Bearer $KEY"   # everything, chronologically

当您需要完整的 FHIR 模型时,相同的数据可在 /fhir/R4 处获取,使用相同的 ID(FHIR R4 API)。

6. 连接实验室和设备

7. 访问患者已有的记录 (OAuth)

如果该用户已经在 Anpheros 中拥有记录(例如通过 Anpheros Daily),您的应用可以请求访问权限,而不是创建新患者:注册一个应用,将用户引导至您所需的 scope 的同意页面,用 code 交换 token,然后使用 access token 调用 API。用户可以选择访问时长,并可以随时撤销访问权限。详情请参阅:Authentication and OAuth。

8. 使用 Webhook 响应变更

curl -X POST $BASE/v1/webhooks -H "Authorization: Bearer $KEY" -H 'content-type: application/json' \
     -d '{"url": "https://your.app/anpheros/hook", "events": ["resource.created", "consent.revoked"]}'

验证每次推送的 Anpheros-Signature 头部 (Webhooks)。

9. 使用 SDK

相同的流程,使用 TypeScript 实现:

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

const anpheros = new Anpheros({ auth: apiKey(process.env.ANPHEROS_KEY!) });
const { data: patients } = await anpheros.patients.list();
const vitals = await anpheros.observations.list(patients[0].id, { category: 'vital-signs', limit: 20 });

同样形状的 Dart / Flutter 客户端可在 anpheros_sdk (SDKs) 中找到。

上线生产环境之前

相关资源

Try it free in the sandbox · first FHIR call in 5 minutesFree · 30 synthetic patients · no card

Product updates by email

New features, guides and the end of the beta. One email a month at most.

Send me occasional Anpheros Platform updates by email (new features, API changes, guides). I'll confirm by email and can unsubscribe in one click from any email. Privacy