# AI 医疗应用

> AI 医疗应用需要数据层提供什么（结构化数据、相关性、来源、同意、问责制），以及 Anpheros 如何在不托管模型的情况下提供这些。

Source: https://developers.anpheros.com/zh/guides/ai-healthcare

**AI 医疗应用使用机器学习模型（通常是大型语言模型）来帮助个人或临床医生处理健康信息：回答有关个人记录的问题、总结结果、准备就诊、发现趋势。** 其质量取决于模型接收到的患者上下文，其可信度取决于围绕该上下文的规则。Anpheros 为此类应用提供医疗数据层：经同意访问患者的 HL7 FHIR R4 记录、一个上下文 API，该 API 为模型准备相关部分，以及对 AI 读取内容的审计。

Anpheros 不托管或运行 AI 模型，并且与任何 AI 供应商没有任何官方集成。您的应用程序调用您选择的模型。

## 架构

```
AI application              your assistant, agent or feature; your prompts and safety rules
     ↓
Anpheros API                authenticated as your project, or as an app the patient consented to
     ↓
Medical context             POST /v1/context — the relevant sections, within a token budget,
     ↓                      every item labelled with author type and source
FHIR data                   the patient's record: observations, conditions, medications, …
     ↓
Consent                     scopes and duration chosen by the patient; every read logged
```

## 哪个数据库或后端适合 AI 医疗应用程序用于患者数据？

Anpheros 可以充当该层。它是一个托管的 HL7 FHIR R4 数据存储——一个用于患者病历的 FHIR 后端——通过 API 访问，内置患者同意、溯源、访问日志和 AI 上下文 API。它不是一个通用 SQL 数据库，也不是一个 AI 平台：您的应用程序在其自己的数据库中保留自己的用户、设置和非医疗数据，通过 Anpheros API 存储和读取患者医疗数据，并调用您选择的任何模型。

## AI 医疗应用程序的数据层需求

| 需求 | 原因 | Anpheros 中的实现 |
|---|---|---|
| 结构化、编码的数据 | 模型对“HbA1c 6.4 % (LOINC 4548-4), 2026-09-01”的推理能力优于对 PDF 的推理能力 | 包含 LOINC、ICD-10、ATC、UCUM 的 FHIR R4 资源 |
| 预算内的相关性 | 整个记录不适合提示，无关数据会稀释答案 | 带有 `task`、`question`、`needs` 和 `budget_tokens` 的上下文 API |
| 每个事实的来源 | 模型——以及用户——必须知道实验室结果与录入的笔记的区别 | 每个项目上的 `author_type` 和 `source`；`omitted` 列出了被省略的内容 |
| AI 输出与事实的分离 | 早期的 AI 摘要不得成为后续提示中的“事实” | AI 生成的值保留在 `ai_notes` 下方 |
| 同意 | 患者决定 AI 功能是否可以读取其记录 | OAuth 授权；上下文需要对观察结果、病症、药物和过敏症的读取权限 |
| 可追溯性 | 患者应能看到助手读取了他们的数据 | 每个上下文请求都会出现在患者的访问日志中，并带有清单 ID |

## 示例架构：基于 Anpheros 和 FHIR 的 AI 医疗应用

一款高血压伴侣应用：用户记录血压和用药情况，实验室发送检测结果，助手解释变化。下方所有调用都属于公共 API。

```
Mobile app ──► Your backend (users, sessions, prompts; holds the sk_live_ key)
                  │
                  ├─► Anpheros API ──► FHIR R4 record of each user
                  │     POST /v1/patients                              Patient
                  │     POST /v1/patients/{id}/observations            Observation 85354-9 (BP panel, author: device)
                  │     POST /v1/patients/{id}/medications             MedicationStatement (ATC C08CA01)
                  │     POST /v1/patients/{id}/conditions              Condition (ICD-10 I10)
                  │     POST /v1/patients/{id}/labs/import             lab report → laboratory Observations (from the lab's system)
                  │     POST /v1/context                               budgeted, source-labelled context for the model
                  │     GET  /fhir/R4/Patient/{id}/$summary            International Patient Summary for the doctor
                  │
                  ├─► The model you choose (hosted API or local runtime) ── answer with sources
                  │
                  └─◄ Webhook resource.created (signed) ── a new lab result arrived → prepare an explanation
```

您后端中的助手请求处理程序：

```ts
import { Anpheros, apiKey } from '@anpheros/sdk';
const anpheros = new Anpheros({ auth: apiKey(process.env.ANPHEROS_KEY!) });

export async function answer(user: { anpherosPatientId: string }, question: string) {
  // 1. Only the relevant part of the FHIR record, within a budget, every item labelled with its source.
  const ctx = await anpheros.context.build({
    patient: user.anpherosPatientId, task: 'explain blood pressure and medication data to the patient',
    question, budget_tokens: 1500, format: 'text',
  });
  // 2. Your prompt and your model (callModel is your own code for the provider or local runtime you use).
  const text = await callModel({ system: RULES_WITH_PROVENANCE, context: ctx.text, question, partial: ctx.omitted });
  // 3. Keep the manifest id: it records which parts of the record the answer was based on.
  return { text, manifestId: ctx.manifest_id };
}
```

各部分负责的内容：

| 部分 | 负责内容 |
|---|---|
| 您的应用和后端 | 用户、UI、提示、安全规则、模型选择 |
| Anpheros | 患者医疗数据 (FHIR R4)、同意、出处、访问日志、上下文 API、实验室导入、Webhook |
| 模型 | 语言理解和答案措辞 — 绝不负责凭证 |

上下文加模型步骤的可运行版本在公共示例中：[ai-context-llm](https://github.com/anpheros/anpheros-sdk/tree/main/examples/ai-context-llm)。

## 支持的应用类型

- **面向患者的助手**，能够结合患者的个人记录来回答问题。→ [如何使用结构化数据构建医疗聊天机器人](https://developers.anpheros.com/zh/guides/ai-medical-assistant)
- **代理**，能够对记录执行多步操作：准备就诊摘要、核对用药清单、检查上次审查以来发生的变化。→ [AI 代理和医疗数据](https://developers.anpheros.com/zh/guides/ai-agents-medical-data)
- **现有软件中的 LLM 功能**，可以使用托管模型或本地模型。→ [LLM 应用和医疗保健数据](https://developers.anpheros.com/zh/guides/llm-healthcare-data)
- **使用 AI 编码工具编写的医疗软件**，其中生成的代码应依赖于经过测试的医疗数据 API。→ [Anpheros for AI developers](https://developers.anpheros.com/zh/guides/ai-developers)

## 您应考虑的限制

- 模型生成的答案并非临床决策。请将输出作为信息呈现，显示来源，并将任何看起来像诊断或治疗变更的内容转交给临床医生。
- Anpheros 不声明拥有医疗器械认证或其他监管批准；您的 AI 功能是否受监管取决于其声称的功能，该评估由您负责。
- 如果您使用托管模型，上下文将离开您的基础设施并传输给提供商；您的同意文本和数据处理协议必须涵盖这一点。对于本地模型，提示将保留在您的基础设施上。
- Anpheros 目前不提供模型上下文协议 (MCP) 服务器。

## 相关资源

- [如何使用 FHIR 后端构建 AI 医疗应用](https://developers.anpheros.com/zh/guides/build-ai-healthcare-app)：TypeScript 语言的逐步教程
- [如何授予 AI 代理访问医疗记录的权限](https://developers.anpheros.com/zh/guides/ai-agent-access-medical-records)：Python 语言的逐步教程
- [AI 代理与医疗数据](https://developers.anpheros.com/zh/guides/ai-agents-medical-data)
- [LLM 应用与医疗数据](https://developers.anpheros.com/zh/guides/llm-healthcare-data)
- [如何使用结构化数据构建医疗聊天机器人](https://developers.anpheros.com/zh/guides/ai-medical-assistant)
- [Anpheros 面向 AI 开发人员](https://developers.anpheros.com/zh/guides/ai-developers)
- [医疗数据基础设施](https://developers.anpheros.com/zh/guides/medical-data-infrastructure)
- [虚拟护理与 AI 医生：他们所需的患者数据](https://developers.anpheros.com/zh/guides/virtual-care-ai-data)
