How can hospital AI services connect to electronic health records? Six Mermaid diagrams trace the calls and write-backs

August 13, 2025

A doctor selects a lab order and wants to see the last result before signing. Ten minutes later, the same doctor finishes a consultation and wants the software to draft a note. AI can help with both, but the first result has to arrive before signature, whereas the second can run in the background and requires the doctor to check it line by line. Simply drawing a line from “model” to “electronic health record” on an architecture diagram doesn't show the difference.

In my April presentation, I argued for building applications on top of existing systems. Later I received a set of hospital AI integration diagrams and wanted to keep the Mermaid format while translating each workflow clearly. The six diagrams below retain the original questions and main participants. I redrew them to follow the direction of requests in the standard interfaces. They are design examples for discussion.

1. If a hospital already has an EHR, where does the model get its data?

Start with one path through the middle. The electronic health record (EHR) stores patient records. An authorized application can read a standard resource, such as a lab result, through the FHIR interface. An integration engine receives messages pushed by departments such as the laboratory. The AI gateway handles incoming calls, and the model service computes results from its inputs. Analysts may use a separate, authorized historical dataset for validation.

flowchart TB
    E["病历应用"] <-->|内部读写| DB[("病历库")]
    E <--> API["病历对外接口"]
    API <-->|FHIR 资源与工作流调用| G["AI 网关"]
    G --> M["模型服务"]
    L["检验科 LIS"] <-->|HL7 v2 消息| I["集成引擎"]
    I <--> API
    H["院外获准交换的数据"] --> I
    P["影像档案 PACS"] -->|影像| M
    D["远程监测设备"] --> Q["事件流"]
    Q --> M
    M <--> F["模型需要的输入字段"]
    M --> R["人工复核"]
    R --> API
    I --> W[("历史分析库")]
    API --> W
    W --> X["按授权准备训练资料"] --> V["版本登记"] --> M
    G --> A["身份、授权与审计"]
    M --> A
    M --> T["运行监控"]

In the diagram, the EHR application reads and writes its internal database. Its external interface exchanges FHIR resources and workflow calls with the AI gateway. The integration engine exchanges HL7 v2 messages with the laboratory information system (LIS), accepts authorized outside data, and connects to the EHR interface. The model service receives calls through the gateway, images from the PACS archive, and event streams from remote monitoring devices. It uses the required input fields and sends results through human review to the EHR interface. The integration engine and EHR interface feed a historical analytics database, from which authorized training data are prepared and versions registered for service. Both the gateway and model service connect to identity, authorization, and auditing. The model service also reports to operational monitoring.

The model service turns source material into inputs it can compute on, often called “features.” For example, to calculate the interval between two lab measurements, preserve their collection times and units. An institution handling claims transactions would separately agree on administrative interfaces such as X12. When a doctor opens a patient record, the service needs to know which patient and what information it may read on this occasion. SMART on FHIR defines how an EHR launches an external application, supplies patient context, and authorizes access. At each new hospital, confirm which resources and permissions it exposes.1

2. How does a suggestion reach the doctor while an order is being placed?

Suppose the doctor selects a complete blood count and the service finds a recent result for the same test. CDS Hooks is a calling convention for clinical decision support. The order-select hook indicates that an order has just been selected. The EHR sends a request and waits. The service can return a card with the previous result or a link. The implementation team validates which situations justify an alert.2

sequenceDiagram
    participant D as 医生
    participant E as 病历界面
    participant S as 决策支持服务
    participant M as 模型服务
    participant A as 授权详情应用
    D->>E: 选中检验医嘱
    E->>S: 发送 order-select 事件与获准的上下文
    S->>M: 提交待评估的输入
    M-->>S: 返回评分与依据
    alt 达到本地提示条件
        S-->>E: 建议卡,附上次结果或详情链接
        E-->>D: 展示建议
        D->>E: 采纳或覆写
        E->>S: 如支持反馈,发送卡片处理结果
    else 无需打断
        S-->>E: 返回空卡片列表或信息卡
    end
    opt 医生要求看详情
        E->>A: 带当前患者上下文启动应用
        A-->>D: 显示结果来源
    end

The doctor selects a lab order in the EHR. The EHR sends the order-select event and authorized context to the decision support service, which submits inputs to the model and receives a score and its basis. If local alert criteria are met, the service returns a suggestion card with the prior result or a detail link. The EHR shows the card, the doctor accepts or overrides it, and the EHR sends feedback on the disposition if supported. If no interruption is needed, the service returns an empty card list or an informational card. If the doctor asks for details, the EHR launches an authorized app with the current patient context and the app shows the source.

“Accepted” describes what happened to a card. To validate whether the model's judgment was correct, you still need outcomes and evaluation criteria. The team also has to agree in advance whether the doctor can proceed to sign if the service times out.

3. Who signs the final report after imaging analysis?

The original CT images are stored in a PACS, a picture archiving and communication system. DICOM is the imaging standard used by scanners and imaging software. The model service needs the study's unique identifier to request images from the archive. Its findings can be presented to a radiologist as candidate annotations with recorded provenance.3

sequenceDiagram
    participant E as 病历
    participant I as 接口引擎
    participant R as 放射排程和报告系统
    participant C as CT 设备
    participant P as 影像档案
    participant A as AI 服务
    participant D as 放射科医生
    E->>I: 发检查申请
    I->>R: 登记待做项目
    C->>R: 查询设备工作清单
    R-->>C: 返回选中项目的标识
    C->>P: 归档影像
    A->>P: 按检查标识取图
    P-->>A: 返回图像
    A->>P: 保存关联原片的机器标记或结构化结果
    A-->>E: 如接口约定,发布带来源和状态的候选报告引用
    D->>P: 查看原片与标记
    D->>R: 审核并签发报告
    R->>I: 发送已签发结果
    I-->>E: 关联原申请,提供报告与原片入口

The EHR sends an imaging order through the interface engine to the radiology scheduling and reporting system. The CT scanner queries its modality worklist, receives the selected item's identifier, and archives the images. The AI service requests images from the archive by study identifier, receives them, and saves machine annotations or structured results linked to the originals. Where the interface agreement allows, it publishes a reference to a candidate report with its source and status to the EHR. The radiologist views the originals and annotations, reviews and signs the report in the reporting system, and the signed result returns through the interface engine. The EHR links it to the original order and provides access to the report and images.

The EHR might show “original images available” first and “report signed by physician” later. Test both statuses separately. To implement the button at the end, see How a doctor opens the correct CT study.

4. How does consultation audio become a note signed by the doctor?

A consultation may discuss both the patient's medication history and that of a relative. Even a word-for-word accurate transcript can lead to a summary that merges the two. The review interface needs to let the doctor correct the attribution. In the ambient documentation pilot described by Stanford Medicine, clinicians likewise edited and approved the final version.4

flowchart LR
    C["依约取得同意后录音"] --> T["语音转文字"]
    T --> G["生成问诊记录草稿"]
    G --> P["按院方规则检查敏感信息"]
    P --> D["医生核对内容"]
    D -->|修改后签署| E["正式病历"]
    D -->|退回修订| G
    E -->|按发布规则开放| V["患者门户"]

The workflow records audio after obtaining consent as agreed, transcribes it, drafts the consultation note, and checks for sensitive information under hospital rules. The doctor checks the contents and can send the draft back for revision or edit and sign it as the official record. The patient portal receives access according to release rules.

For acceptance testing, use a fictional consultation with a family history, have the doctor correct an attribution, and check which version finally appears in the portal. Also establish where the recording, transcript, generated draft, and signed text are each stored and who can read them.

5. Six months after launch, how do you know which version the doctor used?

Suppose the laboratory changes instruments or measurement units. The input distribution can change, and scores validated under the old conditions may change too. Drift monitoring means checking for such changes on an ongoing basis. A model registry records approved versions, allowing operations staff to trace which version generated a given alert.5

flowchart TB
    R["病历、检验、影像和设备记录"] --> D["按用途授权并去标识"]
    D --> W["历史数据集"] --> F["准备模型输入"] --> T["训练候选版本"]
    T --> V["在保留样本及不同人群中验证"]
    V -->|需调整| T
    V -->|审核通过| G["登记数据和模型版本"]
    G --> B["构建并发布服务"] --> S["在线模型"]
    E["病历请求"] --> S --> UI["医生看到结果"]
    UI --> H["记录临床反馈"] --> F
    S --> M["比较输入、表现及服务故障"]
    M --> L["保留模型说明与审计记录"]
    M -->|需要复核或重新训练| T

EHR, laboratory, imaging, and device records are authorized for the intended use and de-identified. From the historical dataset, the team prepares inputs, trains a candidate, and validates it on held-out samples and different populations. Results needing adjustment go back for training. An approved candidate's data and model versions are registered, then the service is built and deployed. The online model answers EHR requests, doctors see the results, and clinical feedback is recorded for input preparation. Monitoring compares inputs, performance, and service failures, retains model documentation and audit records, and can trigger review or retraining.

After detecting a change, the team can pause a feature, revert to the last approved version, or revalidate. Before using doctors' feedback as research data, clarify whether it records an action, a judgment, or a final outcome.

6. If a lab result arrives at night, does the doctor have to keep a page open?

A background task can compute an assessment when data change. ADT messages cover patient movements such as admission, discharge, and transfer. ORU messages carry observation results. Alternatively, register criteria with a FHIR service that supports subscriptions and read the data after receiving a callback. Either source can wake the workers below.6

flowchart LR
    A["入转出 ADT 与检验 ORU"] --> I["集成引擎"]
    I --> Q["持久事件流"]
    S["FHIR 订阅回调"] --> Q
    Q --> W["后台任务:评估败血症风险"]
    Q --> X["后台再入院评估任务"]
    W --> F["保存评估、时间、版本和来源"]
    X --> F
    E["医生下次进入约定工作步骤"] --> C["病历调用决策支持服务"]
    C -->|读已有评估| F
    C --> UI["返回卡片,医生查看"]

ADT and lab ORU messages reach a durable event stream through the integration engine. FHIR subscription callbacks can feed the same stream. Background jobs for sepsis risk and readmission assessments consume events and save the assessment, time, version, and source. When the doctor next reaches the agreed workflow step, the EHR calls the decision support service. The service reads the stored assessment and returns a card for the doctor.

The model completes its work at night. The doctor opens the record in the morning, triggering the interface call. These are separate events. In a test, stop the model service between the two and check whether the stored assessment can still be read and what the interface displays when it expires. For handling a lost callback connection, see the subscription, catch-up reads, and replay experiment.

Footnotes

  1. Health Level Seven International. (n.d.). SMART App Launch v2.2.0. HL7. App launch flow. ↩

  2. Health Level Seven International. (n.d.). CDS Hooks 2.0. HL7. Service response and feedback · Order Select, workflow. ↩

  3. DICOM Standards Committee. (2025). DICOM PS3.18, Web services. NEMA. §10.4, Retrieve transaction. ↩

  4. Stanford Medicine. (2024, March). Ambient artificial intelligence technology to assist Stanford Medicine clinicians with taking notes. Stanford Medicine News. Pilot workflow and clinician approval. ↩

  5. U.S. Food and Drug Administration. (n.d.). Good machine learning practice for medical device development: Guiding principles. FDA. Product life cycle and deployed models. ↩

  6. Health Level Seven International. (2019). Subscription. FHIR R4 v4.0.1. §2.46.1, Scope and usage. ↩

© 2025 borui. All rights reserved. This content may be freely reproduced, displayed, modified, or distributed with proper attribution to borui and a link to the article: borui (2025-08-13). How can hospital AI services connect to electronic health records? Six Mermaid diagrams trace the calls and write-backs. https://caiborui.com/blog/2025-08-13-zh-hospital-ai-workflows-entrans

@misc{borui2025-aad346ce,
  author = {borui},
  title = {{How can hospital AI services connect to electronic health records? Six Mermaid diagrams trace the calls and write-backs}},
  year = {2025},
  publisher = {borui's blog},
  url = {https://caiborui.com/blog/2025-08-13-zh-hospital-ai-workflows-entrans}
}