So I have an application that I am building on the side for experience which is like a Personal Health Record. I am using Java and Java FX to complete this task. Essentially I have a method in a database helper class to get all of the Medical Providers as Provider objects into an ArrayList instance. Instead of it showing all of the attributes of the Object it is referencing, how do I customize this to just show their name and credentials. Keep in mind that this is connected to a MySQL database instance, and each Provider object has a variable called dbID, which is how the queriers are run. So I will need to get the dbID value when the option in the combobox is selected.
Code to get Information from DB:
public ArrayList<Provider> getAllProvidersByPatientID(int patientID) throws SQLException
{
ArrayList<Provider> providerArrayList = new ArrayList<>();
connect = ConnectionManager.getConnection();
statement = connect.createStatement();
resultSet = statement.executeQuery("SELECT * FROM PROVIDER WHERE patientID = " + patientID);
while(resultSet.next())
{
Provider p = new Provider();
p.setDbID(resultSet.getInt("idPROVIDER"));
p.setFirstName(resultSet.getString("firstName"));
p.setLastName(resultSet.getString("lastName"));
p.setCredentials(resultSet.getString("credentials"));
p.setSpecialty(resultSet.getString("specialty"));
p.setNpiNumber(resultSet.getString("NPI_Number"));
p.setStartedSeeing(resultSet.getDate("startDate"));
p.setStoppedSeeing(resultSet.getDate("endDate"));
p.setPhoneNumber(resultSet.getString("phoneNumber"));
p.setFaxNumber(resultSet.getString("faxNumber"));
p.setNotes(resultSet.getString("notes"));
boolean isActive;
if(resultSet.getInt("active") == 1)
isActive = true;
else
isActive = false;
p.setActive(isActive);
providerArrayList.add(p);
}
return providerArrayList;
}
Variables of the Provider Class:
public class Provider {
private String firstName;
private int dbID;
private String lastName;
private String credentials;
private String organization;
private String specialty;
private String npiNumber;
private Date startedSeeing;
private Date stoppedSeeing;
private String phoneNumber;
private String faxNumber;
private String address;
private String notes;
private boolean active;
//All variables here have getters and setters.
}
This is the code snippet that I used to fill the combobox:
providerCB.getItems().addAll(providerDBHelper.getAllProvidersByPatientID(1));
Which is almost like it calls the toString() method to fill in the combobox dropdowns.