This commit is contained in:
2025-11-12 07:10:48 +01:00
parent 08c6f9745f
commit 3038c87b5d
5 changed files with 477 additions and 57 deletions

View File

@@ -1,59 +1,60 @@
import requests
import json
from pathlib import Path
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
TOKEN_PATH = Path("token.txt")
REQUEST_ID = "092a0c63-28be-4c6b-ab3b-204e1e2641d4"
CLINIC_SLUG = "mudr-buzalkova"
import pymysql
from datetime import datetime
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
GRAPHQL_QUERY = r"""
query ClinicRequestDetail_GetPatientRequest2(
$requestId: UUID!,
) {
patientRequestMedicalRecords: listMedicalRecordsForPatientRequest(
attachmentTypes: [ECRF_FILL_ATTACHMENT, MESSAGE_ATTACHMENT, PATIENT_REQUEST_ATTACHMENT]
patientRequestId: $requestId
pageInfo: {first: 100, offset: 0}
) {
attachmentType
id
medicalRecord {
contentType
description
downloadUrl
id
url
visibleToPatient
}
}
# ==============================
# ⚙️ CONFIGURATION
# ==============================
DB_CONFIG = {
"host": "192.168.1.76",
"port": 3307,
"user": "root",
"password": "Vlado9674+",
"database": "medevio",
"charset": "utf8mb4",
}
REQUEST_ID = "4476f9f8-d7b7-4381-b056-a44897413bcd"
# ==============================
# 🧩 READ CONVERSATION
# ==============================
conn = pymysql.connect(**DB_CONFIG)
cur = conn.cursor(pymysql.cursors.DictCursor)
sql = """
SELECT
id,
sender_name,
text,
created_at,
attachment_url,
attachment_description,
attachment_content_type
FROM medevio_conversation
WHERE request_id = %s
ORDER BY created_at ASC;
"""
cur.execute(sql, (REQUEST_ID,))
rows = cur.fetchall()
variables = {
"requestId": REQUEST_ID,
}
print(f"💬 Conversation for request {REQUEST_ID}:")
print("" * 100)
headers = {
"Authorization": f"Bearer {read_token(TOKEN_PATH)}",
"Content-Type": "application/json",
"Accept": "application/json",
}
for r in rows:
created = r["created_at"].strftime("%Y-%m-%d %H:%M") if r["created_at"] else "unknown"
sender = r["sender_name"] or "(unknown)"
text = (r["text"] or "").strip().replace("\n", " ")
payload = {
"operationName": "ClinicRequestDetail_GetPatientRequest2",
"query": GRAPHQL_QUERY,
"variables": variables,
}
print(f"[{created}] {sender}: {text}")
print("📡 Querying Medevio API...\n")
r = requests.post("https://api.medevio.cz/graphql", json=payload, headers=headers)
print(f"HTTP status: {r.status_code}\n")
print(json.dumps(r.json(), indent=2, ensure_ascii=False))
if r["attachment_url"]:
print(f" 📎 Attachment: {r['attachment_description']} ({r['attachment_content_type']})")
print(f" URL: {r['attachment_url']}")
print()
cur.close()
conn.close()