| @@ -1,8 +1,6 @@ | |||||
| package de.uniluebeck.mi.projmi6.db; | package de.uniluebeck.mi.projmi6.db; | ||||
| import de.uniluebeck.mi.projmi6.model.Fall; | |||||
| import de.uniluebeck.mi.projmi6.model.Patient; | |||||
| import de.uniluebeck.mi.projmi6.model.Station; | |||||
| import de.uniluebeck.mi.projmi6.model.*; | |||||
| import java.sql.PreparedStatement; | import java.sql.PreparedStatement; | ||||
| import java.sql.ResultSet; | import java.sql.ResultSet; | ||||
| @@ -22,7 +20,8 @@ public class DBHandler { | |||||
| "`Geburtsdatum`=?, `Geburtsname`=?, `Geschlecht`=?, `KassenID`=?, `LetzterBearbeiter`=?, `Nachname`=?, " + | "`Geburtsdatum`=?, `Geburtsname`=?, `Geschlecht`=?, `KassenID`=?, `LetzterBearbeiter`=?, `Nachname`=?, " + | ||||
| "`Ort`=?, `PLZ`=?, `Strasse`=?, `Telefon`=?, `Versichertennummer`=?, `Vorname`=? WHERE `ID`=?"; | "`Ort`=?, `PLZ`=?, `Strasse`=?, `Telefon`=?, `Versichertennummer`=?, `Vorname`=? WHERE `ID`=?"; | ||||
| private static final String SELECT_ALL_STATIONEN = "SELECT * FROM `stammstation`"; | private static final String SELECT_ALL_STATIONEN = "SELECT * FROM `stammstation`"; | ||||
| private static final String SELECT_ALL_FAELLE = "SELECT * FROM `fall`"; | |||||
| private static final String SELECT_FAELLE_BY_PATID = "SELECT * FROM `fall` WHERE `patientid` = ?"; | |||||
| private static final String SELECT_DIAGNOSE_BY_ID = "SELECT * FROM `diagnose` WHERE `diagid` = ?"; | |||||
| public static List<Patient> getAllPatients() throws SQLException { | public static List<Patient> getAllPatients() throws SQLException { | ||||
| Statement statement = MySqlConnFactory.getConnection().createStatement(); | Statement statement = MySqlConnFactory.getConnection().createStatement(); | ||||
| @@ -60,10 +59,7 @@ public class DBHandler { | |||||
| // patient.setGeschlecht(Patient.Geschlecht.valueOf(rs.getString("geschlecht"))); TODO | // patient.setGeschlecht(Patient.Geschlecht.valueOf(rs.getString("geschlecht"))); TODO | ||||
| patient.setVersichertennummer(rs.getString("versichertennummer")); | patient.setVersichertennummer(rs.getString("versichertennummer")); | ||||
| patient.setKassenID(rs.getInt("kassenid")); | patient.setKassenID(rs.getInt("kassenid")); | ||||
| patient.setErsteller(rs.getInt("ersteller")); | |||||
| patient.setErstellDatumZeit(rs.getTimestamp("erstelldatum").toLocalDateTime()); | |||||
| patient.setBearbeiter(rs.getInt("letzterbearbeiter")); | |||||
| patient.setBearbeitetDatumZeit(rs.getTimestamp("letztesbearbeitungsdatum").toLocalDateTime()); | |||||
| setVersionInformation(patient, rs); | |||||
| return patient; | return patient; | ||||
| } | } | ||||
| @@ -71,6 +67,7 @@ public class DBHandler { | |||||
| PreparedStatement statement = MySqlConnFactory.getConnection().prepareStatement(UPDATE_PATIENT); | PreparedStatement statement = MySqlConnFactory.getConnection().prepareStatement(UPDATE_PATIENT); | ||||
| statement.setString(1, patient.getCave()); | statement.setString(1, patient.getCave()); | ||||
| statement.setString(2, patient.getFamilienstand().toString()); | statement.setString(2, patient.getFamilienstand().toString()); | ||||
| // TODO | |||||
| } | } | ||||
| public static List<Station> getAllStationen() throws SQLException { | public static List<Station> getAllStationen() throws SQLException { | ||||
| @@ -95,9 +92,10 @@ public class DBHandler { | |||||
| return station; | return station; | ||||
| } | } | ||||
| public static List<Fall> getAllFaelle() throws SQLException { | |||||
| Statement statement = MySqlConnFactory.getConnection().createStatement(); | |||||
| ResultSet rs = statement.executeQuery(SELECT_ALL_FAELLE); | |||||
| public static List<Fall> getFaelleByPatID(int id) throws SQLException { | |||||
| PreparedStatement statement = MySqlConnFactory.getConnection().prepareStatement(SELECT_FAELLE_BY_PATID); | |||||
| statement.setInt(1, id); | |||||
| ResultSet rs = statement.executeQuery(); | |||||
| List<Fall> faelle = new ArrayList<>(); | List<Fall> faelle = new ArrayList<>(); | ||||
| while (rs.next()) { | while (rs.next()) { | ||||
| @@ -111,9 +109,44 @@ public class DBHandler { | |||||
| Fall fall = new Fall(); | Fall fall = new Fall(); | ||||
| fall.setFallID(rs.getInt("fallid")); | fall.setFallID(rs.getInt("fallid")); | ||||
| fall.setAufnahmeDatum(rs.getTimestamp("aufnahmedatum").toLocalDateTime()); | |||||
| fall.setEntlassungsDatum(rs.getTimestamp("entlassungsdatum").toLocalDateTime()); | |||||
| fall.setHauptDiagnose(getDiagnose(rs.getInt("hauptdiagnose"), fall)); | |||||
| return fall; | return fall; | ||||
| } | } | ||||
| private static Diagnose getDiagnose(int hauptdiagnose, Fall fall) throws SQLException { | |||||
| Diagnose diagnose = getDiagnose(hauptdiagnose); | |||||
| diagnose.setFall(fall); | |||||
| return diagnose; | |||||
| } | |||||
| private static Diagnose getDiagnose(int id) throws SQLException { | |||||
| PreparedStatement statement = MySqlConnFactory.getConnection().prepareStatement(SELECT_DIAGNOSE_BY_ID); | |||||
| ResultSet rs = statement.executeQuery(); | |||||
| return getDiagnose(rs); | |||||
| } | |||||
| private static Diagnose getDiagnose(ResultSet rs) throws SQLException { | |||||
| Diagnose diagnose = new Diagnose(); | |||||
| diagnose.setFreiText(rs.getString("freitext")); | |||||
| diagnose.setArzt(new Mitarbeiter(rs.getInt("arzt"))); | |||||
| diagnose.setDiagArt(DiagArt.parseInt(rs.getInt("diagart"))); | |||||
| setVersionInformation(diagnose, rs); | |||||
| diagnose.setIcd10code(new Icd10Code(rs.getString("icd10code"), "", rs.getInt("icd10version"))); // TODO: das geht auch in huebsch | |||||
| return diagnose; | |||||
| } | |||||
| private static void setVersionInformation(Version t, ResultSet rs) throws SQLException { | |||||
| t.setErsteller(rs.getInt("ersteller")); | |||||
| t.setErstellDatumZeit(rs.getTimestamp("erstelldatum").toLocalDateTime()); | |||||
| t.setBearbeiter(rs.getInt("letzterbearbeiter")); | |||||
| t.setBearbeitetDatumZeit(rs.getTimestamp("letztesbearbeitungsdatum").toLocalDateTime()); | |||||
| } | |||||
| } | } | ||||