IntelliJ seems to not recognize my getter methods

62 Views Asked by At

I'm trying to display data from a database in a TableView in JavaFx, and I'm using the class CheckAssunzione for creating my assunzione object that will be used to populate the table. I also have a refresh button that should update the lines in the table but is not working either. I don't get any errors/warnings in the terminal so I really don't know what is wrong but it's not filling up my table at all. Thanks for your help

DBUTILS CLASS THAT DOES THE DB QUERIES
    // assunzioni registrate dal paziente di ogni farmaco a lui prescritto
    public static int getAssunzioniGiornalierePerFarmaco(int pid, int fid) {
        Connection connection = DBConnection.getConn();
        PreparedStatement pst = null;
        try {
            pst = connection.prepareStatement("SELECT COUNT(pid) AS n_ass FROM assunzione WHERE  pid = ? AND fid = ? AND date(dataora) = current_date");
            pst.setInt(1, pid);
            pst.setInt(2, fid);
            ResultSet rs = pst.executeQuery();
            if (rs.next()) {
                return rs.getInt("n_ass");
            }
        }catch (SQLException e){
            System.out.println("Errore lettura dati" + e.getMessage());
        }
        return 0;
    }

    //assunzioni prescritte al paziente di ogni farmaco
    public static int getAssunzioniPrescrittePerFarmaco(int pid, int fid) {
        Connection connection = DBConnection.getConn();
        PreparedStatement pst = null;
        try {
            pst = connection.prepareStatement("SELECT n_ass FROM terapia WHERE  pid = ? AND fid = ?");
            pst.setInt(1, pid);
            pst.setInt(2, fid);
            ResultSet rs = pst.executeQuery();
            if (rs.next()) {
                return rs.getInt("n_ass");
            }
        }catch (SQLException e){
            System.out.println("Errore lettura dati" + e.getMessage());
        }
        return 0;
    }
}
CHECKASSUNZIONE CLASS
package com.example.demosw2023;

public class CheckAssunzione {
    private String nomeF;
    private int n_assP;
    private int n_assG;

    public CheckAssunzione(String nomeF, int n_assP, int n_assG) {
        this.nomeF = nomeF;
        this.n_assP = n_assP;
        this.n_assG = n_assG;
    }

    public String getNomeF() {
        return nomeF;
    }

    public int getN_assP() {
        return n_assP;
    }

    public int getN_assG() {
        return n_assG;
    }
}
CONTROLLER CLASS THAT HAS THE TABLE
package com.example.demosw2023;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import java.net.URL;
import java.sql.*;
import java.util.ResourceBundle;

public class LoggedInPazController implements Initializable{
    static int pidPaz;
    static {
        pidPaz = GetPid.pid;
    }
    @FXML
    private Button b_logout;
    @FXML
    private Label label_welcome;
    @FXML
    private Button b_pressione;
    @FXML
    private Button b_sintomi;
    @FXML
    private Button b_farmaci;
    @FXML
    private Button b_segnalazioni;
    @FXML
    private Button b_contatta;
    @FXML
    private Button b_terapie;
    @FXML
    private Button b_refresh;

    @FXML
    private TableView<CheckAssunzione> tb_checkassunzioni;
    ObservableList<CheckAssunzione> alert = FXCollections.observableArrayList();
    @FXML
    private TableColumn<CheckAssunzione, String> tc_farmaco;
    @FXML
    private TableColumn<CheckAssunzione, Integer> tc_assunzioniGiornaliere;
    @FXML
    private TableColumn<CheckAssunzione, Integer> tc_assunzioniPrescritte;

    public void visualizzaAssunzioni(int pidPaz){
        Connection connection = DBConnection.getConn();
        PreparedStatement pst_F;
        ResultSet rs_F;
        try{
            pst_F = connection.prepareStatement("SELECT F.nome, F.fid FROM terapia T JOIN farmaco F on T.fid = F.fid WHERE pid = ?");
            pst_F.setInt(1, pidPaz);
            rs_F = pst_F.executeQuery();

            alert.clear();
            while (rs_F.next()) {
                String nomeF = rs_F.getString("nome");
                int n_assP = DBUtils.getAssunzioniPrescrittePerFarmaco(pidPaz, rs_F.getInt("fid"));
                int n_assG = DBUtils.getAssunzioniGiornalierePerFarmaco(pidPaz, rs_F.getInt("fid"));
                CheckAssunzione assunzione = new CheckAssunzione(nomeF, n_assP, n_assG);
                alert.add(assunzione);
            }
            tb_checkassunzioni.setItems(alert);
        }catch(SQLException e){
            System.out.println("Errore lettura dati" + e.getMessage());
        }

    }

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        tc_farmaco.setCellValueFactory(new PropertyValueFactory<>("nomeF"));
        tc_assunzioniPrescritte.setCellValueFactory(new PropertyValueFactory<>("n_assP"));
        tc_assunzioniGiornaliere.setCellValueFactory(new PropertyValueFactory<>("n_assG"));
        b_refresh.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                visualizzaAssunzioni(pidPaz);
            }
        });

        b_logout.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) { View.changeScene(event, "AccessOpt.fxml", "Log in!");
            }
        });
        b_pressione.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                View.popUpScene(event, "RegistraPressione.fxml", "Registra le pressioni giornaliere");
            }
        });
        b_farmaci.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                View.popUpScene(event, "RegistraAssunzione.fxml", "Registra le assunzioni di farmaci");
            }
        });
        b_contatta.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                View.messageScene(event, "Contatta.fxml", "Contatta medico");
            }
        });
        b_sintomi.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                View.popUpScene(event, "RegistraSintomo.fxml", "Registra i sintomi");
            }
        });
        b_segnalazioni.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                View.popUpScene(event, "RegistraPatologie.fxml", "Registra le patologie");
            }
        });
        b_terapie.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                View.popUpScene(event, "RegistraTerapia.fxml", "Registra terapie concomitanti");
            }
        });

    }

    public void setUserInformation(String nome, String cognome){
        label_welcome.setText("Benvenut@ "+nome+" "+cognome+"!");
    }


}

I've already populated another table using the same procedure and that is working properly.

0

There are 0 best solutions below