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"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true"> <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> <driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize> <synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver> <jdbc-driver>org.sqlite.JDBC</jdbc-driver>

View file

@ -3,6 +3,7 @@
<component name="SqlDialectMappings"> <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/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/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" /> <file url="PROJECT" dialect="SQLite" />
</component> </component>
</project> </project>

Binary file not shown.

View file

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

View file

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

View file

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

View file

@ -36,7 +36,9 @@ public class LockedNurseController {
private final ObservableList<Nurse> nurses = FXCollections.observableArrayList(); private final ObservableList<Nurse> nurses = FXCollections.observableArrayList();
private NurseDao dao; private NurseDao dao;
public void initialize(){ public void initialize() {
this.readAllAndShowInTableView();
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id")); this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
this.columnFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName")); this.columnFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName"));
@ -48,32 +50,47 @@ public class LockedNurseController {
this.columnDeleteDate.setCellValueFactory(new PropertyValueFactory<>("date")); this.columnDeleteDate.setCellValueFactory(new PropertyValueFactory<>("date"));
this.columnDeleteDate.setCellFactory(TextFieldTableCell.forTableColumn()); this.columnDeleteDate.setCellFactory(TextFieldTableCell.forTableColumn());
// this.tableView.setItems(this.nurses); this.tableView.setItems(this.nurses);
} }
private void readAllAndShowInTableView() {
@FXML this.nurses.clear();
public void handleDelete(){ this.dao = DaoFactory.getInstance().createNurseDAO();
Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem(); try {
if (selectedItem != null){ this.nurses.addAll(this.dao.readAllLocked());
try { } catch (SQLException exception) {
DaoFactory.getInstance().createNurseDAO().delete(selectedItem.getId()); exception.printStackTrace();
this.tableView.getItems().remove(selectedItem);
}catch (SQLException exception){
exception.printStackTrace();
}
} }
} }
@FXML @FXML
public void changeLockStatus(){ public void handleDelete() {
Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem(); Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem();
if ( !selectedItem.getisLocked()){ if (selectedItem == null) {
selectedItem.setLocked(true); return;
} else if (selectedItem.getisLocked()) { }
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); 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 { public class Nurse extends Person {
private SimpleIntegerProperty id; private SimpleIntegerProperty id;
private final SimpleStringProperty phoneNumber; private final SimpleStringProperty phoneNumber;
private boolean isLocked; private final SimpleBooleanProperty locked;
public Nurse( public Nurse(
@ -20,19 +20,30 @@ public class Nurse extends Person {
) { ) {
super(firstName, surName); super(firstName, surName);
this.phoneNumber = new SimpleStringProperty(phoneNumber); 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( public Nurse(
int id, int id,
String firstName, String firstName,
String surName, String surName,
String phoneNumber String phoneNumber,
Boolean isLocked
) { ) {
super(firstName, surName); super(firstName, surName);
this.id = new SimpleIntegerProperty(id); this.id = new SimpleIntegerProperty(id);
this.phoneNumber = new SimpleStringProperty(phoneNumber); this.phoneNumber = new SimpleStringProperty(phoneNumber);
this.isLocked = false; this.locked = new SimpleBooleanProperty(isLocked);
} }
public void setPhoneNumber(String phoneNumber) { public void setPhoneNumber(String phoneNumber) {
@ -54,16 +65,20 @@ public class Nurse extends Person {
public SimpleStringProperty phoneNumberProperty() { public SimpleStringProperty phoneNumberProperty() {
return phoneNumber; return phoneNumber;
} }
public boolean getisLocked() {
return isLocked;
public boolean isLocked() {
return locked.get();
} }
public SimpleBooleanProperty lockedProperty() {
return locked;
}
public void setLocked(boolean locked) { public void setLocked(boolean locked) {
isLocked = locked; this.locked.set(locked);
} }
@Override @Override
public String toString() { public String toString() {
return new StringJoiner(System.lineSeparator()) return new StringJoiner(System.lineSeparator())

View file

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

View file

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

View file

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

View file

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