Beruflich Dokumente
Kultur Dokumente
Tablas
Citas:
Consultorios:
Medicos:
Pacientes:
Tratamiento:
public Paciente(String id, String nom, String ape, String fechaNac, String sex)
{
identificacion=id;
nombres=nom;
apellidos=ape;
fechaNacimiento=fechaNac;
sexo=sex;
Paciente(String string) {
throw new UnsupportedOperationException("Not supported yet."); //To change
body of generated methods, choose Tools | Templates.
}
/**
*
* @return the identificacion
*/
/**
*
* @return the apellidos
*/
public String getApellidos() {
return apellidos;
}
/**
*
* @param apellidos the apellidos to set
*/
}
/**
*
* @return the fechaNacimiento
*/
public GestorPaciente()
{
recurso.Conexion conexion= new
recurso.Conexion("Localhost","XE","citas","citas");
conn = conexion.getConexion();
}
}
catch(SQLException exc)
{
JOptionPane.showMessageDialog(null,exc.getMessage());
}
}
public LinkedList<Paciente> getPacientesBy(int parametro, String valor)
{
LinkedList<Paciente> resultado = new LinkedList<>();
String sql="";
switch(parametro)
{
case 1: sql="select * from PACIENTES where pacIdentificacion="+valor+"";
break;
break;
rs.getString("pacNombres"),
rs.getString("pacApellidos"),
rs.getString("pacFechaNacimiento"),
rs.getString("pacSexo")));
}
}
rs.close();
}
catch (SQLException exc)
{
JOptionPane.showMessageDialog(null,exc.getMessage());
}
finally
{
return resultado;
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
vista.RegPacienteInternalFrame pacienteVista;
modelo.Paciente pacienteModelo;
modelo.GestorPaciente gestorPacienteModelo;
if(e.getSource().equals(pacienteVista.RegistrarBtn))
{
String identificacion=pacienteVista.IdentificacionTxt.getText();
String nombres=pacienteVista.NombresTxt.getText();
String apellidos=pacienteVista.ApellidosTxt.getText();
SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
String
fechaNacimiento=formato.format(pacienteVista.FechaNacimientoDtc.getDate());
String sexo=null;
if(pacienteVista.MasculinoOpt.isSelected())
sexo="m";
else
sexo="f";
pacienteModelo= new modelo.Paciente(identificacion, nombres, apellidos,
fechaNacimiento, sexo);
gestorPacienteModelo.registrarPaciente(pacienteModelo);
}
if(e.getSource().equals(pacienteVista.NuevoBtn))
{
pacienteVista.IdentificacionTxt.setText(null);
pacienteVista.NombresTxt.setText(null);
pacienteVista.ApellidosTxt.setText(null);
pacienteVista.FechaNacimientoDtc.setDate(null);
pacienteVista.MasculinoOpt.setSelected(false);
pacienteVista.FemeninoOpt.setSelected(false);
pacienteVista.IdentificacionTxt.requestFocus();
@Override
public void actionPerformed(ActionEvent ae) {
throw new UnsupportedOperationException("Not supported yet."); //To change
body of generated methods, choose Tools | Templates.
}
}
CLASE CONTROLADOR GESTION PACIENTE CONTROL:
package Controlador;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
modelo.GestorPaciente pacientesModelo;
vista.ConsPacienteInternalFrame consultarPacienteVista;
public GestorPacienteControl(vista.ConsPacienteInternalFrame
consultarPacienteVista)
{
this.consultarPacienteVista=consultarPacienteVista;
pacientesModelo=new modelo.GestorPaciente();
}
@Override
public void actionPerformed(ActionEvent e)
{
String valor=consultarPacienteVista.ValorTxt.getText();
int parametro=0;
consultarPacienteVista.getTableModel().setRowCount(0);
consultarPacienteVista.getTableModel().fireTableDataChanged();
if(consultarPacienteVista.IdentificacionOpt.isSelected());
parametro=1;
if(consultarPacienteVista.NombresOpt.isSelected());
parametro=2;
if(consultarPacienteVista.ApellidosOpt.isSelected());
parametro=3;
if(consultarPacienteVista.SexoOpt.isSelected());
parametro=4;
LinkedList<modelo.Paciente>pacientes=pacientesModelo.getPacientesBy(parametr
o, valor);
String registro[] =new String [5];
for(modelo.Paciente p:pacientes)
{
registro[0]=p.getIdentificacion();
registro[1]=p.getNombres();
registro[2]=p.getApellidos();
registro[3]=p.getFechaNacimiento();
registro[4]=p.getSexo();
consultarPacienteVista.getTableModel().addRow(registro);
consultarPacienteVista.getTableModel().fireTableDataChanged();
{
regPacienteInternalFrame=new RegPacienteInternalframe();
consPacienteInternalFrame=new ConsPacienteInternalFrame();
add(regPacienteInternalFrame);
add(consPacienteInternalFrame);
initComponents();
setExtendedState(MAXIMIZED_BOTH);
}
@SuppressWarnings("unchecked")
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("GESTION DE CITAS");
setName("PrincipalJPrame"); // NOI18N
jMenu1.setText("Archivo");
jMenu1.setName("Imprimir Pacientes Registrados"); // NOI18N
jMenu1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenu1ActionPerformed(evt);
}
});
jMenuItem1.setText("Salir");
jMenu1.add(jMenuItem1);
jMenuBar1.add(jMenu1);
jMenu2.setText("Pacientes");
jMenuItem2.setText("Registrar");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem2);
jMenuItem3.setText("Consultar");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem3);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
pack();
}// </editor-fold>
java.util.logging.Logger.getLogger(PrincipalJFrame.class.getName()).log(java.util.lo
gging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(PrincipalJFrame.class.getName()).log(java.util.lo
gging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(PrincipalJFrame.class.getName()).log(java.util.lo
gging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(PrincipalJFrame.class.getName()).log(java.util.lo
gging.Level.SEVERE, null, ex);
}
//</editor-fold>
public RegPacienteInternalframe() {
}
}
}
CONSPACIENTEINTERNALFRAME:
package vista;
import javax.swing.table.DefaultTableModel;
public ConsPacienteInternalFrame() {
initComponents();
gestorpacientesControl=new controlador.GestorPacienteControl(this);
String titulosTabla[]={"Identificacion","Nombres","Apellidos","Fecha
Nac","sexo"};
tabla = new DefaultTableModel(null, titulosTabla);
ResultadosTbl.setModel(tabla);
AceptarBtn.addActionListener(gestorpacientesControl);//
}
public DefaultTableModel getTableModel()
{
return tabla;
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setTitle("Consulta de Pacientes");
buttonGroup1.add(IdentificacionOpt);
IdentificacionOpt.setText("Identificacion");
buttonGroup1.add(NombresOpt);
NombresOpt.setText("Nombres");
buttonGroup1.add(ApellidosOpt);
ApellidosOpt.setText("Apellidos");
buttonGroup1.add(SexoOpt);
SexoOpt.setText("Sexo");
jLabel1.setText("Valor a buscar");
ValorTxt.setName("ValorTxt"); // NOI18N
AceptarBtn.setText("Aceptar");
AceptarBtn.setName("AceptarBtn"); // NOI18N
ResultadosTbl.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
ResultadosTbl.setName("ResultadosTbl"); // NOI18N
jScrollPane1.setViewportView(ResultadosTbl);
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addComponent(IdentificacionOpt)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addGroup(layout.createSequentialGroup()
.addComponent(NombresOpt)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(ApellidosOpt)
.addGap(18, 18, 18)
.addComponent(SexoOpt))
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(ValorTxt,
javax.swing.GroupLayout.PREFERRED_SIZE, 131,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(AceptarBtn))))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE, 359,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(36, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI
NE)
.addComponent(IdentificacionOpt)
.addComponent(NombresOpt)
.addComponent(ApellidosOpt)
.addComponent(SexoOpt))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI
NE)
.addComponent(jLabel1)
.addComponent(ValorTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(AceptarBtn))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE,
294, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
REGPACIENTEINTERNALFRAME:
package vista;
@SuppressWarnings("unchecked")
setClosable(true);
setTitle("Registro de pacientes");
jLabel1.setText("Identificacion:");
jLabel2.setText("Nombres:");
jLabel3.setText("Apellidos:");
jLabel4.setText("Fecha de Nacimiento:");
jLabel5.setText("Sexo:");
IdentificacionTxt.setName("IdentificacionTxt"); // NOI18N
NombresTxt.setName("NombresTxt"); // NOI18N
ApellidosTxt.setName("ApellidosTxt"); // NOI18N
MasculinoOpt.setText("M");
FemeninoOpt.setText("F");
RegistrarBtn.setText("Registrar");
RegistrarBtn.setName("RegistrarBtn"); // NOI18N
NuevoBtn.setText("Nuevo");
NuevoBtn.setName("NuevoBtn"); // NOI18N
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILIN
G)
.addComponent(RegistrarBtn)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5)
.addGap(90, 90, 90)
.addComponent(MasculinoOpt)
.addGap(61, 61, 61)
.addComponent(FemeninoOpt)))
.addGap(27, 27, 27)
.addComponent(NuevoBtn))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G, false)
.addComponent(IdentificacionTxt)
.addComponent(NombresTxt)
.addComponent(ApellidosTxt)
.addComponent(FechaNacimientoDtc,
javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE))))
.addContainerGap(51, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI
NE)
.addComponent(jLabel1)
.addComponent(IdentificacionTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI
NE)
.addComponent(jLabel2)
.addComponent(NombresTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI
NE)
.addComponent(jLabel3)
.addComponent(ApellidosTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILIN
G)
.addComponent(jLabel4)
.addComponent(FechaNacimientoDtc,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI
NE)
.addComponent(jLabel5)
.addComponent(MasculinoOpt)
.addComponent(FemeninoOpt))
.addGap(52, 52, 52)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI
NE)
.addComponent(RegistrarBtn)
.addComponent(NuevoBtn))
.addContainerGap(53, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
import java.sql.*;
import javax.swing.JOptionPane;
}
catch (Exception exc)
{
JOptionPane.showMessageDialog(null, "error de conexion con la
base de datos");
}
}
public Connection getConexion()
{
return conexion;
}
public Connection CerrarConexion() throws SQLException
{
conexion.close();
conexion = null;
return conexion;
}
}
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
@Table(name = "PACIENTES")
@NamedQueries({
@NamedQuery(name = "Pacientes.findAll", query = "SELECT p FROM Pacientes
p")})
public class Pacientes implements Serializable {
public Pacientes() {
}
@Override
public int hashCode() {
int hash = 0;
hash += (pacidentificacion != null ? pacidentificacion.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Pacientes)) {
return false;
}
Pacientes other = (Pacientes) object;
if ((this.pacidentificacion == null && other.pacidentificacion != null) ||
(this.pacidentificacion != null &&
!this.pacidentificacion.equals(other.pacidentificacion))) {
return false;
}
return true;
}
@Override
public String toString() {
return "modelo.Pacientes[ pacidentificacion=" + pacidentificacion + " ]";
}
}
PACIENTESJPACONTROLLER:
package modelo;
import java.io.Serializable;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;
import javax.persistence.EntityNotFoundException;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import modelo.exceptions.NonexistentEntityException;
import modelo.exceptions.PreexistingEntityException;
PACIENTE CONTROL:
package Controlador;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.swing.JOptionPane;
import modelo.exceptions.PreexistingEntityException;
vista.RegPacienteInternalFrame pacienteVista;
modelo.Pacientes pacienteModelo;
modelo.PacientesJpaController gestorPacienteModelo;
}
public void actionPerformedd(ActionEvent e)
{
if(e.getSource().equals(pacienteVista.RegistrarBtn))
{
String identificacion=pacienteVista.IdentificacionTxt.getText();
String nombres=pacienteVista.NombresTxt.getText();
String apellidos=pacienteVista.ApellidosTxt.getText();
SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
String
fechaNacimiento=formato.format(pacienteVista.FechaNacimientoDtc.getDate());
char sexo='0';
if(pacienteVista.MasculinoOpt.isSelected())
sexo='m';
else
sexo='f';
gestorPacienteModelo.create(pacienteModelo);
JOptionPane.showMessageDialog(pacienteVista, "Paciente registrado
correctamente");
}
catch (PreexistingEntityException ex)
{
JOptionPane.showMessageDialog(pacienteVista, "El paciente ya existe");
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(pacienteVista, ex.getMessage());
}
}
if(e.getSource().equals(pacienteVista.NuevoBtn))
{
pacienteVista.IdentificacionTxt.setText(null);
pacienteVista.NombresTxt.setText(null);
pacienteVista.ApellidosTxt.setText(null);
pacienteVista.FechaNacimientoDtc.setDate(null);
pacienteVista.MasculinoOpt.setSelected(false);
pacienteVista.FemeninoOpt.setSelected(false);
pacienteVista.IdentificacionTxt.requestFocus();
@Override
public void actionPerformed(ActionEvent ae) {
throw new UnsupportedOperationException("Not supported yet."); //To change
body of generated methods, choose Tools | Templates.
}
modelo.PacientesJpaController pacientesModelo;
vista.ConsPacienteInternalFrame consultarPacienteVista;
public GestorPacienteControl(vista.ConsPacienteInternalFrame
consultarPacienteVista)
{
this.consultarPacienteVista=consultarPacienteVista;
EntityManagerFactory emf=
Persistence.createEntityManagerFactory("ProyectoCitasPU");
pacientesModelo=new modelo.PacientesJpaController(emf);
}
@Override
public void actionPerformed(ActionEvent e)
{
String valor=consultarPacienteVista.ValorTxt.getText();
int parametro=0;
consultarPacienteVista.getTableModel().setRowCount(0);
consultarPacienteVista.getTableModel().fireTableDataChanged();
if(consultarPacienteVista.IdentificacionOpt.isSelected());
parametro=1;
if(consultarPacienteVista.NombresOpt.isSelected());
parametro=2;
if(consultarPacienteVista.ApellidosOpt.isSelected());
parametro=3;
if(consultarPacienteVista.SexoOpt.isSelected());
parametro=4;
List<modelo.Pacientes> pacientes=pacientesModelo.findPacientesEntities();
for(modelo.Pacientes p:pacientes)
{
switch(parametro)
{
case 1: if (p.getPacidentificacion().equals(valor))
mostrarEnTabla(p);
break;
case 2: if (p.getPacnombres().equals(valor))
mostrarEnTabla(p);
break;
case 3: if (p.getPacapellidos().equals(valor))
mostrarEnTabla(p);
break;
case 4: if (p.getPacsexo().equals(valor))
mostrarEnTabla(p);
break;
}
}
}
private void mostrarEnTabla(modelo.Pacientes p)
{
String registro[] = new String [5];
registro[0]=p.getPacidentificacion();
registro[1]=p.getPacnombres();
registro[2]=p.getPacapellidos();
registro[3]=p.getPacfechanacimiento().toString();
registro[4]=p.getPacsexo().toString();
consultarPacienteVista.getTableModel().addRow(registro);
consultarPacienteVista.getTableModel().fireTableDataChanged();
INFORME:
package reportes;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;
}
}
public void ejecutarReporte(String archivo)
{
try
{
String Reporte = System.getProperty("user.dir") +
"/src/reportes/"+archivo;
JasperReport masterReport =
(JasperReport)JRLoader.loadObject(Reporte);
JasperPrint jasperPrint = JasperFillManager.fillReport(masterReport,
null, conexion);
JasperViewer jviewer = new JasperViewer(jasperPrint,false);
jviewer.setVisible(true);
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null,"error: "+ ex.getMessage());
}
}