Incase of Accidental Resume Folder Emptying
Create the following script, modifying the unit code in the SQL.
Make sure you have a C:\Temp\Resume folder .
import json
import os.path
from sshtunnel import SSHTunnelForwarder
from sqlalchemy.orm import sessionmaker
from ukrdc.database import Connection
fname = os.path.expanduser("~/.config/ukrdc/services/db_conf.json")
print("Configuration File: ", fname)
with open(fname) as fhandle:
params = json.load(fhandle)
# Make an SSH Tunnel to UKRDC DB Live via App Live
with SSHTunnelForwarder(
(params["live_app_ssh"]["HOST"], 22),
ssh_password=params["live_app_ssh"]["PASSWORD"],
ssh_username=params["live_app_ssh"]["USER"],
remote_bind_address=(params["live_app_ssh"]["DBHOST"], 5432),
set_keepalive=60
) as ukrdc_live_tunnel:
# Make a connection to the UKRDC3 database
ukrdc_engine = Connection.get_engine_from_file(
key="ukrdc_live", port=ukrdc_live_tunnel.local_bind_port
)
ukrdc_connection = ukrdc_engine.raw_connection()
ukrdc_cursor = ukrdc_connection.cursor()
ukrdc_sessionmaker = sessionmaker(bind=ukrdc_engine)
ukrdc_session = ukrdc_sessionmaker()
sql_string = """
SELECT PID
FROM
extract.patientrecord
WHERE
ukrdcid in (select ukrdcid from extract.vwe_pkb_members)
AND
sendingfacility = 'RFPFG'
AND
sendingextract in ('UKRDC', 'PVMIG', 'PV')
"""
ukrdc_cursor.execute(sql_string)
results = ukrdc_cursor.fetchall()
for row in results:
output_file = open('C:/Temp/resume/' + row[0], 'w')
output_file.write(row[0])
output_file.close()
Copy the files it creates to .responses/resume on the App server.
If there were any failed files remove those PIDs from the resume folder again.
Run dump.py making sure to add the --resume parameter.