Ejemplo n.º 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
      }
    }
  }
Ejemplo n.º 2
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
        }
      }
    }
  }