@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 开发者门户网站 用于更广泛的FHIR模型
状态 : 此包定义了目标 Bundle- in/ Bundle-out 合同 。 请检查每个组件自己的更改日志, 查看它采用的版本 —— 在此之前, 参考该组件的
integration用于当前 API 的 doc .
安装
npm install @claudebernard/web-component-fhir-utils
集成应用程序
构建输入库, 推动组件所需的任何资源 :
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数字 :
const prescription = createDocumentBundle([medication, medicationRequest], {
date: "2026-10-21",
patientId: patient.id,
practitionerName: "Dr Martin",
});
它返回一个 document 首个条目是 A 的 Bundle Composition (日期、标题、病人、作者) Practitioner。 。 。 .
<bcb-medication-request-editor .medication="${bundle}"></bcb-medication-request-editor>
将交易包套用组件向自己的组件包套用——这是您需要的唯一的集成代码,它从不改变每个组件或每个特性:
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。它们按数组顺序应用,每个都看到前一个结果;选项相同:
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 决定整个处方是否应该去——删除它会保持你的呼声,因为你坚持:
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
}
仅 MedicationRequests 引用已删除 Medication 直接删除。 请求 又一个 药物,只是一种被移除的药 priorPrescription (治疗-替代交换)是现场替换并保存。 未知的ID被忽略 .
清理套装
cleanBundle 返回一个没有其 孤儿 资源(没有链接,也没有链接到Bundle的其他任何资源),而不拖动 Composition.section.entry 引用( 空出部分被删除) 。 其纯而能通.
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 引用,或资源本身.
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数字 :
import { createBundleEntry, createTransactionBundle } from "@claudebernard/web-component-fhir-utils";
const bundle = createTransactionBundle([
createBundleEntry(updatedResource, "PUT"),
createBundleEntry(newResource, "POST"),
]);
对于常见的"本药用请求"取而代之的病例"(剂量超过,治疗替代,.),使用 supersedeMedicationRequest - 它产生搁置 PUT + 链接, 有标记 POST 所以每个部件都以同样的方式代表超级会话:
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数字 :
{
"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 |
更多的工作实例(包括治疗-替代案例)正在 开发者门户 向导.
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) | 删除药物条目,其 MedicationRequests,以及他们的 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的版权. 见 自由主义 详细情况.