-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add basic chart for vital signs observations #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
1c6e032
9a3a19a
fce9ddf
78af59d
c994dc5
8e5db61
6ab2b5c
a46b042
0f05221
0cbc32c
703c8e0
82a1e93
1d3ec29
7bf194d
f5798c2
4340783
58792a6
378e145
deb0158
2465817
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| #!/usr/bin/env python3 | ||
| """Upload openEHR templates to EHRBase. | ||
|
|
||
| Usage: | ||
| python scripts/upload_templates.py [--check-only] | ||
|
|
||
| This script uploads all OPT templates from the templates/ directory to EHRBase. | ||
| Run this after starting EHRBase to ensure all required templates are available. | ||
| """ | ||
|
|
||
| import asyncio | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import httpx | ||
|
|
||
| # Add parent directory to path for imports | ||
| sys.path.insert(0, str(Path(__file__).parent.parent)) | ||
|
|
||
| from src.config import settings | ||
|
|
||
|
|
||
| async def list_templates(client: httpx.AsyncClient) -> list[str]: | ||
| """List existing templates in EHRBase.""" | ||
| response = await client.get("/openehr/v1/definition/template/adl1.4") | ||
| if response.status_code == 200: | ||
| templates = response.json() | ||
| return [t.get("template_id", "") for t in templates] | ||
| return [] | ||
|
|
||
|
|
||
| async def upload_template(client: httpx.AsyncClient, template_path: Path) -> bool: | ||
| """Upload a single template to EHRBase.""" | ||
| template_content = template_path.read_text() | ||
| template_id = template_path.stem # filename without extension | ||
|
|
||
| print(f" Uploading {template_id}...") | ||
|
|
||
| response = await client.post( | ||
| "/openehr/v1/definition/template/adl1.4", | ||
| content=template_content, | ||
| headers={"Content-Type": "application/xml"}, | ||
| ) | ||
|
|
||
| if response.status_code in (200, 201, 204): | ||
| print(f" ✓ {template_id} uploaded successfully") | ||
| return True | ||
| elif response.status_code == 409: | ||
| print(f" ○ {template_id} already exists") | ||
| return True | ||
| else: | ||
| print(f" ✗ {template_id} failed: {response.status_code}") | ||
| try: | ||
| error_detail = response.json() | ||
| print(f" Error: {error_detail}") | ||
| except Exception: | ||
| print(f" Response: {response.text[:500]}") | ||
| return False | ||
|
|
||
|
|
||
| async def main(check_only: bool = False): | ||
| """Upload all templates to EHRBase.""" | ||
| templates_dir = Path(__file__).parent.parent / "templates" | ||
|
|
||
| if not templates_dir.exists(): | ||
| print(f"Templates directory not found: {templates_dir}") | ||
| sys.exit(1) | ||
|
|
||
| template_files = list(templates_dir.glob("*.opt")) | ||
| if not template_files: | ||
| print("No .opt template files found") | ||
| sys.exit(0) | ||
|
|
||
| print(f"Found {len(template_files)} template(s)") | ||
| print(f"EHRBase URL: {settings.ehrbase_url}") | ||
| print() | ||
|
|
||
| auth = None | ||
| if settings.ehrbase_user and settings.ehrbase_password: | ||
| auth = httpx.BasicAuth(settings.ehrbase_user, settings.ehrbase_password) | ||
|
|
||
| async with httpx.AsyncClient(base_url=settings.ehrbase_url, auth=auth) as client: | ||
| # Check EHRBase connectivity | ||
| try: | ||
| response = await client.get("/ehrbase/rest/status") | ||
| if response.status_code != 200: | ||
| print(f"EHRBase not ready: {response.status_code}") | ||
| sys.exit(1) | ||
| print("EHRBase is ready") | ||
| except httpx.ConnectError: | ||
| print("Cannot connect to EHRBase") | ||
| sys.exit(1) | ||
|
|
||
| # List existing templates | ||
| existing = await list_templates(client) | ||
| print(f"Existing templates: {len(existing)}") | ||
| for t in existing: | ||
| print(f" - {t}") | ||
| print() | ||
|
|
||
| if check_only: | ||
| print("Check only mode - not uploading") | ||
| return | ||
|
|
||
| # Upload templates | ||
| print("Uploading templates...") | ||
| success_count = 0 | ||
| for template_path in template_files: | ||
| if await upload_template(client, template_path): | ||
| success_count += 1 | ||
|
|
||
| print() | ||
| print(f"Uploaded {success_count}/{len(template_files)} templates") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| check_only = "--check-only" in sys.argv | ||
| asyncio.run(main(check_only)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,10 +118,16 @@ async def upload_template(self, template_content: str) -> dict[str, Any]: | |
| response = await client.post( | ||
| "/openehr/v1/definition/template/adl1.4", | ||
| content=template_content, | ||
| headers={"Content-Type": "application/XML"} | ||
| headers={ | ||
| "Content-Type": "application/xml", | ||
| "Accept": "application/json, application/xml", | ||
| } | ||
| ) | ||
| response.raise_for_status() | ||
| return response.json() | ||
| # EHRBase may return empty response or XML on success | ||
| if response.headers.get("content-type", "").startswith("application/json"): | ||
| return response.json() | ||
| return {"status": "uploaded"} | ||
|
Comment on lines
+148
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's examine the context around lines 127-130 in client.py
cat -n api/src/ehrbase/client.py | sed -n '115,145p'Repository: platzhersh/open-cis Length of output: 1135 🌐 Web query:
💡 Result: POST /openehr/v1/definition/template/adl1.4 — response format (summary)
Citations: Consider handling the actual response data instead of a synthetic fallback. Per OpenEHR API specification, the template upload endpoint correctly returns 201 Created with response body that is either empty (minimal preference) or contains the template representation in XML or JSON depending on content negotiation and Prefer header. The defensive check for However, the fallback 🤖 Prompt for AI Agents |
||
|
|
||
| async def close(self): | ||
| if self._client: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.