como experto programador, combina los siguientes codigos en uno solo para su funcionamiento completo: import sqlite3
def init(self):
self.conn = sqlite3.connect('medical_records.db')
self.cursor = self.conn.cursor()
self.cursor.execute('''CREATE TABLE IF NOT EXISTS medical_history
(patient_name TEXT, date_of_birth DATE, address TEXT, previous_illnesses TEXT, allergies TEXT, current_medications TEXT, last_visit_date DATE)''')
self.conn.commit()
from tkinter import *
def create_widgets(self):
self.root = Tk()
self.root.title('Registro de Historia Médica Personal')
# Nombre del paciente
Label(self.root, text='Nombre del paciente:').grid(row=0, column=0, sticky=W)
self.name_entry = Entry(self.root)
self.name_entry.grid(row=0, column=1)
# Fecha de nacimiento
Label(self.root, text='Fecha de nacimiento:').grid(row=1, column=0, sticky=W)
self.date_of_birth = DateEntry(self.root, date_pattern='yyyy-mm-dd')
self.date_of_birth.grid(row=1, column=1)
# Dirección
Label(self.root, text='Dirección:').grid(row=2, column=0, sticky=W)
self.address_entry = Entry(self.root)
self.address_entry.grid(row=2, column=1)
# Enfermedades previas
Label(self.root, text='Enfermedades previas:').grid(row=3, column=0, sticky=W)
self.previous_illnesses_listbox = Listbox(self.root)
self.previous_illnesses_listbox.grid(row=3, column=1, rowspan=3)
# Alergias
Label(self.root, text='Alergias:').grid(row=4, column=0, sticky=W)
self.allergies_listbox = Listbox(self.root)
self.allergies_listbox.grid(row=4, column=1)
# Medicamentos actuales
Label(self.root, text='Medicamentos actuales:').grid(row=5, column=0, sticky=W)
self.current_medications_listbox = Listbox(self.root)
self.current_medications_listbox.grid(row=5, column=1)
# Fecha de la última visita médica
Label(self.root, text='Fecha de la última visita médica:').grid(row=6, column=0, sticky=W)
self.last_visit_date = DateEntry(self.root, date_pattern='yyyy-mm-dd')
self.last_visit_date.grid(row=6, column=1)
# Botón guardar
Button(self.root, text='Guardar', command=self.save_record).grid(row=7, column=0, sticky=W)
self.root.mainloop()
def save_record(self):
patient_name = self.name_entry.get()
date_of_birth = self.date_of_birth.get_date()
address = self.address_entry.get()
previous_illnesses = ', '.join(self.previous_illnesses_listbox.get(0, END))
allergies = ', '.join(self.allergies_listbox.get(0, END))
current_medications = ', '.join(self.current_medications_listbox.get(0, END))
last_visit_date = self.last_visit_date.get_date()
self.cursor.execute("INSERT INTO medical_history VALUES (?, ?, ?, ?, ?, ?, ?)", (patient_name, date_of_birth, address, previous_illnesses, allergies, current_medications, last_visit_date))
self.conn.commit()
self.clear_entries()
def clear_entries(self):
self.name_entry.delete(0, END)
self.address_entry.delete(0, END)
self.previous_illnesses_listbox.delete(0, END)
self.allergies_listbox.delete(0, END)
self.current_medications_listbox.delete(0, END)
class App:
def init(self):
self.conn = sqlite3.connect('medical_records.db')
self.cursor = self.conn.cursor()
self.cursor.execute('''CREATE TABLE IF NOT EXISTS medical_history
(patient_name TEXT, date_of_birth DATE, address TEXT, previous_illnesses TEXT, allergies TEXT, current_medications TEXT, last_visit_date DATE)''')
self.root = Tk()
self.root.title('Registro de Historia Médica Personal')
self.create_widgets()
def create_widgets(self):
Label(self.root, text='Nombre del paciente:').grid(row=0, column=0, sticky=W)
self.name_entry = Entry(self.root)
self.name_entry.grid(row=0, column=1)
Label(self.root, text='Fecha de nacimiento:').grid(row=1, column=0, sticky=W)
self.date_of_birth = DateEntry(self.root, date_pattern='yyyy-mm-dd')
self.date_of_birth.grid(row=1, column=1)
Label(self.root, text='Dirección:').grid(row=2, column=0, sticky=W)
self.address_entry = Entry(self.root)
self.address_entry.grid(row=2, column=1)
Label(self.root, text='Enfermedades previas:').grid(row=3, column=0, sticky=W)
self.previous_illnesses_listbox = Listbox(self.root)
self.previous_illnesses_listbox.grid(row=3, column=1, rowspan=3)
Label(self.root, text='Alergias:').grid(row=4, column=0, sticky=W)
self.allergies_listbox = Listbox(self.root)
self.allergies_listbox.grid(row=4, column=1)
Label(self.root, text='Medicamentos actuales:').grid(row=5, column=0, sticky=W)
self.current_medications_listbox = Listbox(self.root)
self.current_medications_listbox.grid(row=5, column=1)
Label(self.root, text='Fecha de la última visita médica:').grid(row=6, column=0, sticky=W)
self.last_visit_date = DateEntry(self.root, date_pattern='yyyy-mm-dd')
self.last_visit_date.grid(row=6, column=1)
Button(self.root, text='Guardar', command=self.save_record).grid(row=7, column=0, sticky=W)
def save_record(self):
patient_name = self.name_entry.get()
date_of_birth = self.date_of_birth.get_date()
address = self.address_entry.get()
previous_illnesses = ', '.join(self.previous_illnesses_listbox.get(0, END))
allergies = ', '.join(self.allergies_listbox.get(0, END))
current_medications = ', '.join(self.current_medications_listbox.get(0, END))
last_visit_date = self.last_visit_date.get_date()
self.cursor.execute("INSERT INTO medical_history VALUES (?, ?, ?, ?, ?, ?, ?)", (patient_name, date_of_birth, address, previous_illnesses, allergies, current_medications, last_visit_date))
self.conn.commit()
self.clear_entries()
def clear_entries(self):
self.name_entry.delete(0, END)
self.address_entry.delete(0, END)
self.previous_illnesses_listbox.delete(0, END)
self.allergies_listbox.delete(0, END)
self.current_medications_listbox.delete(0, END)
if name == 'main':
app = App()