Containers
BaseDocument
dataclass
Bases: DataContainer[str]
Base document container for raw text content.
Source code in healthchain/io/containers/base.py
DataContainer
dataclass
Bases: Generic[T]
A generic container for data.
This class represents a container for data with a specific type T.
ATTRIBUTE | DESCRIPTION |
---|---|
data |
The data stored in the container.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
to_dict |
Converts the container's data to a dictionary. |
to_json |
Converts the container's data to a JSON string. |
from_dict |
Dict[str, Any]) -> "DataContainer": Creates a DataContainer instance from a dictionary. |
from_json |
str) -> "DataContainer": Creates a DataContainer instance from a JSON string. |
Source code in healthchain/io/containers/base.py
Document
dataclass
Bases: BaseDocument
A document container that extends BaseDocument with rich annotation capabilities.
This class extends BaseDocument to handle textual document data and annotations from various sources. It serves as the main data structure passed through processing pipelines, accumulating annotations and analysis results at each step.
The Document class provides a comprehensive representation that can include: - Raw text and basic tokenization - NLP annotations (tokens, entities, embeddings, spaCy docs) - Clinical concepts (problems, medications, allergies) - Structured clinical documents (CCD, FHIR) - Clinical decision support results (cards, actions) - ML model outputs (Hugging Face, LangChain)
ATTRIBUTE | DESCRIPTION |
---|---|
nlp |
Container for NLP-related annotations like tokens and entities
TYPE:
|
concepts |
Container for extracted medical concepts
TYPE:
|
hl7 |
Container for structured clinical documents (CCD, FHIR)
TYPE:
|
cds |
Container for clinical decision support results
TYPE:
|
models |
Container for ML model outputs
TYPE:
|
The class provides methods to: - Add and access medical concepts - Generate structured clinical documents - Get basic text statistics - Iterate over tokens - Access raw text
Inherits from
BaseDocument: Provides base document functionality and raw text storage
Source code in healthchain/io/containers/document.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
|
__post_init__()
Initialize the document with basic tokenization if needed.
Source code in healthchain/io/containers/document.py
add_concepts(problems=None, medications=None, allergies=None)
Add extracted medical concepts to the document.
This method adds medical concepts (problems, medications, allergies) to their respective lists in the document's concepts container. Each concept type is optional and will only be added if provided.
PARAMETER | DESCRIPTION |
---|---|
problems
|
List of medical problems/conditions to add to the document. Defaults to None.
TYPE:
|
medications
|
List of medications to add to the document. Defaults to None.
TYPE:
|
allergies
|
List of allergies to add to the document. Defaults to None.
TYPE:
|
Example
doc.add_concepts( ... problems=[ProblemConcept(display_name="Hypertension")], ... medications=[MedicationConcept(display_name="Aspirin")] ... )
Source code in healthchain/io/containers/document.py
generate_ccd(overwrite=False)
Generate a CCD (Continuity of Care Document) from the current medical concepts.
This method creates or updates a CCD in the hl7 container using the medical concepts (problems, medications, allergies) currently stored in the document. The CCD is a standard format for exchanging clinical information.
PARAMETER | DESCRIPTION |
---|---|
overwrite
|
If True, overwrites any existing CCD data. If False, merges with existing CCD data. Defaults to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
CcdData
|
The generated CCD data.
TYPE:
|
Example
doc.add_concepts(problems=[ProblemConcept(display_name="Hypertension")]) doc.generate_ccd() # Creates CCD with the hypertension problem
Source code in healthchain/io/containers/document.py
Tabular
dataclass
Bases: DataContainer[DataFrame]
A container for tabular data, wrapping a pandas DataFrame.
ATTRIBUTE | DESCRIPTION |
---|---|
data |
The pandas DataFrame containing the tabular data.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__post_init__ |
Validates that the data is a pandas DataFrame. |
columns |
Property that returns a list of column names. |
index |
Property that returns the DataFrame's index. |
dtypes |
Property that returns a dictionary of column names and their data types. |
column_count |
Returns the number of columns in the DataFrame. |
row_count |
Returns the number of rows in the DataFrame. |
get_dtype |
str): Returns the data type of a specific column. |
__iter__ |
Returns an iterator over the column names. |
__len__ |
Returns the number of rows in the DataFrame. |
describe |
Returns a string description of the tabular data. |
remove_column |
str): Removes a column from the DataFrame. |
from_csv |
str, **kwargs): Class method to create a Tabular object from a CSV file. |
from_dict |
Dict[str, Any]): Class method to create a Tabular object from a dictionary. |
to_csv |
str, **kwargs): Saves the DataFrame to a CSV file. |
Source code in healthchain/io/containers/tabular.py
base
BaseDocument
dataclass
Bases: DataContainer[str]
Base document container for raw text content.
Source code in healthchain/io/containers/base.py
DataContainer
dataclass
Bases: Generic[T]
A generic container for data.
This class represents a container for data with a specific type T.
ATTRIBUTE | DESCRIPTION |
---|---|
data |
The data stored in the container.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
to_dict |
Converts the container's data to a dictionary. |
to_json |
Converts the container's data to a JSON string. |
from_dict |
Dict[str, Any]) -> "DataContainer": Creates a DataContainer instance from a dictionary. |
from_json |
str) -> "DataContainer": Creates a DataContainer instance from a JSON string. |
Source code in healthchain/io/containers/base.py
document
CdsAnnotations
dataclass
Container for Clinical Decision Support (CDS) results.
This class stores the outputs from clinical decision support systems, including CDS Hooks cards and suggested clinical actions. The cards contain recommendations, warnings, and other decision support content that can be displayed to clinicians. Actions represent specific clinical tasks or interventions that are suggested based on the analysis.
ATTRIBUTE | DESCRIPTION |
---|---|
_cards |
Internal storage for CDS Hooks cards containing clinical recommendations, warnings, or other decision support content.
TYPE:
|
_actions |
Internal storage for suggested clinical actions that could be taken based on the CDS analysis.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
set_cards |
List[Card]): Sets the list of CDS Hooks cards |
get_cards |
Returns the current list of cards if any exist |
set_actions |
List[Action]): Sets the list of suggested clinical actions |
get_actions |
Returns the current list of actions if any exist |
Source code in healthchain/io/containers/document.py
Document
dataclass
Bases: BaseDocument
A document container that extends BaseDocument with rich annotation capabilities.
This class extends BaseDocument to handle textual document data and annotations from various sources. It serves as the main data structure passed through processing pipelines, accumulating annotations and analysis results at each step.
The Document class provides a comprehensive representation that can include: - Raw text and basic tokenization - NLP annotations (tokens, entities, embeddings, spaCy docs) - Clinical concepts (problems, medications, allergies) - Structured clinical documents (CCD, FHIR) - Clinical decision support results (cards, actions) - ML model outputs (Hugging Face, LangChain)
ATTRIBUTE | DESCRIPTION |
---|---|
nlp |
Container for NLP-related annotations like tokens and entities
TYPE:
|
concepts |
Container for extracted medical concepts
TYPE:
|
hl7 |
Container for structured clinical documents (CCD, FHIR)
TYPE:
|
cds |
Container for clinical decision support results
TYPE:
|
models |
Container for ML model outputs
TYPE:
|
The class provides methods to: - Add and access medical concepts - Generate structured clinical documents - Get basic text statistics - Iterate over tokens - Access raw text
Inherits from
BaseDocument: Provides base document functionality and raw text storage
Source code in healthchain/io/containers/document.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
|
__post_init__()
Initialize the document with basic tokenization if needed.
Source code in healthchain/io/containers/document.py
add_concepts(problems=None, medications=None, allergies=None)
Add extracted medical concepts to the document.
This method adds medical concepts (problems, medications, allergies) to their respective lists in the document's concepts container. Each concept type is optional and will only be added if provided.
PARAMETER | DESCRIPTION |
---|---|
problems
|
List of medical problems/conditions to add to the document. Defaults to None.
TYPE:
|
medications
|
List of medications to add to the document. Defaults to None.
TYPE:
|
allergies
|
List of allergies to add to the document. Defaults to None.
TYPE:
|
Example
doc.add_concepts( ... problems=[ProblemConcept(display_name="Hypertension")], ... medications=[MedicationConcept(display_name="Aspirin")] ... )
Source code in healthchain/io/containers/document.py
generate_ccd(overwrite=False)
Generate a CCD (Continuity of Care Document) from the current medical concepts.
This method creates or updates a CCD in the hl7 container using the medical concepts (problems, medications, allergies) currently stored in the document. The CCD is a standard format for exchanging clinical information.
PARAMETER | DESCRIPTION |
---|---|
overwrite
|
If True, overwrites any existing CCD data. If False, merges with existing CCD data. Defaults to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
CcdData
|
The generated CCD data.
TYPE:
|
Example
doc.add_concepts(problems=[ProblemConcept(display_name="Hypertension")]) doc.generate_ccd() # Creates CCD with the hypertension problem
Source code in healthchain/io/containers/document.py
HL7Data
dataclass
Container for structured clinical document formats.
This class stores and manages structured clinical data in different formats, including CCD (Continuity of Care Document) and FHIR (Fast Healthcare Interoperability Resources).
ATTRIBUTE | DESCRIPTION |
---|---|
_ccd_data |
Clinical data in CCD format, containing problems, medications, allergies and other clinical information.
TYPE:
|
_fhir_data |
Clinical data in FHIR format for clinical decision support.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
update_ccd_from_concepts |
ConceptLists, overwrite: bool = False) -> CcdData: Updates the CCD data with new clinical concepts, either by overwriting or extending existing data. |
get_fhir_data |
Returns the FHIR format clinical data if it exists, otherwise None. |
get_ccd_data |
Returns the CCD format clinical data if it exists, otherwise None. |
Source code in healthchain/io/containers/document.py
update_ccd_from_concepts(concepts, overwrite=False)
Updates the CCD data with new clinical concepts.
This method takes a ConceptLists object containing problems, medications, and allergies, and updates the internal CCD data accordingly. If no CCD data exists, it creates a new CcdData instance.
PARAMETER | DESCRIPTION |
---|---|
concepts
|
The new clinical concepts to add, containing problems, medications, and allergies lists.
TYPE:
|
overwrite
|
If True, replaces existing concepts. If False, extends the existing lists. Defaults to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
CcdData
|
The updated CCD data.
TYPE:
|
Source code in healthchain/io/containers/document.py
ModelOutputs
dataclass
Container for storing and managing third-party integration model outputs.
This class stores outputs from different NLP/ML frameworks like Hugging Face and LangChain, organizing them by task type. It also maintains a list of generated text outputs across frameworks.
ATTRIBUTE | DESCRIPTION |
---|---|
_huggingface_results |
Dictionary storing Hugging Face model outputs, keyed by task name.
TYPE:
|
_langchain_results |
Dictionary storing LangChain outputs, keyed by task name.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
add_output |
str, task: str, output: Any): Adds a model output for a specific source and task. For text generation tasks, also extracts and stores the generated text. |
get_output |
str, task: str, default: Any = None) -> Any: Gets the model output for a specific source and task. Returns default if not found. |
get_generated_text |
Returns the list of generated text outputs |
Source code in healthchain/io/containers/document.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
get_generated_text(source, task)
Returns generated text outputs for a given source and task.
Handles different output formats for Hugging Face and LangChain. For Hugging Face, it extracts the last message content from chat-style outputs and common keys like "generated_text", "summary_text", and "translation". For LangChain, it converts JSON outputs to strings, and returns the output as is if it is already a string.
PARAMETER | DESCRIPTION |
---|---|
source
|
Framework name (e.g., "huggingface", "langchain").
TYPE:
|
task
|
Task name for retrieving generated text.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[str]
|
List[str]: List of generated text outputs, or an empty list if none. |
Source code in healthchain/io/containers/document.py
NlpAnnotations
dataclass
Container for NLP-specific annotations and results.
This class stores various NLP annotations and processing results from text analysis, including preprocessed text, tokens, named entities, embeddings and spaCy documents.
ATTRIBUTE | DESCRIPTION |
---|---|
_preprocessed_text |
The preprocessed version of the input text.
TYPE:
|
_tokens |
List of tokenized words from the text.
TYPE:
|
_entities |
Named entities extracted from the text, with their labels and positions.
TYPE:
|
_embeddings |
Vector embeddings generated from the text.
TYPE:
|
_spacy_doc |
The processed spaCy Doc object.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
add_spacy_doc |
SpacyDoc): Processes a spaCy Doc to extract tokens and entities. |
get_spacy_doc |
Returns the stored spaCy Doc object. |
get_tokens |
Returns the list of tokens. |
set_tokens |
List[str]): Sets the token list. |
set_entities |
List[Dict[str, Any]]): Sets the named entities list. |
get_entities |
Returns the list of named entities. |
get_embeddings |
Returns the vector embeddings. |
set_embeddings |
List[float]): Sets the vector embeddings. |
Source code in healthchain/io/containers/document.py
tabular
Tabular
dataclass
Bases: DataContainer[DataFrame]
A container for tabular data, wrapping a pandas DataFrame.
ATTRIBUTE | DESCRIPTION |
---|---|
data |
The pandas DataFrame containing the tabular data.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__post_init__ |
Validates that the data is a pandas DataFrame. |
columns |
Property that returns a list of column names. |
index |
Property that returns the DataFrame's index. |
dtypes |
Property that returns a dictionary of column names and their data types. |
column_count |
Returns the number of columns in the DataFrame. |
row_count |
Returns the number of rows in the DataFrame. |
get_dtype |
str): Returns the data type of a specific column. |
__iter__ |
Returns an iterator over the column names. |
__len__ |
Returns the number of rows in the DataFrame. |
describe |
Returns a string description of the tabular data. |
remove_column |
str): Removes a column from the DataFrame. |
from_csv |
str, **kwargs): Class method to create a Tabular object from a CSV file. |
from_dict |
Dict[str, Any]): Class method to create a Tabular object from a dictionary. |
to_csv |
str, **kwargs): Saves the DataFrame to a CSV file. |