Skip to content

Commit 7435913

Browse files
Update sandbox docs (#156)
* Remove redundant logging * Remove client.get_request_data raw format - direct access instead * Update docs
1 parent 4e8a666 commit 7435913

File tree

10 files changed

+386
-215
lines changed

10 files changed

+386
-215
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,30 @@ if __name__ == "__main__":
189189
uvicorn.run(app, port=8000)
190190
```
191191

192+
### Testing with Sandbox [[Docs](https://dotimplement.github.io/HealthChain/reference/utilities/sandbox)]
193+
194+
```python
195+
from healthchain.sandbox import SandboxClient
196+
197+
# Test CDS Hooks service with synthetic data
198+
client = SandboxClient(
199+
url="http://localhost:8000/cds/cds-services/discharge-summary",
200+
workflow="encounter-discharge"
201+
)
202+
203+
# Load from test datasets
204+
client.load_from_registry(
205+
"synthea-patient",
206+
data_dir="./data/synthea",
207+
resource_types=["Condition", "DocumentReference"],
208+
sample_size=5
209+
)
210+
211+
# Send requests and save results
212+
responses = client.send_requests()
213+
client.save_results("./output/")
214+
```
215+
192216
## Road Map
193217

194218
- [ ] 🔍 Data provenance and audit trails tracking

docs/cookbook/clinical_coding.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ client = SandboxClient(
231231

232232
# Load sample CDA document
233233
client.load_from_path("./data/notereader_cda.xml")
234+
235+
# Inspect CDA document before sending
236+
# for request in client.requests:
237+
# print(request.document[:1000]) # View first 1000 chars of CDA XML
234238
```
235239

236240
## Run the Complete Example

docs/cookbook/discharge_summarizer.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ client.load_free_text(
168168
csv_path="data/discharge_notes.csv",
169169
column_name="text"
170170
)
171+
172+
# Inspect requests before sending to verify data
173+
# for request in client.requests:
174+
# print(request.prefetch.get('document')) # Get DocumentReference
171175
```
172176

173177
!!! tip "Learn More About Test Data Generation"

docs/quickstart.md

Lines changed: 100 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
# Quickstart
22

33
After [installing HealthChain](installation.md), get up to speed quickly with the core components before diving further into the [full documentation](reference/index.md)!
4+
HealthChain has three main components:
45

5-
HealthChain provides three core tools for healthcare AI integration: **Gateway** for connecting to multiple healthcare systems, **Pipelines** for FHIR-native AI workflows, and **InteropEngine** for healthcare data format conversion between FHIR, CDA, and HL7v2.
6+
- **Gateway:** Connect to multiple healthcare systems with a single API.
7+
- **Pipelines:** Easily build data processing pipelines for both clinical text and [FHIR](https://www.hl7.org/fhir/) data.
8+
- **InteropEngine:** Seamlessly convert between data formats like [FHIR](https://www.hl7.org/fhir/), [HL7 CDA](https://www.hl7.org/implement/standards/product_brief.cfm?product_id=7), and [HL7v2](https://www.hl7.org/implement/standards/product_brief.cfm?product_id=185).
69

7-
## Core Components
810

9-
### HealthChainAPI Gateway 🔌
11+
## Core Components 🧩
1012

11-
The HealthChainAPI provides a unified interface for connecting your AI models to multiple healthcare systems through a single API. Handle FHIR, CDS Hooks, and SOAP/CDA protocols with OAuth2 authentication.
13+
### Gateway 🔌
14+
15+
The [**HealthChainAPI**](./reference/gateway/api.md) provides a unified interface for connecting your AI application and models to multiple healthcare systems through a single API. It automatically handles [FHIR API](https://www.hl7.org/fhir/http.html), [CDS Hooks](https://cds-hooks.org/), and [SOAP/CDA protocols](https://www.hl7.org/implement/standards/product_brief.cfm?product_id=7) with [OAuth2 authentication](https://oauth.net/2/).
1216

1317
[(Full Documentation on Gateway)](./reference/gateway/gateway.md)
1418

@@ -41,51 +45,52 @@ app.register_gateway(fhir)
4145

4246
### Pipeline 🛠️
4347

44-
HealthChain Pipelines provide a flexible way to build and manage processing pipelines for NLP and ML tasks that can easily integrate with electronic health record (EHR) systems.
48+
HealthChain [**Pipelines**](./reference/pipeline/pipeline.md) provide a flexible way to build and manage processing pipelines for NLP and ML tasks that can easily integrate with electronic health record (EHR) systems.
4549

4650
You can build pipelines with three different approaches:
4751

48-
#### 1. Build Your Own Pipeline with Inline Functions
52+
#### 1. Quick Inline Functions
53+
54+
For quick experiments, start by picking the right [**Container**](./reference/pipeline/data_container.md) when you initialize your pipeline (e.g. `Pipeline[Document]()` for clinical text).
4955

50-
This is the most flexible approach, ideal for quick experiments and prototyping. Initialize a pipeline type hinted with the container type you want to process, then add components to your pipeline with the `@add_node` decorator.
56+
Containers make your pipeline FHIR-native by loading and transforming your data (free text, EHR resources, etc.) into structured FHIR-ready formats. Just add your processing functions with `@add_node`, compile with `.build()`, and your pipeline is ready to process FHIR data end-to-end.
5157

52-
Compile the pipeline with `.build()` to use it.
58+
[(Full Documentation on Container)](./reference/pipeline/data_container.md)
5359

5460
```python
5561
from healthchain.pipeline import Pipeline
5662
from healthchain.io import Document
63+
from healthchain.fhir import create_condition
5764

58-
nlp_pipeline = Pipeline[Document]()
65+
pipeline = Pipeline[Document]()
5966

60-
@nlp_pipeline.add_node
61-
def tokenize(doc: Document) -> Document:
62-
doc.tokens = doc.text.split()
63-
return doc
67+
@pipeline.add_node
68+
def extract_diabetes(doc: Document) -> Document:
69+
"""Adds a FHIR Condition for diabetes if mentioned in the text."""
70+
if "diabetes" in doc.text.lower():
71+
condition = create_condition(
72+
code="73211009",
73+
display="Diabetes mellitus",
74+
)
75+
doc.fhir.problem_list.append(condition)
6476

65-
@nlp_pipeline.add_node
66-
def pos_tag(doc: Document) -> Document:
67-
doc.pos_tags = ["NOUN" if token[0].isupper() else "VERB" for token in doc.tokens]
6877
return doc
6978

70-
nlp = nlp_pipeline.build()
71-
72-
doc = Document("Patient has a fracture of the left femur.")
73-
doc = nlp(doc)
79+
pipe = pipeline.build()
7480

75-
print(doc.tokens)
76-
print(doc.pos_tags)
81+
doc = Document("Patient has a history of diabetes.")
82+
doc = pipe(doc)
7783

78-
# ['Patient', 'has', 'fracture', 'of', 'left', 'femur.']
79-
# ['NOUN', 'VERB', 'VERB', 'VERB', 'VERB', 'VERB']
84+
print(doc.fhir.problem_list) # FHIR Condition
8085
```
8186

82-
#### 2. Build Your Own Pipeline with Components, Models, and Connectors
87+
#### 2. Build With Components and Adapters
8388

84-
Components are stateful - they're classes instead of functions. They can be useful for grouping related processing steps together, setting configurations, or wrapping specific model loading steps.
89+
[**Components**](./reference/) are reusable, stateful classes that encapsulate specific processing logic, model loading, or configuration for your pipeline. Use them to organize complex workflows, handle model state, or integrate third-party libraries with minimal setup.
8590

86-
HealthChain comes with a few pre-built components, but you can also easily add your own. You can find more details on the [Components](./reference/pipeline/components/components.md) and [Integrations](./reference/pipeline/integrations/integrations.md) documentation pages.
91+
HealthChain provides a set of ready-to-use [**NLP Integrations**](./reference/pipeline/integrations/integrations.md) for common clinical NLP and ML tasks, and you can easily implement your own.
8792

88-
Add components to your pipeline with the `.add_node()` method and compile with `.build()`.
93+
[(Full Documentation on Components)](./reference/pipeline/components/components.md)
8994

9095
```python
9196
from healthchain.pipeline import Pipeline
@@ -104,18 +109,14 @@ doc = Document("Patient presents with hypertension.")
104109
output = pipe(doc)
105110
```
106111

107-
Let's go one step further! You can use [Adapters](./reference/pipeline/adapters/adapters.md) to work directly with [CDA](https://www.hl7.org.uk/standards/hl7-standards/cda-clinical-document-architecture/) and [FHIR](https://hl7.org/fhir/) data received from healthcare system APIs. Adapters handle format conversion while keeping your pipeline pure ML processing.
112+
You can process legacy healthcare data formats too. [**Adapters**](./reference/pipeline/adapters/adapters.md) convert between healthcare formats like [CDA](https://www.hl7.org/implement/standards/product_brief.cfm?product_id=7) and your pipeline — just parse, process, and format without worrying about low-level data conversion.
113+
114+
[(Full Documentation on Adapters)](./reference/pipeline/adapters/adapters.md)
108115

109116
```python
110-
from healthchain.pipeline import Pipeline
111-
from healthchain.pipeline.components import SpacyNLP
112117
from healthchain.io import CdaAdapter
113118
from healthchain.models import CdaRequest
114119

115-
pipeline = Pipeline()
116-
pipeline.add_node(SpacyNLP.from_model_id("en_core_sci_sm"))
117-
pipe = pipeline.build()
118-
119120
# Use adapter for format conversion
120121
adapter = CdaAdapter()
121122
cda_request = CdaRequest(document="<CDA XML content>")
@@ -128,21 +129,14 @@ output = adapter.format(processed_doc)
128129

129130
#### 3. Use Prebuilt Pipelines
130131

131-
Prebuilt pipelines are pre-configured collections of Components and Models optimized for specific healthcare AI use cases. They offer the highest level of abstraction and are the easiest way to get started.
132+
Prebuilt pipelines are the fastest way to jump into healthcare AI with minimal setup: just load and run. Each pipeline bundles best-practice components and models for common clinical tasks (like coding or summarization) and handles all FHIR/CDA conversion for you. Easily customize or extend pipelines by adding/removing components, or swap models as needed.
132133

133-
For a full list of available prebuilt pipelines and details on how to configure and customize them, see the [Pipelines](./reference/pipeline/pipeline.md) documentation page.
134+
[(Full Documentation on Pipelines)](./reference/pipeline/pipeline.md#prebuilt-)
134135

135136
```python
136137
from healthchain.pipeline import MedicalCodingPipeline
137138
from healthchain.models import CdaRequest
138139

139-
# Load from pre-built chain
140-
chain = ChatPromptTemplate.from_template("Summarize: {text}") | ChatOpenAI()
141-
pipeline = MedicalCodingPipeline.load(chain, source="langchain")
142-
143-
# Or load from model ID
144-
pipeline = MedicalCodingPipeline.from_model_id("facebook/bart-large-cnn", source="huggingface")
145-
146140
# Or load from local model
147141
pipeline = MedicalCodingPipeline.from_local_model("./path/to/model", source="spacy")
148142

@@ -152,7 +146,7 @@ output = pipeline.process_request(cda_request)
152146

153147
### Interoperability 🔄
154148

155-
The HealthChain Interoperability module provides tools for converting between different healthcare data formats, including HL7 FHIR, HL7 CDA, and HL7v2 messages.
149+
The HealthChain Interoperability module provides tools for converting between different healthcare data formats, including FHIR, CDA, and HL7v2 messages.
156150

157151
[(Full Documentation on Interoperability Engine)](./reference/interop/interop.md)
158152

@@ -176,34 +170,88 @@ cda_document = engine.from_fhir(fhir_resources, dest_format=FormatType.CDA)
176170

177171
## Utilities ⚙️
178172

179-
### Sandbox Testing
173+
### Sandbox Client 🧪
180174

181-
Test your AI applications in realistic healthcare contexts with `SandboxClient` for CDS Hooks and clinical documentation workflows.
175+
Use [**SandboxClient**](./reference/utilities/sandbox.md) to quickly test your app against real-world EHR scenarios like CDS Hooks or Clinical Documentation Improvement (CDI) workflows. Load test datasets, send requests to your service, and validate responses in a few lines of code.
182176

183177
[(Full Documentation on Sandbox)](./reference/utilities/sandbox.md)
184178

179+
#### Workflows
180+
181+
A [**workflow**](./reference/utilities/sandbox.md#workflow-protocol-compatibility) represents a specific event in an EHR system that triggers your service (e.g., `patient-view` when opening a patient chart, `encounter-discharge` when discharging a patient).
182+
183+
Workflows determine the request structure, required FHIR resources, and validation rules. Different workflows are compatible with different protocols:
184+
185+
| Workflow Type | Protocol | Example Workflows |
186+
|-------------------------------------|------------|--------------------------------------------------------|
187+
| **CDS Hooks** | REST | `patient-view`, `order-select`, `order-sign`, `encounter-discharge` |
188+
| **Clinical Documentation** | SOAP | `sign-note-inpatient`, `sign-note-outpatient` |
189+
190+
191+
#### Available Dataset Loaders
192+
193+
[**Dataset Loaders**](./reference/utilities/sandbox.md#dataset-loaders) are shortcuts for loading common clinical test datasets from file. Currently available:
194+
195+
| Dataset Key | Description | FHIR Version | Source | Download Link |
196+
|--------------------|---------------------------------------------|--------------|-----------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
197+
| `mimic-on-fhir` | **MIMIC-IV on FHIR Demo Dataset** | R4 | [PhysioNet Project](https://physionet.org/content/mimic-iv-fhir-demo/2.1.0/) | [Download ZIP](https://physionet.org/content/mimic-iv-fhir-demo/get-zip/2.1.0/) (49.5 MB) |
198+
| `synthea-patient` | **Synthea FHIR Patient Records** | R4 | [Synthea Downloads](https://synthea.mitre.org/downloads) | [Download ZIP](https://arc.net/l/quote/hoquexhy) (100 Sample, 36 MB) |
199+
200+
201+
```python
202+
from healthchain.sandbox import list_available_datasets
203+
204+
# See all registered datasets with descriptions
205+
datasets = list_available_datasets()
206+
print(datasets)
207+
```
208+
209+
#### Basic Usage
210+
185211
```python
186212
from healthchain.sandbox import SandboxClient
187213

188-
# Create client with service URL and workflow
214+
# Initialize client with your service URL and workflow
189215
client = SandboxClient(
190-
url="http://localhost:8000/cds/cds-services/my-service",
216+
url="http://localhost:8000/cds/encounter-discharge",
191217
workflow="encounter-discharge"
192218
)
193219

194-
# Load from datasets or files
220+
# Load test data from a registered dataset
195221
client.load_from_registry(
196222
"synthea-patient",
197223
data_dir="./data/synthea",
198224
resource_types=["Condition", "DocumentReference"],
199225
sample_size=3
200226
)
227+
228+
# Optionally inspect before sending
229+
client.preview_requests() # See what will be sent
230+
client.get_status() # Check client state
231+
232+
# Send requests to your service
201233
responses = client.send_requests()
202234
```
203235

204-
### FHIR Helpers
236+
For clinical documentation workflows using SOAP/CDA:
237+
238+
```python
239+
# Use context manager for automatic result saving
240+
with SandboxClient(
241+
url="http://localhost:8000/notereader/ProcessDocument",
242+
workflow="sign-note-inpatient",
243+
protocol="soap"
244+
) as client:
245+
client.load_from_path("./cookbook/data/notereader_cda.xml")
246+
responses = client.send_requests()
247+
# Results automatically saved to ./output/ on success
248+
```
249+
250+
### FHIR Helpers 🔥
205251

206-
The `fhir` module provides a set of helper functions for working with FHIR resources.
252+
Use `healthchain.fhir` helpers to quickly create and manipulate FHIR resources (like `Condition`, `Observation`, etc.) in your code, ensuring they’re standards-compliant with minimal boilerplate.
253+
254+
[(Full Documentation on FHIR Helpers)](./reference/utilities/fhir_helpers.md)
207255

208256
```python
209257
from healthchain.fhir import create_condition
@@ -217,37 +265,5 @@ condition = create_condition(
217265
)
218266
```
219267

220-
[(Full Documentation on FHIR Helpers)](./reference/utilities/fhir_helpers.md)
221-
222-
### Data Generator
223-
224-
You can use the data generator to generate synthetic FHIR data for testing.
225-
226-
The `CdsDataGenerator` generates synthetic [FHIR](https://hl7.org/fhir/) data as [Pydantic](https://docs.pydantic.dev/) models suitable for different CDS workflows. Use it standalone or with `SandboxClient.load_free_text()` to include text-based data.
227-
228-
[(Full Documentation on Data Generators)](./reference/utilities/data_generator.md)
229-
230-
```python
231-
from healthchain.sandbox.generators import CdsDataGenerator
232-
from healthchain.sandbox.workflows import Workflow
233-
234-
# Initialize data generator
235-
data_generator = CdsDataGenerator()
236-
237-
# Generate FHIR resources for specific workflow
238-
data_generator.set_workflow(Workflow.encounter_discharge)
239-
data = data_generator.generate_prefetch()
240-
241-
print(data.model_dump())
242-
243-
# {
244-
# "prefetch": {
245-
# "encounter": {
246-
# "resourceType": ...
247-
# }
248-
# }
249-
# }
250-
```
251-
252268
## Going further ✨
253269
Check out our [Cookbook](cookbook/index.md) section for more worked examples! HealthChain is still in its early stages, so if you have any questions please feel free to reach us on [Github](https://github.com/dotimplement/HealthChain/discussions) or [Discord](https://discord.gg/UQC6uAepUz).

docs/reference/pipeline/integrations/integrations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# HealthChain Integrations
1+
# NLP Integrations
22

33
This document provides an overview of the integration components available in the HealthChain package. These components allow you to easily incorporate popular NLP libraries into your HealthChain pipelines.
44

0 commit comments

Comments
 (0)