Files
medevio/10ReadPozadavky/04 Dalsi.py
2025-11-02 22:31:55 +01:00

102 lines
2.4 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
from pathlib import Path
import requests
TOKEN_PATH = Path("token.txt")
CLINIC_SLUG = "mudr-buzalkova"
# --- Try including `updatedAt` field directly ---
GRAPHQL_QUERY = r"""
query ClinicRequestGrid_ListPatientRequestsForClinic2(
$clinicSlug: String!,
$queueId: String,
$queueAssignment: QueueAssignmentFilter!,
$pageInfo: PageInfo!,
$locale: Locale!
) {
requestsResponse: listPatientRequestsForClinic2(
clinicSlug: $clinicSlug,
queueId: $queueId,
queueAssignment: $queueAssignment,
pageInfo: $pageInfo
) {
count
patientRequests {
id
createdAt
updatedAt # 👈 TESTUJEME, jestli Medevio toto pole podporuje
doneAt
removedAt
displayTitle(locale: $locale)
lastMessage { createdAt }
extendedPatient {
name
surname
identificationNumber
}
}
}
}
"""
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
def main():
token = read_token(TOKEN_PATH)
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json",
"Accept": "application/json",
}
variables = {
"clinicSlug": CLINIC_SLUG,
"queueId": None,
"queueAssignment": "ANY",
"pageInfo": {"first": 3, "offset": 0},
"locale": "cs",
}
payload = {
"operationName": "ClinicRequestGrid_ListPatientRequestsForClinic2",
"query": GRAPHQL_QUERY,
"variables": variables,
}
url = "https://api.medevio.cz/graphql"
print("📡 Querying Medevio GraphQL API (testing `updatedAt` field)...\n")
r = requests.post(url, json=payload, headers=headers)
print(f"HTTP status: {r.status_code}\n")
try:
data = r.json()
except Exception as e:
print("❌ Failed to parse JSON:", e)
print("Raw text:\n", r.text)
return
print("=== JSON response ===")
print(json.dumps(data, indent=2, ensure_ascii=False))
# Quick check: did it return an error message about updatedAt?
errors = data.get("errors")
if errors:
print("\n⚠️ Medevio returned GraphQL error:")
for e in errors:
print(f"{e.get('message')}")
else:
print("\n✅ No errors, `updatedAt` might exist in schema!")
if __name__ == "__main__":
main()