# @claudebernard/web-component-fhir-utils 中文文档

规范地址：https://npmcn.com/package/%40claudebernard/web-component-fhir-utils/

版本：2\.7\.0
npm 元数据更新时间：2026-11-04T08:25:33.983Z
中文译文更新时间：2026-11-10T00:13:54.703Z
软件包许可：未声明

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40claudebernard/web-component-fhir-utils
原文对照：https://npmcn.com/package/%40claudebernard/web-component-fhir-utils/?lang=original

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：120 kB，63 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：0 个
- peer 依赖：@types/fhir ^0\.0\.41
- 首次发布：2026-07-29T09:13:21.805Z
- 最新版本发布：2026-11-04T08:25:33.796Z
- 近 30 天下载量：2879（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：19（近 12 个月 19 个）

## 中文简介

克劳德·贝尔纳网络组件及其集成器的共享FHIR Bundle公用事业(收集/交易捆绑,前作处方链接).

## 安装

```sh
npm install @claudebernard/web-component-fhir-utils
```

也可以使用：`pnpm add @claudebernard/web-component-fhir-utils`、`yarn add @claudebernard/web-component-fhir-utils`、`bun add @claudebernard/web-component-fhir-utils`

## README

# @claudebernard/web-组件-fhir-utils

共享 FHIR( 共享 FHIR ) `Bundle` claude Bernard药物网络组件的助手(`bcb-medication-request-editor`, (中文(简体) ), `bcb-therapeutic-alternative`及其嵌入的应用程序.

这些部件需要小型FHIR `collection` 装入并释放一个 FHIR `transaction` Bundle 描述确切的变化——标准 `Bundle.entry.request.method` 语义学,没有自定义的 DTO. 这个包裹给了你合同的两面 所以你从不写和解密码:

-   **整合应用程序?** 构建输入 Bundle, 然后将输出 Bundle 应用回您的状态 .
-   **搭建组件?** 使用相同的助手来制作符合标准的交易 diff .

参见关于 [Claude Bernard 开发者门户网站](https://platform.claudebernard.fr/doc) 用于更广泛的FHIR模型

> **状态 :** 此包定义了目标 Bundle- in/ Bundle-out 合同 。 请检查每个组件自己的更改日志, 查看它采用的版本 —— 在此之前, 参考该组件的 `integration` 用于当前 API 的 doc .

## 安装

```
npm install @claudebernard/web-component-fhir-utils
```

## 集成应用程序

构建输入库, 推动组件所需的任何资源 :

```ts
import { createCollectionBundle } from "@claudebernard/web-component-fhir-utils";

const bundle = createCollectionBundle();
bundle.entry.push({ resource: medication });
bundle.entry.push({ resource: medicationRequest });
```

包厢是随机的 `id` (UUID) 默认; 用 `createCollectionBundle(resources, { id })`列出若干处方(例如:. `bcb-shared-medication-review`(b) 以下列方式确定每一方: `Bundle.id`,所以保持稳定 如果你重建包。 通过的资源构建的条目 `fullUrl` (单位:千美元)`<resourceType>/<id>`) (中文(简体) ).

建立一个完整的处方(有日期、病人和开具处方者 `bcb-shared-medication-review` 用于按日期排序处方、使用 `createDocumentBundle`数字 :

```ts
const prescription = createDocumentBundle([medication, medicationRequest], {
  date: "2026-10-21",
  patientId: patient.id,
  practitionerName: "Dr Martin",
});
```

它返回一个 `document` 首个条目是 A 的 Bundle `Composition` (日期、标题、病人、作者) `Practitioner`。 。 。 .

```html
<bcb-medication-request-editor .medication="${bundle}"></bcb-medication-request-editor>
```

将交易包套用组件向自己的组件包套用——这是您需要的唯一的集成代码,它从不改变每个组件或每个特性:

```ts
import { applyTransactionBundle } from "@claudebernard/web-component-fhir-utils";

editor.addEventListener("fhir-changes", ({ detail }) => {
  myPrescriptionBundle = applyTransactionBundle(myPrescriptionBundle, detail.bundle);
});
```

`applyTransactionBundle` 懂了吗 `POST` (附录), `PUT` (由 `resourceType` + 键 `id`),以及 `DELETE` (由 `resourceType` + 键 `id`选项 :

| 选项 | 默认 | 效果 |
| --- | --- | --- |
| `onMissingTarget` | `"append"` | `"throw"` 响亮的失败, 而不是默默地插入缺失的 `PUT` / 忽略缺失 `DELETE` |
| `fullUrlFormat` | `"urn:uuid"` | `fullUrl` 给这些条目的调用`POST`,或一个 `PUT` 缺失目标的附件 : `"urn:uuid"` → `urn:uuid:<id>`, (中文(简体) ), `"resource-type"` → `<resourceType>/<id>` (怎样) `createCollectionBundle` ),或函数 `(resource) => string`现有条目保留其 `fullUrl` |

要在行中应用多个交易包, 请使用 `applyTransactionBundles`。它们按数组顺序应用,每个都看到前一个结果;选项相同:

```ts
import { applyTransactionBundles } from "@claudebernard/web-component-fhir-utils";

myPrescriptionBundle = applyTransactionBundles(myPrescriptionBundle, [firstTransaction, secondTransaction], {
  fullUrlFormat: "resource-type",
});
```

## 使用处方包

### 取消药品

`removeMedications` 返回从处方中删除药品的交易条目: `Medication`,每个 `MedicationRequest` 指向它(包括挂起历史)和匹配的参考文献 `Composition.section.entry` 联合国 `PUT` 报告 `Composition`) (中文(简体) ). 像其它diff一样应用它们,然后使用 `isPrescriptionEmpty` 决定整个处方是否应该去——删除它会保持你的呼声,因为你坚持:

```ts
import {
  applyTransactionBundle, createTransactionBundle, isPrescriptionEmpty, removeMedications,
} from "@claudebernard/web-component-fhir-utils";

const entries = removeMedications(myPrescriptionBundle, [medicationId]);
myPrescriptionBundle = applyTransactionBundle(myPrescriptionBundle, createTransactionBundle(entries));

if (isPrescriptionEmpty(myPrescriptionBundle)) {
  // no active MedicationRequest left: delete the prescription on your side
}
```

仅 `MedicationRequest`s 引用已删除 `Medication` 直接删除。 请求 _又一个_ 药物,只是一种被移除的药 `priorPrescription` (治疗-替代交换)是现场替换并保存。 未知的ID被忽略 .

### 清理套装

`cleanBundle` 返回一个没有其 **孤儿** 资源(没有链接,也没有链接到Bundle的其他任何资源),而不拖动 `Composition.section.entry` 引用( 空出部分被删除) 。 其纯而能通.

```ts
import { cleanBundle, getCleanupEntries } from "@claudebernard/web-component-fhir-utils";

myPrescriptionBundle = cleanBundle(myPrescriptionBundle);

// or, to emit the cleanup as part of a transaction diff (DELETE per orphan, PUT per updated Composition):
const entries = getCleanupEntries(myPrescriptionBundle);
```

-   `Composition`, (中文(简体) ), `Patient` 财务报告和审定财务报表 `Practitioner` 永远不会删除, 即使没有链接到它们。 覆盖 `{ keep: ["Composition", ...] }`。 。 。 .
-   非活动资源`on-hold` 历史通过 `priorPrescription`)不是孤儿,被收留.
-   无资源 `id` 因为交易不能针对他们.

### 寻找相关资源

`findResourceReferences` 列出资源 a Bundle 资源引用(`references`和那些引用它的人`referencedBy`),通过每个 `Reference.reference` (单位:千美元)`medication`, (中文(简体) ), `priorPrescription`, (中文(简体) ), `subject`, (中文(简体) ), `Composition.section.entry`(中文(简体) ). `target` 是一个 `id`页:1 `Type/id` 引用,或资源本身.

```ts
import { findResourceReferences } from "@claudebernard/web-component-fhir-utils";

const { referencedBy } = findResourceReferences<MedicationRequest>(bundle, medication, {
  direction: "incoming",
  resourceType: "MedicationRequest",
});
```

| 选项 | 默认 | 效果 |
| --- | --- | --- |
| `direction` | `"both"` | `"outgoing"` (怎样) `target` 参考文献), `"incoming"` (参考内容)或 `"both"` |
| `transitive` | `false` | 跟踪链接直到链条结束 |
| `includeInactive` | `false` | 资源也不再使用,而且不再使用`on-hold`, (中文(简体) ), `stopped`, (中文(简体) ), `cancelled`, (中文(简体) ), `completed`, (中文(简体) ), `entered-in-error`, (中文(简体) ), `inactive`, (中文(简体) ), `revoked`, (中文(简体) ), `deprecated`,或 `active: false`(中文(简体) ) |
| `resourceType` | 全部 | 只返回此类资源 |

不论拼写方式如何,都与参考书目相匹配(`Type/id`, (中文(简体) ), `urn:uuid:<id>`,一个条目的 `fullUrl`; 绝对 URL); 包含的关于Bundle中缺失的资源的引用(`#id`),而克恩语引用被忽略.

## 构建一个构成部分

生成 diff 条目 `createBundleEntry` 编号 : `createTransactionBundle`数字 :

```ts
import { createBundleEntry, createTransactionBundle } from "@claudebernard/web-component-fhir-utils";

const bundle = createTransactionBundle([
  createBundleEntry(updatedResource, "PUT"),
  createBundleEntry(newResource, "POST"),
]);
```

对于常见的"本药用请求"取而代之的病例"(剂量超过,治疗替代,.),使用 `supersedeMedicationRequest` - 它产生搁置 `PUT` + 链接, 有标记 `POST` 所以每个部件都以同样的方式代表超级会话:

```ts
import { PriorPrescriptionReason, supersedeMedicationRequest } from "@claudebernard/web-component-fhir-utils";

const entries = supersedeMedicationRequest(
  originalMedicationRequest,
  { dosageInstruction: newDosage },
  PriorPrescriptionReason.DOSAGE_OVERRIDE,
  { bundle: inputBundle }, // optional, see below
);
```

传出原生活口 `options.bundle` 和每个 `Composition` 列出原始内容 `section.entry` 也得到一个 `PUT` 将该引用交换为新请求,因此文档不再指向待机请求。 无 `bundle`,仅返回以下两个条目.

两个主要条目的形状是这样的 diff 形状是这样的—— 最初的要求去 `on-hold` 通过 `PUT`,新的一个创建 `active` 通过 `POST` 并链接回通过 `priorPrescription`数字 :

```json
{
  "resourceType": "Bundle",
  "type": "transaction",
  "entry": [
    {
      "resource": { "resourceType": "MedicationRequest", "id": "mr-123", "status": "on-hold", "...": "..." },
      "request": { "method": "PUT", "url": "MedicationRequest/mr-123" }
    },
    {
      "resource": {
        "resourceType": "MedicationRequest",
        "id": "mr-456",
        "status": "active",
        "dosageInstruction": ["..."],
        "priorPrescription": {
          "reference": "MedicationRequest/mr-123",
          "extension": [{ "url": "https://platform.claudebernard.fr/fhir/StructureDefinition/prior-prescription-reason", "valueCode": "dosage-override" }]
        }
      },
      "request": { "method": "POST", "url": "MedicationRequest" }
    }
  ]
}
```

### 超会场原因

`PriorPrescriptionReason` 携带 _为什么_ 新要求取代旧要求,因为 `valueCode` 编辑 `priorPrescription` 扩展名。 选择一个符合用户意图的 —— 消费者过滤它 与 `hasPriorPrescriptionReason`数字 :

| 数值 | 代码 | 何时 |
| --- | --- | --- |
| `PriorPrescriptionReason.DOSAGE_OVERRIDE` | `dosage-override` | 同样的药物,剂量改变 |
| `PriorPrescriptionReason.MEDICATION_OVERRIDE` | `medication-override` | 不同的药物,同样的治疗意图 |
| `PriorPrescriptionReason.THERAPEUTIC_ALTERNATIVE` | `therapeutic-alternative` | 备选案文 `bcb-therapeutic-alternative` |

更多的工作实例(包括治疗-替代案例)正在 [开发者门户](https://platform.claudebernard.fr/doc) 向导.

## API 密码

| 导出 | 目的 |
| --- | --- |
| `createCollectionBundle(resources?, options?)` | 构建输入 `collection` 套装( R)`options.id`,默认情况下随机UUID) |
| `createDocumentBundle(resources?, { date, patientId, practitionerName?, id? })` | 构建处方 `document` 套装( R)`Composition` + 键 `Practitioner` (第一个) |
| `createBundleEntry(resource, method, url?)` | 构建一个交易条目( E)`POST`编号 :`PUT`编号 :`DELETE`(中文(简体) ) |
| `createTransactionBundle(entries)` | 将条目围入输出 `transaction` 套装 |
| `applyTransactionBundle(target, transaction, options?)` | 将交易套装到您持有的套装上( T)`options.onMissingTarget`, (中文(简体) ), `options.fullUrlFormat`(中文(简体) ) |
| `applyTransactionBundles(target, transactions, options?)` | 按顺序将多个交易套装在您持有的套装上 |
| `findResourceInBundle(bundle, resourceType, id)` | 按类型 + id 查找资源 |
| `supersedeMedicationRequest(original, changes, reason, { bundle? })` | 建立备用/`priorPrescription`/ 超会话的扩展对; 与 `bundle`中,还有 `PUT` 转换引用到 `Composition.section.entry` |
| `removeMedications(bundle, medicationIds)` | 删除药物条目,其 `MedicationRequest`s,以及他们的 `Composition.section.entry` 参考文献 |
| `isPrescriptionEmpty(bundle)` | 无活动时为真 `MedicationRequest` 左边 |
| `cleanBundle(bundle, options?)` 编号 : `getCleanupEntries(bundle, options?)` | 丢弃无主资源并拖动 `Composition.section.entry` 引用( 作为 Bundle / 作为交易项) |
| `findResourceReferences(bundle, target, options?)` | 资源参考文献`direction`, (中文(简体) ), `transitive`, (中文(简体) ), `includeInactive`, (中文(简体) ), `resourceType`(中文(简体) ) |
| `hasPriorPrescriptionReason(medicationRequest, reason)` | 检查为什么 `MedicationRequest` 替换另一个 |
| `PriorPrescriptionReason`, (中文(简体) ), `PRIOR_PRESCRIPTION_REASON_URL`, (中文(简体) ), `BCB_CODE_SYSTEM` | 共享常数 |

## 版本

此软件包带有版本 `fhir-monorepo` 仓库——一个版本,标签和更改日志 整个回放。 因此出版的版本很少: 发行时间只有npm 软件包实际上已更改.

## 许可证

Cegedim的版权. 见 [自由主义](https://npmcn.com/package/%40claudebernard/web-component-fhir-utils/LICENSE.md) 详细情况.

## 常见问题

### @claudebernard/web-component-fhir-utils 是什么？

克劳德·贝尔纳网络组件及其集成器的共享FHIR Bundle公用事业\(收集/交易捆绑,前作处方链接\)\.

### 如何安装 @claudebernard/web-component-fhir-utils？

在项目目录运行 npm install @claudebernard/web-component-fhir-utils，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@types/fhir（^0\.0\.41）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @claudebernard/web-component-fhir-utils 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @claudebernard/web-component-fhir-utils 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @claudebernard/web-component-fhir-utils 可以商用吗？

@claudebernard/web-component-fhir-utils 使用 未声明 许可。package\.json 没有声明许可证。没有许可证的代码默认保留全部权利，商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括，不构成法律意见，请以许可原文为准。

### @claudebernard/web-component-fhir-utils 的下载量有多少？

根据 npm 官方下载统计，@claudebernard/web-component-fhir-utils 在 2026/10/10 – 2026/11/08 这 30 天内被下载 2,879 次，日均约 96 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @claudebernard/web-component-fhir-utils 还在维护吗？

最新版本 2\.7\.0 发布于 2026/11/04（5 天前）；至今共发布 19 个版本，其中过去 12 个月发布了 19 个；首次发布于 2026/07/29。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

