phenoml 0.0.19__py3-none-any.whl → 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- phenoml/agent/client.py +4 -44
- phenoml/agent/raw_client.py +2 -38
- phenoml/agent/types/agent_create_request.py +0 -5
- phenoml/construe/__init__.py +33 -1
- phenoml/construe/client.py +577 -0
- phenoml/construe/errors/__init__.py +13 -1
- phenoml/construe/errors/not_found_error.py +10 -0
- phenoml/construe/errors/not_implemented_error.py +10 -0
- phenoml/construe/errors/service_unavailable_error.py +10 -0
- phenoml/construe/raw_client.py +1127 -84
- phenoml/construe/types/__init__.py +20 -0
- phenoml/construe/types/code_response.py +32 -0
- phenoml/construe/types/code_system_details.py +37 -0
- phenoml/construe/types/code_system_info.py +27 -0
- phenoml/construe/types/get_code_response.py +34 -0
- phenoml/construe/types/list_code_systems_response.py +20 -0
- phenoml/construe/types/list_codes_response.py +31 -0
- phenoml/construe/types/semantic_search_response.py +25 -0
- phenoml/construe/types/semantic_search_result.py +20 -0
- phenoml/construe/types/text_search_response.py +30 -0
- phenoml/construe/types/text_search_result.py +20 -0
- phenoml/core/client_wrapper.py +2 -2
- {phenoml-0.0.19.dist-info → phenoml-0.1.0.dist-info}/METADATA +1 -1
- {phenoml-0.0.19.dist-info → phenoml-0.1.0.dist-info}/RECORD +26 -13
- {phenoml-0.0.19.dist-info → phenoml-0.1.0.dist-info}/LICENSE +0 -0
- {phenoml-0.0.19.dist-info → phenoml-0.1.0.dist-info}/WHEEL +0 -0
phenoml/construe/client.py
CHANGED
|
@@ -9,6 +9,11 @@ from .types.construe_upload_code_system_response import ConstrueUploadCodeSystem
|
|
|
9
9
|
from .types.extract_codes_result import ExtractCodesResult
|
|
10
10
|
from .types.extract_request_config import ExtractRequestConfig
|
|
11
11
|
from .types.extract_request_system import ExtractRequestSystem
|
|
12
|
+
from .types.get_code_response import GetCodeResponse
|
|
13
|
+
from .types.list_code_systems_response import ListCodeSystemsResponse
|
|
14
|
+
from .types.list_codes_response import ListCodesResponse
|
|
15
|
+
from .types.semantic_search_response import SemanticSearchResponse
|
|
16
|
+
from .types.text_search_response import TextSearchResponse
|
|
12
17
|
from .types.upload_request_format import UploadRequestFormat
|
|
13
18
|
|
|
14
19
|
# this is used as the default value for optional parameters
|
|
@@ -153,6 +158,272 @@ class ConstrueClient:
|
|
|
153
158
|
)
|
|
154
159
|
return _response.data
|
|
155
160
|
|
|
161
|
+
def list_available_code_systems(
|
|
162
|
+
self, *, request_options: typing.Optional[RequestOptions] = None
|
|
163
|
+
) -> ListCodeSystemsResponse:
|
|
164
|
+
"""
|
|
165
|
+
Returns metadata about all available code systems including built-in and custom systems.
|
|
166
|
+
|
|
167
|
+
Parameters
|
|
168
|
+
----------
|
|
169
|
+
request_options : typing.Optional[RequestOptions]
|
|
170
|
+
Request-specific configuration.
|
|
171
|
+
|
|
172
|
+
Returns
|
|
173
|
+
-------
|
|
174
|
+
ListCodeSystemsResponse
|
|
175
|
+
List of available code systems
|
|
176
|
+
|
|
177
|
+
Examples
|
|
178
|
+
--------
|
|
179
|
+
from phenoml import phenoml
|
|
180
|
+
|
|
181
|
+
client = phenoml(
|
|
182
|
+
token="YOUR_TOKEN",
|
|
183
|
+
)
|
|
184
|
+
client.construe.list_available_code_systems()
|
|
185
|
+
"""
|
|
186
|
+
_response = self._raw_client.list_available_code_systems(request_options=request_options)
|
|
187
|
+
return _response.data
|
|
188
|
+
|
|
189
|
+
def list_codes_in_a_code_system(
|
|
190
|
+
self,
|
|
191
|
+
codesystem: str,
|
|
192
|
+
*,
|
|
193
|
+
version: typing.Optional[str] = None,
|
|
194
|
+
cursor: typing.Optional[str] = None,
|
|
195
|
+
limit: typing.Optional[int] = None,
|
|
196
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
197
|
+
) -> ListCodesResponse:
|
|
198
|
+
"""
|
|
199
|
+
Returns a paginated list of all codes in the specified code system.
|
|
200
|
+
|
|
201
|
+
Parameters
|
|
202
|
+
----------
|
|
203
|
+
codesystem : str
|
|
204
|
+
Code system name (e.g., "ICD-10-CM", "SNOMED_CT_US_LITE")
|
|
205
|
+
|
|
206
|
+
version : typing.Optional[str]
|
|
207
|
+
Specific version of the code system. Required if multiple versions exist.
|
|
208
|
+
|
|
209
|
+
cursor : typing.Optional[str]
|
|
210
|
+
Pagination cursor from previous response
|
|
211
|
+
|
|
212
|
+
limit : typing.Optional[int]
|
|
213
|
+
Maximum number of codes to return (default 20)
|
|
214
|
+
|
|
215
|
+
request_options : typing.Optional[RequestOptions]
|
|
216
|
+
Request-specific configuration.
|
|
217
|
+
|
|
218
|
+
Returns
|
|
219
|
+
-------
|
|
220
|
+
ListCodesResponse
|
|
221
|
+
Paginated list of codes
|
|
222
|
+
|
|
223
|
+
Examples
|
|
224
|
+
--------
|
|
225
|
+
from phenoml import phenoml
|
|
226
|
+
|
|
227
|
+
client = phenoml(
|
|
228
|
+
token="YOUR_TOKEN",
|
|
229
|
+
)
|
|
230
|
+
client.construe.list_codes_in_a_code_system(
|
|
231
|
+
codesystem="ICD-10-CM",
|
|
232
|
+
version="2025",
|
|
233
|
+
cursor="cursor",
|
|
234
|
+
limit=1,
|
|
235
|
+
)
|
|
236
|
+
"""
|
|
237
|
+
_response = self._raw_client.list_codes_in_a_code_system(
|
|
238
|
+
codesystem, version=version, cursor=cursor, limit=limit, request_options=request_options
|
|
239
|
+
)
|
|
240
|
+
return _response.data
|
|
241
|
+
|
|
242
|
+
def get_a_specific_code(
|
|
243
|
+
self,
|
|
244
|
+
codesystem: str,
|
|
245
|
+
code_id: str,
|
|
246
|
+
*,
|
|
247
|
+
version: typing.Optional[str] = None,
|
|
248
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
249
|
+
) -> GetCodeResponse:
|
|
250
|
+
"""
|
|
251
|
+
Returns details for a specific code within a code system.
|
|
252
|
+
|
|
253
|
+
Parameters
|
|
254
|
+
----------
|
|
255
|
+
codesystem : str
|
|
256
|
+
Code system name
|
|
257
|
+
|
|
258
|
+
code_id : str
|
|
259
|
+
The code identifier
|
|
260
|
+
|
|
261
|
+
version : typing.Optional[str]
|
|
262
|
+
Specific version of the code system
|
|
263
|
+
|
|
264
|
+
request_options : typing.Optional[RequestOptions]
|
|
265
|
+
Request-specific configuration.
|
|
266
|
+
|
|
267
|
+
Returns
|
|
268
|
+
-------
|
|
269
|
+
GetCodeResponse
|
|
270
|
+
Code details
|
|
271
|
+
|
|
272
|
+
Examples
|
|
273
|
+
--------
|
|
274
|
+
from phenoml import phenoml
|
|
275
|
+
|
|
276
|
+
client = phenoml(
|
|
277
|
+
token="YOUR_TOKEN",
|
|
278
|
+
)
|
|
279
|
+
client.construe.get_a_specific_code(
|
|
280
|
+
codesystem="ICD-10-CM",
|
|
281
|
+
code_id="E11.65",
|
|
282
|
+
version="version",
|
|
283
|
+
)
|
|
284
|
+
"""
|
|
285
|
+
_response = self._raw_client.get_a_specific_code(
|
|
286
|
+
codesystem, code_id, version=version, request_options=request_options
|
|
287
|
+
)
|
|
288
|
+
return _response.data
|
|
289
|
+
|
|
290
|
+
def semantic_search_embedding_based(
|
|
291
|
+
self,
|
|
292
|
+
codesystem: str,
|
|
293
|
+
*,
|
|
294
|
+
text: str,
|
|
295
|
+
version: typing.Optional[str] = None,
|
|
296
|
+
limit: typing.Optional[int] = None,
|
|
297
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
298
|
+
) -> SemanticSearchResponse:
|
|
299
|
+
"""
|
|
300
|
+
Performs semantic similarity search using vector embeddings.
|
|
301
|
+
|
|
302
|
+
**When to use**: Best for natural language queries where you want to find conceptually
|
|
303
|
+
related codes, even when different terminology is used. The search understands meaning,
|
|
304
|
+
not just keywords.
|
|
305
|
+
|
|
306
|
+
**Examples**:
|
|
307
|
+
- Query "trouble breathing at night" finds codes like "Sleep apnea", "Orthopnea",
|
|
308
|
+
"Nocturnal dyspnea" — semantically related but no exact keyword matches
|
|
309
|
+
- Query "heart problems" finds "Myocardial infarction", "Cardiac arrest", "Arrhythmia"
|
|
310
|
+
|
|
311
|
+
**Trade-offs**: Slower than text search (requires embedding generation), but finds
|
|
312
|
+
conceptually similar results that keyword search would miss.
|
|
313
|
+
|
|
314
|
+
See also: `/search/text` for faster keyword-based lookup with typo tolerance.
|
|
315
|
+
|
|
316
|
+
Parameters
|
|
317
|
+
----------
|
|
318
|
+
codesystem : str
|
|
319
|
+
Code system name
|
|
320
|
+
|
|
321
|
+
text : str
|
|
322
|
+
Natural language text to find semantically similar codes for
|
|
323
|
+
|
|
324
|
+
version : typing.Optional[str]
|
|
325
|
+
Specific version of the code system
|
|
326
|
+
|
|
327
|
+
limit : typing.Optional[int]
|
|
328
|
+
Maximum number of results (default 10, max 50)
|
|
329
|
+
|
|
330
|
+
request_options : typing.Optional[RequestOptions]
|
|
331
|
+
Request-specific configuration.
|
|
332
|
+
|
|
333
|
+
Returns
|
|
334
|
+
-------
|
|
335
|
+
SemanticSearchResponse
|
|
336
|
+
Semantic search results ordered by similarity
|
|
337
|
+
|
|
338
|
+
Examples
|
|
339
|
+
--------
|
|
340
|
+
from phenoml import phenoml
|
|
341
|
+
|
|
342
|
+
client = phenoml(
|
|
343
|
+
token="YOUR_TOKEN",
|
|
344
|
+
)
|
|
345
|
+
client.construe.semantic_search_embedding_based(
|
|
346
|
+
codesystem="ICD-10-CM",
|
|
347
|
+
text="patient has trouble breathing at night and wakes up gasping",
|
|
348
|
+
version="version",
|
|
349
|
+
limit=1,
|
|
350
|
+
)
|
|
351
|
+
"""
|
|
352
|
+
_response = self._raw_client.semantic_search_embedding_based(
|
|
353
|
+
codesystem, text=text, version=version, limit=limit, request_options=request_options
|
|
354
|
+
)
|
|
355
|
+
return _response.data
|
|
356
|
+
|
|
357
|
+
def text_search_keyword_based(
|
|
358
|
+
self,
|
|
359
|
+
codesystem: str,
|
|
360
|
+
*,
|
|
361
|
+
q: str,
|
|
362
|
+
version: typing.Optional[str] = None,
|
|
363
|
+
limit: typing.Optional[int] = None,
|
|
364
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
365
|
+
) -> TextSearchResponse:
|
|
366
|
+
"""
|
|
367
|
+
Performs fast full-text search over code IDs and descriptions.
|
|
368
|
+
|
|
369
|
+
**When to use**: Best for autocomplete UIs, code lookup, or when users know part of
|
|
370
|
+
the code ID or specific keywords. Fast response times suitable for typeahead interfaces.
|
|
371
|
+
|
|
372
|
+
**Features**:
|
|
373
|
+
- Substring matching on code IDs (e.g., "11.65" finds "E11.65")
|
|
374
|
+
- Typo tolerance on descriptions (not on code IDs)
|
|
375
|
+
- Fast response times (~10-50ms)
|
|
376
|
+
|
|
377
|
+
**Examples**:
|
|
378
|
+
- Query "E11" finds all codes starting with E11 (diabetes codes)
|
|
379
|
+
- Query "diabtes" (typo) still finds "diabetes" codes
|
|
380
|
+
|
|
381
|
+
**Trade-offs**: Faster than semantic search, but only matches keywords/substrings.
|
|
382
|
+
Won't find conceptually related codes with different terminology.
|
|
383
|
+
|
|
384
|
+
See also: `/search/semantic` for finding conceptually similar codes.
|
|
385
|
+
|
|
386
|
+
Parameters
|
|
387
|
+
----------
|
|
388
|
+
codesystem : str
|
|
389
|
+
Code system name
|
|
390
|
+
|
|
391
|
+
q : str
|
|
392
|
+
Search query (searches code IDs and descriptions)
|
|
393
|
+
|
|
394
|
+
version : typing.Optional[str]
|
|
395
|
+
Specific version of the code system
|
|
396
|
+
|
|
397
|
+
limit : typing.Optional[int]
|
|
398
|
+
Maximum number of results (default 20, max 100)
|
|
399
|
+
|
|
400
|
+
request_options : typing.Optional[RequestOptions]
|
|
401
|
+
Request-specific configuration.
|
|
402
|
+
|
|
403
|
+
Returns
|
|
404
|
+
-------
|
|
405
|
+
TextSearchResponse
|
|
406
|
+
Text search results
|
|
407
|
+
|
|
408
|
+
Examples
|
|
409
|
+
--------
|
|
410
|
+
from phenoml import phenoml
|
|
411
|
+
|
|
412
|
+
client = phenoml(
|
|
413
|
+
token="YOUR_TOKEN",
|
|
414
|
+
)
|
|
415
|
+
client.construe.text_search_keyword_based(
|
|
416
|
+
codesystem="ICD-10-CM",
|
|
417
|
+
q="E11.65",
|
|
418
|
+
version="version",
|
|
419
|
+
limit=1,
|
|
420
|
+
)
|
|
421
|
+
"""
|
|
422
|
+
_response = self._raw_client.text_search_keyword_based(
|
|
423
|
+
codesystem, q=q, version=version, limit=limit, request_options=request_options
|
|
424
|
+
)
|
|
425
|
+
return _response.data
|
|
426
|
+
|
|
156
427
|
|
|
157
428
|
class AsyncConstrueClient:
|
|
158
429
|
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
@@ -307,3 +578,309 @@ class AsyncConstrueClient:
|
|
|
307
578
|
text=text, system=system, config=config, request_options=request_options
|
|
308
579
|
)
|
|
309
580
|
return _response.data
|
|
581
|
+
|
|
582
|
+
async def list_available_code_systems(
|
|
583
|
+
self, *, request_options: typing.Optional[RequestOptions] = None
|
|
584
|
+
) -> ListCodeSystemsResponse:
|
|
585
|
+
"""
|
|
586
|
+
Returns metadata about all available code systems including built-in and custom systems.
|
|
587
|
+
|
|
588
|
+
Parameters
|
|
589
|
+
----------
|
|
590
|
+
request_options : typing.Optional[RequestOptions]
|
|
591
|
+
Request-specific configuration.
|
|
592
|
+
|
|
593
|
+
Returns
|
|
594
|
+
-------
|
|
595
|
+
ListCodeSystemsResponse
|
|
596
|
+
List of available code systems
|
|
597
|
+
|
|
598
|
+
Examples
|
|
599
|
+
--------
|
|
600
|
+
import asyncio
|
|
601
|
+
|
|
602
|
+
from phenoml import Asyncphenoml
|
|
603
|
+
|
|
604
|
+
client = Asyncphenoml(
|
|
605
|
+
token="YOUR_TOKEN",
|
|
606
|
+
)
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
async def main() -> None:
|
|
610
|
+
await client.construe.list_available_code_systems()
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
asyncio.run(main())
|
|
614
|
+
"""
|
|
615
|
+
_response = await self._raw_client.list_available_code_systems(request_options=request_options)
|
|
616
|
+
return _response.data
|
|
617
|
+
|
|
618
|
+
async def list_codes_in_a_code_system(
|
|
619
|
+
self,
|
|
620
|
+
codesystem: str,
|
|
621
|
+
*,
|
|
622
|
+
version: typing.Optional[str] = None,
|
|
623
|
+
cursor: typing.Optional[str] = None,
|
|
624
|
+
limit: typing.Optional[int] = None,
|
|
625
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
626
|
+
) -> ListCodesResponse:
|
|
627
|
+
"""
|
|
628
|
+
Returns a paginated list of all codes in the specified code system.
|
|
629
|
+
|
|
630
|
+
Parameters
|
|
631
|
+
----------
|
|
632
|
+
codesystem : str
|
|
633
|
+
Code system name (e.g., "ICD-10-CM", "SNOMED_CT_US_LITE")
|
|
634
|
+
|
|
635
|
+
version : typing.Optional[str]
|
|
636
|
+
Specific version of the code system. Required if multiple versions exist.
|
|
637
|
+
|
|
638
|
+
cursor : typing.Optional[str]
|
|
639
|
+
Pagination cursor from previous response
|
|
640
|
+
|
|
641
|
+
limit : typing.Optional[int]
|
|
642
|
+
Maximum number of codes to return (default 20)
|
|
643
|
+
|
|
644
|
+
request_options : typing.Optional[RequestOptions]
|
|
645
|
+
Request-specific configuration.
|
|
646
|
+
|
|
647
|
+
Returns
|
|
648
|
+
-------
|
|
649
|
+
ListCodesResponse
|
|
650
|
+
Paginated list of codes
|
|
651
|
+
|
|
652
|
+
Examples
|
|
653
|
+
--------
|
|
654
|
+
import asyncio
|
|
655
|
+
|
|
656
|
+
from phenoml import Asyncphenoml
|
|
657
|
+
|
|
658
|
+
client = Asyncphenoml(
|
|
659
|
+
token="YOUR_TOKEN",
|
|
660
|
+
)
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
async def main() -> None:
|
|
664
|
+
await client.construe.list_codes_in_a_code_system(
|
|
665
|
+
codesystem="ICD-10-CM",
|
|
666
|
+
version="2025",
|
|
667
|
+
cursor="cursor",
|
|
668
|
+
limit=1,
|
|
669
|
+
)
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
asyncio.run(main())
|
|
673
|
+
"""
|
|
674
|
+
_response = await self._raw_client.list_codes_in_a_code_system(
|
|
675
|
+
codesystem, version=version, cursor=cursor, limit=limit, request_options=request_options
|
|
676
|
+
)
|
|
677
|
+
return _response.data
|
|
678
|
+
|
|
679
|
+
async def get_a_specific_code(
|
|
680
|
+
self,
|
|
681
|
+
codesystem: str,
|
|
682
|
+
code_id: str,
|
|
683
|
+
*,
|
|
684
|
+
version: typing.Optional[str] = None,
|
|
685
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
686
|
+
) -> GetCodeResponse:
|
|
687
|
+
"""
|
|
688
|
+
Returns details for a specific code within a code system.
|
|
689
|
+
|
|
690
|
+
Parameters
|
|
691
|
+
----------
|
|
692
|
+
codesystem : str
|
|
693
|
+
Code system name
|
|
694
|
+
|
|
695
|
+
code_id : str
|
|
696
|
+
The code identifier
|
|
697
|
+
|
|
698
|
+
version : typing.Optional[str]
|
|
699
|
+
Specific version of the code system
|
|
700
|
+
|
|
701
|
+
request_options : typing.Optional[RequestOptions]
|
|
702
|
+
Request-specific configuration.
|
|
703
|
+
|
|
704
|
+
Returns
|
|
705
|
+
-------
|
|
706
|
+
GetCodeResponse
|
|
707
|
+
Code details
|
|
708
|
+
|
|
709
|
+
Examples
|
|
710
|
+
--------
|
|
711
|
+
import asyncio
|
|
712
|
+
|
|
713
|
+
from phenoml import Asyncphenoml
|
|
714
|
+
|
|
715
|
+
client = Asyncphenoml(
|
|
716
|
+
token="YOUR_TOKEN",
|
|
717
|
+
)
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
async def main() -> None:
|
|
721
|
+
await client.construe.get_a_specific_code(
|
|
722
|
+
codesystem="ICD-10-CM",
|
|
723
|
+
code_id="E11.65",
|
|
724
|
+
version="version",
|
|
725
|
+
)
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
asyncio.run(main())
|
|
729
|
+
"""
|
|
730
|
+
_response = await self._raw_client.get_a_specific_code(
|
|
731
|
+
codesystem, code_id, version=version, request_options=request_options
|
|
732
|
+
)
|
|
733
|
+
return _response.data
|
|
734
|
+
|
|
735
|
+
async def semantic_search_embedding_based(
|
|
736
|
+
self,
|
|
737
|
+
codesystem: str,
|
|
738
|
+
*,
|
|
739
|
+
text: str,
|
|
740
|
+
version: typing.Optional[str] = None,
|
|
741
|
+
limit: typing.Optional[int] = None,
|
|
742
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
743
|
+
) -> SemanticSearchResponse:
|
|
744
|
+
"""
|
|
745
|
+
Performs semantic similarity search using vector embeddings.
|
|
746
|
+
|
|
747
|
+
**When to use**: Best for natural language queries where you want to find conceptually
|
|
748
|
+
related codes, even when different terminology is used. The search understands meaning,
|
|
749
|
+
not just keywords.
|
|
750
|
+
|
|
751
|
+
**Examples**:
|
|
752
|
+
- Query "trouble breathing at night" finds codes like "Sleep apnea", "Orthopnea",
|
|
753
|
+
"Nocturnal dyspnea" — semantically related but no exact keyword matches
|
|
754
|
+
- Query "heart problems" finds "Myocardial infarction", "Cardiac arrest", "Arrhythmia"
|
|
755
|
+
|
|
756
|
+
**Trade-offs**: Slower than text search (requires embedding generation), but finds
|
|
757
|
+
conceptually similar results that keyword search would miss.
|
|
758
|
+
|
|
759
|
+
See also: `/search/text` for faster keyword-based lookup with typo tolerance.
|
|
760
|
+
|
|
761
|
+
Parameters
|
|
762
|
+
----------
|
|
763
|
+
codesystem : str
|
|
764
|
+
Code system name
|
|
765
|
+
|
|
766
|
+
text : str
|
|
767
|
+
Natural language text to find semantically similar codes for
|
|
768
|
+
|
|
769
|
+
version : typing.Optional[str]
|
|
770
|
+
Specific version of the code system
|
|
771
|
+
|
|
772
|
+
limit : typing.Optional[int]
|
|
773
|
+
Maximum number of results (default 10, max 50)
|
|
774
|
+
|
|
775
|
+
request_options : typing.Optional[RequestOptions]
|
|
776
|
+
Request-specific configuration.
|
|
777
|
+
|
|
778
|
+
Returns
|
|
779
|
+
-------
|
|
780
|
+
SemanticSearchResponse
|
|
781
|
+
Semantic search results ordered by similarity
|
|
782
|
+
|
|
783
|
+
Examples
|
|
784
|
+
--------
|
|
785
|
+
import asyncio
|
|
786
|
+
|
|
787
|
+
from phenoml import Asyncphenoml
|
|
788
|
+
|
|
789
|
+
client = Asyncphenoml(
|
|
790
|
+
token="YOUR_TOKEN",
|
|
791
|
+
)
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
async def main() -> None:
|
|
795
|
+
await client.construe.semantic_search_embedding_based(
|
|
796
|
+
codesystem="ICD-10-CM",
|
|
797
|
+
text="patient has trouble breathing at night and wakes up gasping",
|
|
798
|
+
version="version",
|
|
799
|
+
limit=1,
|
|
800
|
+
)
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
asyncio.run(main())
|
|
804
|
+
"""
|
|
805
|
+
_response = await self._raw_client.semantic_search_embedding_based(
|
|
806
|
+
codesystem, text=text, version=version, limit=limit, request_options=request_options
|
|
807
|
+
)
|
|
808
|
+
return _response.data
|
|
809
|
+
|
|
810
|
+
async def text_search_keyword_based(
|
|
811
|
+
self,
|
|
812
|
+
codesystem: str,
|
|
813
|
+
*,
|
|
814
|
+
q: str,
|
|
815
|
+
version: typing.Optional[str] = None,
|
|
816
|
+
limit: typing.Optional[int] = None,
|
|
817
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
818
|
+
) -> TextSearchResponse:
|
|
819
|
+
"""
|
|
820
|
+
Performs fast full-text search over code IDs and descriptions.
|
|
821
|
+
|
|
822
|
+
**When to use**: Best for autocomplete UIs, code lookup, or when users know part of
|
|
823
|
+
the code ID or specific keywords. Fast response times suitable for typeahead interfaces.
|
|
824
|
+
|
|
825
|
+
**Features**:
|
|
826
|
+
- Substring matching on code IDs (e.g., "11.65" finds "E11.65")
|
|
827
|
+
- Typo tolerance on descriptions (not on code IDs)
|
|
828
|
+
- Fast response times (~10-50ms)
|
|
829
|
+
|
|
830
|
+
**Examples**:
|
|
831
|
+
- Query "E11" finds all codes starting with E11 (diabetes codes)
|
|
832
|
+
- Query "diabtes" (typo) still finds "diabetes" codes
|
|
833
|
+
|
|
834
|
+
**Trade-offs**: Faster than semantic search, but only matches keywords/substrings.
|
|
835
|
+
Won't find conceptually related codes with different terminology.
|
|
836
|
+
|
|
837
|
+
See also: `/search/semantic` for finding conceptually similar codes.
|
|
838
|
+
|
|
839
|
+
Parameters
|
|
840
|
+
----------
|
|
841
|
+
codesystem : str
|
|
842
|
+
Code system name
|
|
843
|
+
|
|
844
|
+
q : str
|
|
845
|
+
Search query (searches code IDs and descriptions)
|
|
846
|
+
|
|
847
|
+
version : typing.Optional[str]
|
|
848
|
+
Specific version of the code system
|
|
849
|
+
|
|
850
|
+
limit : typing.Optional[int]
|
|
851
|
+
Maximum number of results (default 20, max 100)
|
|
852
|
+
|
|
853
|
+
request_options : typing.Optional[RequestOptions]
|
|
854
|
+
Request-specific configuration.
|
|
855
|
+
|
|
856
|
+
Returns
|
|
857
|
+
-------
|
|
858
|
+
TextSearchResponse
|
|
859
|
+
Text search results
|
|
860
|
+
|
|
861
|
+
Examples
|
|
862
|
+
--------
|
|
863
|
+
import asyncio
|
|
864
|
+
|
|
865
|
+
from phenoml import Asyncphenoml
|
|
866
|
+
|
|
867
|
+
client = Asyncphenoml(
|
|
868
|
+
token="YOUR_TOKEN",
|
|
869
|
+
)
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
async def main() -> None:
|
|
873
|
+
await client.construe.text_search_keyword_based(
|
|
874
|
+
codesystem="ICD-10-CM",
|
|
875
|
+
q="E11.65",
|
|
876
|
+
version="version",
|
|
877
|
+
limit=1,
|
|
878
|
+
)
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
asyncio.run(main())
|
|
882
|
+
"""
|
|
883
|
+
_response = await self._raw_client.text_search_keyword_based(
|
|
884
|
+
codesystem, q=q, version=version, limit=limit, request_options=request_options
|
|
885
|
+
)
|
|
886
|
+
return _response.data
|
|
@@ -6,6 +6,18 @@ from .bad_request_error import BadRequestError
|
|
|
6
6
|
from .conflict_error import ConflictError
|
|
7
7
|
from .failed_dependency_error import FailedDependencyError
|
|
8
8
|
from .internal_server_error import InternalServerError
|
|
9
|
+
from .not_found_error import NotFoundError
|
|
10
|
+
from .not_implemented_error import NotImplementedError
|
|
11
|
+
from .service_unavailable_error import ServiceUnavailableError
|
|
9
12
|
from .unauthorized_error import UnauthorizedError
|
|
10
13
|
|
|
11
|
-
__all__ = [
|
|
14
|
+
__all__ = [
|
|
15
|
+
"BadRequestError",
|
|
16
|
+
"ConflictError",
|
|
17
|
+
"FailedDependencyError",
|
|
18
|
+
"InternalServerError",
|
|
19
|
+
"NotFoundError",
|
|
20
|
+
"NotImplementedError",
|
|
21
|
+
"ServiceUnavailableError",
|
|
22
|
+
"UnauthorizedError",
|
|
23
|
+
]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from ...core.api_error import ApiError
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class NotFoundError(ApiError):
|
|
9
|
+
def __init__(self, body: typing.Optional[typing.Any], headers: typing.Optional[typing.Dict[str, str]] = None):
|
|
10
|
+
super().__init__(status_code=404, headers=headers, body=body)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from ...core.api_error import ApiError
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class NotImplementedError(ApiError):
|
|
9
|
+
def __init__(self, body: typing.Optional[typing.Any], headers: typing.Optional[typing.Dict[str, str]] = None):
|
|
10
|
+
super().__init__(status_code=501, headers=headers, body=body)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from ...core.api_error import ApiError
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ServiceUnavailableError(ApiError):
|
|
9
|
+
def __init__(self, body: typing.Optional[typing.Any], headers: typing.Optional[typing.Dict[str, str]] = None):
|
|
10
|
+
super().__init__(status_code=503, headers=headers, body=body)
|