Пример #1
0
  /**
   * Changes a patient in the database
   *
   * @param p The Patient object containing the new data (should have the same ID as the patient to
   *     replace)
   */
  public void updatePatient(Patient p) {
    try {
      statement =
          con.prepareStatement(
              "UPDATE patients SET firstname=?, lastname=?, preferredname=?, volunteer=?, "
                  + "gender=?, notes=?, clinic=?, availability=?, myoscar_verified=?, alerts=?, volunteer2=? WHERE patient_ID=?");
      statement.setString(1, p.getFirstName());
      statement.setString(2, p.getLastName());
      statement.setString(3, p.getPreferredName());
      statement.setInt(4, p.getVolunteer());
      statement.setString(5, p.getGender());
      statement.setString(6, p.getNotes());
      statement.setString(7, p.getClinic());
      statement.setString(8, p.getAvailability());
      statement.setString(9, p.getMyoscarVerified());
      statement.setString(10, p.getAlerts());
      statement.setInt(11, p.getPartner());
      statement.setInt(12, p.getPatientID());

      statement.execute();
    } catch (SQLException e) {
      System.out.println("Error: Could not update patient");
      e.printStackTrace();
    } finally {
      try {
        statement.close();
      } catch (Exception e) {
        // Ignore
      }
    }
  }
Пример #2
0
  /** Avoid duplicated record in DB */
  private boolean isExist(Patient patient) {
    int count = 0;
    try {
      statement =
          con.prepareStatement(
              "SELECT COUNT(*) as c FROM patients WHERE UPPER(firstname) = UPPER(?) "
                  + "AND UPPER(lastname) = UPPER(?) AND UPPER(email) = UPPER(?)");
      statement.setString(1, patient.getFirstName());
      statement.setString(2, patient.getLastName());
      statement.setString(3, patient.getEmail());

      rs = statement.executeQuery();
      rs.first();

      count = rs.getInt("c");

      if (rs != null) rs.close();

    } catch (SQLException e) {
      System.out.println("Error: Could not count volunteers");
      e.printStackTrace();

    } finally {
      try { // close statement
        if (statement != null) statement.close();
      } catch (Exception e) {
        // Ignore
      }
    }

    if (count > 0) return true;
    else return false;
  }
Пример #3
0
  /**
   * Saves a patient in the database
   *
   * @param p The Patient object to save
   */
  public void createPatient(Patient p) {
    // check if it is new record in DB
    if (!isExist(p)) {
      try {
        statement =
            con.prepareStatement(
                "INSERT INTO patients (firstname, lastname, preferredname, volunteer,"
                    + " gender, notes, volunteer2, alerts, myoscar_verified, clinic, availability) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
        statement.setString(1, p.getFirstName());
        statement.setString(2, p.getLastName());
        statement.setString(3, p.getPreferredName());
        statement.setInt(4, p.getVolunteer());
        statement.setString(5, p.getGender());
        statement.setString(6, p.getNotes());
        statement.setInt(7, p.getPartner());
        statement.setString(8, p.getAlerts());
        statement.setString(9, p.getMyoscarVerified());
        statement.setString(10, p.getClinic());
        statement.setString(11, p.getAvailability());

        statement.execute();
      } catch (SQLException e) {
        System.out.println("Error: Could not create patient");
        e.printStackTrace();
      } finally {
        try {
          statement.close();
        } catch (Exception e) {
          // Ignore
        }
      }
    }
  }