notebook
This commit is contained in:
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Medicus
|
||||||
7
.idea/Medicus1.iml
generated
Normal file
7
.idea/Medicus1.iml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
168
2025-06-17 Files and Folders.py
Normal file
168
2025-06-17 Files and Folders.py
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
import os
|
||||||
|
import mysql.connector
|
||||||
|
from mysql.connector import Error
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
class FileSystemToMySQL:
|
||||||
|
def __init__(self, host, port,user, password, database):
|
||||||
|
self.host = host
|
||||||
|
self.port=port
|
||||||
|
self.user = user
|
||||||
|
self.password = password
|
||||||
|
self.database = database
|
||||||
|
self.connection = None
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
try:
|
||||||
|
self.connection = mysql.connector.connect(
|
||||||
|
host=self.host,
|
||||||
|
port=self.port,
|
||||||
|
user=self.user,
|
||||||
|
password=self.password,
|
||||||
|
database=self.database
|
||||||
|
)
|
||||||
|
if self.connection.is_connected():
|
||||||
|
print("Connected to MySQL database")
|
||||||
|
self._initialize_database()
|
||||||
|
except Error as e:
|
||||||
|
print(f"Error connecting to MySQL: {e}")
|
||||||
|
|
||||||
|
def _initialize_database(self):
|
||||||
|
cursor = self.connection.cursor()
|
||||||
|
|
||||||
|
# Create tables if they don't exist
|
||||||
|
cursor.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS folders (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
path VARCHAR(767) NOT NULL,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
parent_id INT NULL,
|
||||||
|
created_at DATETIME NOT NULL,
|
||||||
|
updated_at DATETIME NOT NULL,
|
||||||
|
FOREIGN KEY (parent_id) REFERENCES folders(id) ON DELETE CASCADE,
|
||||||
|
UNIQUE (path)
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
cursor.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS files (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
folder_id INT NOT NULL,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
size INT NOT NULL,
|
||||||
|
created_at DATETIME NOT NULL,
|
||||||
|
updated_at DATETIME NOT NULL,
|
||||||
|
FOREIGN KEY (folder_id) REFERENCES folders(id) ON DELETE CASCADE,
|
||||||
|
UNIQUE (folder_id, name)
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
self.connection.commit()
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
|
def _get_folder_id(self, folder_path):
|
||||||
|
cursor = self.connection.cursor()
|
||||||
|
cursor.execute("SELECT id FROM folders WHERE path = %s", (folder_path,))
|
||||||
|
result = cursor.fetchone()
|
||||||
|
cursor.close()
|
||||||
|
return result[0] if result else None
|
||||||
|
|
||||||
|
def _insert_folder(self, folder_path, parent_id=None):
|
||||||
|
folder_name = os.path.basename(folder_path)
|
||||||
|
now = datetime.now()
|
||||||
|
|
||||||
|
cursor = self.connection.cursor()
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT INTO folders (path, name, parent_id, created_at, updated_at)
|
||||||
|
VALUES (%s, %s, %s, %s, %s)
|
||||||
|
ON DUPLICATE KEY UPDATE updated_at = %s
|
||||||
|
""", (folder_path, folder_name, parent_id, now, now, now))
|
||||||
|
|
||||||
|
folder_id = cursor.lastrowid
|
||||||
|
if folder_id == 0: # If it was an update
|
||||||
|
folder_id = self._get_folder_id(folder_path)
|
||||||
|
|
||||||
|
self.connection.commit()
|
||||||
|
cursor.close()
|
||||||
|
return folder_id
|
||||||
|
|
||||||
|
def store_file(self, file_path, folder_path):
|
||||||
|
try:
|
||||||
|
# First ensure the folder exists
|
||||||
|
folder_id = self._insert_folder(folder_path)
|
||||||
|
|
||||||
|
# Read file content
|
||||||
|
with open(file_path, 'rb') as file:
|
||||||
|
file_content = file.read()
|
||||||
|
|
||||||
|
file_name = os.path.basename(file_path)
|
||||||
|
file_size = os.path.getsize(file_path)
|
||||||
|
now = datetime.now()
|
||||||
|
|
||||||
|
cursor = self.connection.cursor()
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT INTO files (folder_id, name, size, created_at, updated_at)
|
||||||
|
VALUES (%s, %s, %s, %s, %s)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
size = VALUES(size),
|
||||||
|
updated_at = VALUES(updated_at)
|
||||||
|
""", (folder_id, file_name, file_size, now, now))
|
||||||
|
|
||||||
|
self.connection.commit()
|
||||||
|
cursor.close()
|
||||||
|
print(f"Stored/updated file: {file_name} in folder: {folder_path}")
|
||||||
|
except Error as e:
|
||||||
|
print(f"Error storing file {file_path}: {e}")
|
||||||
|
|
||||||
|
def store_directory(self, directory_path, parent_folder_path=None):
|
||||||
|
try:
|
||||||
|
# Ensure the parent folder exists
|
||||||
|
parent_id = None
|
||||||
|
if parent_folder_path:
|
||||||
|
parent_id = self._insert_folder(parent_folder_path)
|
||||||
|
|
||||||
|
# Store the current directory
|
||||||
|
dir_id = self._insert_folder(directory_path, parent_id)
|
||||||
|
|
||||||
|
# Store all files in the directory
|
||||||
|
for item in os.listdir(directory_path):
|
||||||
|
full_path = os.path.join(directory_path, item)
|
||||||
|
if os.path.isfile(full_path):
|
||||||
|
self.store_file(full_path, directory_path)
|
||||||
|
elif os.path.isdir(full_path):
|
||||||
|
self.store_directory(full_path, directory_path)
|
||||||
|
|
||||||
|
print(f"Stored directory: {directory_path}")
|
||||||
|
except Error as e:
|
||||||
|
print(f"Error storing directory {directory_path}: {e}")
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
if self.connection and self.connection.is_connected():
|
||||||
|
self.connection.close()
|
||||||
|
print("MySQL connection closed")
|
||||||
|
|
||||||
|
|
||||||
|
# Example usage
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# Database configuration
|
||||||
|
db_config = {
|
||||||
|
'host': '192.168.1.76',
|
||||||
|
'port': '3307',
|
||||||
|
'user': 'root',
|
||||||
|
'password': 'Vlado9674+',
|
||||||
|
'database': 'file_storage_db'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initialize the file system storage
|
||||||
|
fs_storage = FileSystemToMySQL(**db_config)
|
||||||
|
fs_storage.connect()
|
||||||
|
|
||||||
|
# Store a single file
|
||||||
|
# fs_storage.store_file('/path/to/your/file.txt', '/path/to/your')
|
||||||
|
|
||||||
|
# Store an entire directory
|
||||||
|
fs_storage.store_directory(r'u:\Dropbox\!!!Days\Downloads Z230')
|
||||||
|
|
||||||
|
# Close the connection
|
||||||
|
fs_storage.close()
|
||||||
BIN
AMBSUKL214235369G_31DEC2024.pfx
Normal file
BIN
AMBSUKL214235369G_31DEC2024.pfx
Normal file
Binary file not shown.
48
Access.py
Normal file
48
Access.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import os
|
||||||
|
import pyodbc
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
|
||||||
|
# Path to your Access database
|
||||||
|
db_path = r"u:\Dropbox\!!!Days\Downloads Z230\Access\Banka.accdb"
|
||||||
|
# Connection string
|
||||||
|
conn_str = (
|
||||||
|
r"DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};"
|
||||||
|
rf"DBQ={db_path};"
|
||||||
|
)
|
||||||
|
# Connect to database
|
||||||
|
conn = pyodbc.connect(conn_str)
|
||||||
|
|
||||||
|
# Create cursor
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute("delete from transactions")
|
||||||
|
conn.commit()
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
length = 10 # desired length
|
||||||
|
chars = string.ascii_letters + string.digits # A-Z, a-z, 0-9
|
||||||
|
|
||||||
|
# Example query
|
||||||
|
# cursor.execute("SELECT * FROM contacts")
|
||||||
|
print("Start")
|
||||||
|
for n in range(10000):
|
||||||
|
random_str = ''.join(random.choices(chars, k=length))
|
||||||
|
cursor.execute("insert into contacts (company) values (?)",(random_str))
|
||||||
|
print("stop")
|
||||||
|
conn.commit()
|
||||||
|
print("committed")
|
||||||
|
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
# Example query
|
||||||
|
cursor.execute("SELECT * FROM contacts")
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
|
for row in rows:
|
||||||
|
print(row)
|
||||||
|
|
||||||
|
|
||||||
|
# Close connection
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
105
DatovaSchranka.py
Normal file
105
DatovaSchranka.py
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
# Přihlašovací údaje
|
||||||
|
username = 'eupo5s'
|
||||||
|
password = 'Michalka25+'
|
||||||
|
schrankaid='bk7e6j2'
|
||||||
|
|
||||||
|
from zeep import Client
|
||||||
|
from zeep.wsse.username import UsernameToken
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import base64
|
||||||
|
|
||||||
|
# Přihlašovací údaje
|
||||||
|
USERNAME = 'eupo5s'
|
||||||
|
PASSWORD = 'Michalka25+'
|
||||||
|
WSDL_URL = 'https://..../ds.wsdl' # upravit dle prostředí
|
||||||
|
|
||||||
|
# Inicializace klienta
|
||||||
|
client = Client(wsdl=WSDL_URL, wsse=UsernameToken(USERNAME, PASSWORD))
|
||||||
|
|
||||||
|
# Kontrola přihlášení
|
||||||
|
try:
|
||||||
|
owner_info = client.service.GetOwnerInfoFromLogin()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Chyba přihlášení: {e}")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
# Zobrazení základních údajů o přihlášeném účtu
|
||||||
|
print("Přihlášen jako:", owner_info.dbID, owner_info.firmName)
|
||||||
|
|
||||||
|
# Vytvoření adresáře pro testovací soubory
|
||||||
|
out_dir = os.path.abspath('test_isds_py')
|
||||||
|
os.makedirs(out_dir, exist_ok=True)
|
||||||
|
|
||||||
|
# Vytvoření a odeslání testovacích zpráv
|
||||||
|
filenames = []
|
||||||
|
for i, text in enumerate(["První testovací soubor", "Druhý testovací soubor"], 1):
|
||||||
|
fn = os.path.join(out_dir, f"TESTISDS_{i}.txt")
|
||||||
|
with open(fn, 'w', encoding='utf-8') as f:
|
||||||
|
f.write(text)
|
||||||
|
filenames.append(fn)
|
||||||
|
|
||||||
|
# Nahraj přílohy
|
||||||
|
files_struct = []
|
||||||
|
for fn in filenames:
|
||||||
|
with open(fn, "rb") as f:
|
||||||
|
data = base64.b64encode(f.read()).decode('ascii')
|
||||||
|
files_struct.append({
|
||||||
|
'dmFileDescr': os.path.basename(fn),
|
||||||
|
'dmMimeType': 'text/plain',
|
||||||
|
'dmEncodedContent': data,
|
||||||
|
})
|
||||||
|
|
||||||
|
# Vytvoření a odeslání zprávy (parametry uprav podle vlastního scénáře!)
|
||||||
|
msg_id = client.service.CreateMessage(
|
||||||
|
senderDBID=None,
|
||||||
|
subject="Testovaci zasilka z Pythonu",
|
||||||
|
isUrgent=False,
|
||||||
|
senderOrgUnitCode=None,
|
||||||
|
# níže: příjemce
|
||||||
|
dbIDRecipient="231",
|
||||||
|
recipientFirmName="Nase org jednotka",
|
||||||
|
recipientOrgUnitNum=-1,
|
||||||
|
recipientOrgUnitName="ncj. 589",
|
||||||
|
receiverPersonCode=None,
|
||||||
|
toHands="K rukam p.Novaka",
|
||||||
|
deepAttachments=files_struct
|
||||||
|
)
|
||||||
|
|
||||||
|
print("MessageID:", msg_id)
|
||||||
|
|
||||||
|
# Chvíle čekání
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
# Stažení přijatých zpráv v intervalu
|
||||||
|
records = client.service.GetListOfReceivedMessages(
|
||||||
|
startTime="2009-11-01T00:00:00",
|
||||||
|
endTime="2010-10-01T00:00:00",
|
||||||
|
recNo=0,
|
||||||
|
maxRec=100,
|
||||||
|
recordType=1023,
|
||||||
|
customFilter=None
|
||||||
|
)
|
||||||
|
|
||||||
|
for rec in records.dmRecord:
|
||||||
|
print(f"ID zasilky: {rec.dmID}, odesilatel: {rec.dmSender}")
|
||||||
|
received_id = rec.dmID
|
||||||
|
break
|
||||||
|
|
||||||
|
# Stažení jedné zprávy
|
||||||
|
msg = client.service.MessageDownload(received_id)
|
||||||
|
print("Stažená zpráva:", msg.dmDm.dmID)
|
||||||
|
|
||||||
|
# Uložení souborů
|
||||||
|
for file in msg.dmDm.dmFiles.dmFile:
|
||||||
|
content = base64.b64decode(file.dmEncodedContent)
|
||||||
|
path = os.path.join(out_dir, file.dmFileDescr)
|
||||||
|
with open(path, 'wb') as f:
|
||||||
|
f.write(content)
|
||||||
|
print("Uloženo:", path)
|
||||||
|
|
||||||
|
# Označení jako stáhnuto
|
||||||
|
client.service.MarkMessageAsDownloaded(received_id)
|
||||||
|
print("Označeno jako přečtené")
|
||||||
|
|
||||||
|
# Můžeme pokračovat implementací dalších funkcí: GetDeliveryInfo, SignedMessageDownloadToFile, GetListOfSentMessages, FindDataBox, CheckDataBox…
|
||||||
276
Davka001.py
Normal file
276
Davka001.py
Normal file
@@ -0,0 +1,276 @@
|
|||||||
|
import os
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
hlav = namedtuple("Hlavicka", ["typ", "char", "dtyp", "dico",
|
||||||
|
"dpob", "drok", "dmes", "dcid", "dpoc", "dbody",
|
||||||
|
"dfin", "ddpp", "dvdr1", "dvdr2", "ddtyp"])
|
||||||
|
av=namedtuple("Aveta",["typ","hcid","hstr","hpoc","hpor","hcpo","htpp","hico","hvar","hodb","hrod","hzdg","hkon","hicz",
|
||||||
|
"hcdz","hrez","hccel","hcbod","dtyp"])
|
||||||
|
vv=namedtuple("Vveta",["typ","vdat","vkod","vpoc","vodb","vdia","vbod","vtyp"])
|
||||||
|
zv=namedtuple("Zveta",["typ","hcid","hstr","hpoc","hpor","hico","hvar","hodb","hrod","hzdg","hrez","hccel","htyp"])
|
||||||
|
lv=namedtuple("Lveta",["typ","ldat","ltpr","lzvl","lkod","lmno","lfin","lvdg","ltyp"])
|
||||||
|
def lveta(retezec):
|
||||||
|
TYP= retezec[0:1]
|
||||||
|
LDAT= retezec[1:9]
|
||||||
|
LTPR= retezec[9:10]
|
||||||
|
LZVL= retezec[10:11]
|
||||||
|
LKOD= retezec[11:18]
|
||||||
|
LMNO=retezec[18:29]
|
||||||
|
LFIN= retezec[29:39]
|
||||||
|
LVDG= retezec[39:44]
|
||||||
|
VTYP= retezec[44:45]
|
||||||
|
print(TYP, LDAT, LTPR, LZVL,LKOD,LMNO,LFIN,LVDG,VTYP)
|
||||||
|
Lveta = lv(TYP, LDAT, LTPR, LZVL,LKOD,LMNO,LFIN,LVDG,VTYP)
|
||||||
|
print(Lveta)
|
||||||
|
|
||||||
|
def vveta(retezec):
|
||||||
|
TYP= retezec[0:1]
|
||||||
|
VDAT= retezec[1:9]
|
||||||
|
VKOD= retezec[9:14]
|
||||||
|
VPOC= retezec[14:15]
|
||||||
|
VODB=retezec[15:18]
|
||||||
|
VDIA= retezec[18:23]
|
||||||
|
VBOD= retezec[23:30]
|
||||||
|
VTYP= retezec[30:31]
|
||||||
|
print(TYP, VDAT, VKOD, VPOC,VODB,VDIA,VBOD,VTYP)
|
||||||
|
Vveta = vv(TYP, VDAT, VKOD, VPOC,VODB,VDIA,VBOD,VTYP)
|
||||||
|
print(Vveta)
|
||||||
|
|
||||||
|
def zveta(retezec):
|
||||||
|
TYP= retezec[0:1]
|
||||||
|
HCID= retezec[1:8]
|
||||||
|
HSTR= retezec[8:9]
|
||||||
|
HPOC= retezec[9:10]
|
||||||
|
HPOR= retezec[10:13]
|
||||||
|
HICO= retezec[13:21]
|
||||||
|
HVAR= retezec[21:27]
|
||||||
|
HODB= retezec[27:30]
|
||||||
|
HROD= retezec[30:40]
|
||||||
|
HZDG= retezec[40:45]
|
||||||
|
HREZ= retezec[45:55]
|
||||||
|
HCCEL= retezec[55:66]
|
||||||
|
DTYP= retezec[66:67]
|
||||||
|
print(TYP, HCID, HSTR, HPOC,HPOR,HICO,HVAR,HODB,HROD,HZDG,HREZ,HCCEL,DTYP )
|
||||||
|
Zveta = zv(TYP, HCID, HSTR, HPOC,HPOR,HICO,HVAR,HODB,HROD,HZDG,HREZ,HCCEL,DTYP )
|
||||||
|
print(Zveta)
|
||||||
|
|
||||||
|
def prvniradek(retezec):
|
||||||
|
TYP = retezec[0:1] # Typ věty „D“ – úvodní věta dávky
|
||||||
|
CHAR = retezec[1:2] # Charakter dávky (viz dále ) – určuje stav předkládaných dokladů v dávce
|
||||||
|
DTYP = retezec[2:4] # typ dávky, číselný kód
|
||||||
|
DICO = retezec[4:12] # IPZ
|
||||||
|
DPOB = retezec[12:16] # kod oblastního pracoviště pojišťovny
|
||||||
|
DROK = retezec[16:20] # rok
|
||||||
|
DMES = retezec[20:22] # měsíc
|
||||||
|
DCID = retezec[22:28] # Číslo dávky – jednoznačné číslo dávky v rámci PZS a roku
|
||||||
|
DPOC = retezec[28:31] # počet dokladů v dávce, slouží k ověření kompletnosti
|
||||||
|
DBODY = retezec[31:42] # nepovinné, počet bodů
|
||||||
|
DFIN = float(retezec[42:60]) # nepovinné, celková částka za doklady
|
||||||
|
DDPP = retezec[60:61] # druh pojistného plnění
|
||||||
|
DVDR1 = retezec[61:74]
|
||||||
|
DVDR2 = retezec[74:87]
|
||||||
|
DDTYP = retezec[87:88]
|
||||||
|
print(TYP, CHAR, DTYP, DICO, DPOB, DROK, DMES, DCID, DPOC, DBODY, DFIN, DDPP, DVDR1,DVDR2,DDTYP)
|
||||||
|
hlavicka=hlav(TYP, CHAR, DTYP, DICO, DPOB, DROK, DMES, DCID, DPOC, DBODY, DFIN, DDPP, DVDR1,DVDR2,DDTYP)
|
||||||
|
print(hlavicka.dvdr1)
|
||||||
|
|
||||||
|
def aveta(retezec):
|
||||||
|
TYP= retezec[0:1]
|
||||||
|
HCID= retezec[1:8]
|
||||||
|
HSTR= retezec[8:9]
|
||||||
|
HPOC= retezec[9:10]
|
||||||
|
HPOR= retezec[10:13]
|
||||||
|
HCPO= retezec[13:16]
|
||||||
|
HTPP= retezec[16:17]
|
||||||
|
HICO= retezec[17:25]
|
||||||
|
HVAR= retezec[25:31]
|
||||||
|
HODB= retezec[31:34]
|
||||||
|
HROD= retezec[34:44]
|
||||||
|
HZDG= retezec[44:49]
|
||||||
|
HKON= retezec[49:50]
|
||||||
|
HICZ= retezec[50:58]
|
||||||
|
HCDZ= retezec[58:65]
|
||||||
|
HREZ= retezec[65:75]
|
||||||
|
HCCEL= retezec[75:85]
|
||||||
|
HCBOD= retezec[85:92]
|
||||||
|
DTYP= retezec[92:93]
|
||||||
|
print(TYP, HCID, HSTR, HPOC,HPOR,HCPO,HTPP,HICO,HVAR,HODB,HROD,HZDG,HKON,HICZ,HCDZ,HREZ,HCCEL,HCBOD,DTYP )
|
||||||
|
Aveta = av(TYP, HCID, HSTR, HPOC,HPOR,HCPO,HTPP,HICO,HVAR,HODB,HROD,HZDG,HKON,HICZ,HCDZ,HREZ,HCCEL,HCBOD,DTYP)
|
||||||
|
print(Aveta)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
konec=0
|
||||||
|
# with open(r"u:\Dropbox\!!!Days\Downloads Z230\Dávky\DataKDavka (6).111","r",encoding='cp852') as f:
|
||||||
|
# for importradku in f.readlines():
|
||||||
|
# if importradku[0]=="D":
|
||||||
|
# print(importradku)
|
||||||
|
# prvniradek(importradku)
|
||||||
|
# if importradku[0]=="A":
|
||||||
|
# konec=0
|
||||||
|
# print(importradku)
|
||||||
|
# aveta(importradku)
|
||||||
|
# if importradku[0] == "V":
|
||||||
|
# print(importradku)
|
||||||
|
# vveta(importradku)
|
||||||
|
# if importradku[0]=="Z":
|
||||||
|
# print(importradku)
|
||||||
|
# zveta(importradku)
|
||||||
|
# if importradku[0] == "L":
|
||||||
|
# konec = 1
|
||||||
|
# print(importradku)
|
||||||
|
# lveta(importradku)
|
||||||
|
# if konec==2:
|
||||||
|
# exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
#010 Projdi vsechny davky
|
||||||
|
|
||||||
|
root_davky_dir=r"u:\Dropbox\!!!Days\Downloads Z230\Dávky\Data"
|
||||||
|
#010.0 os.walk
|
||||||
|
# for root, folders, files in os.walk(root_davky_dir):
|
||||||
|
# for file in files:
|
||||||
|
# print(file)
|
||||||
|
|
||||||
|
#010.1 pathlib
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# # all txt files in current dir
|
||||||
|
# for p in Path(".").glob("*.txt"):
|
||||||
|
# print(p)
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from decimal import Decimal, InvalidOperation
|
||||||
|
import re
|
||||||
|
|
||||||
|
# ---- header spec (0-based) ----
|
||||||
|
# name, type, length, start, description (optional)
|
||||||
|
HEADER_SPEC = [
|
||||||
|
("TYP", "C", 1, 0, "Typ věty (má být 'D')"),
|
||||||
|
("CHAR", "C", 1, 1, "Charakter dávky (např. 'P')"),
|
||||||
|
("DTYP", "C", 2, 2, "Typ dávky (např. '98')"),
|
||||||
|
("DICO", "C", 8, 4, "IČZ PZS"),
|
||||||
|
("DPOB", "C", 4, 12, "Územní pracoviště"),
|
||||||
|
("DROK", "N", 4, 16, "Rok uzavření dokladů"),
|
||||||
|
("DMES", "N", 2, 20, "Měsíc uzavření dokladů"),
|
||||||
|
("DCID", "N", 6, 22, "Číslo dávky"),
|
||||||
|
("DPOC", "N", 3, 28, "Počet dokladů"),
|
||||||
|
("DBODY", "N", 11, 31, "Počet bodů v dávce (volitelné)"),
|
||||||
|
("DFIN", "$", 18, 42, "Celkem Kč (18.2, volitelné)"),
|
||||||
|
("DDPP", "C", 1, 60, "Druh pojistného vztahu"),
|
||||||
|
("DVDR1", "C", 13, 61, "Verze DR 1"),
|
||||||
|
("DVDR2", "C", 13, 74, "Verze DR 2"),
|
||||||
|
("DDTYP", "C", 1, 87, "Doplněk typu věty"),
|
||||||
|
]
|
||||||
|
|
||||||
|
def _slice0(s: str, start: int, length: int) -> str:
|
||||||
|
"""0-based safe slice."""
|
||||||
|
if s is None: return ""
|
||||||
|
return s[start:start+length] if start < len(s) else ""
|
||||||
|
|
||||||
|
def _parse_char(s: str):
|
||||||
|
s = (s or "").strip()
|
||||||
|
return s or None
|
||||||
|
|
||||||
|
def _parse_int(s: str):
|
||||||
|
if s is None: return None
|
||||||
|
digits = re.sub(r"\D", "", s)
|
||||||
|
return int(digits) if digits else None
|
||||||
|
|
||||||
|
def _parse_money(s: str):
|
||||||
|
"""Parse money field '18.2': spaces allowed, comma or dot; returns Decimal or None."""
|
||||||
|
if s is None: return None
|
||||||
|
s = s.replace("\u00A0", " ").strip().replace(" ", "").replace(",", ".")
|
||||||
|
if not s: return None
|
||||||
|
try:
|
||||||
|
# keep precision with Decimal
|
||||||
|
val = Decimal(s)
|
||||||
|
# optional: round to 2 decimal places
|
||||||
|
return val.quantize(Decimal("0.01"))
|
||||||
|
except (InvalidOperation, ValueError):
|
||||||
|
return None
|
||||||
|
|
||||||
|
def parse_davka_header_line(line: str, strict=True) -> dict:
|
||||||
|
"""
|
||||||
|
Parse header (first line) of a dávka according to HEADER_SPEC (0-based).
|
||||||
|
Returns dict with typed values. Raises if not a 'DP98' header (strict=True).
|
||||||
|
"""
|
||||||
|
if not line:
|
||||||
|
raise ValueError("Empty header line.")
|
||||||
|
if strict and not line.startswith("DP98"):
|
||||||
|
raise ValueError(f"Invalid header prefix {line[:4]!r}; expected 'DP98'.")
|
||||||
|
|
||||||
|
out = {"raw": line}
|
||||||
|
# field parsing per spec
|
||||||
|
for name, typ, length, start, *_ in HEADER_SPEC:
|
||||||
|
raw_val = _slice0(line, start, length)
|
||||||
|
if typ == "C":
|
||||||
|
out[name] = _parse_char(raw_val)
|
||||||
|
elif typ == "N":
|
||||||
|
out[name] = _parse_int(raw_val)
|
||||||
|
elif typ == "$":
|
||||||
|
out[name] = _parse_money(raw_val)
|
||||||
|
else:
|
||||||
|
out[name] = raw_val # fallback
|
||||||
|
|
||||||
|
# basic validations (soft)
|
||||||
|
if strict:
|
||||||
|
if out.get("TYP") != "D":
|
||||||
|
raise ValueError(f"TYP must be 'D', got {out.get('TYP')!r}")
|
||||||
|
if out.get("DTYP") != "98":
|
||||||
|
raise ValueError(f"DTYP must be '98', got {out.get('DTYP')!r}")
|
||||||
|
|
||||||
|
# Optional month sanity check (accepts '01'..'12' and '00')
|
||||||
|
m = out.get("DMES")
|
||||||
|
if m is not None and m not in range(0, 13): # 0..12
|
||||||
|
# keep value but you could raise or log here
|
||||||
|
pass
|
||||||
|
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# recursive
|
||||||
|
exts=("111","201","205","207","209","211")
|
||||||
|
keep={}
|
||||||
|
for soubor in Path(root_davky_dir).rglob("KDAVKA.*"):
|
||||||
|
if not soubor.is_file():
|
||||||
|
print(f"{soubor} neni platny soubor")
|
||||||
|
continue
|
||||||
|
if soubor.suffix.lstrip(".") not in exts:
|
||||||
|
print(f"{soubor} nema platnou koncovku")
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
with soubor.open("r",encoding="cp1250",errors="strict",newline="") as f:
|
||||||
|
if f.read(4)=="DP98": #takovy soubor chceme brat v potaz
|
||||||
|
keep[str(soubor)]={"File":soubor}
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
print(keep)
|
||||||
|
|
||||||
|
|
||||||
|
#020 Read headers of davky in keep
|
||||||
|
for soubor in keep: #
|
||||||
|
|
||||||
|
|
||||||
|
# def get_kdavka(root_dir, exts=("111","201","205","207","209","211")):
|
||||||
|
# root = Path(root_dir)
|
||||||
|
# wanted = {e.upper() for e in exts}
|
||||||
|
# keep = []
|
||||||
|
# for p in root.rglob("KDAVKA.*"):
|
||||||
|
# if not p.is_file():
|
||||||
|
# continue
|
||||||
|
# if p.suffix.lstrip(".").upper() not in wanted:
|
||||||
|
# continue
|
||||||
|
# try:
|
||||||
|
# with p.open("r", encoding="cp1250", errors="strict", newline="") as f:
|
||||||
|
# if f.read(4) == "DP98": # read just 4 chars, cp1250 is single-byte
|
||||||
|
# keep.append(p)
|
||||||
|
# except UnicodeDecodeError:
|
||||||
|
# # bad file — skip
|
||||||
|
# continue
|
||||||
|
# keep.sort()
|
||||||
|
# print(f"{len(keep)} davky (DP98) found under {root}")
|
||||||
|
# return keep
|
||||||
85
FIO1.py
Normal file
85
FIO1.py
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
import json
|
||||||
|
from datetime import datetime
|
||||||
|
import os
|
||||||
|
import pyodbc
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
|
||||||
|
# Path to your Access database
|
||||||
|
db_path = r"u:\Dropbox\!!!Days\Downloads Z230\Access\Banka.accdb"
|
||||||
|
# Connection string
|
||||||
|
conn_str = (
|
||||||
|
r"DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};"
|
||||||
|
rf"DBQ={db_path};"
|
||||||
|
)
|
||||||
|
# Connect to database
|
||||||
|
conn = pyodbc.connect(conn_str)
|
||||||
|
|
||||||
|
# Create cursor
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute("delete from transactions")
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Load from file, načtení bankovních pohybů
|
||||||
|
with open(r"u:\Dropbox\!!!Days\Downloads Z230\Fio\pohyby.json", "r", encoding="utf-8") as f:
|
||||||
|
transactions = json.load(f)
|
||||||
|
# print(transactions["accountStatement"]["transactionList"])
|
||||||
|
# Process
|
||||||
|
for tx in transactions["accountStatement"]["transactionList"]["transaction"]:
|
||||||
|
#ID pohybu
|
||||||
|
idpohybu=str(tx["column22"]["value"])
|
||||||
|
datum=tx["column0"]["value"]
|
||||||
|
|
||||||
|
#Datum transakce
|
||||||
|
datum = datetime.strptime(datum, "%Y-%m-%d%z")
|
||||||
|
datum = datum.date()
|
||||||
|
|
||||||
|
#Částka
|
||||||
|
objem = int(tx["column1"]["value"])
|
||||||
|
|
||||||
|
#Měna
|
||||||
|
mena = tx["column14"]["value"]
|
||||||
|
|
||||||
|
#Název protiúčtu
|
||||||
|
nazevprotiuctu=tx["column10"]["value"]
|
||||||
|
|
||||||
|
#Typ transakce
|
||||||
|
typ = tx["column8"]["value"]
|
||||||
|
|
||||||
|
#Konstantní symbol
|
||||||
|
if tx["column4"] is not None:
|
||||||
|
kss=tx["column4"]["value"]
|
||||||
|
else:
|
||||||
|
kss=""
|
||||||
|
|
||||||
|
# Provedl
|
||||||
|
if tx["column9"] is not None:
|
||||||
|
provedl = tx["column9"]["value"]
|
||||||
|
else:
|
||||||
|
provedl = ""
|
||||||
|
|
||||||
|
# ID pokynu
|
||||||
|
if tx["column17"] is not None:
|
||||||
|
idpokynu = str(tx["column17"]["value"])
|
||||||
|
else:
|
||||||
|
idpokynu = ""
|
||||||
|
|
||||||
|
|
||||||
|
# print (idpohybu,datum,objem,mena,nazevprotiuctu,typ,kss,provedl,idpokynu)
|
||||||
|
# if idpohybu=="3016989040":
|
||||||
|
# # Uložení do Accessu, jestli ještě neexistuje")
|
||||||
|
# cursor.execute("insert into transactions (idpohybu, datum) values (?,?)", (idpohybu, datum))
|
||||||
|
# conn.commit()
|
||||||
|
# print("committed")
|
||||||
|
|
||||||
|
print (idpohybu,datum,objem,mena,nazevprotiuctu,typ,kss,provedl,idpokynu)
|
||||||
|
print(type(idpohybu))
|
||||||
|
# Uložení do Accessu, jestli ještě neexistuje")
|
||||||
|
cursor.execute("insert into transactions (idpohybu, datum,objem,mena,nazevprotiuctu,ks,typ,provedl,idpokynu) values (?,?,?,?,?,?,?,?,?)",
|
||||||
|
(idpohybu, datum,objem, mena, nazevprotiuctu,kss,typ,provedl,idpokynu))
|
||||||
|
# cursor.execute("insert into transactions (idpohybu) values (?)", (idpohybu))
|
||||||
|
conn.commit()
|
||||||
|
print("committed")
|
||||||
78
Kontakty01.py
Normal file
78
Kontakty01.py
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import firebirdsql,re
|
||||||
|
|
||||||
|
def get_connection():
|
||||||
|
return firebirdsql.connect(
|
||||||
|
host="192.168.1.4",
|
||||||
|
port=3050,
|
||||||
|
database=r"z:\medicus 3\data\medicus.fdb", # path must be valid on the server
|
||||||
|
user="SYSDBA",
|
||||||
|
password="masterkey",
|
||||||
|
charset="WIN1250",
|
||||||
|
)
|
||||||
|
def get_registrovani(cur): #vrati list rodnych cisel registrovanych pacientu "registrovani"
|
||||||
|
cur.execute("""
|
||||||
|
select rodcis from registr join kar
|
||||||
|
on registr.idpac=kar.idpac where
|
||||||
|
kar.vyrazen!='A' and
|
||||||
|
kar.rodcis is not null and
|
||||||
|
idicp!=0 and
|
||||||
|
datum_zruseni is null
|
||||||
|
""")
|
||||||
|
registrovani=[]
|
||||||
|
for radek in cur.fetchall():
|
||||||
|
registrovani.append(radek[0])
|
||||||
|
return registrovani
|
||||||
|
|
||||||
|
def je_registrovany(con,rodcis):
|
||||||
|
cur=conn.cursor()
|
||||||
|
cur.execute("""
|
||||||
|
select 1 from registr join kar
|
||||||
|
on registr.idpac=kar.idpac where
|
||||||
|
kar.vyrazen!='A' and
|
||||||
|
kar.rodcis is not null and
|
||||||
|
idicp!=0 and
|
||||||
|
datum_zruseni is null
|
||||||
|
and rodcis=%s
|
||||||
|
limit 1
|
||||||
|
""")
|
||||||
|
cur.execute(sql, (rodcis,))
|
||||||
|
return cur.fetchone() is not None
|
||||||
|
|
||||||
|
def strip_cz_prefix(num: str) -> str:
|
||||||
|
# remove spaces and non-digits first
|
||||||
|
n = re.sub(r"\D", "", num)
|
||||||
|
|
||||||
|
# strip +420, 00420 or 420 at start
|
||||||
|
if n.startswith("00420"):
|
||||||
|
return n[5:]
|
||||||
|
elif n.startswith("420"):
|
||||||
|
return n[3:]
|
||||||
|
else:
|
||||||
|
return n
|
||||||
|
|
||||||
|
def is_cz_mobile(num: str) -> bool:
|
||||||
|
nmbr=strip_cz_prefix(num)
|
||||||
|
MOBILE_PREFIXES = ("60", "72", "73", "77", "79")
|
||||||
|
# now check length and prefix
|
||||||
|
return len(nmbr) == 9 and nmbr[:2] in MOBILE_PREFIXES
|
||||||
|
|
||||||
|
def get_mobile(rodcis,conn):
|
||||||
|
sql = f"""
|
||||||
|
SELECT kar.prijmeni, kar.rodcis,
|
||||||
|
karkontakt.poradi, karkontakt.kontakt
|
||||||
|
FROM karkontakt join kar on kar.idpac=karkontakt.idpac
|
||||||
|
where kar.rodcis={rodcis}
|
||||||
|
"""
|
||||||
|
cur=conn.cursor()
|
||||||
|
mobil={}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
conn = get_connection()
|
||||||
|
cur = conn.cursor()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# print(get_mobile("340415112",conn))
|
||||||
|
print(is_cz_mobile("283893084"))
|
||||||
58
PDF - doplnění jména.py
Normal file
58
PDF - doplnění jména.py
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import os,re,fdb,time
|
||||||
|
import logging
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
|
def set_single_page_view (filepdfin):
|
||||||
|
from pikepdf import Pdf, Dictionary, Name
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
pdf=Pdf.open(filepdfin,allow_overwriting_input=True)
|
||||||
|
# file_only_path=os.path.dirname(filepdfin)
|
||||||
|
# file_without_ext = Path(filepdfin).stem
|
||||||
|
pdf.Root.PageLayout=Name('/SinglePage')
|
||||||
|
pdf.Root.PageMode=Name('/UseNone')
|
||||||
|
pdf.save()
|
||||||
|
|
||||||
|
|
||||||
|
# Connect to the Firebird database
|
||||||
|
conn = fdb.connect(
|
||||||
|
dsn=r'localhost:u:\medicus 3\data\medicus.fdb', # Database path
|
||||||
|
user='SYSDBA', # Username
|
||||||
|
password="masterkey", # Password,
|
||||||
|
charset="win1250")
|
||||||
|
# cur = conn.cursor()
|
||||||
|
|
||||||
|
cesta=r"u:\dropbox\ordinace\Dokumentace_ke_zpracování"
|
||||||
|
|
||||||
|
for file in os.listdir(cesta):
|
||||||
|
if file.upper().endswith((".PDF")) and os.path.isfile(os.path.join(cesta,file)):
|
||||||
|
pattern=r"(\d{9,10}) ((?:(?:19|20)\d\d)-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])) (\[.*)"
|
||||||
|
nalezeno=re.search(pattern,file)
|
||||||
|
if nalezeno:
|
||||||
|
print(nalezeno.groups())
|
||||||
|
x=nalezeno.groups()
|
||||||
|
rodcis=nalezeno.group(1)
|
||||||
|
datum=nalezeno.group(2)
|
||||||
|
konec=nalezeno.group(5)
|
||||||
|
print(datum)
|
||||||
|
print(konec)
|
||||||
|
print(rodcis,type(rodcis))
|
||||||
|
cur = conn.cursor()
|
||||||
|
cur.execute("select prijmeni, jmeno from kar where rodcis=?",(rodcis,))
|
||||||
|
x = cur.fetchone()
|
||||||
|
if x:
|
||||||
|
if len(x[0].split(" "))==1:
|
||||||
|
prijmeni=x[0]
|
||||||
|
else:
|
||||||
|
prijmeni=x[0].split(" ")[0]
|
||||||
|
if len(x[1].split(" "))==1:
|
||||||
|
jmeno=x[1]
|
||||||
|
else:
|
||||||
|
prijmeni=x[1].split(" ")[0]
|
||||||
|
konecsouboru=file.split(rodcis)[1]
|
||||||
|
novejmeno=rodcis+" "+datum+" "+prijmeni.strip()+", "+jmeno.strip()+" "+konec
|
||||||
|
print(novejmeno)
|
||||||
|
os.rename(os.path.join(cesta,file),os.path.join(cesta,novejmeno))
|
||||||
|
cur.close()
|
||||||
|
|
||||||
22
PDFmanipulation (2).py
Normal file
22
PDFmanipulation (2).py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import os,re
|
||||||
|
|
||||||
|
|
||||||
|
def set_single_page_view (filepdfin):
|
||||||
|
from pikepdf import Pdf, Dictionary, Name
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
pdf=Pdf.open(filepdfin,allow_overwriting_input=True)
|
||||||
|
# file_only_path=os.path.dirname(filepdfin)
|
||||||
|
# file_without_ext = Path(filepdfin).stem
|
||||||
|
pdf.Root.PageLayout=Name('/SinglePage')
|
||||||
|
pdf.Root.PageMode=Name('/UseNone')
|
||||||
|
pdf.save()
|
||||||
|
|
||||||
|
|
||||||
|
# set_single_page_view(r"u:\Dropbox\!!!Days\Downloads Z230\Dokumentace\a.pdf")
|
||||||
|
|
||||||
|
cesta=r"u:\dropbox\ordinace\Dokumentace_ke_zpracování"
|
||||||
|
|
||||||
|
for file in os.listdir(cesta):
|
||||||
|
if file.upper().endswith((".PDF")) and os.path.isfile(os.path.join(cesta,file)):
|
||||||
|
set_single_page_view(os.path.join(cesta,file))
|
||||||
10
Pojistovna.py
Normal file
10
Pojistovna.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# client certificate (no private key)
|
||||||
|
certorig=r"u:\Dropbox\!!!Days\Downloads Z230\cert\MB komerční full do 2026-01-22.pfx"
|
||||||
|
certpem=r"u:\Dropbox\!!!Days\Downloads Z230\cert\client.pem"
|
||||||
|
|
||||||
|
openssl pkcs12 -in certorig -clcerts -nokeys -out certpem
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
361
Reporty01.py
Normal file
361
Reporty01.py
Normal file
@@ -0,0 +1,361 @@
|
|||||||
|
import os
|
||||||
|
import fdb
|
||||||
|
import csv,time,pandas as pd
|
||||||
|
import openpyxl
|
||||||
|
|
||||||
|
|
||||||
|
PathToSaveCSV=r"U:\Dropbox\Ordinace\Test"
|
||||||
|
timestr = time.strftime("%Y-%m-%d %H-%M-%S ")
|
||||||
|
CSVname="Pacienti.xlsx"
|
||||||
|
# PathToSaveCSV=r"//tower/tempspeed"
|
||||||
|
|
||||||
|
con = fdb.connect(
|
||||||
|
host='localhost', database=r'm:\MEDICUS\data\medicus.FDB',
|
||||||
|
user='sysdba', password='masterkey',charset='WIN1250')
|
||||||
|
|
||||||
|
# Create a Cursor object that operates in the context of Connection con:
|
||||||
|
cur = con.cursor()
|
||||||
|
|
||||||
|
# import openpyxl module
|
||||||
|
import openpyxl
|
||||||
|
import xlwings as xw
|
||||||
|
wb = openpyxl.Workbook()
|
||||||
|
sheet = wb.active
|
||||||
|
# wb.save("sample.xlsx")
|
||||||
|
|
||||||
|
|
||||||
|
#Načtení očkování registrovaných pacientů
|
||||||
|
cur.execute("select rodcis,prijmeni,jmeno,ockzaz.datum,kodmz,ockzaz.poznamka,latka,nazev,expire from registr join kar on registr.idpac=kar.idpac join ockzaz on registr.idpac=ockzaz.idpac where datum_zruseni is null and kar.vyrazen!='A' and kar.rodcis is not null and idicp!=0 order by ockzaz.datum desc")
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.title="Očkování"
|
||||||
|
sheet.append(["Rodne cislo","Prijmeni","Jmeno","Datum ockovani","Kod MZ","Sarze","Latka","Nazev","Expirace"])
|
||||||
|
#nacteno jsou ockovani
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#Načtení registrovaných pacientů
|
||||||
|
cur.execute("select rodcis,prijmeni,jmeno,datum_registrace,registr.idpac,poj from registr join kar on registr.idpac=kar.idpac where kar.vyrazen!='A' and kar.rodcis is not null and idicp!=0 and datum_zruseni is null")
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
wb.create_sheet('Registrovani',0)
|
||||||
|
sheet=wb['Registrovani']
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Prijmeni","Jmeno","Datum registrace","ID pacienta","Pojistovna"])
|
||||||
|
#nacteno jsou registrovani
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
|
||||||
|
#Načtení receptů
|
||||||
|
cur.execute("""select
|
||||||
|
kar.rodcis,
|
||||||
|
TRIM(kar.prijmeni) ||' '|| substring(kar.jmeno from 1 for 1) ||'.' as jmeno,
|
||||||
|
recept.datum,
|
||||||
|
TRIM(recept.lek) ||' '|| trim(recept.dop) as lek,
|
||||||
|
recept.expori AS Poc,
|
||||||
|
CASE
|
||||||
|
WHEN recept.opakovani is null THEN 1
|
||||||
|
ELSE recept.opakovani
|
||||||
|
END AS OP,
|
||||||
|
recept.uhrada,
|
||||||
|
recept.dsig,
|
||||||
|
recept.NOTIFIKACE_KONTAKT as notifikace,
|
||||||
|
recept_epodani.erp,
|
||||||
|
recept_epodani.vystavitel_jmeno,
|
||||||
|
recept.atc,
|
||||||
|
recept.CENAPOJ,
|
||||||
|
recept.cenapac
|
||||||
|
from recept LEFT Join RECEPT_EPODANI on recept.id_epodani=recept_epodani.id
|
||||||
|
LEFT join kar on recept.idpac=kar.idpac
|
||||||
|
order by datum desc,erp desc"""
|
||||||
|
)
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
wb.create_sheet('Recepty',0)
|
||||||
|
sheet=wb['Recepty']
|
||||||
|
|
||||||
|
sheet.title="Recepty"
|
||||||
|
sheet.append(["Rodné číslo","Jméno","Datum vystavení","Název leku","Poč.","Op.","Úhr.","Da signa","Notifikace","eRECEPT","Vystavil","ATC","Cena pojišťovna","Cena pacient"])
|
||||||
|
#nacteno jsou ockovani
|
||||||
|
for row in nacteno:
|
||||||
|
try:
|
||||||
|
sheet.append(row)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
#Načtení vykony vsech
|
||||||
|
cur.execute("select dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,dokladd.pocvyk,dokladd.ddgn,dokladd.body,vykony.naz "
|
||||||
|
"from kar join dokladd on kar.rodcis=dokladd.rodcis join vykony on dokladd.kod=vykony.kod where (datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null) order by dokladd.datose desc,dokladd.rodcis")
|
||||||
|
|
||||||
|
wb.create_sheet('Vykony',0)
|
||||||
|
sheet=wb['Vykony']
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum vykonu","Kod","Pocet","Dg.","Body","Nazev"])
|
||||||
|
#nacteno jsou ockovani
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
#Načtení neschopenek
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
def pocet_dni(zacnes,konnes,pracne):
|
||||||
|
dnes=datetime.date.today()
|
||||||
|
if pracne=='A':
|
||||||
|
return (dnes-zacnes).days
|
||||||
|
if pracne=='N' and zacnes is not None and konnes is not None and zacnes<=konnes:
|
||||||
|
return (konnes-zacnes).days
|
||||||
|
else:
|
||||||
|
return "NA"
|
||||||
|
|
||||||
|
cur.execute("select nes.idpac, "
|
||||||
|
"kar.rodcis, "
|
||||||
|
"TRIM(prijmeni) ||', '|| TRIM(jmeno), "
|
||||||
|
"nes.datnes, "
|
||||||
|
"nes.ecn, "
|
||||||
|
"nes.zacnes, "
|
||||||
|
"nes.pracne, "
|
||||||
|
"nes.konnes, "
|
||||||
|
"nes.diagno, "
|
||||||
|
"nes.kondia, "
|
||||||
|
"nes.updated "
|
||||||
|
"from nes "
|
||||||
|
"left join kar on nes.idpac=kar.idpac where nes.datnes<=current_date "
|
||||||
|
"order by datnes desc")
|
||||||
|
|
||||||
|
|
||||||
|
tmpnacteno_vse=[]
|
||||||
|
nacteno_vse=cur.fetchall()
|
||||||
|
|
||||||
|
cur.execute("select nes.idpac, "
|
||||||
|
"kar.rodcis, "
|
||||||
|
"TRIM(prijmeni) ||', '|| TRIM(jmeno), "
|
||||||
|
"nes.datnes, "
|
||||||
|
"nes.ecn, "
|
||||||
|
"nes.zacnes, "
|
||||||
|
"nes.pracne, "
|
||||||
|
"nes.konnes, "
|
||||||
|
"nes.diagno, "
|
||||||
|
"nes.kondia, "
|
||||||
|
"nes.updated "
|
||||||
|
"from nes "
|
||||||
|
"left join kar on nes.idpac=kar.idpac where nes.datnes<=current_date and pracne='A'"
|
||||||
|
"order by datnes desc")
|
||||||
|
|
||||||
|
tmpnacteno_aktivni=[]
|
||||||
|
nacteno_aktivni=cur.fetchall()
|
||||||
|
|
||||||
|
for row in nacteno_vse:
|
||||||
|
tmpnacteno_vse.append((row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],pocet_dni(row[5],row[7],row[6]),row[8],row[9],row[10]))
|
||||||
|
|
||||||
|
for row in nacteno_aktivni:
|
||||||
|
(tmpnacteno_aktivni.append((row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],pocet_dni(row[5],row[7],row[6]),row[8],row[9],row[10])))
|
||||||
|
|
||||||
|
wb.create_sheet('Neschopenky všechny',0)
|
||||||
|
sheet=wb["Neschopenky všechny"]
|
||||||
|
sheet.append(["ID pac","Rodne cislo","Jmeno","Datum neschopenky","Číslo neschopenky","Zacatek","Aktivní?","Konec","Pocet dni","Diagnoza zacatel","Diagnoza konec","Aktualizovano"])
|
||||||
|
for row in tmpnacteno_vse:
|
||||||
|
sheet.append(row)
|
||||||
|
|
||||||
|
wb.create_sheet('Neschopenky aktivní',0)
|
||||||
|
sheet=wb["Neschopenky aktivní"]
|
||||||
|
sheet.append(["ID pac","Rodne cislo","Jmeno","Datum neschopenky","Číslo neschopenky","Zacatek","Aktivní?","Konec","Pocet dni","Diagnoza zacatel","Diagnoza konec","Aktualizovano"])
|
||||||
|
for row in tmpnacteno_aktivni:
|
||||||
|
sheet.append(row)
|
||||||
|
|
||||||
|
#Načtení preventivni prohlidky
|
||||||
|
cur.execute("select all dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,vykony.naz,dokladd.ddgn,dokladd.body "
|
||||||
|
"from dokladd left join kar on dokladd.rodcis=kar.rodcis join vykony on dokladd.kod=vykony.kod where "
|
||||||
|
"((datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null)) and (dokladd.kod=1022 or dokladd.kod=1021) "
|
||||||
|
"order by datose desc")
|
||||||
|
|
||||||
|
wb.create_sheet('Preventivni prohlidky',0)
|
||||||
|
sheet=wb['Preventivni prohlidky']
|
||||||
|
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum","Kod","Název","Dg.","Body"])
|
||||||
|
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
#Nacteni INR
|
||||||
|
cur.execute("select all dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,vykony.naz,dokladd.ddgn,dokladd.body "
|
||||||
|
"from dokladd left join kar on dokladd.rodcis=kar.rodcis join vykony on dokladd.kod=vykony.kod where "
|
||||||
|
"((datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null)) and (dokladd.kod=01443) "
|
||||||
|
"order by datose desc")
|
||||||
|
|
||||||
|
wb.create_sheet('INR',0)
|
||||||
|
sheet=wb['INR']
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum","Kod","Název","Dg.","Body"])
|
||||||
|
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
#Nacteni CRP
|
||||||
|
cur.execute("select all dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,vykony.naz,dokladd.ddgn,dokladd.body "
|
||||||
|
"from dokladd left join kar on dokladd.rodcis=kar.rodcis join vykony on dokladd.kod=vykony.kod where "
|
||||||
|
"((datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null)) and (dokladd.kod=02230 or dokladd.kod=09111) "
|
||||||
|
"order by datose desc,dokladd.rodcis,dokladd.kod")
|
||||||
|
|
||||||
|
wb.create_sheet('CRP',0)
|
||||||
|
sheet=wb['CRP']
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum","Kod","Název","Dg.","Body"])
|
||||||
|
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
|
||||||
|
#Nacteni Holter
|
||||||
|
cur.execute("select all dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,vykony.naz,dokladd.ddgn,dokladd.body "
|
||||||
|
"from dokladd left join kar on dokladd.rodcis=kar.rodcis join vykony on dokladd.kod=vykony.kod where "
|
||||||
|
"((datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null)) and (dokladd.kod=17129) "
|
||||||
|
"order by datose desc,dokladd.rodcis,dokladd.kod")
|
||||||
|
|
||||||
|
wb.create_sheet('Holter',0)
|
||||||
|
sheet=wb['Holter']
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum","Kod","Název","Dg.","Body"])
|
||||||
|
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
#Nacteni prostata
|
||||||
|
cur.execute("select all dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,vykony.naz,dokladd.ddgn,dokladd.body "
|
||||||
|
"from dokladd left join kar on dokladd.rodcis=kar.rodcis join vykony on dokladd.kod=vykony.kod where "
|
||||||
|
"((datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null)) and (dokladd.kod=01130 or dokladd.kod=01131 or dokladd.kod=01132 or dokladd.kod=01133 or dokladd.kod=01134) "
|
||||||
|
"order by datose desc,dokladd.rodcis,dokladd.kod")
|
||||||
|
|
||||||
|
wb.create_sheet('Prostata',0)
|
||||||
|
sheet=wb['Prostata']
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum","Kod","Název","Dg.","Body"])
|
||||||
|
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
#Nacteni TOKS
|
||||||
|
cur.execute("select all dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,vykony.naz,dokladd.ddgn,dokladd.body "
|
||||||
|
"from dokladd left join kar on dokladd.rodcis=kar.rodcis join vykony on dokladd.kod=vykony.kod where "
|
||||||
|
"((datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null)) and "
|
||||||
|
"(dokladd.kod=15118 or dokladd.kod=15119 or dokladd.kod=15120 or dokladd.kod=15121) "
|
||||||
|
"order by datose desc,dokladd.rodcis,dokladd.kod")
|
||||||
|
|
||||||
|
wb.create_sheet('TOKS',0)
|
||||||
|
sheet=wb['TOKS']
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum","Kod","Název","Dg.","Body"])
|
||||||
|
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
#Nacteni COVID
|
||||||
|
cur.execute("select all dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,vykony.naz,dokladd.ddgn,dokladd.body "
|
||||||
|
"from dokladd left join kar on dokladd.rodcis=kar.rodcis join vykony on dokladd.kod=vykony.kod where "
|
||||||
|
"((datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null)) and "
|
||||||
|
"(dokladd.kod=01306) "
|
||||||
|
"order by datose desc,dokladd.rodcis,dokladd.kod")
|
||||||
|
|
||||||
|
wb.create_sheet('COVID',0)
|
||||||
|
sheet=wb['COVID']
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum","Kod","Název","Dg.","Body"])
|
||||||
|
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
#Nacteni Streptest
|
||||||
|
cur.execute("select all dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,vykony.naz,dokladd.ddgn,dokladd.body "
|
||||||
|
"from dokladd left join kar on dokladd.rodcis=kar.rodcis join vykony on dokladd.kod=vykony.kod where "
|
||||||
|
"((datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null)) and "
|
||||||
|
"(dokladd.kod=02220) "
|
||||||
|
"order by datose desc,dokladd.rodcis,dokladd.kod")
|
||||||
|
|
||||||
|
wb.create_sheet('Streptest',0)
|
||||||
|
sheet=wb['Streptest']
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum","Kod","Název","Dg.","Body"])
|
||||||
|
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
|
||||||
|
|
||||||
|
# autofilter
|
||||||
|
for ws in wb.worksheets:
|
||||||
|
# Get the maximum number of rows and columns
|
||||||
|
max_row = ws.max_row
|
||||||
|
max_column = ws.max_column
|
||||||
|
ws.auto_filter.ref = f"A1:{openpyxl.utils.get_column_letter(max_column)}{max_row}"
|
||||||
|
# ws.auto_filter.ref = ws.dimensions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
|
||||||
|
# Tento modul je pouze na autofit jednotlivych sloupcu na vsech listech workbooku
|
||||||
|
file = os.path.join(PathToSaveCSV ,timestr+CSVname)
|
||||||
|
with xw.App(visible=False) as app:
|
||||||
|
wb = xw.Book(file)
|
||||||
|
for sheet in range(len(wb.sheets)):
|
||||||
|
ws = wb.sheets[sheet]
|
||||||
|
ws.autofit()
|
||||||
|
|
||||||
|
# centrování receptů
|
||||||
|
sheet = wb.sheets['Recepty']
|
||||||
|
for sloupec in ["C:C", "E:E", "F:F", "G:G", "I:I", "M:M", "N:N"]:
|
||||||
|
sheet.range(sloupec).api.HorizontalAlignment = 3 # 3 = Center
|
||||||
|
|
||||||
|
|
||||||
|
wb.save()
|
||||||
|
wb.close()
|
||||||
|
|
||||||
|
|
||||||
346
Reporty02.py
Normal file
346
Reporty02.py
Normal file
@@ -0,0 +1,346 @@
|
|||||||
|
import os
|
||||||
|
import fdb
|
||||||
|
import csv,time,pandas as pd
|
||||||
|
import openpyxl
|
||||||
|
|
||||||
|
|
||||||
|
PathToSaveCSV=r"U:\Dropbox\Ordinace\Test"
|
||||||
|
timestr = time.strftime("%Y-%m-%d %H-%M-%S ")
|
||||||
|
CSVname="Pacienti.xlsx"
|
||||||
|
# PathToSaveCSV=r"//tower/tempspeed"
|
||||||
|
|
||||||
|
con = fdb.connect(
|
||||||
|
host='localhost', database=r'm:\MEDICUS\data\medicus.FDB',
|
||||||
|
user='sysdba', password='masterkey',charset='WIN1250')
|
||||||
|
|
||||||
|
# Create a Cursor object that operates in the context of Connection con:
|
||||||
|
cur = con.cursor()
|
||||||
|
|
||||||
|
# import openpyxl module
|
||||||
|
import openpyxl
|
||||||
|
import xlwings as xw
|
||||||
|
wb = openpyxl.Workbook()
|
||||||
|
sheet = wb.active
|
||||||
|
# wb.save("sample.xlsx")
|
||||||
|
|
||||||
|
|
||||||
|
#Načtení registrovaných pacientů
|
||||||
|
cur.execute("select rodcis,prijmeni,jmeno,datum_registrace,registr.idpac,poj from registr join kar on registr.idpac=kar.idpac where kar.vyrazen!='A' and kar.rodcis is not null and idicp!=0 and datum_zruseni is null")
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
wb.create_sheet('Registrovani',0)
|
||||||
|
sheet=wb['Registrovani']
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Prijmeni","Jmeno","Datum registrace","ID pacienta","Pojistovna"])
|
||||||
|
#nacteno jsou registrovani
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
|
||||||
|
#Načtení receptů
|
||||||
|
cur.execute("""select
|
||||||
|
kar.rodcis,
|
||||||
|
TRIM(kar.prijmeni) ||' '|| substring(kar.jmeno from 1 for 1) ||'.' as jmeno,
|
||||||
|
recept.datum,
|
||||||
|
TRIM(recept.lek) ||' '|| trim(recept.dop) as lek,
|
||||||
|
recept.expori AS Poc,
|
||||||
|
CASE
|
||||||
|
WHEN recept.opakovani is null THEN 1
|
||||||
|
ELSE recept.opakovani
|
||||||
|
END AS OP,
|
||||||
|
recept.uhrada,
|
||||||
|
recept.dsig,
|
||||||
|
recept.NOTIFIKACE_KONTAKT as notifikace,
|
||||||
|
recept_epodani.erp,
|
||||||
|
recept_epodani.vystavitel_jmeno,
|
||||||
|
recept.atc,
|
||||||
|
recept.CENAPOJ,
|
||||||
|
recept.cenapac
|
||||||
|
from recept LEFT Join RECEPT_EPODANI on recept.id_epodani=recept_epodani.id
|
||||||
|
LEFT join kar on recept.idpac=kar.idpac
|
||||||
|
order by datum desc,erp desc"""
|
||||||
|
)
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
wb.create_sheet('Recepty',0)
|
||||||
|
sheet=wb['Recepty']
|
||||||
|
|
||||||
|
sheet.title="Recepty"
|
||||||
|
sheet.append(["Rodné číslo","Jméno","Datum vystavení","Název leku","Poč.","Op.","Úhr.","Da signa","Notifikace","eRECEPT","Vystavil","ATC","Cena pojišťovna","Cena pacient"])
|
||||||
|
#nacteno jsou ockovani
|
||||||
|
for row in nacteno:
|
||||||
|
try:
|
||||||
|
sheet.append(row)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
#Načtení vykony vsech
|
||||||
|
cur.execute("select dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,dokladd.pocvyk,dokladd.ddgn,dokladd.body,vykony.naz "
|
||||||
|
"from kar join dokladd on kar.rodcis=dokladd.rodcis join vykony on dokladd.kod=vykony.kod where (datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null) order by dokladd.datose desc,dokladd.rodcis")
|
||||||
|
|
||||||
|
wb.create_sheet('Vykony',0)
|
||||||
|
sheet=wb['Vykony']
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum vykonu","Kod","Pocet","Dg.","Body","Nazev"])
|
||||||
|
#nacteno jsou ockovani
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
#Načtení neschopenek
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
def pocet_dni(zacnes,konnes,pracne):
|
||||||
|
dnes=datetime.date.today()
|
||||||
|
if pracne=='A':
|
||||||
|
return (dnes-zacnes).days
|
||||||
|
if pracne=='N' and zacnes is not None and konnes is not None and zacnes<=konnes:
|
||||||
|
return (konnes-zacnes).days
|
||||||
|
else:
|
||||||
|
return "NA"
|
||||||
|
|
||||||
|
cur.execute("select nes.idpac, "
|
||||||
|
"kar.rodcis, "
|
||||||
|
"TRIM(prijmeni) ||', '|| TRIM(jmeno), "
|
||||||
|
"nes.datnes, "
|
||||||
|
"nes.ecn, "
|
||||||
|
"nes.zacnes, "
|
||||||
|
"nes.pracne, "
|
||||||
|
"nes.konnes, "
|
||||||
|
"nes.diagno, "
|
||||||
|
"nes.kondia, "
|
||||||
|
"nes.updated "
|
||||||
|
"from nes "
|
||||||
|
"left join kar on nes.idpac=kar.idpac where nes.datnes<=current_date "
|
||||||
|
"order by datnes desc")
|
||||||
|
|
||||||
|
|
||||||
|
tmpnacteno_vse=[]
|
||||||
|
nacteno_vse=cur.fetchall()
|
||||||
|
|
||||||
|
cur.execute("select nes.idpac, "
|
||||||
|
"kar.rodcis, "
|
||||||
|
"TRIM(prijmeni) ||', '|| TRIM(jmeno), "
|
||||||
|
"nes.datnes, "
|
||||||
|
"nes.ecn, "
|
||||||
|
"nes.zacnes, "
|
||||||
|
"nes.pracne, "
|
||||||
|
"nes.konnes, "
|
||||||
|
"nes.diagno, "
|
||||||
|
"nes.kondia, "
|
||||||
|
"nes.updated "
|
||||||
|
"from nes "
|
||||||
|
"left join kar on nes.idpac=kar.idpac where nes.datnes<=current_date and pracne='A'"
|
||||||
|
"order by datnes desc")
|
||||||
|
|
||||||
|
tmpnacteno_aktivni=[]
|
||||||
|
nacteno_aktivni=cur.fetchall()
|
||||||
|
|
||||||
|
for row in nacteno_vse:
|
||||||
|
tmpnacteno_vse.append((row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],pocet_dni(row[5],row[7],row[6]),row[8],row[9],row[10]))
|
||||||
|
|
||||||
|
for row in nacteno_aktivni:
|
||||||
|
(tmpnacteno_aktivni.append((row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],pocet_dni(row[5],row[7],row[6]),row[8],row[9],row[10])))
|
||||||
|
|
||||||
|
wb.create_sheet('Neschopenky všechny',0)
|
||||||
|
sheet=wb["Neschopenky všechny"]
|
||||||
|
sheet.append(["ID pac","Rodne cislo","Jmeno","Datum neschopenky","Číslo neschopenky","Zacatek","Aktivní?","Konec","Pocet dni","Diagnoza zacatel","Diagnoza konec","Aktualizovano"])
|
||||||
|
for row in tmpnacteno_vse:
|
||||||
|
sheet.append(row)
|
||||||
|
|
||||||
|
wb.create_sheet('Neschopenky aktivní',0)
|
||||||
|
sheet=wb["Neschopenky aktivní"]
|
||||||
|
sheet.append(["ID pac","Rodne cislo","Jmeno","Datum neschopenky","Číslo neschopenky","Zacatek","Aktivní?","Konec","Pocet dni","Diagnoza zacatel","Diagnoza konec","Aktualizovano"])
|
||||||
|
for row in tmpnacteno_aktivni:
|
||||||
|
sheet.append(row)
|
||||||
|
|
||||||
|
#Načtení preventivni prohlidky
|
||||||
|
cur.execute("select all dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,vykony.naz,dokladd.ddgn,dokladd.body "
|
||||||
|
"from dokladd left join kar on dokladd.rodcis=kar.rodcis join vykony on dokladd.kod=vykony.kod where "
|
||||||
|
"((datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null)) and (dokladd.kod=1022 or dokladd.kod=1021) "
|
||||||
|
"order by datose desc")
|
||||||
|
|
||||||
|
wb.create_sheet('Preventivni prohlidky',0)
|
||||||
|
sheet=wb['Preventivni prohlidky']
|
||||||
|
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum","Kod","Název","Dg.","Body"])
|
||||||
|
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
#Nacteni INR
|
||||||
|
cur.execute("select all dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,vykony.naz,dokladd.ddgn,dokladd.body "
|
||||||
|
"from dokladd left join kar on dokladd.rodcis=kar.rodcis join vykony on dokladd.kod=vykony.kod where "
|
||||||
|
"((datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null)) and (dokladd.kod=01443) "
|
||||||
|
"order by datose desc")
|
||||||
|
|
||||||
|
wb.create_sheet('INR',0)
|
||||||
|
sheet=wb['INR']
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum","Kod","Název","Dg.","Body"])
|
||||||
|
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
#Nacteni CRP
|
||||||
|
cur.execute("select all dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,vykony.naz,dokladd.ddgn,dokladd.body "
|
||||||
|
"from dokladd left join kar on dokladd.rodcis=kar.rodcis join vykony on dokladd.kod=vykony.kod where "
|
||||||
|
"((datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null)) and (dokladd.kod=02230 or dokladd.kod=09111) "
|
||||||
|
"order by datose desc,dokladd.rodcis,dokladd.kod")
|
||||||
|
|
||||||
|
wb.create_sheet('CRP',0)
|
||||||
|
sheet=wb['CRP']
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum","Kod","Název","Dg.","Body"])
|
||||||
|
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
|
||||||
|
#Nacteni Holter
|
||||||
|
cur.execute("select all dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,vykony.naz,dokladd.ddgn,dokladd.body "
|
||||||
|
"from dokladd left join kar on dokladd.rodcis=kar.rodcis join vykony on dokladd.kod=vykony.kod where "
|
||||||
|
"((datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null)) and (dokladd.kod=17129) "
|
||||||
|
"order by datose desc,dokladd.rodcis,dokladd.kod")
|
||||||
|
|
||||||
|
wb.create_sheet('Holter',0)
|
||||||
|
sheet=wb['Holter']
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum","Kod","Název","Dg.","Body"])
|
||||||
|
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
#Nacteni prostata
|
||||||
|
cur.execute("select all dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,vykony.naz,dokladd.ddgn,dokladd.body "
|
||||||
|
"from dokladd left join kar on dokladd.rodcis=kar.rodcis join vykony on dokladd.kod=vykony.kod where "
|
||||||
|
"((datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null)) and (dokladd.kod=01130 or dokladd.kod=01131 or dokladd.kod=01132 or dokladd.kod=01133 or dokladd.kod=01134) "
|
||||||
|
"order by datose desc,dokladd.rodcis,dokladd.kod")
|
||||||
|
|
||||||
|
wb.create_sheet('Prostata',0)
|
||||||
|
sheet=wb['Prostata']
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum","Kod","Název","Dg.","Body"])
|
||||||
|
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
#Nacteni TOKS
|
||||||
|
cur.execute("select all dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,vykony.naz,dokladd.ddgn,dokladd.body "
|
||||||
|
"from dokladd left join kar on dokladd.rodcis=kar.rodcis join vykony on dokladd.kod=vykony.kod where "
|
||||||
|
"((datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null)) and "
|
||||||
|
"(dokladd.kod=15118 or dokladd.kod=15119 or dokladd.kod=15120 or dokladd.kod=15121) "
|
||||||
|
"order by datose desc,dokladd.rodcis,dokladd.kod")
|
||||||
|
|
||||||
|
wb.create_sheet('TOKS',0)
|
||||||
|
sheet=wb['TOKS']
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum","Kod","Název","Dg.","Body"])
|
||||||
|
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
#Nacteni COVID
|
||||||
|
cur.execute("select all dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,vykony.naz,dokladd.ddgn,dokladd.body "
|
||||||
|
"from dokladd left join kar on dokladd.rodcis=kar.rodcis join vykony on dokladd.kod=vykony.kod where "
|
||||||
|
"((datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null)) and "
|
||||||
|
"(dokladd.kod=01306) "
|
||||||
|
"order by datose desc,dokladd.rodcis,dokladd.kod")
|
||||||
|
|
||||||
|
wb.create_sheet('COVID',0)
|
||||||
|
sheet=wb['COVID']
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum","Kod","Název","Dg.","Body"])
|
||||||
|
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
#Nacteni Streptest
|
||||||
|
cur.execute("select all dokladd.rodcis,TRIM(prijmeni) ||', '|| TRIM(jmeno),dokladd.datose,dokladd.kod,vykony.naz,dokladd.ddgn,dokladd.body "
|
||||||
|
"from dokladd left join kar on dokladd.rodcis=kar.rodcis join vykony on dokladd.kod=vykony.kod where "
|
||||||
|
"((datose>=vykony.platiod and datose<=vykony.platido) OR (datose>=vykony.platiod and vykony.platido is null)) and "
|
||||||
|
"(dokladd.kod=02220) "
|
||||||
|
"order by datose desc,dokladd.rodcis,dokladd.kod")
|
||||||
|
|
||||||
|
wb.create_sheet('Streptest',0)
|
||||||
|
sheet=wb['Streptest']
|
||||||
|
|
||||||
|
nacteno=cur.fetchall()
|
||||||
|
print(len(nacteno))
|
||||||
|
|
||||||
|
sheet.append(["Rodne cislo","Jmeno","Datum","Kod","Název","Dg.","Body"])
|
||||||
|
|
||||||
|
for row in nacteno:
|
||||||
|
sheet.append(row)
|
||||||
|
|
||||||
|
|
||||||
|
# autofilter
|
||||||
|
for ws in wb.worksheets:
|
||||||
|
# Get the maximum number of rows and columns
|
||||||
|
max_row = ws.max_row
|
||||||
|
max_column = ws.max_column
|
||||||
|
ws.auto_filter.ref = f"A1:{openpyxl.utils.get_column_letter(max_column)}{max_row}"
|
||||||
|
# ws.auto_filter.ref = ws.dimensions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wb.save(os.path.join(PathToSaveCSV ,timestr+CSVname))
|
||||||
|
|
||||||
|
|
||||||
|
# Tento modul je pouze na autofit jednotlivych sloupcu na vsech listech workbooku
|
||||||
|
file = os.path.join(PathToSaveCSV ,timestr+CSVname)
|
||||||
|
with xw.App(visible=False) as app:
|
||||||
|
wb = xw.Book(file)
|
||||||
|
for sheet in range(len(wb.sheets)):
|
||||||
|
ws = wb.sheets[sheet]
|
||||||
|
ws.autofit()
|
||||||
|
|
||||||
|
# centrování receptů
|
||||||
|
sheet = wb.sheets['Recepty']
|
||||||
|
for sloupec in ["C:C", "E:E", "F:F", "G:G", "I:I", "M:M", "N:N"]:
|
||||||
|
sheet.range(sloupec).api.HorizontalAlignment = 3 # 3 = Center
|
||||||
|
|
||||||
|
|
||||||
|
wb.save()
|
||||||
|
wb.close()
|
||||||
|
|
||||||
|
|
||||||
17
SMSCallBackDebug.py
Normal file
17
SMSCallBackDebug.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
from flask import Flask, request
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.route("/diafaan-callback", methods=["GET", "POST"])
|
||||||
|
def diafaan_callback():
|
||||||
|
print("==== Callback received ====")
|
||||||
|
print("Method :", request.method)
|
||||||
|
print("Headers:", dict(request.headers))
|
||||||
|
print("Args :", request.args) # query string for GET
|
||||||
|
print("Form :", request.form) # form fields for POST
|
||||||
|
print("JSON :", request.get_json(silent=True))
|
||||||
|
print("==========================\n", flush=True)
|
||||||
|
return "OK" # must return 200 so Diafaan knows it succeeded
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# Install flask if needed: pip install flask
|
||||||
|
app.run(host="0.0.0.0", port=8088)
|
||||||
34
eRecept.py
Normal file
34
eRecept.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#test přístupu do eReceptu
|
||||||
|
# erecept_poc.py
|
||||||
|
import os
|
||||||
|
from requests import Session
|
||||||
|
from requests_pkcs12 import Pkcs12Adapter
|
||||||
|
from zeep import Client
|
||||||
|
from zeep.transports import Transport
|
||||||
|
|
||||||
|
PFX_FILE = "AMBSUKL214235369G_31DEC2024.pfx"
|
||||||
|
PFX_PASSWORD = os.getenv("Vlado7309208104++", "") # nebo zadejte přímo jako řetězec
|
||||||
|
# WSDL_URL = "https://<ERECEPT_ENDPOINT>/path?wsdl" # doplňte
|
||||||
|
WSDL_URL = "https://lekar-soap.erecept.sukl.cz/cuer/Lekar?wsdl" # doplňte
|
||||||
|
|
||||||
|
# Session s PFX (obstará klientskou autentizaci mTLS) https://lekar-soap.erecept.sukl.cz/cuer/Lekar?wsdl
|
||||||
|
sess = Session()
|
||||||
|
sess.mount("https://", Pkcs12Adapter(pkcs12_filename=PFX_FILE, pkcs12_password=PFX_PASSWORD))
|
||||||
|
|
||||||
|
# zeep klient s naší session
|
||||||
|
transport = Transport(session=sess, timeout=30)
|
||||||
|
client = Client(wsdl=WSDL_URL, transport=transport)
|
||||||
|
|
||||||
|
# Pro kontrolu: vylistuj dostupné služby a operace
|
||||||
|
for service in client.wsdl.services.values():
|
||||||
|
print(f"Service: {service.name}")
|
||||||
|
for port in service.ports.values():
|
||||||
|
ops = sorted(port.binding._operations.values(), key=lambda o: o.name)
|
||||||
|
print(f" Port: {port.name}")
|
||||||
|
for op in ops:
|
||||||
|
print(f" Operation: {op.name}")
|
||||||
|
|
||||||
|
# Příklad volání (názvy/parametry dle WSDL):
|
||||||
|
# headers = {"UserID": "...", "WorkplaceID": "..."} # ilustrativní
|
||||||
|
# resp = client.service.NazevOperace(requestPayload, _soapheaders=headers)
|
||||||
|
# print(resp)
|
||||||
24
fio.py
Normal file
24
fio.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
|
# Replace with your actual token
|
||||||
|
API_TOKEN = "v0GJaAVeefzV1lnx1jPCf2nFF7SuOPzzrL5tobPNsC7oCChXG4hahDYVb8Rdcex0"
|
||||||
|
|
||||||
|
# Example: download last 30 days of transactions in JSON
|
||||||
|
url = f"https://fioapi.fio.cz/v1/rest/periods/v0GJaAVeefzV1lnx1jPCf2nFF7SuOPzzrL5tobPNsC7oCChXG4hahDYVb8Rdcex0/2000-01-01/2025-07-23/transactions.json"
|
||||||
|
|
||||||
|
response = requests.get(url)
|
||||||
|
print(response)
|
||||||
|
data = response.json()
|
||||||
|
|
||||||
|
with open(r"u:\Dropbox\!!!Days\Downloads Z230\Fio\pohyby.json", "w", encoding="utf-8") as f:
|
||||||
|
json.dump(data, f, ensure_ascii=False, indent=4)
|
||||||
|
#
|
||||||
|
# # Print some info
|
||||||
|
# for trans in data['accountStatement']['transactionList']['transaction']:
|
||||||
|
# print(f"Date: {trans['column0']['value']}")
|
||||||
|
# print(f"Amount: {trans['column1']['value']}")
|
||||||
|
# print(f"Currency: {trans['column14']['value']}")
|
||||||
|
# print(f"Sender/Receiver: {trans['column10']['value']}")
|
||||||
|
# print(f"Message: {trans['column16']['value']}")
|
||||||
|
# print("-" * 40)
|
||||||
32
outlook.py
Normal file
32
outlook.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import win32com.client
|
||||||
|
|
||||||
|
|
||||||
|
def process_outlook_emails_from_root():
|
||||||
|
# Connect to Outlook
|
||||||
|
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
|
||||||
|
|
||||||
|
# Get the root folder of the mailbox
|
||||||
|
root_folder = outlook.Folders.Item(1) # Typically the first item is the root
|
||||||
|
|
||||||
|
# Recursive function to process all folders
|
||||||
|
def process_folder(folder):
|
||||||
|
print(f"\nProcessing folder: {folder.Name}")
|
||||||
|
|
||||||
|
# # Iterate through all items in the current folder
|
||||||
|
# for item in folder.Items:
|
||||||
|
# if item.Class == 43: # 43 is the class for MailItem
|
||||||
|
# print(f"Found email - Subject: {item.Subject}")
|
||||||
|
# print(f" From: {item.SenderName}")
|
||||||
|
# print(f" Received: {item.ReceivedTime}")
|
||||||
|
# # Add your email processing logic here
|
||||||
|
|
||||||
|
# Recursively process subfolders
|
||||||
|
for subfolder in folder.Folders:
|
||||||
|
process_folder(subfolder)
|
||||||
|
|
||||||
|
# Start processing from the root folder
|
||||||
|
process_folder(root_folder)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
process_outlook_emails_from_root()
|
||||||
24
tagpdf.py
Normal file
24
tagpdf.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
from pypdf import PdfReader, PdfWriter
|
||||||
|
|
||||||
|
# Load the existing PDF
|
||||||
|
reader = PdfReader(r"u:\Dropbox\!!!Days\Downloads Z230\output11.pdf")
|
||||||
|
writer = PdfWriter()
|
||||||
|
|
||||||
|
# Copy all pages to the writer
|
||||||
|
for page in reader.pages:
|
||||||
|
writer.add_page(page)
|
||||||
|
|
||||||
|
#Get metadata
|
||||||
|
metadata = reader.metadata
|
||||||
|
author = metadata.get("/Author","")
|
||||||
|
author=author+', YourName'
|
||||||
|
print(author)
|
||||||
|
|
||||||
|
# Set metadata
|
||||||
|
writer.add_metadata({"/Author": ""})
|
||||||
|
writer.add_metadata({"/Author": author})
|
||||||
|
|
||||||
|
# Save the updated PDF
|
||||||
|
with open(r"u:\Dropbox\!!!Days\Downloads Z230\output11.pdf", "wb") as f:
|
||||||
|
writer.write(f)
|
||||||
|
|
||||||
35
tinker.py
Normal file
35
tinker.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import tkinter as tk
|
||||||
|
from tkinter import messagebox
|
||||||
|
|
||||||
|
def on_select(event):
|
||||||
|
# Get selected item's index
|
||||||
|
selection = listbox.curselection()
|
||||||
|
if selection:
|
||||||
|
index = selection[0]
|
||||||
|
# Get the selected item
|
||||||
|
item = listbox.get(index)
|
||||||
|
# Update label or show a message
|
||||||
|
label.config(text=f"Selected: {item}")
|
||||||
|
# Or display a message box
|
||||||
|
# messagebox.showinfo("Selection", f"You selected: {item}")
|
||||||
|
|
||||||
|
root = tk.Tk()
|
||||||
|
root.title("Listbox Example")
|
||||||
|
|
||||||
|
# Sample list of items
|
||||||
|
items = ["Apple", "Ban Banana", "Cherry", "Date", "Elderberry"]
|
||||||
|
|
||||||
|
# Create a Listbox widget
|
||||||
|
listbox = tk.Listbox(root)
|
||||||
|
for item in items:
|
||||||
|
listbox.insert(tk.END, item)
|
||||||
|
listbox.pack(padx=10, pady=10)
|
||||||
|
|
||||||
|
# Bind the select event
|
||||||
|
listbox.bind('<<ListboxSelect>>', on_select)
|
||||||
|
|
||||||
|
# Label to display selected item
|
||||||
|
label = tk.Label(root, text="Select an item")
|
||||||
|
label.pack(pady=5)
|
||||||
|
|
||||||
|
root.mainloop()
|
||||||
Reference in New Issue
Block a user