Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added docs/api/graph.rst
Empty file.
15 changes: 15 additions & 0 deletions docs/api/graph/pyhealth.graph.KnowledgeGraph.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pyhealth.graph.KnowledgeGraph
==============================

Overview
--------
Knowledge graph data structure for healthcare code systems.
Stores (head, relation, tail) triples and provides k-hop subgraph
extraction for patient-level graph construction.

API Reference
-------------
.. automodule:: pyhealth.graph.knowledge_graph
:members:
:undoc-members:
:show-inheritance:
5 changes: 4 additions & 1 deletion docs/api/processors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Available Processors
- ``StageNetTensorProcessor``: Tensor processing for StageNet
- ``MultiHotProcessor``: For multi-hot encoding
- ``IgnoreProcessor``: A special feature processor that marks a feature to be ignored.
- ``GraphProcessor``: For knowledge graph subgraph extraction (e.g., GraphCare, G-BERT)

Usage Examples
--------------
Expand Down Expand Up @@ -276,6 +277,7 @@ Common string keys for automatic processor selection:
- ``"time_image"``: For time-stamped image sequences
- ``"tensor"``: For pre-processed tensors
- ``"raw"``: For raw/unprocessed data
- ``"graph"``: For knowledge graph subgraphs

Writing Custom FeatureProcessors
---------------------------------
Expand Down Expand Up @@ -470,4 +472,5 @@ API Reference
processors/pyhealth.processors.IgnoreProcessor
processors/pyhealth.processors.MultiHotProcessor
processors/pyhealth.processors.StageNetProcessor
processors/pyhealth.processors.StageNetTensorProcessor
processors/pyhealth.processors.StageNetTensorProcessor
processors/pyhealth.processors.GraphProcessor
15 changes: 15 additions & 0 deletions docs/api/processors/pyhealth.processors.GraphProcessor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pyhealth.processors.GraphProcessor
====================================

Overview
--------
Processor that converts medical codes into patient-level PyG subgraphs
using a provided KnowledgeGraph. Registered as ``"graph"`` in the
processor registry.

API Reference
-------------
.. automodule:: pyhealth.processors.graph_processor
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ Quick Navigation

api/data
api/datasets
api/graph
api/tasks
api/models
api/processors
Expand Down
9 changes: 9 additions & 0 deletions pyhealth/datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

MODULE_CACHE_PATH = os.path.join(BASE_CACHE_PATH, "datasets")
create_directory(MODULE_CACHE_PATH)
#PyG import for graph-based models
try:
from torch_geometric.data import Data as PyGData, Batch as PyGBatch
HAS_PYG = True
except ImportError:
HAS_PYG = False


# basic tables which are a part of the defined datasets
Expand Down Expand Up @@ -294,6 +300,9 @@ def collate_fn_dict_with_padding(batch: List[dict]) -> dict:

# Return as tuple (time, values)
collated[key] = (collated_times, collated_values)
# PyG Data objects (graph processor output)
elif HAS_PYG and isinstance(values[0], PyGData):
collated[key] = PyGBatch.from_data_list(values)

elif isinstance(values[0], torch.Tensor):
# Check if shapes are the same
Expand Down
3 changes: 3 additions & 0 deletions pyhealth/graph/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from pyhealth.graph.knowledge_graph import KnowledgeGraph

__all__ = ["KnowledgeGraph"]
Loading