notebookVB
This commit is contained in:
96
02 testík.py
96
02 testík.py
@@ -15,6 +15,9 @@ from datetime import date
|
||||
import pymysql
|
||||
from pymysql.cursors import DictCursor
|
||||
from pprint import pprint
|
||||
from functions import get_medicus_connection
|
||||
from functions import get_mysql_connection
|
||||
import time, random
|
||||
|
||||
# ------------------- CONFIG -------------------
|
||||
ENDPOINT = "https://prod.b2b.vzp.cz/B2BProxy/HttpProxy/RegistracePojistencePZSB2B" # case-sensitive
|
||||
@@ -23,8 +26,8 @@ PFX_PASS = "Vlado7309208104++" # <-- your export password
|
||||
VERIFY = True # or path to CA PEM, e.g. r"C:\certs\vzp_ca.pem"
|
||||
|
||||
# Patient + query
|
||||
# RC = "7309208104" # rodné číslo without slash
|
||||
RC = "280616/091" # rodné číslo without slash
|
||||
RC = "7309208104" # rodné číslo without slash
|
||||
# RC = "280616/091" # rodné číslo without slash
|
||||
K_DATU = date.today().isoformat() # YYYY-MM-DD
|
||||
ODBORNOSTI = ["001"] # VPL (adult GP)
|
||||
|
||||
@@ -171,32 +174,85 @@ ON DUPLICATE KEY UPDATE
|
||||
print(f"\nUpserted rows: {len(payloads)}")
|
||||
return len(payloads)
|
||||
|
||||
def prepare_processed_rcs():
|
||||
consql=get_mysql_connection()
|
||||
cursql=consql.cursor()
|
||||
|
||||
sql="""
|
||||
WITH ranked AS (
|
||||
SELECT
|
||||
vreg.*,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY rc
|
||||
ORDER BY query_date DESC
|
||||
) AS rn
|
||||
FROM vzp_registrace AS vreg
|
||||
)
|
||||
SELECT rc
|
||||
FROM ranked
|
||||
WHERE rn = 1
|
||||
"""
|
||||
|
||||
cursql.execute(sql)
|
||||
rows=cursql.fetchall()
|
||||
print(f"Pocet jiz zpracovanych rodnych cisel v MYSQL MEDEVIO je {len(rows)}")
|
||||
rc_set_vzp = {row["rc"] for row in rows}
|
||||
return (rc_set_vzp)
|
||||
|
||||
# ------------------- MAIN FLOW -------------------
|
||||
def main():
|
||||
# Build SOAP envelope
|
||||
envelope = build_envelope(RC, K_DATU, ODBORNOSTI)
|
||||
|
||||
# mTLS session
|
||||
session = requests.Session()
|
||||
session.mount("https://", Pkcs12Adapter(pkcs12_filename=PFX_PATH, pkcs12_password=PFX_PASS))
|
||||
con = get_medicus_connection()
|
||||
cur = con.cursor()
|
||||
cur.execute("select rodcis, prijmeni, jmeno from kar where rodcis starting with '0'")
|
||||
# cur.execute("select first 2 rodcis, prijmeni, jmeno from kar where rodcis starting with '0'")
|
||||
|
||||
# Vytvor seznam rodnych cisel, která už máme
|
||||
rc_set_vzp = prepare_processed_rcs()
|
||||
|
||||
rows = cur.fetchall()
|
||||
print(f"Pocet vybranych radku z tabulky KAR je: {len(rows)}")
|
||||
|
||||
for row in rows:
|
||||
if row[0] in rc_set_vzp:
|
||||
continue
|
||||
else:
|
||||
print(row[0], row[1], row[2])
|
||||
K_DATU = date.today().isoformat() # YYYY-MM-DD
|
||||
ODBORNOSTI = ["001"]
|
||||
RC=row[0]
|
||||
|
||||
# Build SOAP envelope
|
||||
envelope = build_envelope(RC, K_DATU, ODBORNOSTI)
|
||||
|
||||
# mTLS session
|
||||
session = requests.Session()
|
||||
session.mount("https://", Pkcs12Adapter(pkcs12_filename=PFX_PATH, pkcs12_password=PFX_PASS))
|
||||
|
||||
headers = {
|
||||
"Content-Type": "text/xml; charset=utf-8",
|
||||
"SOAPAction": "process", # Oracle composite usually expects this
|
||||
}
|
||||
|
||||
# Call service
|
||||
resp = session.post(ENDPOINT, data=envelope.encode("utf-8"),
|
||||
headers=headers, timeout=30, verify=VERIFY)
|
||||
print("HTTP:", resp.status_code)
|
||||
|
||||
# (Optional) Uncomment to see raw XML
|
||||
# print(resp.text)
|
||||
|
||||
# Parse and save
|
||||
rows, stav = parse_registrace(resp.text)
|
||||
upsert_rows(RC, K_DATU, rows, stav, resp.text)
|
||||
|
||||
time.sleep(random.uniform(1, 5))
|
||||
|
||||
|
||||
|
||||
headers = {
|
||||
"Content-Type": "text/xml; charset=utf-8",
|
||||
"SOAPAction": "process", # Oracle composite usually expects this
|
||||
}
|
||||
|
||||
# Call service
|
||||
resp = session.post(ENDPOINT, data=envelope.encode("utf-8"),
|
||||
headers=headers, timeout=30, verify=VERIFY)
|
||||
print("HTTP:", resp.status_code)
|
||||
|
||||
# (Optional) Uncomment to see raw XML
|
||||
# print(resp.text)
|
||||
|
||||
# Parse and save
|
||||
rows, stav = parse_registrace(resp.text)
|
||||
upsert_rows(RC, K_DATU, rows, stav, resp.text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user