97 lines
2.2 KiB
Python
97 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import json
|
|
import requests
|
|
from pathlib import Path
|
|
|
|
# ============================
|
|
# CONFIG
|
|
# ============================
|
|
TOKEN_PATH = Path("token.txt")
|
|
|
|
# vlož libovolný existující request ID
|
|
REQUEST_ID = "3fc9b28c-ada2-4d21-ab2d-fe60ad29fd8f"
|
|
|
|
GRAPHQL_NOTES_QUERY = r"""
|
|
query ClinicRequestNotes_Get($patientRequestId: String!) {
|
|
notes: getClinicPatientRequestNotes(requestId: $patientRequestId) {
|
|
id
|
|
content
|
|
createdAt
|
|
updatedAt
|
|
createdBy {
|
|
id
|
|
name
|
|
surname
|
|
}
|
|
}
|
|
}
|
|
"""
|
|
|
|
# ============================
|
|
# TOKEN
|
|
# ============================
|
|
def read_token(p: Path) -> str:
|
|
tok = p.read_text(encoding="utf-8").strip()
|
|
if tok.startswith("Bearer "):
|
|
tok = tok.split(" ", 1)[1]
|
|
return tok
|
|
|
|
# ============================
|
|
# FETCH
|
|
# ============================
|
|
def fetch_notes(request_id, token):
|
|
url = "https://api.medevio.cz/graphql"
|
|
|
|
headers = {
|
|
"Authorization": f"Bearer {token}",
|
|
"Content-Type": "application/json",
|
|
"Accept": "application/json",
|
|
}
|
|
|
|
variables = {"patientRequestId": request_id}
|
|
|
|
payload = {
|
|
"operationName": "ClinicRequestNotes_Get",
|
|
"query": GRAPHQL_NOTES_QUERY,
|
|
"variables": variables,
|
|
}
|
|
|
|
r = requests.post(url, json=payload, headers=headers)
|
|
r.raise_for_status()
|
|
return r.json()
|
|
|
|
# ============================
|
|
# MAIN
|
|
# ============================
|
|
def main():
|
|
token = read_token(TOKEN_PATH)
|
|
|
|
print(f"\n🔍 Fetching NOTES for request:\n ID = {REQUEST_ID}\n")
|
|
|
|
data = fetch_notes(REQUEST_ID, token)
|
|
|
|
print("📄 FULL RAW JSON:\n")
|
|
print(json.dumps(data, indent=2, ensure_ascii=False))
|
|
|
|
print("\n📝 Parsed notes:\n")
|
|
notes = data.get("data", {}).get("notes") or []
|
|
if not notes:
|
|
print(" (no notes found)")
|
|
return
|
|
|
|
for n in notes:
|
|
author = n.get("createdBy")
|
|
print(f"--- Note {n.get('id')} ---")
|
|
print(f"Created: {n.get('createdAt')}")
|
|
print(f"Updated: {n.get('updatedAt')}")
|
|
if author:
|
|
print(f"Author: {author.get('name')} {author.get('surname')}")
|
|
print("Content:")
|
|
print(n.get("content"))
|
|
print()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|