#24: Implement Deprecated and Available medications
This commit is contained in:
parent
6e33101494
commit
0aea0911b4
12 changed files with 89 additions and 24 deletions
Binary file not shown.
|
@ -117,7 +117,7 @@ public class MedicationFixture implements Fixture<Medication> {
|
||||||
"Unterhautinjektion",
|
"Unterhautinjektion",
|
||||||
120
|
120
|
||||||
));
|
));
|
||||||
medications.add(new Medication(
|
Medication deprecatedMedication = new Medication(
|
||||||
"Levothyroxin",
|
"Levothyroxin",
|
||||||
"Sandoz",
|
"Sandoz",
|
||||||
List.of(
|
List.of(
|
||||||
|
@ -129,7 +129,9 @@ public class MedicationFixture implements Fixture<Medication> {
|
||||||
"Herzrasen, Gewichtsverlust",
|
"Herzrasen, Gewichtsverlust",
|
||||||
"Oral",
|
"Oral",
|
||||||
90
|
90
|
||||||
));
|
);
|
||||||
|
deprecatedMedication.setIsDeprecated(true);
|
||||||
|
medications.add(deprecatedMedication);
|
||||||
medications.add(new Medication(
|
medications.add(new Medication(
|
||||||
"Warfarin",
|
"Warfarin",
|
||||||
"Apotex Inc.",
|
"Apotex Inc.",
|
||||||
|
|
|
@ -49,6 +49,8 @@ public class MainWindowController {
|
||||||
@FXML
|
@FXML
|
||||||
private Tab medicationTab;
|
private Tab medicationTab;
|
||||||
@FXML
|
@FXML
|
||||||
|
private Tab availableMedicationTab;
|
||||||
|
@FXML
|
||||||
private TabPane medicationTabPane;
|
private TabPane medicationTabPane;
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane deprecatedMedicationPage;
|
private AnchorPane deprecatedMedicationPage;
|
||||||
|
@ -71,7 +73,7 @@ public class MainWindowController {
|
||||||
|
|
||||||
activeNurseTab.setOnSelectionChanged(event -> loadActiveNursePage());
|
activeNurseTab.setOnSelectionChanged(event -> loadActiveNursePage());
|
||||||
lockedNurseTab.setOnSelectionChanged(event -> loadLockedNursePage());
|
lockedNurseTab.setOnSelectionChanged(event -> loadLockedNursePage());
|
||||||
medicationTab.setOnSelectionChanged(event -> loadMedicationPage());
|
availableMedicationTab.setOnSelectionChanged(event -> loadAvailableMedicationPage());
|
||||||
deprecatedMedicationTab.setOnSelectionChanged(event -> loadDeprecatedMedicationPage());
|
deprecatedMedicationTab.setOnSelectionChanged(event -> loadDeprecatedMedicationPage());
|
||||||
|
|
||||||
nurseTabPane.getSelectionModel().select(activeNurseTab);
|
nurseTabPane.getSelectionModel().select(activeNurseTab);
|
||||||
|
@ -164,10 +166,22 @@ public class MainWindowController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadMedicationPage()
|
||||||
|
{
|
||||||
|
SelectionModel<Tab> selectionModel = medicationTabPane.getSelectionModel();
|
||||||
|
Tab selectedTab = selectionModel.getSelectedItem();
|
||||||
|
if(selectedTab == availableMedicationTab){
|
||||||
|
loadAvailableMedicationPage();
|
||||||
|
}
|
||||||
|
if(selectedTab == deprecatedMedicationTab){
|
||||||
|
loadDeprecatedMedicationPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the medication page into its tab.
|
* Loads the medication page into its tab.
|
||||||
*/
|
*/
|
||||||
private void loadMedicationPage() {
|
private void loadAvailableMedicationPage() {
|
||||||
try {
|
try {
|
||||||
BorderPane medicationPane = FXMLLoader.load(
|
BorderPane medicationPane = FXMLLoader.load(
|
||||||
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/medication/AllMedicationView.fxml"))
|
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/medication/AllMedicationView.fxml"))
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class AllMedicationController {
|
||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
readAllAndShowInTableView();
|
this.readAllAndShowInTableView();
|
||||||
|
|
||||||
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
|
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
|
||||||
this.columnName.setCellValueFactory(new PropertyValueFactory<>("name"));
|
this.columnName.setCellValueFactory(new PropertyValueFactory<>("name"));
|
||||||
|
@ -85,6 +85,7 @@ public class AllMedicationController {
|
||||||
this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock"));
|
this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock"));
|
||||||
|
|
||||||
this.tableView.setItems(this.medications);
|
this.tableView.setItems(this.medications);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,7 +94,7 @@ public class AllMedicationController {
|
||||||
public void readAllAndShowInTableView() {
|
public void readAllAndShowInTableView() {
|
||||||
this.dao = DaoFactory.getInstance().createMedicationDAO();
|
this.dao = DaoFactory.getInstance().createMedicationDAO();
|
||||||
try {
|
try {
|
||||||
this.medications.setAll(dao.readAll());
|
this.medications.setAll(dao.readAllAvailable());
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -125,7 +126,7 @@ public class AllMedicationController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void handleChangeAvailable() {
|
public void handleChangeAvailable() {
|
||||||
Medication selectedItem = tableView.getSelectionModel().getSelectedItem();
|
Medication selectedItem = this.tableView.getSelectionModel().getSelectedItem();
|
||||||
if (selectedItem == null) {
|
if (selectedItem == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -136,7 +137,7 @@ public class AllMedicationController {
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
readAllAndShowInTableView();
|
this.readAllAndShowInTableView();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -38,9 +38,8 @@ public class DeprecatedMedicationController {
|
||||||
private final ObservableList<Medication> medications = FXCollections.observableArrayList();
|
private final ObservableList<Medication> medications = FXCollections.observableArrayList();
|
||||||
private MedicationDao dao;
|
private MedicationDao dao;
|
||||||
|
|
||||||
@FXML
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
readAllAndShowInTableView();
|
this.readAllAndShowInTableView();
|
||||||
|
|
||||||
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
|
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
|
||||||
this.columnName.setCellValueFactory(new PropertyValueFactory<>("name"));
|
this.columnName.setCellValueFactory(new PropertyValueFactory<>("name"));
|
||||||
|
@ -65,15 +64,17 @@ public class DeprecatedMedicationController {
|
||||||
this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock"));
|
this.columnCurrentStock.setCellValueFactory(new PropertyValueFactory<>("currentStock"));
|
||||||
|
|
||||||
this.tableView.setItems(this.medications);
|
this.tableView.setItems(this.medications);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal method to read all data and set it to the table view.
|
* Internal method to read all data and set it to the table view.
|
||||||
*/
|
*/
|
||||||
public void readAllAndShowInTableView() {
|
public void readAllAndShowInTableView() {
|
||||||
|
this.medications.clear();
|
||||||
this.dao = DaoFactory.getInstance().createMedicationDAO();
|
this.dao = DaoFactory.getInstance().createMedicationDAO();
|
||||||
try {
|
try {
|
||||||
this.medications.setAll(dao.readAllDeprecated());
|
this.medications.setAll(this.dao.readAllDeprecated());
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -91,7 +92,7 @@ public class DeprecatedMedicationController {
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
readAllAndShowInTableView();
|
this.readAllAndShowInTableView();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class Medication {
|
||||||
String possibleSideEffects,
|
String possibleSideEffects,
|
||||||
String administrationMethod,
|
String administrationMethod,
|
||||||
int currentStock,
|
int currentStock,
|
||||||
boolean isDepreacted
|
boolean isDeprecated
|
||||||
) {
|
) {
|
||||||
this.id = new SimpleIntegerProperty(id);
|
this.id = new SimpleIntegerProperty(id);
|
||||||
this.name = new SimpleStringProperty(name);
|
this.name = new SimpleStringProperty(name);
|
||||||
|
@ -70,7 +70,7 @@ public class Medication {
|
||||||
this.possibleSideEffects = new SimpleStringProperty(possibleSideEffects);
|
this.possibleSideEffects = new SimpleStringProperty(possibleSideEffects);
|
||||||
this.administrationMethod = new SimpleStringProperty(administrationMethod);
|
this.administrationMethod = new SimpleStringProperty(administrationMethod);
|
||||||
this.currentStock = new SimpleIntegerProperty(currentStock);
|
this.currentStock = new SimpleIntegerProperty(currentStock);
|
||||||
this.isDeprecated = new SimpleBooleanProperty(isDepreacted);
|
this.isDeprecated = new SimpleBooleanProperty(isDeprecated);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
|
|
|
@ -86,7 +86,6 @@ public class MedicationDao implements Dao<Medication> {
|
||||||
SELECT medication.*, medication_ingredient.name
|
SELECT medication.*, medication_ingredient.name
|
||||||
FROM medication LEFT JOIN
|
FROM medication LEFT JOIN
|
||||||
medication_ingredient ON medication.id = medication_ingredient.id
|
medication_ingredient ON medication.id = medication_ingredient.id
|
||||||
WHERE medication.isDeprecated = false
|
|
||||||
""";
|
""";
|
||||||
ResultSet result = connection.prepareStatement(SQL).executeQuery();
|
ResultSet result = connection.prepareStatement(SQL).executeQuery();
|
||||||
|
|
||||||
|
@ -133,7 +132,8 @@ public class MedicationDao implements Dao<Medication> {
|
||||||
final String SQL = """
|
final String SQL = """
|
||||||
SELECT medication.*, medication_ingredient.name
|
SELECT medication.*, medication_ingredient.name
|
||||||
FROM medication LEFT JOIN
|
FROM medication LEFT JOIN
|
||||||
medication_ingredient ON medication.id = medication_ingredient.id
|
medication_ingredient
|
||||||
|
ON medication.id = medication_ingredient.id
|
||||||
WHERE medication.isDeprecated = true
|
WHERE medication.isDeprecated = true
|
||||||
""";
|
""";
|
||||||
ResultSet result = connection.prepareStatement(SQL).executeQuery();
|
ResultSet result = connection.prepareStatement(SQL).executeQuery();
|
||||||
|
@ -177,6 +177,55 @@ public class MedicationDao implements Dao<Medication> {
|
||||||
return medications;
|
return medications;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Medication> readAllAvailable() throws SQLException {
|
||||||
|
final String SQL = """
|
||||||
|
SELECT medication.*, medication_ingredient.name
|
||||||
|
FROM medication LEFT JOIN
|
||||||
|
medication_ingredient
|
||||||
|
ON medication.id = medication_ingredient.id
|
||||||
|
WHERE medication.isDeprecated = false
|
||||||
|
""";
|
||||||
|
ResultSet result = connection.prepareStatement(SQL).executeQuery();
|
||||||
|
|
||||||
|
List<Medication> medications = new ArrayList<>();
|
||||||
|
Map<Integer, List<Ingredient>> ingredientMap = new HashMap<>();
|
||||||
|
|
||||||
|
int currentMedicationId;
|
||||||
|
int lastMedicationId = -1;
|
||||||
|
while (result.next()) {
|
||||||
|
currentMedicationId = result.getInt(1);
|
||||||
|
if (currentMedicationId != lastMedicationId) {
|
||||||
|
Medication medication = new Medication(
|
||||||
|
result.getInt(1),
|
||||||
|
result.getString(2),
|
||||||
|
result.getString(3),
|
||||||
|
new ArrayList<>(),
|
||||||
|
result.getString(4),
|
||||||
|
result.getString(5),
|
||||||
|
result.getInt(6),
|
||||||
|
result.getBoolean(7)
|
||||||
|
);
|
||||||
|
medications.add(medication);
|
||||||
|
}
|
||||||
|
List<Ingredient> ingredients = ingredientMap.computeIfAbsent(currentMedicationId, k -> new ArrayList<>());
|
||||||
|
String ingredientName = result.getString(8);
|
||||||
|
if(ingredientName == null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ingredients.add(new Ingredient(ingredientName));
|
||||||
|
lastMedicationId = currentMedicationId;
|
||||||
|
}
|
||||||
|
for (Medication medication : medications) {
|
||||||
|
List<Ingredient> ingredients = ingredientMap.get(medication.getId());
|
||||||
|
if(ingredients.isEmpty()){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
medication.setIngredients(ingredientMap.get(medication.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return medications;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Medication medication) throws SQLException {
|
public void update(Medication medication) throws SQLException {
|
||||||
final String SQL = """
|
final String SQL = """
|
||||||
|
@ -195,8 +244,8 @@ public class MedicationDao implements Dao<Medication> {
|
||||||
preparedStatement.setString(3, medication.getPossibleSideEffects());
|
preparedStatement.setString(3, medication.getPossibleSideEffects());
|
||||||
preparedStatement.setString(4, medication.getAdministrationMethod());
|
preparedStatement.setString(4, medication.getAdministrationMethod());
|
||||||
preparedStatement.setInt(5, medication.getCurrentStock());
|
preparedStatement.setInt(5, medication.getCurrentStock());
|
||||||
preparedStatement.setInt(6, medication.getId());
|
preparedStatement.setBoolean(6, medication.isDeprecated());
|
||||||
preparedStatement.setBoolean(7, medication.isDeprecated());
|
preparedStatement.setInt(7, medication.getId());
|
||||||
preparedStatement.executeUpdate();
|
preparedStatement.executeUpdate();
|
||||||
|
|
||||||
final String ingredientDeleteSQL = """
|
final String ingredientDeleteSQL = """
|
||||||
|
|
|
@ -112,6 +112,4 @@ public class NurseDao extends DaoImp<Nurse> {
|
||||||
statement.setInt(1, id);
|
statement.setInt(1, id);
|
||||||
return statement;
|
return statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class AllTreatmentController {
|
||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
readAllAndShowInTableView();
|
|
||||||
comboBoxPatientSelection.setItems(patientSelection);
|
comboBoxPatientSelection.setItems(patientSelection);
|
||||||
comboBoxPatientSelection.getSelectionModel().select("alle");
|
comboBoxPatientSelection.getSelectionModel().select("alle");
|
||||||
|
|
||||||
|
@ -109,6 +109,7 @@ public class AllTreatmentController {
|
||||||
);
|
);
|
||||||
|
|
||||||
this.createComboBoxData();
|
this.createComboBoxData();
|
||||||
|
readAllAndShowInTableView();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab fx:id="medicationTab" text="Medikamente">
|
<Tab fx:id="medicationTab" text="Medikamente">
|
||||||
<TabPane fx:id="medicationTabPane" tabClosingPolicy="UNAVAILABLE">
|
<TabPane fx:id="medicationTabPane" tabClosingPolicy="UNAVAILABLE">
|
||||||
<Tab fx:id="allMedicationTab" text="Medikamente">
|
<Tab fx:id="availableMedicationTab" text="Medikamente">
|
||||||
<AnchorPane fx:id="medicationPage"/>
|
<AnchorPane fx:id="medicationPage"/>
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab fx:id="deprecatedMedicationTab" text="Veraltete Medikamente">
|
<Tab fx:id="deprecatedMedicationTab" text="Veraltete Medikamente">
|
||||||
|
|
|
@ -6,5 +6,5 @@ CREATE TABLE medication
|
||||||
possibleSideEffects TEXT NOT NULL,
|
possibleSideEffects TEXT NOT NULL,
|
||||||
administrationMethod TEXT NOT NULL,
|
administrationMethod TEXT NOT NULL,
|
||||||
currentStock INTEGER NOT NULL,
|
currentStock INTEGER NOT NULL,
|
||||||
isDeprecated BOOLEAN NOT NULL DEFAULT FALSE
|
isDeprecated BOOLEAN NOT NULL DEFAULT false
|
||||||
)
|
)
|
|
@ -74,7 +74,6 @@
|
||||||
onAction="#handleDelete"
|
onAction="#handleDelete"
|
||||||
prefWidth="90.0"
|
prefWidth="90.0"
|
||||||
text="Löschen"
|
text="Löschen"
|
||||||
|
|
||||||
/>
|
/>
|
||||||
</HBox>
|
</HBox>
|
||||||
</right>
|
</right>
|
||||||
|
|
Loading…
Reference in a new issue