-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
black formatting
- Loading branch information
Showing
8 changed files
with
182 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from pyvis.network import Network | ||
|
||
from fhir_query import ResourceDB | ||
|
||
|
||
def _container(): | ||
"""Create a pyvis container.""" | ||
return Network(notebook=True, cdn_resources="in_line") # filter_menu=True, select_menu=True | ||
|
||
|
||
def _load(net: Network, aggregation: dict) -> Network: | ||
"""Load the aggregation into the visualization network.""" | ||
# add vertices | ||
for resource_type, _ in aggregation.items(): | ||
assert "count" in _, _ | ||
net.add_node(resource_type, label=f"{resource_type}/{_['count']}") | ||
# add edges | ||
for resource_type, _ in aggregation.items(): | ||
for ref in _.get("references", {}): | ||
count = _["references"][ref]["count"] | ||
if resource_type not in net.get_nodes(): | ||
net.add_node(resource_type, label=f"{resource_type}/?") | ||
if ref not in net.get_nodes(): | ||
net.add_node(ref, label=f"{ref}/?") | ||
net.add_edge(resource_type, ref, title=count, value=count) | ||
return net | ||
|
||
|
||
def visualize_aggregation(aggregation: dict, output_path: str) -> None: | ||
"""Visualize the aggregation.""" | ||
# Load it into a pyvis | ||
net = _load(_container(), aggregation) | ||
net.save_graph(str(output_path)) | ||
net.show_buttons(filter_=["physics"]) | ||
|
||
|
||
def create_network_graph(db_path: str, output_path: str) -> None: | ||
"""Render metadata as a network graph into output_path. | ||
\b | ||
db_path: The directory path to the db. | ||
output_path: The path to save the network graph. | ||
""" | ||
db = ResourceDB(db_path=db_path) | ||
visualize_aggregation(db.aggregate(), output_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,6 @@ httpx | |
|
||
fhir.resources==8.0.0b4 | ||
dotty-dict | ||
nested_lookup | ||
pyvis | ||
click_default_group |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,40 @@ | ||
from click.testing import CliRunner | ||
from fhir_query.cli import main | ||
from fhir_query.cli import cli | ||
|
||
|
||
def test_default_option() -> None: | ||
"""Test default option.""" | ||
runner = CliRunner() | ||
result = runner.invoke(cli, ["--help"]) | ||
print(result.output) | ||
output = result.output | ||
for _ in ["main*", "summarize", "visualize"]: | ||
assert _ in output, f"Expected {_} in {output}" | ||
|
||
|
||
def test_help_option() -> None: | ||
"""Test help option.""" | ||
runner = CliRunner() | ||
result = runner.invoke(main, "--help") | ||
result = runner.invoke(cli, ["main", "--help"]) | ||
output = result.output | ||
print(output) | ||
assert "Usage:" in output | ||
assert "--fhir-base-url" in output | ||
assert "--graph-definition-id" in output | ||
assert "--graph-definition-file-path" in output | ||
assert "--start-resource-type" in output | ||
assert "--start-resource-id" in output | ||
assert "--db_path" in output | ||
assert "--db-path" in output | ||
assert "--dry-run" in output | ||
assert "--debug" in output | ||
assert "--log-file" in output | ||
|
||
|
||
def test_visualize_help() -> None: | ||
"""Test visualizer help.""" | ||
runner = CliRunner() | ||
result = runner.invoke(cli, ["visualize", "--help"]) | ||
output = result.output | ||
assert "Usage:" in output | ||
assert "--db-path" in output | ||
assert "--output-path" in output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters