parent
275aa3252a
commit
39ddd391f8
7 changed files with 148 additions and 87 deletions
|
@ -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>
|
||||||
|
|
Binary file not shown.
|
@ -1,17 +1,17 @@
|
||||||
package de.hitec.nhplus.fixtures;
|
package de.hitec.nhplus.fixtures;
|
||||||
|
|
||||||
import de.hitec.nhplus.Main;
|
|
||||||
import de.hitec.nhplus.datastorage.DaoFactory;
|
|
||||||
import de.hitec.nhplus.medication.Ingredient;
|
|
||||||
import de.hitec.nhplus.medication.Medication;
|
|
||||||
import de.hitec.nhplus.medication.database.MedicationDao;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import de.hitec.nhplus.Main;
|
||||||
|
import de.hitec.nhplus.datastorage.DaoFactory;
|
||||||
|
import de.hitec.nhplus.medication.Ingredient;
|
||||||
|
import de.hitec.nhplus.medication.Medication;
|
||||||
|
import de.hitec.nhplus.medication.database.MedicationDao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Fixture} for {@link Medication}.
|
* {@link Fixture} for {@link Medication}.
|
||||||
*
|
*
|
||||||
|
@ -20,11 +20,13 @@ import java.util.*;
|
||||||
public class MedicationFixture implements Fixture<Medication> {
|
public class MedicationFixture implements Fixture<Medication> {
|
||||||
private static final String SCHEMA = "/de/hitec/nhplus/medication/database/Medication.sql";
|
private static final String SCHEMA = "/de/hitec/nhplus/medication/database/Medication.sql";
|
||||||
private static final String INGREDIENT_SCHEMA = "/de/hitec/nhplus/medication/database/Medication_Ingredient.sql";
|
private static final String INGREDIENT_SCHEMA = "/de/hitec/nhplus/medication/database/Medication_Ingredient.sql";
|
||||||
|
private static final String ALTERNATIVE_SCHEMA = "/de/hitec/nhplus/medication/database/Medication_Alternative.sql";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dropTable(Connection connection) throws SQLException {
|
public void dropTable(Connection connection) throws SQLException {
|
||||||
connection.createStatement().execute("DROP TABLE IF EXISTS medication");
|
connection.createStatement().execute("DROP TABLE IF EXISTS medication");
|
||||||
connection.createStatement().execute("DROP TABLE IF EXISTS medication_ingredient");
|
connection.createStatement().execute("DROP TABLE IF EXISTS medication_ingredient");
|
||||||
|
connection.createStatement().execute("DROP TABLE IF EXISTS medication_alternative");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,16 +34,25 @@ public class MedicationFixture implements Fixture<Medication> {
|
||||||
|
|
||||||
final InputStream schema = Main.class.getResourceAsStream(SCHEMA);
|
final InputStream schema = Main.class.getResourceAsStream(SCHEMA);
|
||||||
final InputStream ingredientSchema = Main.class.getResourceAsStream(INGREDIENT_SCHEMA);
|
final InputStream ingredientSchema = Main.class.getResourceAsStream(INGREDIENT_SCHEMA);
|
||||||
|
final InputStream alternativeSchema = Main.class.getResourceAsStream(ALTERNATIVE_SCHEMA);
|
||||||
|
|
||||||
assert schema != null;
|
assert schema != null;
|
||||||
assert ingredientSchema != null;
|
assert ingredientSchema != null;
|
||||||
|
assert alternativeSchema != null;
|
||||||
|
|
||||||
String SQL = new Scanner(schema, StandardCharsets.UTF_8)
|
String SQL = new Scanner(schema, StandardCharsets.UTF_8)
|
||||||
.useDelimiter("\\A")
|
.useDelimiter("\\A")
|
||||||
.next();
|
.next();
|
||||||
String ingredientSQL = ";" + new Scanner(ingredientSchema, StandardCharsets.UTF_8)
|
String ingredientSQL = ";" + new Scanner(ingredientSchema, StandardCharsets.UTF_8)
|
||||||
.useDelimiter("\\A")
|
.useDelimiter("\\A")
|
||||||
.next();
|
.next();
|
||||||
|
String alternativeSQL = ";" + new Scanner(alternativeSchema, StandardCharsets.UTF_8)
|
||||||
|
.useDelimiter("\\A")
|
||||||
|
.next();
|
||||||
|
|
||||||
connection.createStatement().execute(SQL);
|
connection.createStatement().execute(SQL);
|
||||||
connection.createStatement().execute(ingredientSQL);
|
connection.createStatement().execute(ingredientSQL);
|
||||||
|
connection.createStatement().execute(alternativeSQL);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,81 +78,87 @@ public class MedicationFixture implements Fixture<Medication> {
|
||||||
Ingredient warfarinnatrium = new Ingredient("Warfarinnatrium");
|
Ingredient warfarinnatrium = new Ingredient("Warfarinnatrium");
|
||||||
|
|
||||||
medications.add(new Medication(
|
medications.add(new Medication(
|
||||||
"Metformin",
|
"Metformin",
|
||||||
"AstraZeneca",
|
"AstraZeneca",
|
||||||
List.of(
|
List.of(
|
||||||
metforminhydrochlorid,
|
metforminhydrochlorid,
|
||||||
cellulose,
|
cellulose,
|
||||||
povidon,
|
povidon,
|
||||||
magnesiumstearat
|
magnesiumstearat
|
||||||
),
|
),
|
||||||
"Übelkeit, Durchfall, Laktatazidose (selten)",
|
"Übelkeit, Durchfall, Laktatazidose (selten)",
|
||||||
"Oral",
|
"Oral",
|
||||||
100
|
100,
|
||||||
|
new ArrayList<>()
|
||||||
));
|
));
|
||||||
medications.add(new Medication(
|
medications.add(new Medication(
|
||||||
"Lisinopril",
|
"Lisinopril",
|
||||||
"Teva Pharmaceuticals",
|
"Teva Pharmaceuticals",
|
||||||
List.of(
|
List.of(
|
||||||
lisinoprilDihydrat,
|
lisinoprilDihydrat,
|
||||||
mannitol,
|
mannitol,
|
||||||
calciumphosphat,
|
calciumphosphat,
|
||||||
magnesiumstearat
|
magnesiumstearat
|
||||||
),
|
),
|
||||||
"Schwindel, trockener Husten",
|
"Schwindel, trockener Husten",
|
||||||
"Oral",
|
"Oral",
|
||||||
150
|
150,
|
||||||
|
new ArrayList<>()
|
||||||
));
|
));
|
||||||
medications.add(new Medication(
|
medications.add(new Medication(
|
||||||
"Simvastatin",
|
"Simvastatin",
|
||||||
"Mylan",
|
"Mylan",
|
||||||
List.of(
|
List.of(
|
||||||
simvastatin,
|
simvastatin,
|
||||||
laktose,
|
laktose,
|
||||||
cellulose,
|
cellulose,
|
||||||
magnesiumstearat
|
magnesiumstearat
|
||||||
),
|
),
|
||||||
"Muskelschmerzen, Leberprobleme(selten)",
|
"Muskelschmerzen, Leberprobleme(selten)",
|
||||||
"Oral",
|
"Oral",
|
||||||
80
|
80,
|
||||||
|
new ArrayList<>()
|
||||||
));
|
));
|
||||||
medications.add(new Medication(
|
medications.add(new Medication(
|
||||||
"Enoxaparin",
|
"Enoxaparin",
|
||||||
"Sanofi",
|
"Sanofi",
|
||||||
List.of(
|
List.of(
|
||||||
enoxaparinNatrium,
|
enoxaparinNatrium,
|
||||||
benzylalkohol,
|
benzylalkohol,
|
||||||
wasser
|
wasser
|
||||||
),
|
),
|
||||||
"Blutungen, Reaktionen an der Injektionsstelle",
|
"Blutungen, Reaktionen an der Injektionsstelle",
|
||||||
"Unterhautinjektion",
|
"Unterhautinjektion",
|
||||||
120
|
120,
|
||||||
|
new ArrayList<>()
|
||||||
));
|
));
|
||||||
medications.add(new Medication(
|
medications.add(new Medication(
|
||||||
"Levothyroxin",
|
"Levothyroxin",
|
||||||
"Sandoz",
|
"Sandoz",
|
||||||
List.of(
|
List.of(
|
||||||
levothyroxinnatrium,
|
levothyroxinnatrium,
|
||||||
laktose,
|
laktose,
|
||||||
staerke,
|
staerke,
|
||||||
akaziengummi
|
akaziengummi
|
||||||
),
|
),
|
||||||
"Herzrasen, Gewichtsverlust",
|
"Herzrasen, Gewichtsverlust",
|
||||||
"Oral",
|
"Oral",
|
||||||
90
|
90,
|
||||||
|
new ArrayList<>()
|
||||||
));
|
));
|
||||||
medications.add(new Medication(
|
medications.add(new Medication(
|
||||||
"Warfarin",
|
"Warfarin",
|
||||||
"Apotex Inc.",
|
"Apotex Inc.",
|
||||||
List.of(
|
List.of(
|
||||||
warfarinnatrium,
|
warfarinnatrium,
|
||||||
laktose,
|
laktose,
|
||||||
staerke,
|
staerke,
|
||||||
magnesiumstearat
|
magnesiumstearat
|
||||||
),
|
),
|
||||||
"Blutungen, Blutergüsse",
|
"Blutungen, Blutergüsse",
|
||||||
"Oral",
|
"Oral",
|
||||||
110
|
110,
|
||||||
|
new ArrayList<>()
|
||||||
));
|
));
|
||||||
MedicationDao dao = DaoFactory.getInstance().createMedicationDAO();
|
MedicationDao dao = DaoFactory.getInstance().createMedicationDAO();
|
||||||
Map<String, Medication> medicationsByName = new HashMap<>();
|
Map<String, Medication> medicationsByName = new HashMap<>();
|
||||||
|
|
|
@ -23,6 +23,7 @@ public class Medication {
|
||||||
private final SimpleStringProperty possibleSideEffects;
|
private final SimpleStringProperty possibleSideEffects;
|
||||||
private final SimpleStringProperty administrationMethod;
|
private final SimpleStringProperty administrationMethod;
|
||||||
private final SimpleIntegerProperty currentStock;
|
private final SimpleIntegerProperty currentStock;
|
||||||
|
private final SimpleListProperty<Medication> alternativeMedication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor allows instantiating a {@link Medication} object,
|
* This constructor allows instantiating a {@link Medication} object,
|
||||||
|
@ -37,7 +38,8 @@ public class Medication {
|
||||||
List<Ingredient> ingredients,
|
List<Ingredient> ingredients,
|
||||||
String possibleSideEffects,
|
String possibleSideEffects,
|
||||||
String administrationMethod,
|
String administrationMethod,
|
||||||
int currentStock
|
int currentStock,
|
||||||
|
List<Medication> alternativeMedication
|
||||||
) {
|
) {
|
||||||
this.name = new SimpleStringProperty(name);
|
this.name = new SimpleStringProperty(name);
|
||||||
this.manufacturer = new SimpleStringProperty(manufacturer);
|
this.manufacturer = new SimpleStringProperty(manufacturer);
|
||||||
|
@ -45,6 +47,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.alternativeMedication = new SimpleListProperty<>(FXCollections.observableArrayList(alternativeMedication));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,7 +60,8 @@ public class Medication {
|
||||||
List<Ingredient> ingredients,
|
List<Ingredient> ingredients,
|
||||||
String possibleSideEffects,
|
String possibleSideEffects,
|
||||||
String administrationMethod,
|
String administrationMethod,
|
||||||
int currentStock
|
int currentStock,
|
||||||
|
List<Medication> alternativeMedication
|
||||||
) {
|
) {
|
||||||
this.id = new SimpleIntegerProperty(id);
|
this.id = new SimpleIntegerProperty(id);
|
||||||
this.name = new SimpleStringProperty(name);
|
this.name = new SimpleStringProperty(name);
|
||||||
|
@ -66,6 +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.alternativeMedication = new SimpleListProperty<>(FXCollections.observableArrayList(alternativeMedication));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
|
@ -124,6 +129,18 @@ public class Medication {
|
||||||
this.possibleSideEffects.set(possibleSideEffects);
|
this.possibleSideEffects.set(possibleSideEffects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ObservableList<Medication> getAlternativeMedication() {
|
||||||
|
return alternativeMedication.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleListProperty<Medication> alternativeMedicationProperty() {
|
||||||
|
return alternativeMedication;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlternativeMedication(ObservableList<Medication> alternativeMedication) {
|
||||||
|
this.alternativeMedication.set(alternativeMedication);
|
||||||
|
}
|
||||||
|
|
||||||
public String getAdministrationMethod() {
|
public String getAdministrationMethod() {
|
||||||
return administrationMethod.get();
|
return administrationMethod.get();
|
||||||
}
|
}
|
||||||
|
@ -162,6 +179,7 @@ public class Medication {
|
||||||
.add("Possible Side Effects: " + this.getPossibleSideEffects())
|
.add("Possible Side Effects: " + this.getPossibleSideEffects())
|
||||||
.add("Administration Method: " + this.getAdministrationMethod())
|
.add("Administration Method: " + this.getAdministrationMethod())
|
||||||
.add("Current Stock: " + this.getCurrentStock())
|
.add("Current Stock: " + this.getCurrentStock())
|
||||||
|
.add("Alternative Medication" + this.getAlternativeMedication())
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,8 @@ public class MedicationModalController {
|
||||||
new ArrayList<>(),
|
new ArrayList<>(),
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
0
|
0,
|
||||||
|
new ArrayList<>()
|
||||||
);
|
);
|
||||||
this.buttonSave.setDisable(true);
|
this.buttonSave.setDisable(true);
|
||||||
}
|
}
|
||||||
|
@ -161,10 +162,11 @@ public class MedicationModalController {
|
||||||
alternativeMediaction.add(new Medication(
|
alternativeMediaction.add(new Medication(
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
List.of(),
|
new ArrayList<>(),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
-1
|
-1,
|
||||||
|
new ArrayList<>()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,18 @@ public class MedicationDao implements Dao<Medication> {
|
||||||
ingredientStatement.setString(2, ingredient.getName());
|
ingredientStatement.setString(2, ingredient.getName());
|
||||||
ingredientStatement.execute();
|
ingredientStatement.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final String alternativeMedicationSQL = """
|
||||||
|
INSERT INTO medication_alternative
|
||||||
|
(id, alternativeId)
|
||||||
|
VALUES (?, ?);
|
||||||
|
""";
|
||||||
|
for (Medication alternative : medication.getAlternativeMedication()) {
|
||||||
|
PreparedStatement alternativeStatement = this.connection.prepareStatement(alternativeMedicationSQL);
|
||||||
|
alternativeStatement.setInt(1, newId);
|
||||||
|
alternativeStatement.setInt(2, alternative.getId());
|
||||||
|
alternativeStatement.execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -82,9 +94,12 @@ public class MedicationDao implements Dao<Medication> {
|
||||||
@Override
|
@Override
|
||||||
public List<Medication> readAll() throws SQLException {
|
public List<Medication> readAll() throws SQLException {
|
||||||
final String SQL = """
|
final String SQL = """
|
||||||
SELECT medication.*, medication_ingredient.name
|
SELECT medication.*, medication_ingredient.name, medication_alternative.alternativeId
|
||||||
FROM medication LEFT JOIN
|
FROM medication
|
||||||
|
LEFT JOIN
|
||||||
medication_ingredient ON medication.id = medication_ingredient.id
|
medication_ingredient ON medication.id = medication_ingredient.id
|
||||||
|
LEFT JOIN
|
||||||
|
medication_alternative ON medication.id = medication_alternative.id
|
||||||
""";
|
""";
|
||||||
ResultSet result = connection.prepareStatement(SQL).executeQuery();
|
ResultSet result = connection.prepareStatement(SQL).executeQuery();
|
||||||
|
|
||||||
|
@ -103,7 +118,8 @@ public class MedicationDao implements Dao<Medication> {
|
||||||
new ArrayList<>(),
|
new ArrayList<>(),
|
||||||
result.getString(4),
|
result.getString(4),
|
||||||
result.getString(5),
|
result.getString(5),
|
||||||
result.getInt(6)
|
result.getInt(6),
|
||||||
|
new ArrayList<>()
|
||||||
);
|
);
|
||||||
medications.add(medication);
|
medications.add(medication);
|
||||||
}
|
}
|
||||||
|
@ -188,10 +204,11 @@ public class MedicationDao implements Dao<Medication> {
|
||||||
result.getInt(1),
|
result.getInt(1),
|
||||||
result.getString(2),
|
result.getString(2),
|
||||||
result.getString(3),
|
result.getString(3),
|
||||||
List.of(),
|
new ArrayList<>(),
|
||||||
result.getString(4),
|
result.getString(4),
|
||||||
result.getString(5),
|
result.getString(5),
|
||||||
result.getInt(6)
|
result.getInt(6),
|
||||||
|
new ArrayList<>()
|
||||||
);
|
);
|
||||||
|
|
||||||
List<Ingredient> ingredients = new ArrayList<>();
|
List<Ingredient> ingredients = new ArrayList<>();
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
CREATE TABLE medication_alternative
|
||||||
|
(
|
||||||
|
id INTEGER NOT NULL ,
|
||||||
|
alternativeId INTEGER NOT NULL ,
|
||||||
|
FOREIGN KEY (id) REFERENCES medication (id) ON DELETE CASCADE,
|
||||||
|
FOREIGN KEY (alternativeId) REFERENCES medication (id) ON DELETE CASCADE
|
||||||
|
)
|
Loading…
Reference in a new issue