Z230
This commit is contained in:
92
30 ManipulacePoznámek/100 JednoducheCteni1poznamky.py
Normal file
92
30 ManipulacePoznámek/100 JednoducheCteni1poznamky.py
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from pathlib import Path
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# UTF-8 safety
|
||||||
|
try:
|
||||||
|
sys.stdout.reconfigure(encoding='utf-8')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# === CONFIG ===
|
||||||
|
|
||||||
|
TOKEN_PATH = Path("token.txt")
|
||||||
|
GRAPHQL_URL = "https://api.medevio.cz/graphql"
|
||||||
|
REQUEST_ID = "e17536c4-ed22-4242-ada5-d03713e0b7ac" # požadavek který sledujeme
|
||||||
|
|
||||||
|
|
||||||
|
def read_token(path: Path) -> str:
|
||||||
|
t = path.read_text().strip()
|
||||||
|
if t.startswith("Bearer "):
|
||||||
|
return t.split(" ", 1)[1]
|
||||||
|
return t
|
||||||
|
|
||||||
|
|
||||||
|
# === QUERY ===
|
||||||
|
|
||||||
|
QUERY = r"""
|
||||||
|
query ClinicRequestNotes_Get($patientRequestId: String!) {
|
||||||
|
notes: getClinicPatientRequestNotes(requestId: $patientRequestId) {
|
||||||
|
id
|
||||||
|
content
|
||||||
|
createdAt
|
||||||
|
updatedAt
|
||||||
|
createdBy {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
surname
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def run_query(request_id, token):
|
||||||
|
payload = {
|
||||||
|
"operationName": "ClinicRequestNotes_Get",
|
||||||
|
"query": QUERY,
|
||||||
|
"variables": {"patientRequestId": request_id},
|
||||||
|
}
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"Bearer {token}",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
|
||||||
|
r = requests.post(GRAPHQL_URL, json=payload, headers=headers)
|
||||||
|
r.raise_for_status()
|
||||||
|
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
token = read_token(TOKEN_PATH)
|
||||||
|
|
||||||
|
print(f"🔍 Čtu interní klinické poznámky k požadavku {REQUEST_ID} ...\n")
|
||||||
|
|
||||||
|
data = run_query(REQUEST_ID, token)
|
||||||
|
|
||||||
|
notes = data.get("data", {}).get("notes", [])
|
||||||
|
if not notes:
|
||||||
|
print("📭 Žádné klinické poznámky nejsou uložené.")
|
||||||
|
return
|
||||||
|
|
||||||
|
print(f"📌 Nalezeno {len(notes)} poznámek:\n")
|
||||||
|
|
||||||
|
for n in notes:
|
||||||
|
print("──────────────────────────────")
|
||||||
|
print(f"🆔 ID: {n['id']}")
|
||||||
|
print(f"👤 Vytvořil: {n['createdBy']['surname']} {n['createdBy']['name']}")
|
||||||
|
print(f"📅 createdAt: {n['createdAt']}")
|
||||||
|
print(f"🕒 updatedAt: {n['updatedAt']}")
|
||||||
|
print("📝 Obsah:")
|
||||||
|
print(n['content'])
|
||||||
|
print("")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
121
30 ManipulacePoznámek/101 JednoducheDoplneniInterniPoznamky.py
Normal file
121
30 ManipulacePoznámek/101 JednoducheDoplneniInterniPoznamky.py
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from pathlib import Path
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# UTF-8 handling
|
||||||
|
try:
|
||||||
|
sys.stdout.reconfigure(encoding='utf-8')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# === CONFIG ===
|
||||||
|
|
||||||
|
TOKEN_PATH = Path("token.txt")
|
||||||
|
GRAPHQL_URL = "https://api.medevio.cz/graphql"
|
||||||
|
|
||||||
|
REQUEST_ID = "e17536c4-ed22-4242-ada5-d03713e0b7ac" # požadavek
|
||||||
|
NOTE_PREPEND_TEXT = "🔥 NOVÝ TESTOVACÍ ŘÁDEK\n" # text, který se přidá NA ZAČÁTEK
|
||||||
|
|
||||||
|
|
||||||
|
# === Helpers ===
|
||||||
|
|
||||||
|
def read_token(p: Path) -> str:
|
||||||
|
t = p.read_text().strip()
|
||||||
|
if t.startswith("Bearer "):
|
||||||
|
return t.split(" ", 1)[1]
|
||||||
|
return t
|
||||||
|
|
||||||
|
|
||||||
|
# === Queries ===
|
||||||
|
|
||||||
|
QUERY_GET_NOTES = r"""
|
||||||
|
query ClinicRequestNotes_Get($patientRequestId: String!) {
|
||||||
|
notes: getClinicPatientRequestNotes(requestId: $patientRequestId) {
|
||||||
|
id
|
||||||
|
content
|
||||||
|
createdAt
|
||||||
|
updatedAt
|
||||||
|
createdBy {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
surname
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
MUTATION_UPDATE_NOTE = r"""
|
||||||
|
mutation ClinicRequestNotes_Update($noteInput: UpdateClinicPatientRequestNoteInput!) {
|
||||||
|
updateClinicPatientRequestNote(noteInput: $noteInput) {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
# === Core functions ===
|
||||||
|
|
||||||
|
def gql(query, variables, token):
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"Bearer {token}",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
payload = {"query": query, "variables": variables}
|
||||||
|
|
||||||
|
r = requests.post(GRAPHQL_URL, json=payload, headers=headers)
|
||||||
|
r.raise_for_status()
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
def get_internal_note(request_id, token):
|
||||||
|
data = gql(QUERY_GET_NOTES, {"patientRequestId": request_id}, token)
|
||||||
|
notes = data.get("data", {}).get("notes", [])
|
||||||
|
return notes[0] if notes else None
|
||||||
|
|
||||||
|
|
||||||
|
def update_internal_note(note_id, new_content, token):
|
||||||
|
variables = {"noteInput": {"id": note_id, "content": new_content}}
|
||||||
|
return gql(MUTATION_UPDATE_NOTE, variables, token)
|
||||||
|
|
||||||
|
|
||||||
|
# === MAIN ===
|
||||||
|
|
||||||
|
def main():
|
||||||
|
token = read_token(TOKEN_PATH)
|
||||||
|
|
||||||
|
print(f"🔍 Načítám interní poznámku pro požadavek {REQUEST_ID}...\n")
|
||||||
|
|
||||||
|
note = get_internal_note(REQUEST_ID, token)
|
||||||
|
if not note:
|
||||||
|
print("❌ Nebyla nalezena žádná interní klinická poznámka!")
|
||||||
|
return
|
||||||
|
|
||||||
|
note_id = note["id"]
|
||||||
|
old_content = note["content"] or ""
|
||||||
|
|
||||||
|
print("📄 Původní obsah:")
|
||||||
|
print(old_content)
|
||||||
|
print("────────────────────────────\n")
|
||||||
|
|
||||||
|
# ===============================
|
||||||
|
# PREPEND new text
|
||||||
|
# ===============================
|
||||||
|
new_content = NOTE_PREPEND_TEXT + old_content
|
||||||
|
|
||||||
|
print("📝 Nový obsah který odešlu:")
|
||||||
|
print(new_content)
|
||||||
|
print("────────────────────────────\n")
|
||||||
|
|
||||||
|
# UPDATE
|
||||||
|
result = update_internal_note(note_id, new_content, token)
|
||||||
|
|
||||||
|
print(f"✅ Hotovo! Poznámka {note_id} aktualizována.")
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
1
30 ManipulacePoznámek/token.txt
Normal file
1
30 ManipulacePoznámek/token.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
nYvrvgflIKcDiQg8Hhpud+qG8iGZ8eH8su4nyT/Mgcm7XQp65ygY9s39+O01wIpk/7sKd6fBHkiKvsqH
|
||||||
Reference in New Issue
Block a user