| @@ -27,12 +27,15 @@ import javafx.stage.StageStyle; | |||
| public class Main extends Application { | |||
| private HL7Server2 server; | |||
| /** | |||
| * Cuz building the GUI from FXML is a bit costly, | |||
| * it's done from its own thread. | |||
| */ | |||
| private Task<Parent> loadMainWindowTask = new Task<Parent>(){ | |||
| @Override | |||
| protected Parent call() throws Exception { | |||
| @@ -70,14 +73,11 @@ public class Main extends Application { | |||
| Parent root = fxmlLoader.load(); | |||
| // TODO: Jojo, das muss irgendwie am ende noch geschlossen werden! | |||
| HL7Server2 hl7server = new HL7Server2(mainController); | |||
| //hl7server.stop(); | |||
| //hl7server.shutdown(); | |||
| server = new HL7Server2(mainController); | |||
| return root; | |||
| } | |||
| }; | |||
| /** | |||
| * The applications logo (an owl). | |||
| */ | |||
| @@ -93,6 +93,15 @@ public class Main extends Application { | |||
| } | |||
| @Override | |||
| public void stop() throws Exception { | |||
| if (server != null) { | |||
| server.stop(); | |||
| server.shutdown(); | |||
| } | |||
| super.stop(); | |||
| } | |||
| @Override | |||
| public void start(Stage primaryStage) { | |||
| System.out.println(getClass().getClassLoader().getResource("").toExternalForm()); | |||
| @@ -156,6 +156,12 @@ public class DBHandler { | |||
| "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; | |||
| private static final String DELETE_STATHIST = "DELETE FROM `stationshistorie` WHERE `StatHistID` =?"; | |||
| private static final String SELECT_FALLIDS_BY_PATID = "SELECT `fallid` FROM `fall` WHERE `patientid` =?"; | |||
| private static final String INSERT_HL7NACHRICHT_ = "INSERT INTO `hl7_nachrichten` " + | |||
| "(`hl7msg`," + | |||
| "`timestamp`," + | |||
| "`source`," + | |||
| "`direction`) " + | |||
| "VALUES (?, ?, ?, ?)"; | |||
| private DBHandler() { | |||
| @@ -835,11 +841,21 @@ public class DBHandler { | |||
| return hl7entries; | |||
| } | |||
| public static void setHL7LogEntry(HL7LogEntry entry) throws SQLException { | |||
| PreparedStatement statement = MySqlConnectionFactory.getConnection().prepareStatement(INSERT_HL7NACHRICHT_); | |||
| statement.setString(1, entry.getMessage()); | |||
| statement.setTimestamp(2, Timestamp.valueOf(entry.getTimestamp())); | |||
| statement.setString(3, entry.getSource()); | |||
| statement.setString(4, entry.getDirection().toString()); | |||
| statement.execute(); | |||
| } | |||
| private static HL7LogEntry getHL7LogEntry(ResultSet rs) throws SQLException { | |||
| HL7LogEntry entry = new HL7LogEntry(rs.getInt("msgid")); | |||
| entry.setMessage(rs.getString("hl7msg")); | |||
| entry.setTimestamp(rs.getTimestamp("timestamp").toLocalDateTime()); | |||
| entry.setSource(rs.getString("source")); | |||
| entry.setDirection(HL7LogEntry.Direction.parseDirection(rs.getString("direction"))); | |||
| return entry; | |||
| } | |||
| @@ -15,6 +15,7 @@ import ca.uhn.hl7v2.protocol.ReceivingApplicationException; | |||
| import de.uniluebeck.mi.projmi6.controller.MainController; | |||
| import de.uniluebeck.mi.projmi6.db.DBHandler; | |||
| import de.uniluebeck.mi.projmi6.model.*; | |||
| import javafx.application.Platform; | |||
| import java.io.IOException; | |||
| import java.sql.SQLException; | |||
| @@ -86,7 +87,8 @@ public class HL7Receiver2<T extends AbstractMessage> implements ReceivingApplica | |||
| Patient patient = mainctrl.getStammdaten().getPatienten().stream().filter(p -> p.getPatID() == patid).findFirst().orElse(null); | |||
| if (patient == null) { | |||
| logHL7MessageToDatabase(message, msh, metadata); | |||
| logInHL7MessageToDatabase(message, msh, metadata); | |||
| updateUI(new HL7Message(patient, -1, LocalDateTime.now(), "Patient nicht gefunden.", true)); | |||
| return generateACKWithAR(message, "Patient nicht gefunden."); | |||
| } | |||
| @@ -106,7 +108,8 @@ public class HL7Receiver2<T extends AbstractMessage> implements ReceivingApplica | |||
| e.printStackTrace(); | |||
| } | |||
| if (fallids.isEmpty() || !fallids.contains(fallid)) { | |||
| logHL7MessageToDatabase(message, msh, metadata); | |||
| logInHL7MessageToDatabase(message, msh, metadata); | |||
| updateUI(new HL7Message(patient, -1, LocalDateTime.now(), "Fall nicht gefunden.?", true)); | |||
| return generateACKWithAR(message, "Fall nicht gefunden."); | |||
| } | |||
| @@ -141,7 +144,8 @@ public class HL7Receiver2<T extends AbstractMessage> implements ReceivingApplica | |||
| // TODO: Oder einfach ueberspringen? | |||
| continue; | |||
| // TODO: Behandeln von sonder Codes. K35.9V (Verdacht...) | |||
| // logHL7MessageToDatabase(message, msh, metadata); | |||
| // logInHL7MessageToDatabase(message, msh, metadata); | |||
| // updateUI(new HL7Message(patient, -1, LocalDateTime.now(), "ICD10 Code nicht gefunden.", true)); | |||
| // return generateACKWithAR(message, "ICD10 Code nicht gefunden."); | |||
| } | |||
| diagnose.setIcd10code(icd10code); | |||
| @@ -152,7 +156,8 @@ public class HL7Receiver2<T extends AbstractMessage> implements ReceivingApplica | |||
| String einweisenderarzt = dg1.getDiagnosingClinician(0).encode(); // Wir holen uns immer den ersten der verantwortlichen Aerzte... // (DG1-16) | |||
| mitarbeiter = mainctrl.getStammdaten().getMitarbeiter().stream().filter(m -> m.getEinweisenderArzt().equals(einweisenderarzt)).findFirst().orElse(null); | |||
| if (mitarbeiter == null) { | |||
| logHL7MessageToDatabase(message, msh, metadata); | |||
| logInHL7MessageToDatabase(message, msh, metadata); | |||
| updateUI(new HL7Message(patient, -1, LocalDateTime.now(), "Mitarbeiter nicht gefunden.", true)); | |||
| return generateACKWithAR(message, "Mitarbeiter nicht gefunden."); | |||
| } | |||
| } else { | |||
| @@ -189,7 +194,8 @@ public class HL7Receiver2<T extends AbstractMessage> implements ReceivingApplica | |||
| // TODO: Oder einfach ueberspringen? | |||
| continue; | |||
| // TODO: Behandeln von sonder Codes. | |||
| // logHL7MessageToDatabase(message, msh, metadata); | |||
| // logInHL7MessageToDatabase(message, msh, metadata); | |||
| // updateUI(new HL7Message(patient, -1, LocalDateTime.now(), "OPS Code nicht gefunden.", true)); | |||
| // return generateACKWithAR(message, "OPS Code nicht gefunden."); | |||
| } | |||
| untersuchung.setOpscode(opscode); | |||
| @@ -202,7 +208,8 @@ public class HL7Receiver2<T extends AbstractMessage> implements ReceivingApplica | |||
| String einweisenderarzt = pr1.getProcedurePractitioner(0).encode(); // Wir holen uns immer den ersten der verantwortlichen Aerzte... | |||
| mitarbeiter = mainctrl.getStammdaten().getMitarbeiter().stream().filter(m -> m.getEinweisenderArzt().equals(einweisenderarzt)).findFirst().orElse(null); | |||
| if (mitarbeiter == null) { | |||
| logHL7MessageToDatabase(message, msh, metadata); | |||
| logInHL7MessageToDatabase(message, msh, metadata); | |||
| updateUI(new HL7Message(patient, -1, LocalDateTime.now(), "Mitarbeiter nicht gefunden.", true)); | |||
| return generateACKWithAR(message, "Mitarbeiter nicht gefunden."); | |||
| } | |||
| } else { | |||
| @@ -235,9 +242,9 @@ public class HL7Receiver2<T extends AbstractMessage> implements ReceivingApplica | |||
| } | |||
| // HL7 Nachricht loggen. | |||
| logHL7MessageToDatabase(message, msh, metadata); | |||
| logInHL7MessageToDatabase(message, msh, metadata); | |||
| // TODO: Runnable...??? Jojo??? | |||
| //updatedFallIDs.forEach(id -> mainctrl.getMessageController().addMessage(new HL7Message(patient, id, LocalDateTime.now(), "Was soll hier wohl stehen?", false))); | |||
| updatedFallIDs.forEach(id -> updateUI(new HL7Message(patient, id, LocalDateTime.now(), "Was soll hier wohl stehen?", false))); | |||
| return generateACK(message); | |||
| } | |||
| @@ -250,16 +257,31 @@ public class HL7Receiver2<T extends AbstractMessage> implements ReceivingApplica | |||
| return generateACK(message); | |||
| } | |||
| private void logHL7MessageToDatabase(Message message, MSH msh, Map<String, Object> metadata) throws HL7Exception { | |||
| private void logHL7MessageToDatabase(Message message, MSH msh, Map<String, Object> metadata, HL7LogEntry.Direction direction) throws HL7Exception { | |||
| String sendind_ip = metadata.get("SENDING_IP").toString(); | |||
| String sendind_port = metadata.get("SENDING_PORT").toString(); | |||
| LocalDateTime ldt = HL7Util2.parseLocalDateTime(msh.getDateTimeOfMessage().getTime()); | |||
| HL7LogEntry entry = new HL7LogEntry(); | |||
| entry.setMessage(message.encode()); | |||
| entry.setTimestamp(ldt); | |||
| entry.setSource(sendind_ip + ":" + sendind_port); | |||
| entry.setDirection(direction); | |||
| try { | |||
| String sendind_ip = metadata.get("SENDING_IP").toString(); | |||
| String sendind_port = metadata.get("SENDING_PORT").toString(); | |||
| LocalDateTime ldt = HL7Util2.parseLocalDateTime(msh.getDateTimeOfMessage().getTime()); | |||
| DBHandler.setHL7Nachricht(message.encode(), ldt, sendind_ip + ":" + sendind_port); | |||
| // DBHandler.setHL7Nachricht(message.encode(), ldt, sendind_ip + ":" + sendind_port); | |||
| DBHandler.setHL7LogEntry(entry); | |||
| } catch (SQLException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| private void logInHL7MessageToDatabase(Message message, MSH msh, Map<String, Object> metadata) throws HL7Exception { | |||
| logHL7MessageToDatabase(message, msh, metadata, HL7LogEntry.Direction.IN); | |||
| } | |||
| private void updateUI(HL7Message hl7message) { | |||
| Platform.runLater(() -> mainctrl.getMessageController().addMessage(hl7message)); | |||
| } | |||
| } | |||
| @@ -1,150 +0,0 @@ | |||
| package de.uniluebeck.mi.projmi6.hapi2; | |||
| import ca.uhn.hl7v2.HL7Exception; | |||
| import ca.uhn.hl7v2.model.AbstractMessage; | |||
| import ca.uhn.hl7v2.model.Message; | |||
| import ca.uhn.hl7v2.model.v251.group.BAR_P05_PROCEDURE; | |||
| import ca.uhn.hl7v2.model.v251.group.BAR_P05_VISIT; | |||
| import ca.uhn.hl7v2.model.v251.message.ADT_A01; | |||
| import ca.uhn.hl7v2.model.v251.message.BAR_P05; | |||
| import ca.uhn.hl7v2.model.v251.segment.*; | |||
| import ca.uhn.hl7v2.protocol.ReceivingApplication; | |||
| import ca.uhn.hl7v2.protocol.ReceivingApplicationException; | |||
| import de.uniluebeck.mi.projmi6.model.*; | |||
| import java.io.IOException; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| /** | |||
| * Created by nils on 20.11.2015. | |||
| */ | |||
| public class HL7Recever2<T extends AbstractMessage> implements ReceivingApplication { | |||
| private final Class<T> type; | |||
| public HL7Recever2(Class<T> type) { | |||
| this.type = type; | |||
| } | |||
| @Override | |||
| public Message processMessage(Message message, Map<String, Object> metadata) throws ReceivingApplicationException, HL7Exception { | |||
| if (type == ADT_A01.class) { | |||
| return processADT_A01(message, metadata); | |||
| } | |||
| if (type == BAR_P05.class) { | |||
| return processBAR_P05(message, metadata); | |||
| } | |||
| // TODO: Handle unknown Messages, maybe write to database, sen ACK and go on. | |||
| try { | |||
| return message.generateACK(); | |||
| } catch (IOException e) { | |||
| throw new HL7Exception(e); | |||
| } | |||
| } | |||
| @Override | |||
| public boolean canProcess(Message message) { | |||
| // TODO: Erstmal alles processen. | |||
| return true; | |||
| } | |||
| private Message generateACK(Message message) throws HL7Exception { | |||
| try { | |||
| return message.generateACK(); | |||
| } catch (IOException e) { | |||
| throw new HL7Exception(e); | |||
| } | |||
| } | |||
| private Message processBAR_P05(Message message, Map<String, Object> metadata) throws HL7Exception { | |||
| Patient patient = new Patient(); | |||
| List<Fall> faelle = new ArrayList<>(); | |||
| List<Untersuchung> ALLE_UNTERSUCHUNGEN = new ArrayList<>(); | |||
| List<Diagnose> ALLE_DIAGNOSEN = new ArrayList<>(); | |||
| BAR_P05 bar_p05 = (BAR_P05) message; | |||
| MSH msh = bar_p05.getMSH(); | |||
| PID pid = bar_p05.getPID(); | |||
| patient.setPatID(Integer.parseInt(pid.getPatientID().encode())); | |||
| List<BAR_P05_VISIT> visits = bar_p05.getVISITAll(); | |||
| // Ab hier wird es dirty. | |||
| for (BAR_P05_VISIT visit : visits) { | |||
| Fall fall = new Fall(); | |||
| fall.setPatient(patient); | |||
| List<Diagnose> diagnosen = new ArrayList<>(); | |||
| List<Untersuchung> untersuchungen = new ArrayList<>(); | |||
| PV1 pv1 = visit.getPV1(); | |||
| // TODO: Extract Station(PV1-3-1),Fachabteilung(PV1-3-4),Aufnahmedatum(PV1-44),Entlassungsdatum(PV1-45),Fallnummer(PV1-19) | |||
| Station station = new Station(); | |||
| station.setStation(pv1.getAssignedPatientLocation().getPointOfCare().encode()); | |||
| station.setAbteilung(pv1.getAssignedPatientLocation().getFacility().encode()); | |||
| StationsHistorie hist = new StationsHistorie(); | |||
| hist.setStationKey(station.getStation()); | |||
| hist.setAufnahmeDatum(HL7Util2.parseLocalDateTime(pv1.getAdmitDateTime().getTime())); | |||
| hist.setEntlassungsDatum(HL7Util2.parseLocalDateTime(pv1.getDischargeDateTime()[0].getTime())); | |||
| fall.setFallID(Integer.parseInt(pv1.getVisitNumber().encode())); | |||
| List<DG1> dg1s = visit.getDG1All(); | |||
| for (DG1 dg1 : dg1s) { | |||
| Icd10Code icd10code = new Icd10Code(dg1.getDiagnosisCodeDG1().getIdentifier().encode(), "", 20); // TODO: Version hard gecoded. | |||
| // TODO: Mitarbeiter ID anhand von EinweisenderArzt erkennen! | |||
| String einweisenderarzt = dg1.getDiagnosingClinician(0).encode(); // TODO: Wir holen uns immer den ersten der verantwortlichen Aerzte... | |||
| int mitarbid = 1000; // TODO: SQL: SELECT * FROM Mitarbeiter WHERE einweisenderarzt = ... | |||
| Mitarbeiter mitarbeiter = new Mitarbeiter(mitarbid); | |||
| Diagnose diagnose = new Diagnose(); | |||
| diagnose.setIcd10code(icd10code); | |||
| diagnose.setArzt(mitarbeiter); // TODO: (DG1-16) | |||
| diagnose.setFall(fall); | |||
| // diagnose.setDiagArt(); // TODO: (DG1-6) // Enum umstellen???? | |||
| diagnosen.add(diagnose); | |||
| } | |||
| List<BAR_P05_PROCEDURE> procedures = visit.getPROCEDUREAll(); | |||
| for (BAR_P05_PROCEDURE procedure : procedures) { | |||
| PR1 pr1 = procedure.getPR1(); | |||
| Untersuchung untersuchung = new Untersuchung(); | |||
| untersuchung.setFall(fall); | |||
| OpsCode opscode = new OpsCode(pr1.getProcedureCode().encode(), "", 20); // TODO: Version hardcoded... | |||
| untersuchung.setOpscode(opscode); | |||
| untersuchung.setUntersuchungsdatum(HL7Util2.parseLocalDateTime(pr1.getProcedureDateTime().getTime())); | |||
| String einweisenderarzt = pr1.getPr112_ProcedurePractitioner(0).encode(); // TODO: Wieder nur den ersten Arzt.. | |||
| int mitarbid = 1000; // TODO: Siehe oben | |||
| untersuchung.setDurchfuehrenderArzt(new Mitarbeiter(mitarbid)); | |||
| // TODO: Extract OPS(3), Zeitpunkt(5), Arzt(12) | |||
| untersuchungen.add(untersuchung); | |||
| } | |||
| // TODO: hier jeweils Fall, Untersuchung und Diagnosen in die Datenbank schreiben... | |||
| faelle.add(fall); | |||
| ALLE_DIAGNOSEN.addAll(diagnosen); | |||
| ALLE_UNTERSUCHUNGEN.addAll(untersuchungen); | |||
| } | |||
| return generateACK(message); | |||
| } | |||
| private Message processADT_A01(Message message, Map<String, Object> metadata) throws HL7Exception { | |||
| ADT_A01 adt_a01 = (ADT_A01) message; | |||
| System.out.println(adt_a01.toString()); | |||
| return generateACK(message); | |||
| } | |||
| } | |||
| @@ -39,16 +39,6 @@ public class HL7Server2 { | |||
| server.start(); | |||
| } | |||
| // TODO: Remove, for testing purpose only! | |||
| public static void main(String[] args) throws InterruptedException { | |||
| HL7Server2 srv = new HL7Server2(null); | |||
| for (; ; ) { | |||
| } | |||
| //srv.stop(); | |||
| //srv.shutdown(); | |||
| } | |||
| public void stop() { | |||
| if (server != null && server.isRunning()) { | |||
| server.stop(); | |||
| @@ -9,26 +9,44 @@ import java.time.LocalDateTime; | |||
| * Created by 631806 on 19.11.15. | |||
| */ | |||
| public class HL7LogEntry { | |||
| private final int msgid; | |||
| private final SimpleStringProperty message = new SimpleStringProperty(this, "message"); | |||
| private final SimpleStringProperty source = new SimpleStringProperty(this, "source"); | |||
| private final SimpleObjectProperty<Direction> direction = new SimpleObjectProperty<>(this, "direction"); | |||
| private final SimpleObjectProperty<LocalDateTime> timestamp = new SimpleObjectProperty<>(this, "timestamp"); | |||
| private int msgid; | |||
| public HL7LogEntry() { | |||
| } | |||
| public HL7LogEntry(int msgid) { | |||
| this.msgid = msgid; | |||
| } | |||
| public LocalDateTime getTimestamp() { | |||
| return timestamp.get(); | |||
| public Direction getDirection() { | |||
| return direction.get(); | |||
| } | |||
| public SimpleObjectProperty<LocalDateTime> timestampProperty() { | |||
| return timestamp; | |||
| public void setDirection(Direction direction) { | |||
| this.direction.set(direction); | |||
| } | |||
| public SimpleObjectProperty<Direction> directionProperty() { | |||
| return direction; | |||
| } | |||
| public LocalDateTime getTimestamp() { | |||
| return timestamp.get(); | |||
| } | |||
| public void setTimestamp(LocalDateTime timestamp) { | |||
| this.timestamp.set(timestamp); | |||
| } | |||
| public SimpleObjectProperty<LocalDateTime> timestampProperty() { | |||
| return timestamp; | |||
| } | |||
| public int getMsgid() { | |||
| return msgid; | |||
| } | |||
| @@ -37,26 +55,51 @@ public class HL7LogEntry { | |||
| return message.get(); | |||
| } | |||
| public SimpleStringProperty messageProperty() { | |||
| return message; | |||
| } | |||
| public void setMessage(String message) { | |||
| this.message.set(message); | |||
| } | |||
| public String getSource() { | |||
| return source.get(); | |||
| public SimpleStringProperty messageProperty() { | |||
| return message; | |||
| } | |||
| public SimpleStringProperty sourceProperty() { | |||
| return source; | |||
| public String getSource() { | |||
| return source.get(); | |||
| } | |||
| public void setSource(String source) { | |||
| this.source.set(source); | |||
| } | |||
| public SimpleStringProperty sourceProperty() { | |||
| return source; | |||
| } | |||
| private final SimpleObjectProperty<LocalDateTime> timestamp = new SimpleObjectProperty<>(this, "timestamp"); | |||
| public enum Direction { | |||
| IN("in"), | |||
| OUT("out"), | |||
| UNKNOWN("o"); | |||
| private final String direction; | |||
| Direction(String direction) { | |||
| this.direction = direction; | |||
| } | |||
| public static Direction parseDirection(String direction) { | |||
| switch (direction) { | |||
| case "in": | |||
| return IN; | |||
| case "out": | |||
| return OUT; | |||
| default: | |||
| return UNKNOWN; | |||
| } | |||
| } | |||
| @Override | |||
| public String toString() { | |||
| return direction; | |||
| } | |||
| } | |||
| } | |||