Compare commits

..

2 commits

Author SHA1 Message Date
arminribic
d8a7c9a59c #10: Update Views to Reflect Locked and Active Nurses
All checks were successful
Quality Check / Qualty Check (push) Successful in 9s
2024-05-14 14:53:42 +02:00
arminribic
f212cfe760 #10: Modify Model, Dao and Fixtures 2024-05-14 14:53:10 +02:00
12 changed files with 130 additions and 67 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="nursingHome.db" uuid="5a5b8be1-080b-4129-b89d-42f1ea832b90">
<data-source source="LOCAL" name="Database" uuid="5a5b8be1-080b-4129-b89d-42f1ea832b90">
<driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>

View file

@ -3,6 +3,7 @@
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/src/main/java/de/hitec/nhplus/patient/database/PatientDao.java" dialect="GenericSQL" />
<file url="file://$PROJECT_DIR$/src/main/java/de/hitec/nhplus/treatment/database/TreatmentDao.java" dialect="GenericSQL" />
<file url="file://$PROJECT_DIR$/src/main/java/de/hitec/nhplus/treatment/database/NurseDao.java" dialect="GenericSQL" />
<file url="PROJECT" dialect="SQLite" />
</component>
</project>

Binary file not shown.

View file

@ -40,6 +40,14 @@ public class NurseFixture implements Fixture<Nurse> {
"Armout",
"9876543210"
));
nurses.add(new Nurse(
"Björnd",
"Heideberger",
"69420",
true
));
NurseDao dao = DaoFactory.getInstance().createNurseDAO();
for (Nurse nurse : nurses) {
dao.create(nurse);

View file

@ -3,6 +3,7 @@ package de.hitec.nhplus.main;
import de.hitec.nhplus.Main;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.SelectionModel;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.AnchorPane;
@ -23,30 +24,30 @@ public class MainWindowController {
@FXML
private Tab treatmentTab;
@FXML
private TabPane nurseTabPane;
@FXML
private AnchorPane nursePage;
@FXML
private Tab nurseTab;
@FXML
private AnchorPane lockedNursePage;
@FXML
private Tab lockedNurseTab;
private TabPane nurseTabPane;
@FXML
private AnchorPane activeNursePage;
@FXML
private Tab activeNurseTab;
@FXML
private AnchorPane lockedNursePage;
@FXML
private Tab lockedNurseTab;
@FXML
public void initialize() {
loadPatientPage();
mainTabPane.getSelectionModel().select(patientTab);
nurseTabPane.getSelectionModel().select(activeNurseTab);
patientTab.setOnSelectionChanged(event -> loadPatientPage());
treatmentTab.setOnSelectionChanged(event -> loadTreatmentsPage());
nurseTab.setOnSelectionChanged(event -> loadNursePage());
nurseTabPane.getSelectionModel().select(activeNurseTab);
activeNurseTab.setOnSelectionChanged(event -> loadActiveNursePage());
lockedNurseTab.setOnSelectionChanged(event -> loadLockedNursePage());
}
@ -82,15 +83,18 @@ public class MainWindowController {
}
private void loadNursePage() {
try {
nurseTabPane.getSelectionModel().select(activeNurseTab);
SelectionModel<Tab> selectionModel = nurseTabPane.getSelectionModel();
Tab selectedTab = selectionModel.getSelectedItem();
if(selectedTab == activeNurseTab){
loadActiveNursePage();
} catch (Exception exception) {
exception.printStackTrace();
}
if(selectedTab == lockedNurseTab){
loadLockedNursePage();
}
}
private void loadActiveNursePage() {
System.out.println("TODO: Active Nurse");
try {
BorderPane activeNursePane = FXMLLoader.load(
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/nurse/AllNurseView.fxml"))
@ -106,6 +110,7 @@ public class MainWindowController {
}
private void loadLockedNursePage() {
System.out.println("TODO: Locked Nurse");
try {
BorderPane lockedNursePane = FXMLLoader.load(
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/nurse/LockedNurseView.fxml"))

View file

@ -78,7 +78,7 @@ public class AllNurseController {
this.nurses.clear();
this.dao = DaoFactory.getInstance().createNurseDAO();
try {
this.nurses.addAll(this.dao.readAll());
this.nurses.addAll(this.dao.readAllActive());
}catch (SQLException exception){
exception.printStackTrace();
}
@ -100,14 +100,17 @@ public class AllNurseController {
@FXML
public void handleLock(){
Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem();
if (selectedItem != null){
if (selectedItem == null){
return;
}
try {
DaoFactory.getInstance().createNurseDAO().delete(selectedItem.getId());
this.tableView.getItems().remove(selectedItem);
selectedItem.setLocked(true);
this.dao.update(selectedItem);
}catch (SQLException exception){
exception.printStackTrace();
}
}
readAllAndShowInTableView();
}
private void clearTextfields() {

View file

@ -37,6 +37,8 @@ public class LockedNurseController {
private NurseDao dao;
public void initialize() {
this.readAllAndShowInTableView();
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
this.columnFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName"));
@ -48,32 +50,47 @@ public class LockedNurseController {
this.columnDeleteDate.setCellValueFactory(new PropertyValueFactory<>("date"));
this.columnDeleteDate.setCellFactory(TextFieldTableCell.forTableColumn());
// this.tableView.setItems(this.nurses);
this.tableView.setItems(this.nurses);
}
@FXML
public void handleDelete(){
Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem();
if (selectedItem != null){
private void readAllAndShowInTableView() {
this.nurses.clear();
this.dao = DaoFactory.getInstance().createNurseDAO();
try {
DaoFactory.getInstance().createNurseDAO().delete(selectedItem.getId());
this.tableView.getItems().remove(selectedItem);
this.nurses.addAll(this.dao.readAllLocked());
} catch (SQLException exception) {
exception.printStackTrace();
}
}
}
@FXML
public void changeLockStatus(){
public void handleDelete() {
Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem();
if ( !selectedItem.getisLocked()){
selectedItem.setLocked(true);
} else if (selectedItem.getisLocked()) {
selectedItem.setLocked(false);
if (selectedItem == null) {
return;
}
try {
this.dao.delete(selectedItem.getId());
} catch (SQLException exception) {
exception.printStackTrace();
}
}
@FXML
public void changeUnlock() {
Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem();
if (selectedItem == null) {
return;
}
try {
selectedItem.setLocked(false);
this.dao.update(selectedItem);
} catch (SQLException exception) {
exception.printStackTrace();
}
readAllAndShowInTableView();
}
}

View file

@ -10,7 +10,7 @@ import java.util.StringJoiner;
public class Nurse extends Person {
private SimpleIntegerProperty id;
private final SimpleStringProperty phoneNumber;
private boolean isLocked;
private final SimpleBooleanProperty locked;
public Nurse(
@ -20,19 +20,30 @@ public class Nurse extends Person {
) {
super(firstName, surName);
this.phoneNumber = new SimpleStringProperty(phoneNumber);
this.isLocked = false;
this.locked = new SimpleBooleanProperty(false);
}
public Nurse(
String firstName,
String surName,
String phoneNumber,
Boolean isLocked
) {
super(firstName, surName);
this.phoneNumber = new SimpleStringProperty(phoneNumber);
this.locked = new SimpleBooleanProperty(isLocked);
}
public Nurse(
int id,
String firstName,
String surName,
String phoneNumber
String phoneNumber,
Boolean isLocked
) {
super(firstName, surName);
this.id = new SimpleIntegerProperty(id);
this.phoneNumber = new SimpleStringProperty(phoneNumber);
this.isLocked = false;
this.locked = new SimpleBooleanProperty(isLocked);
}
public void setPhoneNumber(String phoneNumber) {
@ -54,16 +65,20 @@ public class Nurse extends Person {
public SimpleStringProperty phoneNumberProperty() {
return phoneNumber;
}
public boolean getisLocked() {
return isLocked;
public boolean isLocked() {
return locked.get();
}
public SimpleBooleanProperty lockedProperty() {
return locked;
}
public void setLocked(boolean locked) {
isLocked = locked;
this.locked.set(locked);
}
@Override
public String toString() {
return new StringJoiner(System.lineSeparator())

View file

@ -19,13 +19,14 @@ public class NurseDao extends DaoImp<Nurse> {
protected PreparedStatement getCreateStatement(Nurse nurse) throws SQLException {
final String SQL = """
INSERT INTO nurse
(firstName, surName, phoneNumber)
VALUES (?, ?, ?)
(firstName, surName, phoneNumber, isLocked)
VALUES (?, ?, ?, ?)
""";
PreparedStatement statement = this.connection.prepareStatement(SQL);
statement.setString(1, nurse.getFirstName());
statement.setString(2, nurse.getSurName());
statement.setString(3, nurse.getPhoneNumber());
statement.setBoolean(4, nurse.isLocked());
return statement;
}
@ -43,7 +44,8 @@ public class NurseDao extends DaoImp<Nurse> {
result.getInt(1),
result.getString(2),
result.getString(3),
result.getString(4)
result.getString(4),
result.getBoolean(5)
);
}
@ -62,20 +64,32 @@ public class NurseDao extends DaoImp<Nurse> {
return list;
}
public List<Nurse> readAllActive() throws SQLException {
final String SQL = "SELECT * FROM nurse WHERE isLocked=false";
return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery());
}
public List<Nurse> readAllLocked() throws SQLException {
final String SQL = "SELECT * FROM nurse WHERE isLocked=true";
return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery());
}
@Override
protected PreparedStatement getUpdateStatement(Nurse nurse) throws SQLException {
final String SQL = """
UPDATE nurse SET
firstName = ?,
surName = ?,
phoneNumber = ?
phoneNumber = ?,
isLocked = ?
WHERE id = ?
""";
PreparedStatement statement = this.connection.prepareStatement(SQL);
statement.setString(1, nurse.getFirstName());
statement.setString(2, nurse.getSurName());
statement.setString(3, nurse.getPhoneNumber());
statement.setInt(4, nurse.getId());
statement.setBoolean(4, nurse.isLocked());
statement.setInt(5, nurse.getId());
return statement;
}

View file

@ -17,11 +17,11 @@
<AnchorPane fx:id="treatmentPage"/>
</Tab>
<Tab fx:id="nurseTab" text="Pfleger">
<TabPane fx:id="nurseTabPane">
<TabPane fx:id="nurseTabPane" tabClosingPolicy="UNAVAILABLE">
<Tab fx:id="activeNurseTab" text="Pfleger">
<AnchorPane fx:id="activeNursePage"/>
</Tab>
<Tab fx:id="lockedNurseTab" text="Gesperrt">
<Tab fx:id="lockedNurseTab" text="Gesperrte Pfleger">
<AnchorPane fx:id="lockedNursePage"/>
</Tab>
</TabPane>

View file

@ -56,7 +56,13 @@
<right>
<HBox>
<spacing>8.0</spacing>
<Button
fx:id="buttonUnlock"
mnemonicParsing="false"
onAction="#changeUnlock"
prefWidth="90.0"
text="Entsperren"
/>
<Button
fx:id="buttonDelete"
mnemonicParsing="false"
@ -64,13 +70,6 @@
prefWidth="90.0"
text="Löschen"
/>
<Button
fx:id="buttonUnlock"
mnemonicParsing="false"
onAction="#changeLockStatus"
prefWidth="90.0"
text="Entsperren"
/>
</HBox>
</right>
</BorderPane>

View file

@ -3,5 +3,6 @@ CREATE TABLE nurse
id INTEGER PRIMARY KEY AUTOINCREMENT,
firstName TEXT NOT NULL,
surName TEXT NOT NULL,
phoneNumber TEXT NOT NULL
phoneNumber TEXT NOT NULL,
isLocked BOOLEAN NOT NULL DEFAULT false
)