Compare commits
No commits in common. "e881adcc041aa1742c58ff1309d547be414a1b73" and "60c47098c6dccf2fb500dc89b75494ad779d46a4" have entirely different histories.
e881adcc04
...
60c47098c6
2 changed files with 7 additions and 14 deletions
|
@ -67,6 +67,7 @@ public class MedicationFixture implements Fixture<Medication> {
|
||||||
Ingredient warfarinnatrium = new Ingredient("Warfarinnatrium");
|
Ingredient warfarinnatrium = new Ingredient("Warfarinnatrium");
|
||||||
|
|
||||||
medications.add(new Medication(
|
medications.add(new Medication(
|
||||||
|
1,
|
||||||
"Metformin",
|
"Metformin",
|
||||||
"AstraZeneca",
|
"AstraZeneca",
|
||||||
List.of(
|
List.of(
|
||||||
|
@ -80,6 +81,7 @@ public class MedicationFixture implements Fixture<Medication> {
|
||||||
100
|
100
|
||||||
));
|
));
|
||||||
medications.add(new Medication(
|
medications.add(new Medication(
|
||||||
|
2,
|
||||||
"Lisinopril",
|
"Lisinopril",
|
||||||
"Teva Pharmaceuticals",
|
"Teva Pharmaceuticals",
|
||||||
List.of(
|
List.of(
|
||||||
|
@ -93,6 +95,7 @@ public class MedicationFixture implements Fixture<Medication> {
|
||||||
150
|
150
|
||||||
));
|
));
|
||||||
medications.add(new Medication(
|
medications.add(new Medication(
|
||||||
|
3,
|
||||||
"Simvastatin",
|
"Simvastatin",
|
||||||
"Mylan",
|
"Mylan",
|
||||||
List.of(
|
List.of(
|
||||||
|
@ -106,6 +109,7 @@ public class MedicationFixture implements Fixture<Medication> {
|
||||||
80
|
80
|
||||||
));
|
));
|
||||||
medications.add(new Medication(
|
medications.add(new Medication(
|
||||||
|
4,
|
||||||
"Enoxaparin",
|
"Enoxaparin",
|
||||||
"Sanofi",
|
"Sanofi",
|
||||||
List.of(
|
List.of(
|
||||||
|
@ -118,6 +122,7 @@ public class MedicationFixture implements Fixture<Medication> {
|
||||||
120
|
120
|
||||||
));
|
));
|
||||||
medications.add(new Medication(
|
medications.add(new Medication(
|
||||||
|
5,
|
||||||
"Levothyroxin",
|
"Levothyroxin",
|
||||||
"Sandoz",
|
"Sandoz",
|
||||||
List.of(
|
List.of(
|
||||||
|
@ -131,6 +136,7 @@ public class MedicationFixture implements Fixture<Medication> {
|
||||||
90
|
90
|
||||||
));
|
));
|
||||||
medications.add(new Medication(
|
medications.add(new Medication(
|
||||||
|
6,
|
||||||
"Warfarin",
|
"Warfarin",
|
||||||
"Apotex Inc.",
|
"Apotex Inc.",
|
||||||
List.of(
|
List.of(
|
||||||
|
|
|
@ -29,7 +29,6 @@ public class MedicationDao implements Dao<Medication> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create(Medication medication) throws SQLException {
|
public void create(Medication medication) throws SQLException {
|
||||||
connection.setAutoCommit(false); //Switch to Manual Commit, to do an SQL Transaction
|
|
||||||
final String medicationSQL = """
|
final String medicationSQL = """
|
||||||
INSERT INTO medication
|
INSERT INTO medication
|
||||||
(name, manufacturer, possibleSideEffects, administrationMethod, currentStock)
|
(name, manufacturer, possibleSideEffects, administrationMethod, currentStock)
|
||||||
|
@ -43,15 +42,6 @@ public class MedicationDao implements Dao<Medication> {
|
||||||
medicationStatement.setInt(5, medication.getCurrentStock());
|
medicationStatement.setInt(5, medication.getCurrentStock());
|
||||||
medicationStatement.execute();
|
medicationStatement.execute();
|
||||||
|
|
||||||
ResultSet generatedKeys = connection.createStatement().executeQuery("SELECT last_insert_rowid()");
|
|
||||||
connection.commit(); //Finish SQL Transaction
|
|
||||||
connection.setAutoCommit(true); //Switch back Mode
|
|
||||||
|
|
||||||
if (!generatedKeys.next()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int newId = generatedKeys.getInt(1);
|
|
||||||
|
|
||||||
final String ingredientSQL = """
|
final String ingredientSQL = """
|
||||||
INSERT INTO medication_ingredient
|
INSERT INTO medication_ingredient
|
||||||
(id, name)
|
(id, name)
|
||||||
|
@ -59,7 +49,7 @@ public class MedicationDao implements Dao<Medication> {
|
||||||
""";
|
""";
|
||||||
for (Ingredient ingredient : medication.getIngredients()) {
|
for (Ingredient ingredient : medication.getIngredients()) {
|
||||||
PreparedStatement ingredientStatement = this.connection.prepareStatement(ingredientSQL);
|
PreparedStatement ingredientStatement = this.connection.prepareStatement(ingredientSQL);
|
||||||
ingredientStatement.setInt(1, newId);
|
ingredientStatement.setInt(1, medication.getId());
|
||||||
ingredientStatement.setString(2, ingredient.getName());
|
ingredientStatement.setString(2, ingredient.getName());
|
||||||
ingredientStatement.execute();
|
ingredientStatement.execute();
|
||||||
}
|
}
|
||||||
|
@ -114,9 +104,6 @@ public class MedicationDao implements Dao<Medication> {
|
||||||
lastMedicationId = currentMedicationId;
|
lastMedicationId = currentMedicationId;
|
||||||
}
|
}
|
||||||
for (Medication medication : medications) {
|
for (Medication medication : medications) {
|
||||||
if(!ingredientMap.containsKey(medication.getId())){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
medication.setIngredients(ingredientMap.get(medication.getId()));
|
medication.setIngredients(ingredientMap.get(medication.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue