| @@ -3,8 +3,8 @@ package de.uniluebeck.mi.projmi6.db; | |||
| import de.uniluebeck.mi.projmi6.model.*; | |||
| import java.sql.*; | |||
| import java.sql.Date; | |||
| import java.util.*; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| /** | |||
| * Created by nils on 15.11.2015. | |||
| @@ -13,7 +13,7 @@ public class DBHandler { | |||
| private static final String SELECT_ALL_PATIENTS = "SELECT * FROM `patient`"; | |||
| private static final String SELECT_PATIENT_BY_ID = "SELECT * FROM `patient` WHERE `id` = ?"; | |||
| private static final String UPDATE_PATIENT = "UPDATE `patient` " + | |||
| private static final String UPDATE_PATIENT = "UPDATE `patient`" + | |||
| "SET `CAVE`=?," + | |||
| "`Familienstand`=?," + | |||
| "`Geburtsdatum`=?," + | |||
| @@ -29,7 +29,7 @@ public class DBHandler { | |||
| "`Versichertennummer`=?," + | |||
| "`Vorname`=?" + | |||
| "WHERE `ID`=?"; | |||
| private static final String INSERT_PATIENT = "INSERT INTO `patient` " + | |||
| private static final String INSERT_PATIENT = "INSERT INTO `patient`" + | |||
| "(`CAVE`," + | |||
| "`Familienstand`," + | |||
| "`Geburtsdatum`," + | |||
| @@ -49,7 +49,7 @@ public class DBHandler { | |||
| "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; | |||
| private static final String SELECT_ALL_STATIONEN = "SELECT * FROM `stammstation`"; | |||
| private static final String SELECT_FAELLE_BY_PATID = "SELECT * FROM `fall` WHERE `patientid` = ?"; | |||
| private static final String INSERT_FALL = "INSERT INTO `fall` " + | |||
| private static final String INSERT_FALL = "INSERT INTO `fall`" + | |||
| "(`Aufnahmedatum`," + | |||
| "`Entlassungsdatum`," + | |||
| "`Vorstelldatum`," + | |||
| @@ -57,22 +57,21 @@ public class DBHandler { | |||
| "`Fallart`," + | |||
| "`Selbsteinweisung`," + | |||
| "`Hauptdiagnose`," + | |||
| "`PatientID`," + | |||
| "`Versichertennummer`," + | |||
| "`KassenID`," + | |||
| "`storniert`," + | |||
| "`Letzter Bearbeiter`" + | |||
| "`Ersteller`)," + | |||
| "`LetzterBearbeiter`," + | |||
| "`PatientID`," + | |||
| "`Ersteller`)" + | |||
| "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; | |||
| private static final String UPDATE_FALL = "UPDATE `fall`" + | |||
| "SET `Aufnahmedatum`=?," + | |||
| "`Entlassungsdatum`=?," + | |||
| "`Vorstelldatum`=?" + | |||
| "`Vorstelldatum`=?," + | |||
| "`EinweisenderArzt`=?," + | |||
| "Fallart=?," + | |||
| "`Selbsteinweisung`=?," + | |||
| "Hauptdiagnose=?," + | |||
| "`PatientID`=?," + | |||
| "`Versichertennummer`=?," + | |||
| "KassenID=?," + | |||
| "`storniert`=?," + | |||
| @@ -85,6 +84,25 @@ public class DBHandler { | |||
| private static final String SELECT_OPSCODE_BY_ID = "SELECT * FROM `stammops` WHERE `opscode` = ? AND `version` = ?"; | |||
| private static final String SELECT_ALL_MITARBEITER = "SELECT * FROM `mitarbeiter`"; | |||
| private static final String SELECT_UNTERS_BY_FALLID = "SELECT * FROM `untersuchung` WHERE `fallid` = ?"; | |||
| private static final String INSERT_UNTERSUCHUNG = "INSERT INTO `untersuchung`" + | |||
| "(`DurchfuehrenderArzt`," + | |||
| "`FallID`," + | |||
| "`OPSCode`," + | |||
| "`OPSVersion`," + | |||
| "`storniert`," + | |||
| "`Untersuchungsdatum`," + | |||
| "`LetzterBearbeiter`" + | |||
| "`Ersteller`)," + | |||
| "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; | |||
| private static final String UPDATE_UNTERSUCHUNG = "UPDATE `untersuchung`" + | |||
| "SET `DurchfuehrenderArzt`=?," + | |||
| "`FallID`=?," + | |||
| "`OPSCode`=?," + | |||
| "`OPSVersion`=?," + | |||
| "`storniert`=?," + | |||
| "`Untersuchundatum`=?" + | |||
| "`LetzterBearbeiter`" + | |||
| "WHERE `UnterID`=?"; | |||
| private static final String SELECT_MITARBEITER_BY_ID = "SELECT * FROM `mitarbeiter` WHERE `mitarbid` = ?"; | |||
| private static final String SELECT_DIAGNOSE_BY_FALLID = "SELECT * FROM `diagnose` WHERE `fallid` = ?"; | |||
| private static final String SELECT_ALL_KASSEN = "SELECT * FROM `kasse`"; | |||
| @@ -241,63 +259,53 @@ public class DBHandler { | |||
| return fall; | |||
| } | |||
| // TODO: Mach eins aus insert und update (boolean Flag in die Methode) | |||
| // private static void setInsertFall(Fall fall, int mitarbid, boolean isUpdate) { | |||
| public static void insertFall(Fall fall, int mitarbid) throws SQLException { | |||
| /*PreparedStatement statement; | |||
| public static void setFall(Fall fall, int mitarbid, boolean isUpdate) throws SQLException { | |||
| PreparedStatement statement; | |||
| if (isUpdate) { | |||
| statement = MySqlConnFactory.getConnection().prepareStatement(INSERT_FALL); | |||
| statement = MySqlConnFactory.getConnection().prepareStatement(UPDATE_FALL); | |||
| } else { | |||
| statement = MySqlConnFactory.getConnection().prepareStatement(INSERT_FALL); | |||
| }*/ | |||
| PreparedStatement statement = MySqlConnFactory.getConnection().prepareStatement(INSERT_FALL); | |||
| if (fall.getAufnahmeDatum() != null) | |||
| statement.setTimestamp(1, Timestamp.valueOf(fall.getAufnahmeDatum())); // Aufnahmedatum | |||
| if (fall.getEntlassungsDatum() != null) | |||
| statement.setTimestamp(2, Timestamp.valueOf(fall.getEntlassungsDatum())); // Entlassungsdatum | |||
| if (fall.getVorstellDatum() != null) | |||
| statement.setTimestamp(3, Timestamp.valueOf(fall.getVorstellDatum())); // Vorstelldatum | |||
| if (fall.getEinweisenderArzt() != null) | |||
| statement.setInt(4, fall.getEinweisenderArzt().getMitarbID()); // EinweisenderArzt | |||
| statement.setString(5, fall.getFallArt().id()); // Fallart | |||
| statement.setBoolean(6, fall.getSelbsteinweisung()); // Selbsteinweisung | |||
| if (fall.getHauptDiagnose() != null) | |||
| statement.setInt(7, fall.getHauptDiagnose().getDiagID()); // Hauptdiagnose | |||
| statement.setInt(8, fall.getPatient().getPatID()); // PatientID | |||
| statement.setString(9, fall.getVersichertenNummer()); // Versichertennummer | |||
| if (fall.getKasse() != null) | |||
| statement.setInt(10, fall.getKasse().getKassenID()); // KassenID | |||
| statement.setBoolean(11, fall.getStorniert()); // storniert | |||
| statement.setInt(12, mitarbid); // Letzter Bearbeiter | |||
| // if (!isUpdate) | |||
| statement.setInt(13, mitarbid); // Ersteller | |||
| statement.execute(); | |||
| } | |||
| // TODO: Kann dann weg. | |||
| public static void updateFall(Fall fall, int mitarbid) throws SQLException { | |||
| PreparedStatement statement = MySqlConnFactory.getConnection().prepareStatement(UPDATE_FALL); | |||
| } | |||
| if (fall.getAufnahmeDatum() != null) | |||
| if (fall.getAufnahmeDatum() != null) { | |||
| statement.setTimestamp(1, Timestamp.valueOf(fall.getAufnahmeDatum())); // Aufnahmedatum | |||
| if (fall.getEntlassungsDatum() != null) | |||
| } else { | |||
| statement.setTimestamp(1, null); | |||
| } | |||
| if (fall.getEntlassungsDatum() != null) { | |||
| statement.setTimestamp(2, Timestamp.valueOf(fall.getEntlassungsDatum())); // Entlassungsdatum | |||
| if (fall.getVorstellDatum() != null) | |||
| } else { | |||
| statement.setTimestamp(2, null); | |||
| } | |||
| if (fall.getVorstellDatum() != null) { | |||
| statement.setTimestamp(3, Timestamp.valueOf(fall.getVorstellDatum())); // Vorstelldatum | |||
| if (fall.getEinweisenderArzt() != null) | |||
| } else { | |||
| statement.setTimestamp(3, null); | |||
| } | |||
| if (fall.getEinweisenderArzt() != null) { | |||
| statement.setInt(4, fall.getEinweisenderArzt().getMitarbID()); // EinweisenderArzt | |||
| } else { | |||
| statement.setTimestamp(4, null); | |||
| } | |||
| statement.setString(5, fall.getFallArt().id()); // Fallart | |||
| statement.setBoolean(6, fall.getSelbsteinweisung()); // Selbsteinweisung | |||
| if (fall.getHauptDiagnose() != null) | |||
| if (fall.getHauptDiagnose() != null) { | |||
| statement.setInt(7, fall.getHauptDiagnose().getDiagID()); // Hauptdiagnose | |||
| statement.setInt(8, fall.getPatient().getPatID()); // PatientID | |||
| statement.setString(9, fall.getVersichertenNummer()); // Versichertennummer | |||
| if (fall.getKasse() != null) | |||
| statement.setInt(10, fall.getKasse().getKassenID()); // KassenID | |||
| statement.setBoolean(11, fall.getStorniert()); // storniert | |||
| statement.setInt(12, mitarbid); // Letzter Bearbeiter | |||
| } else { | |||
| statement.setTimestamp(7, null); | |||
| } | |||
| statement.setString(8, fall.getVersichertenNummer()); // Versichertennummer | |||
| if (fall.getKasse() != null) { | |||
| statement.setInt(9, fall.getKasse().getKassenID()); // KassenID | |||
| } else { | |||
| statement.setTimestamp(9, null); | |||
| } | |||
| statement.setBoolean(10, fall.getStorniert()); // storniert | |||
| statement.setInt(11, mitarbid); // Letzter Bearbeiter | |||
| if (!isUpdate) { | |||
| statement.setInt(12, fall.getPatient().getPatID()); // PatientID | |||
| statement.setInt(13, mitarbid); // Ersteller | |||
| } | |||
| statement.execute(); | |||
| } | |||
| @@ -444,6 +452,27 @@ public class DBHandler { | |||
| return untersuchungen; | |||
| } | |||
| public static void setUntersuchung(Untersuchung untersuchung, int mitarbid, boolean isUpdate) throws SQLException { | |||
| PreparedStatement statement; | |||
| if (isUpdate) { | |||
| statement = MySqlConnFactory.getConnection().prepareStatement(UPDATE_UNTERSUCHUNG); | |||
| } else { | |||
| statement = MySqlConnFactory.getConnection().prepareStatement(INSERT_UNTERSUCHUNG); | |||
| } | |||
| statement.setInt(1, untersuchung.getDurchfuehrenderArzt().getMitarbID()); // DurchfuehrenderArzt | |||
| statement.setInt(2, untersuchung.getFall().getFallID()); // FallID | |||
| statement.setString(3, untersuchung.getOpscode().getOpsCode()); // OPSCode | |||
| statement.setInt(4, untersuchung.getOpscode().getVersion()); // OPSVersion | |||
| statement.setBoolean(5, untersuchung.getStorniert()); // storniert | |||
| statement.setTimestamp(6, Timestamp.valueOf(untersuchung.getUntersuchungsdatum())); // Untersuchungsdatum | |||
| statement.setInt(7, mitarbid); // Letzter Bearbeiter | |||
| if (!isUpdate) | |||
| statement.setInt(8, mitarbid); // Ersteller | |||
| statement.execute(); | |||
| } | |||
| private static Untersuchung getUntersuchung(ResultSet rs, Fall fall) throws SQLException { | |||
| Untersuchung untersuchung = new Untersuchung(); | |||
| untersuchung.setUntersID(rs.getInt("untersid")); | |||
| @@ -489,4 +518,8 @@ public class DBHandler { | |||
| setVersionInformation(kasse, rs); | |||
| return kasse; | |||
| } | |||
| public static void setFall(Fall fall, int mitarbid) throws SQLException { | |||
| setFall(fall, mitarbid, false); | |||
| } | |||
| } | |||