Skip to content

Commit 4e8a666

Browse files
Add sandbox dataset loaders (#155)
* Add loaders wip and removed prefetch model * Tidy sandboxclient API and tests * Consolidate url params and make synth gen more explicit * Add synthea dataloader * Add bundle counting helper * Update cookbook usage * Add error handling for empty responses * Update tests * Update docs
1 parent 584d582 commit 4e8a666

39 files changed

+2371
-537
lines changed

cookbook/cds_discharge_summarizer_hf_chat.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,11 @@ def start_api():
8181

8282
# Create sandbox client and load test data
8383
client = SandboxClient(
84-
api_url="http://localhost:8000",
85-
endpoint="/cds/cds-services/discharge-summarizer",
84+
url="http://localhost:8000/cds/cds-services/discharge-summarizer",
85+
workflow="encounter-discharge",
8686
)
8787
# Load discharge notes from CSV
8888
client.load_free_text(
89-
workflow="encounter-discharge",
9089
csv_path="data/discharge_notes.csv",
9190
column_name="text",
9291
)

cookbook/cds_discharge_summarizer_hf_trf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ def start_api():
5454

5555
# Create sandbox client and load test data
5656
client = SandboxClient(
57-
api_url="http://localhost:8000",
58-
endpoint="/cds/cds-services/discharge-summarizer",
57+
url="http://localhost:8000/cds/cds-services/discharge-summarizer",
58+
workflow="encounter-discharge",
5959
)
6060
# Load discharge notes from CSV
6161
client.load_free_text(
62-
workflow="encounter-discharge",
6362
csv_path="data/discharge_notes.csv",
6463
column_name="text",
6564
)

cookbook/notereader_clinical_coding_fhir.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ def run_server():
132132

133133
# Create sandbox client for testing
134134
client = SandboxClient(
135-
api_url="http://localhost:8000", endpoint="/notereader/fhir/", protocol="soap"
135+
url="http://localhost:8000/notereader/fhir/",
136+
workflow="sign-note-inpatient",
137+
protocol="soap",
136138
)
137139
# Load clinical document from file
138140
client.load_from_path("./data/notereader_cda.xml")

docs/cookbook/clinical_coding.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ from healthchain.sandbox import SandboxClient
224224

225225
# Create sandbox client for SOAP/CDA testing
226226
client = SandboxClient(
227-
api_url="http://localhost:8000",
228-
endpoint="/notereader/ProcessDocument",
227+
url="http://localhost:8000/notereader/ProcessDocument",
229228
workflow="sign-note-inpatient",
230229
protocol="soap"
231230
)

docs/cookbook/discharge_summarizer.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,14 @@ from healthchain.sandbox import SandboxClient
159159

160160
# Create sandbox client for testing
161161
client = SandboxClient(
162-
api_url="http://localhost:8000",
163-
endpoint="/cds/cds-services/discharge-summarizer",
162+
url="http://localhost:8000/cds/cds-services/discharge-summarizer",
164163
workflow="encounter-discharge"
165164
)
166165

167166
# Load discharge notes from CSV and generate FHIR data
168167
client.load_free_text(
169168
csv_path="data/discharge_notes.csv",
170-
column_name="text",
171-
workflow="encounter-discharge"
169+
column_name="text"
172170
)
173171
```
174172

docs/quickstart.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,19 @@ Test your AI applications in realistic healthcare contexts with `SandboxClient`
185185
```python
186186
from healthchain.sandbox import SandboxClient
187187

188-
# Create client and load test data
188+
# Create client with service URL and workflow
189189
client = SandboxClient(
190-
api_url="http://localhost:8000",
191-
endpoint="/cds/cds-services/my-service",
190+
url="http://localhost:8000/cds/cds-services/my-service",
192191
workflow="encounter-discharge"
193192
)
194193

195194
# Load from datasets or files
196-
client.load_from_registry("synthea", num_patients=5)
195+
client.load_from_registry(
196+
"synthea-patient",
197+
data_dir="./data/synthea",
198+
resource_types=["Condition", "DocumentReference"],
199+
sample_size=3
200+
)
197201
responses = client.send_requests()
198202
```
199203

docs/reference/utilities/data_generator.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ According to the [UK ONS synthetic data classification](https://www.ons.gov.uk/m
1010

1111
## CDS Data Generator
1212

13-
The `.generate_prefetch()` method will return a `Prefetch` model with the `prefetch` field populated with a dictionary of FHIR resources. Each key in the dictionary corresponds to a FHIR resource type, and the value is a list of FHIR resources of that type. For more information, check out the [CDS Hooks documentation](https://cds-hooks.org/specification/current/#providing-fhir-resources-to-a-cds-service).
13+
The `.generate_prefetch()` method will return a dictionary of resources. Each key in the dictionary corresponds to a FHIR resource type, and the value is a list of FHIR resources or a Bundle of that type. For more information, check out the [CDS Hooks documentation](https://cds-hooks.org/specification/current/#providing-fhir-resources-to-a-cds-service).
1414

1515
For each workflow, a pre-configured list of FHIR resources is randomly generated and placed in the `prefetch` field of a `CDSRequest`.
1616

@@ -33,16 +33,14 @@ You can use the data generator with `SandboxClient.load_free_text()` or standalo
3333

3434
# Create client
3535
client = SandboxClient(
36-
api_url="http://localhost:8000",
37-
endpoint="/cds/cds-services/my-service",
36+
url="http://localhost:8000/cds/cds-services/my-service",
3837
workflow="encounter-discharge"
3938
)
4039

4140
# Generate FHIR data from clinical notes
4241
client.load_free_text(
4342
csv_path="./data/discharge_notes.csv",
4443
column_name="text",
45-
workflow="encounter-discharge",
4644
random_seed=42
4745
)
4846

0 commit comments

Comments
 (0)