public SearchPatient(final String type, final int docID) {

    try {
      // "Load" the JDBC driver
      Class.forName("java.sql.Driver");

      // Establish the connection to the database
      String url = "jdbc:mysql://localhost:3306/cse";
      conn = DriverManager.getConnection(url, "root", "admin");
    } catch (Exception e) {
      System.err.println("Got an exception!");
      System.err.println(e.getMessage());
    }

    // Menu
    // MENU ACTIONS

    // Action to view new patient registered
    class NewPatientAction extends AbstractAction {
      private static final long serialVersionUID = 1L;

      public NewPatientAction() {
        putValue(SHORT_DESCRIPTION, "View list of new patients");
      }

      public void actionPerformed(ActionEvent e) {
        ViewRegisteredPatients vp = new ViewRegisteredPatients("new");
        vp.setVisible(true);
        ViewRegisteredPatients.hasNew = false;
      }
    }
    Action newPatientAction = new NewPatientAction();

    // Action to view all patient registered
    class AllPatientAction extends AbstractAction {
      private static final long serialVersionUID = 1L;

      public AllPatientAction() {
        putValue(SHORT_DESCRIPTION, "View list of all patients");
      }

      public void actionPerformed(ActionEvent e) {
        ViewRegisteredPatients vp = new ViewRegisteredPatients("all");
        vp.setVisible(true);
      }
    }
    Action allPatientAction = new AllPatientAction();

    // Action to open Statistical Report
    class StatsReportAction implements MenuListener {
      public void menuSelected(MenuEvent e) {
        StatsReport report = new StatsReport();
        setAlwaysOnTop(false);
        report.setVisible(true);
        report.setAlwaysOnTop(true);
      }

      public void menuDeselected(MenuEvent e) {}

      public void menuCanceled(MenuEvent e) {}
    }

    // Action to open Statistical Report
    class ProfileAction implements MenuListener {
      public void menuSelected(MenuEvent e) {
        Profile profilePage = new Profile("staff", docID, type);
        profilePage.setVisible(true);
        dispose();
      }

      public void menuDeselected(MenuEvent e) {}

      public void menuCanceled(MenuEvent e) {}
    }

    // MENU COMPONENTS
    menu = new JMenuBar();

    menuOp1 = new JMenu();
    menuOp2 = new JMenu();
    menuOp3 = new JMenu();
    menuOp4 = new JMenu();
    menuOp5 = new JMenu();

    menuOp1.setText("Profile");
    menuOp1.addMenuListener(new ProfileAction());

    optionsFrame = new JFrame("Options");

    optionsContainer = new JPanel();
    optionsContainer.setLayout(new BoxLayout(optionsContainer, BoxLayout.Y_AXIS));
    optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));

    if (type.equals("Doctor")) // if a doctor is logging in
    {
      menuOp2.setText("Patients");
      menuOp3.setText("Appointments Request");
      menuOp4.setText("View Medical Alerts");

      menuItem1 = new JMenuItem("Search Patient");

      menuOp2.add(menuItem1);

      menu.add(menuOp1);
      menu.add(menuOp2);
      menu.add(menuOp3);
      menu.add(menuOp4);

      // optionsFrame
      optionUpdateHCC = new JLabel("Update Healthcare Condition");
      optionUpdateHCC.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionUpdateHCC.addMouseListener(new MouseUpdateHCCListener());

      optionPrescription = new JLabel("e-Prescription");
      optionPrescription.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      // optionPrescription.addMouseListener(new MousePrescriptionListener());

      optionLabRecord = new JLabel("View Lab Records");
      optionLabRecord.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionLabRecord.addMouseListener(new MouseLabRecordListener());

      optionUpdateHCR = new JLabel("Update Healthcare Records");
      optionUpdateHCR.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionUpdateHCR.addMouseListener(new MouseUpdateHCRListener());

      // add option to container
      optionsContainer.add(optionUpdateHCC);
      optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));
      optionsContainer.add(optionPrescription);
      optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));
      optionsContainer.add(optionLabRecord);
      optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));
      optionsContainer.add(optionLabRecord);
      optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));
      optionsContainer.add(optionUpdateHCR);
    } else if (type.equals("HSP")) // if the HSP is logging in
    {
      menuOp2.setText("Patients");
      menuOp3.setText("Appointment Request");
      menuOp4.setText("View Medical Alerts");
      menuOp5.setText("Generate Statistical Report");
      menuOp5.addMenuListener(new StatsReportAction());

      menuItem1 = new JMenuItem("Search Patient");
      menuOp6 = new JMenu("List of Registered Patient");
      menuOp6.setMnemonic(KeyEvent.VK_S);

      menuItem2 = new JMenuItem(newPatientAction);
      menuItem2.setText("List of New Registered Patient");
      menuItem3 = new JMenuItem(allPatientAction);
      menuItem3.setText("List of All Registered Patient");

      menuOp2.add(menuItem1);
      menuOp2.add(menuOp6);
      menuOp6.add(menuItem2);
      menuOp6.add(menuItem3);

      menu.add(menuOp1);
      menu.add(menuOp2);
      menu.add(menuOp3);
      menu.add(menuOp4);
      menu.add(menuOp5);

      // optionsFrame
      optionUpdateHCC = new JLabel("Update Healthcare Condition");
      optionUpdateHCC.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionUpdateHCC.addMouseListener(new MouseUpdateHCCListener());

      optionLabRecord = new JLabel("View Lab Records");
      optionLabRecord.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionLabRecord.addMouseListener(new MouseLabRecordListener());

      optionHCR = new JLabel("Upload Healthcare Records");
      optionHCR.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionHCR.addMouseListener(new MouseUploadHCRListener());

      optionUpdateHCR = new JLabel("Update Healthcare Records");
      optionUpdateHCR.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionUpdateHCR.addMouseListener(new MouseUpdateHCRListener());

      // add option to container
      optionsContainer.add(optionUpdateHCC);
      optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));
      optionsContainer.add(optionLabRecord);
      optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));
      optionsContainer.add(optionLabRecord);
      optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));
      optionsContainer.add(optionHCR);
      optionsContainer.add(Box.createRigidArea(new Dimension(20, 5)));
      optionsContainer.add(optionUpdateHCR);
    } else if (type.equals("Pharmacist")) // if the Pharmacist is logging in
    {
      menuOp2.setText("Patients");

      menuItem1 = new JMenuItem("Search Patients");

      menuOp2.add(menuItem1);

      menu.add(menuOp1);
      menu.add(menuOp2);

      // optionsFrame
      optionViewPrescription = new JLabel("View e-Prescription");
      optionViewPrescription.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionViewPrescription.addMouseListener(new MouseViewPrescriptionListener());

      // add option to container
      optionsContainer.add(optionViewPrescription);

    } else if (type.equals("Nurse")) // if the nurse is logging in
    {
      menuOp2.setText("Patients");

      menuItem1 = new JMenuItem("Search Patients");

      menuOp2.add(menuItem1);

      menu.add(menuOp1);
      menu.add(menuOp2);

      // optionsFrame
      optionUpdateHCR = new JLabel("Update Healthcare Records");
      optionUpdateHCR.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      optionUpdateHCR.addMouseListener(new MouseUpdateHCRListener());

      // add option to container
      optionsContainer.add(optionUpdateHCR);
    }

    // Labels
    firstNameLabel = new JLabel(" First name:"); // first name label
    lastNameLabel = new JLabel("Last name:"); // last name label
    patientListLabel = new JLabel("Patient List:"); // patient list label

    // Text Fields
    firstNameField = new JTextField(10); // first name text field
    lastNameField = new JTextField(10); // last name text field

    // Buttons
    searchButton = new JButton("Search"); // search button
    searchButton.addActionListener(new SearchButtonListener()); // add listener

    selectButton = new JButton("Select");
    selectButton.addActionListener(new SelectButtonListener()); // add listener

    cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new CancelButtonListener()); // add listener

    // JPanels
    firstNamePanel = new JPanel(); // First name panel
    firstNamePanel.add(firstNameLabel);
    firstNamePanel.add(firstNameField);

    lastNamePanel = new JPanel(); // Last name panel
    lastNamePanel.add(lastNameLabel);
    lastNamePanel.add(lastNameField);

    patientInfoPanel = new JPanel();
    patientInfoPanel.setLayout(new BoxLayout(patientInfoPanel, BoxLayout.X_AXIS));
    patientInfoPanel.add(firstNamePanel);
    patientInfoPanel.add(lastNamePanel);
    patientInfoPanel.add(searchButton);

    buttonPanel = new JPanel(); // button panel
    buttonPanel.add(selectButton);
    buttonPanel.add(cancelButton);

    // Patient List
    patientVector = new Vector(); // Vector of Patient objects
    patientList =
        new JList(patientVector); // creates a JList that show the content of the recordVector

    scrollPatientList = new JScrollPane(patientList); // add scroll option to the list
    patientList.setSelectionMode(
        ListSelectionModel.SINGLE_SELECTION); // Allow the selection of only one item at a time

    String[] patients = new String[1000000];

    // Populates the patient list with the patients from the database
    if (type.equals("Doctor")) {
      int i = 0;
      try {
        // checks if the patient is a patient of the doctor logged
        statement = conn.createStatement();
        rs =
            statement.executeQuery(
                "SELECT * FROM appointments WHERE `docID`='" + docID + "' ORDER BY `patientID`");

        while (rs.next()) {
          int patientID = rs.getInt("patientID");
          patients[i] = String.valueOf(patientID);

          i++;
        }

        String[] patientSet =
            (String[]) new HashSet(Arrays.asList(patients)).toArray(new String[0]);

        // gets information from the specific set of patients
        for (int j = 0; j < patientSet.length; j++) {
          statement = conn.createStatement();
          rs =
              statement.executeQuery(
                  "SELECT * FROM patient WHERE `idpatient`='" + patientSet[j] + "';");

          while (rs.next()) {
            Patient obj = new Patient();
            obj.setFirstName(rs.getString("fname"));
            obj.setLastName(rs.getString("lname"));
            obj.setDOB(rs.getString("dob"));
            obj.setPatientId(Integer.parseInt(patientSet[j]));

            patientVector.add(obj);
          }
        }

      } catch (Exception e) {
        System.err.println("Got an exception! ");
        System.err.println(e.getMessage());
        System.err.println(e);
      }
    } else {
      try {
        statement = conn.createStatement();
        rs = statement.executeQuery("SELECT * FROM patient ORDER BY fname");

        while (rs.next()) {
          Patient obj = new Patient();
          obj.setFirstName(rs.getString("fname"));
          obj.setLastName(rs.getString("lname"));
          obj.setDOB(rs.getString("dob"));
          obj.setPatientId(rs.getInt("idpatient"));

          patientVector.add(obj);
        }
      } catch (Exception e) {
        System.err.println("Got an exception! ");
        System.err.println(e.getMessage());
      }
    }

    searchVector = new Vector();

    // set options frame
    optionsFrame.add(optionsContainer);
    optionsFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // close the window on close
    optionsFrame.setSize(300, 150); // set size of window
    optionsFrame.setLocation(600, 280);
    optionsFrame.setVisible(false);

    searchPanel = new JPanel();
    searchPanel.setLayout(new BoxLayout(searchPanel, BoxLayout.Y_AXIS));
    searchPanel.add(patientInfoPanel);
    searchPanel.add(patientListLabel);
    searchPanel.add(scrollPatientList);
    searchPanel.add(buttonPanel);

    Border padding = BorderFactory.createEmptyBorder(20, 20, 10, 10);
    searchPanel.setBorder(padding);

    setJMenuBar(menu);
    add(searchPanel);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(1200, 580);
  }
Пример #2
0
  private void jbInit() throws Exception {
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    this.setIconImage(icon.getImage());
    this.addComponentListener(
        new java.awt.event.ComponentAdapter() {
          public void componentShown(ComponentEvent e) {
            this_componentShown(e);
          }
        });
    this.getContentPane().setLayout(borderLayout1);
    this.addWindowListener(
        new java.awt.event.WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            this_windowClosing(e);
          }
        });
    this.setJMenuBar(menuBar);

    // This size is chosen so that when the user hits the Info tool, the
    // window
    // fits between the lower edge of the TaskFrame and the lower edge of
    // the
    // WorkbenchFrame. See the call to #setSize in InfoFrame. [Jon Aquino]
    setSize(900, 665);

    // OUTLINE_DRAG_MODE is excruciatingly slow in JDK 1.4.1, so don't use
    // it.
    // (although it's supposed to be fixed in 1.4.2, which has not yet been
    // released). (see Sun Java Bug ID 4665237). [Jon Aquino]
    // desktopPane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    messageLabel.setOpaque(true);
    memoryLabel.setText("jLabel1");
    wmsLabel.setHorizontalAlignment(SwingConstants.LEFT);
    wmsLabel.setText(" ");
    this.getContentPane().add(statusPanel, BorderLayout.SOUTH);
    exitMenuItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            exitMenuItem_actionPerformed(e);
          }
        });
    windowMenu.addMenuListener(
        new javax.swing.event.MenuListener() {
          public void menuCanceled(MenuEvent e) {}

          public void menuDeselected(MenuEvent e) {}

          public void menuSelected(MenuEvent e) {
            windowMenu_menuSelected(e);
          }
        });
    coordinateLabel.setBorder(BorderFactory.createLoweredBevelBorder());
    wmsLabel.setBorder(BorderFactory.createLoweredBevelBorder());
    coordinateLabel.setText(" ");
    statusPanel.setLayout(gridBagLayout1);
    statusPanel.setBorder(BorderFactory.createRaisedBevelBorder());
    messageLabel.setBorder(BorderFactory.createLoweredBevelBorder());
    messageLabel.setText(" ");
    timeLabel.setBorder(BorderFactory.createLoweredBevelBorder());
    timeLabel.setText(" ");
    memoryLabel.setBorder(BorderFactory.createLoweredBevelBorder());
    memoryLabel.setText(" ");
    menuBar.add(fileMenu);
    menuBar.add(windowMenu);
    getContentPane().add(toolBar, BorderLayout.NORTH);
    getContentPane().add(desktopPane, BorderLayout.CENTER);
    fileMenu.addSeparator();
    fileMenu.add(exitMenuItem);
    statusPanel.add(
        coordinateLabel,
        new GridBagConstraints(
            5,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));
    statusPanel.add(
        timeLabel,
        new GridBagConstraints(
            2,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));
    statusPanel.add(
        messageLabel,
        new GridBagConstraints(
            1,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));

    // Give memoryLabel the 1.0 weight. All the rest should have their
    // sizes
    // configured using #configureStatusLabel. [Jon Aquino]
    statusPanel.add(
        memoryLabel,
        new GridBagConstraints(
            3,
            1,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));
    statusPanel.add(
        wmsLabel,
        new GridBagConstraints(
            4,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));
  }