|
import requests |
|
|
|
def print_tree(node, prefix="", visited=None): |
|
"""Recursive function to print a refined tree structure without duplicates.""" |
|
if visited is None: |
|
visited = set() |
|
|
|
node_id = node["node_id"] |
|
|
|
if node_id in visited: |
|
print(f"{prefix}(already listed) {node_id}") |
|
return |
|
visited.add(node_id) |
|
|
|
print(f"{prefix}{node_id}") |
|
children = node.get("descendants", []) |
|
for i, child in enumerate(children): |
|
|
|
new_prefix = f"{prefix}βββ " if i < len(children) - 1 else f"{prefix}βββ " |
|
print_tree(child, new_prefix, visited) |
|
|
|
|
|
base_url = "http://localhost:5000" |
|
|
|
|
|
print("\n--- Testing Graph Loading ---") |
|
response = requests.post(f"{base_url}/load_graph") |
|
print("Load Graph Response:", response.json()) |
|
|
|
|
|
print("\n--- Testing Node Creation ---") |
|
create_data = { |
|
"node_id": "patient_123", |
|
"data": {"name": "John Doe", "age": 45, "medical_conditions": ["hypertension", "diabetes"]}, |
|
"domain": "Healthcare", |
|
"type": "Patient" |
|
} |
|
response = requests.post(f"{base_url}/create_node", json=create_data) |
|
print("Create Node Response:", response.json()) |
|
|
|
|
|
print("\n--- Testing Inspect Relationships for Node (Healthcare) ---") |
|
response = requests.get(f"{base_url}/inspect_relationships?node_id=Healthcare") |
|
relationships = response.json() |
|
print("Inspect Relationships for Healthcare:") |
|
|
|
|
|
root_node = { |
|
"node_id": relationships["node_id"], |
|
"descendants": relationships["relationships"]["child_relations"] |
|
} |
|
print_tree(root_node) |