def __main__(): op = opciones.diagnose_opciones() if not op: print echo('No se encuentran las opciones de conexión. No se puede conectar a la base de datos de Diagnose.') exit(1) print echo('Escriba las fechas en formato AAAA/MM/DD para filtrar la búsqueda.\nDeje vacía la pregunta si no desea filtrar por fecha.') dt0 = get_dt('Fecha desde') dt1 = get_dt('Fecha hasta') print 'Conectando a la base de datos...' host = pymy.get_host() conn, cur = pymy.get_conn_cursor(host) print 'Servicios disponibles:' data = find_servs(cur) serv = get_serv(data) servname = serv and [i['detalle'] for i in data if i['id'] == serv][0] or None sql = makesearch(dt0, dt1, serv) print 'Consultando...' cur.execute(sql) print 'Recuperando datos...' data = cur.fetchall() print 'Listo.' print2screen(data) html = makehtml(op, dt0, dt1, servname) print2html(html, data)
def main(): # Leer opciones de Diagnose host = try_(pymy.get_host()) # Conectar con base de datos conn, cur = try_(pymy.get_conn_cursor(host)) # Pedir al usuario el número de alerta e = try_(alertas.get_id()) # Buscar alerta en la base de datos er = alertas.get_record(cur, e) if er: ers = alertas.ALERTA.format(**er) print echo(ers) raw_input() logpath = get_cfg() if not logpath: logpath = './' elif '%DBOX%' in logpath: dbox = dropbox.get_dropbox_folder() or './' logpath = logpath.replace('%DBOX%', dbox) if os.path.isdir(logpath): fn = os.path.normpath(os.path.join(logpath, 'alertas.txt')) with open(fn, 'w') as f: f.write(ers) os.startfile(fn) else: print echo('No se encuentra el número de error'), e waitnquit(1)
def __main__(): op = opciones.diagnose_opciones() if not op: print echo( 'No se encuentran las opciones de conexión. No se puede conectar a la base de datos de Diagnose.' ) exit(1) print echo( 'Escriba las fechas en formato AAAA/MM/DD para filtrar la búsqueda.\nDeje vacía la pregunta si no desea filtrar por fecha.' ) dt0 = get_dt('Fecha desde') dt1 = get_dt('Fecha hasta') print 'Conectando a la base de datos...' host = pymy.get_host() conn, cur = pymy.get_conn_cursor(host) print 'Servicios disponibles:' data = find_servs(cur) serv = get_serv(data) servname = serv and [i['detalle'] for i in data if i['id'] == serv][0] or None sql = makesearch(dt0, dt1, serv) print 'Consultando...' cur.execute(sql) print 'Recuperando datos...' data = cur.fetchall() print 'Listo.' print2screen(data) html = makehtml(op, dt0, dt1, servname) print2html(html, data)
def find_servs(cur): cur.execute( "SELECT DISTINCT c.id, c.detalle FROM atencion a JOIN turnos t ON a.idturno = t.idturno JOIN common c ON c.id = t.tipo_estudio;" ) data = cur.fetchall() for i in data: print echo('{id:7d}\t{detalle}'.format(**i)) return data
def print2screen(data): print print echo('Frecuencia de diagnósticos en consultas') print '-----\t------\t---------' print 'Cant.\tCIE-10\tDesc.' print '-----\t------\t---------' for rec in data: print echo('{q:5d}\t{cie10:5s}\t{descripcion}'.format(**rec)) print
def get_input(): res = [] print echo('Ingrese cada número a buscar seguido de Enter. Enter solo para terminar.') while True: r = raw_input('Buscar: ').strip() if r == '': break if not r.isdigit(): print echo('¡NO ES UN NÚMERO!') continue res.append(r) return res
def get_serv(data): while True: r = raw_input(echo('Ingrese código del servicio: ')).strip() if not r: break elif r.isdigit() and int(r) in [i['id'] for i in data]: return int(r)
def get_id(): while 1: e = raw_input(echo('Número de documento: ')) if e == '': return None if e.isdigit(): e = int(e) break return e
def get_id(): while 1: e = raw_input(echo("Número de error: ")) if e == "": return None if e.isdigit(): e = int(e) break return e
def get_ym(): if argv and len(argv) == 3 and argv[1].isdigit() and argv[2].isdigit() and 2010 < int(argv[1]) < 2020 and 1 <= int(argv[2]) <= 12: y = int(argv[1]) m = int(argv[2]) else: while True: r = raw_input(echo('Año: ')).strip() if not r: exit(1) if r.isdigit() and 2010 < int(r) < 2020: y = int(r) break while True: r = raw_input(echo('Mes: ')).strip() if not r: exit(1) if r.isdigit() and 1 <= int(r) <= 12: m = int(r) break return dict((('y', y), ('m', m)))
def get_host(): op = opciones.diagnose_opciones() if not op: import re print echo('No se pudieron leer las opciones de conexión de Diagnose.') while 1: ip = raw_input(echo('Escriba la dirección IP del servidor de Diagnose:')).strip().lower() if ip == '': return None if ip == 'localhost': return ip try: ipparts = [int(p) for p in ip.split('.')] except ValueError: continue if len(ipparts) == 4: if len(filter(lambda x: (x >= 0 and x < 256), ipparts)) == 4: break return ip else: return op['server']
def __main__(): op = opciones.diagnose_opciones() if not op: print echo('No se encuentran las opciones de conexión. No se puede conectar a la base de datos de Diagnose.') exit(1) print echo('Escriba las fechas en formato AAAA-MM-DD para filtrar la búsqueda.\nDeje vacía la pregunta si no desea filtrar por fecha.') dt0 = get_dt('Fecha desde') dt1 = get_dt('Fecha hasta') print 'Conectando a la base de datos...' host = pymy.get_host() conn, cur = pymy.get_conn_cursor(host) sql = makesearch(dt0, dt1) print 'Consultando...' cur.execute(sql) print 'Recuperando datos...' data = cur.fetchall() print 'Listo.' html = makehtml(op, dt0, dt0) print2html(html, data)
def get_prof(cur): cur.execute("SELECT id FROM common WHERE Tipo = 'servicios_p' AND Detalle = 'ODONTOLOGIA';") rec = cur.fetchone() odonto = rec['id'] cur.execute("SELECT IdPerson, Nombre FROM person WHERE tipo_servicio = {} AND IdPerson IN (SELECT idPerson FROM consultorio);".format(odonto)) data = cur.fetchall() profs = dict() for rec in data: profs[rec['IdPerson']] = rec['Nombre'] while True: for rec in data: print '{IdPerson:5d}\t{Nombre}'.format(**rec) r = raw_input(echo('Código: ')).strip() if r.isdigit() and int(r) in profs: return {'odonto': odonto, 'person': int(r), 'nombre': profs[int(r)]}
def get_prof(cur): cur.execute( "SELECT id FROM common WHERE Tipo = 'servicios_p' AND Detalle = 'ODONTOLOGIA';" ) rec = cur.fetchone() odonto = rec['id'] cur.execute( "SELECT IdPerson, Nombre FROM person WHERE tipo_servicio = {} AND IdPerson IN (SELECT idPerson FROM consultorio);" .format(odonto)) data = cur.fetchall() profs = dict() for rec in data: profs[rec['IdPerson']] = rec['Nombre'] while True: for rec in data: print '{IdPerson:5d}\t{Nombre}'.format(**rec) r = raw_input(echo('Código: ')).strip() if r.isdigit() and int(r) in profs: return { 'odonto': odonto, 'person': int(r), 'nombre': profs[int(r)] }
# -*- coding: latin-1 -*- import os.path from pydiag import pymy from pydiag.connection import DiagnoseConnection from spiutils.utils import echo, waitnquit host = pymy.get_host() conn, cur = pymy.get_conn_cursor(host) cur.execute("SHOW TABLES LIKE 'tConfiguracion';") if not cur.fetchone(): print echo('No existe la tabla tConfiguracion.') else: cur.execute("SELECT * FROM tConfiguracion WHERE conf_modulo = 'diagnose' AND conf_clave = 'actualizador' AND conf_atributo = 'path';") r = cur.fetchone() if not r: print echo('No se encuentra ruta de actualización.') else: path = r['conf_valor'] print echo('Ruta de actualización: ' + path) if os.path.isfile(os.path.join(path, 'diagnose.exe')): print echo('Se encontró diagnose.exe en la ruta.') else: print echo('No se encuentra diagnose.exe en la ruta.') waitnquit(0)
# -*- coding: latin-1 -*- from pydiag import pymy from spiutils.utils import echo host = pymy.get_host() conn, cur = pymy.get_conn_cursor(host, 'diagnose') cur.execute( 'SELECT COUNT(*) AS q FROM paciente WHERE dt_created BETWEEN (NOW() - INTERVAL 1 WEEK) AND NOW();' ) r = cur.fetchone() print echo('{0} pacientes creados en la última semana.'.format(r['q'])) cur.execute( 'SELECT COUNT(*) AS q FROM paciente WHERE dt_created BETWEEN (NOW() - INTERVAL 1 MONTH) AND NOW();' ) r = cur.fetchone() print echo('{0} pacientes creados en el último mes.'.format(r['q']))
# -*- coding: latin-1 -*- import pymysql from pydiag import personas, opciones, pymy from spiutils.utils import echo import sys if __name__ == '__main__': # Leer opciones de Diagnose host = pymy.get_host() if not host: print echo('No se encontró host de base de datos.') sys.exit(1) # Conectar con base de datos conn, cur = pymy.get_conn_cursor(server=host, db='personas') if not (conn and cur): print echo('No se pudo conectar a {0}.'.format(host)) sys.exit(2) while 1: e = personas.get_id() if not e: break er = personas.get_record(cur, e) if len(er) == 0: print echo('No se encontraron personas con ese número de documento.') print for i, p in enumerate(er): print '{:2}'.format(i + 1), personas.PERSONA0.format(**p) print while 1: n = raw_input(echo('Seleccione número para ver detalles: ')).strip()
# -*- coding: latin-1 -*- from pydiag import pymy from spiutils.utils import echo host = pymy.get_host() conn, cur = pymy.get_conn_cursor(host, 'diagnose') cur.execute('SELECT COUNT(*) AS q FROM paciente WHERE dt_created BETWEEN (NOW() - INTERVAL 1 WEEK) AND NOW();') r = cur.fetchone() print echo('{0} pacientes creados en la última semana.'.format(r['q'])) cur.execute('SELECT COUNT(*) AS q FROM paciente WHERE dt_created BETWEEN (NOW() - INTERVAL 1 MONTH) AND NOW();') r = cur.fetchone() print echo('{0} pacientes creados en el último mes.'.format(r['q']))
from spiutils.utils import echo, waitnquit def get_format(fn): if zipfile.is_zipfile(fn): return 'zip' else: with open(fn, 'rb') as rarf: magic = rarf.read(7) if magic == 'Rar!\x1a\x07\x00': return 'rar' X = tempfile.mkdtemp() if len(sys.argv) < 2: print echo('Se requiere al menos un parámetro.') waitnquit(1) fn = sys.argv[1] if not os.path.isfile(fn): print echo('El primer parámetro debe ser un nombre de archivo existente.') waitnquit(2) fmt = get_format(fn) if not fmt: print echo('El archivo no parece ser un archivo ZIP o RAR.') waitnquit(3) mysql_exe = find_mysql.find_mysql_binary('mysql.exe') if not mysql_exe: print echo('No se encuentra mysql.exe.')
import sys, os, subprocess, tempfile, zipfile from spiutils import find_mysql from spiutils.utils import echo, waitnquit def get_format(fn): if zipfile.is_zipfile(fn): return 'zip' else: with open(fn, 'rb') as rarf: magic = rarf.read(7) if magic == 'Rar!\x1a\x07\x00': return 'rar' if len(sys.argv) < 2: print echo('Se requiere al menos un parámetro.') waitnquit(1) mysql_exe = find_mysql.find_mysql_binary('mysql.exe') if not mysql_exe: print echo('No se encuentra mysql.exe.') waitnquit(4) for fn in sys.argv[1:]: if not os.path.isfile(fn): print echo('El parámetro debe ser un nombre de archivo existente.') waitnquit(2) fmt = get_format(fn) if not fmt:
def get_format(fn): if zipfile.is_zipfile(fn): return "zip" else: with open(fn, "rb") as rarf: magic = rarf.read(7) if magic == "Rar!\x1a\x07\x00": return "rar" X = tempfile.mkdtemp() if len(sys.argv) < 2: print echo("Se requiere al menos un parámetro.") waitnquit(1) fn = sys.argv[1] if not os.path.isfile(fn): print echo("El primer parámetro debe ser un nombre de archivo existente.") waitnquit(2) fmt = get_format(fn) if not fmt: print echo("El archivo no parece ser un archivo ZIP o RAR.") waitnquit(3) mysql_exe = find_mysql.find_mysql_binary("mysql.exe") if not mysql_exe: print echo("No se encuentra mysql.exe.")
def find_servs(cur): cur.execute("SELECT DISTINCT c.id, c.detalle FROM atencion a JOIN turnos t ON a.idturno = t.idturno JOIN common c ON c.id = t.tipo_estudio;") data = cur.fetchall() for i in data: print echo('{id:7d}\t{detalle}'.format(**i)) return data