diff --git a/pom.xml b/pom.xml
index b8b8785..0a4031c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,4 @@
-
4.0.0
imi
@@ -67,5 +67,15 @@
hapi-structures-v251
2.2
+
+ org.slf4j
+ slf4j-log4j12
+ 1.6.6
+
+
+ log4j
+ log4j
+ 1.2.17
+
\ No newline at end of file
diff --git a/src/main/java/de/uniluebeck/mi/projmi6/Main.java b/src/main/java/de/uniluebeck/mi/projmi6/Main.java
index 6d934bf..55a55e4 100644
--- a/src/main/java/de/uniluebeck/mi/projmi6/Main.java
+++ b/src/main/java/de/uniluebeck/mi/projmi6/Main.java
@@ -2,9 +2,7 @@ package de.uniluebeck.mi.projmi6;
import de.uniluebeck.mi.projmi6.controller.MainController;
import de.uniluebeck.mi.projmi6.db.DBHandler;
-import de.uniluebeck.mi.projmi6.model.Kasse;
-import de.uniluebeck.mi.projmi6.model.Mitarbeiter;
-import de.uniluebeck.mi.projmi6.model.OpsCode;
+import de.uniluebeck.mi.projmi6.hapi2.HL7Server2;
import javafx.application.Application;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.collections.FXCollections;
@@ -14,7 +12,6 @@ import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Parent;
import javafx.scene.Scene;
-import javafx.scene.control.ProgressIndicator;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Background;
@@ -30,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 loadMainWindowTask = new Task(){
+
@Override
protected Parent call() throws Exception {
@@ -72,15 +72,34 @@ public class Main extends Application {
Parent root = fxmlLoader.load();
+ // TODO: Jojo, das muss irgendwie am ende noch geschlossen werden!
+ server = new HL7Server2(mainController);
+
return root;
}
};
-
/**
* The applications logo (an owl).
*/
private Image icon = new Image("icon.png", true);
+ /**
+ * Applications entry point.
+ *
+ * @param args Commandline parameters
+ */
+ public static void main(String[] args) {
+ launch(args);
+ }
+
+ @Override
+ public void stop() throws Exception {
+ if (server != null) {
+ server.stop();
+ server.shutdown();
+ }
+ super.stop();
+ }
@Override
public void start(Stage primaryStage) {
@@ -117,7 +136,7 @@ public class Main extends Application {
*
* @return the splash screen
*/
- public Stage createLoadWindow(ReadOnlyStringProperty progressMessage){
+ public Stage createLoadWindow(ReadOnlyStringProperty progressMessage) {
Text kis = new Text("KIS");
kis.setFont(Font.font(50));
@@ -127,7 +146,7 @@ public class Main extends Application {
Text progress = new Text();
progress.textProperty().bind(progressMessage);
- VBox root = new VBox(gruppe6, new ImageView(icon), kis, progress);
+ VBox root = new VBox(gruppe6, new ImageView(icon), kis, progress);
root.setSpacing(20);
root.setAlignment(Pos.CENTER);
Scene scene = new Scene(root, 400, 500);
@@ -140,13 +159,4 @@ public class Main extends Application {
return stage;
}
-
- /**
- * Applications entry point.
- *
- * @param args Commandline parameters
- */
- public static void main(String[] args) {
- launch(args);
- }
}
diff --git a/src/main/java/de/uniluebeck/mi/projmi6/controller/LogController.java b/src/main/java/de/uniluebeck/mi/projmi6/controller/LogController.java
index fa8855d..b3177a2 100644
--- a/src/main/java/de/uniluebeck/mi/projmi6/controller/LogController.java
+++ b/src/main/java/de/uniluebeck/mi/projmi6/controller/LogController.java
@@ -5,9 +5,7 @@ import de.uniluebeck.mi.projmi6.model.HL7LogEntry;
import javafx.collections.FXCollections;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
-import javafx.scene.control.Button;
-import javafx.scene.control.TableColumn;
-import javafx.scene.control.TableView;
+import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.text.Text;
@@ -31,6 +29,10 @@ public class LogController {
TableColumn colLogTime;
@FXML
+ TableColumn colLogDirection;
+
+
+ @FXML
Button btnRefresh;
@@ -46,9 +48,33 @@ public class LogController {
}
private void initColumns(){
+ colLogDirection.setCellValueFactory(new PropertyValueFactory("direction"));
colLogIp.setCellValueFactory(new PropertyValueFactory("source"));
colLogTime.setCellValueFactory(new PropertyValueFactory("timestamp"));
- colLogIp.setCellValueFactory(new PropertyValueFactory("message"));
+ colLogMessage.setCellValueFactory(new PropertyValueFactory("message"));
+
+ colLogMessage.setCellFactory(column -> {
+ return new TableCell(){
+ private TextArea textArea = new TextArea();
+ {
+ textArea.setEditable(false);
+ textArea.setPrefRowCount(5);
+ }
+
+ @Override
+ protected void updateItem(String item, boolean empty) {
+ super.updateItem(item, empty);
+ this.setText(null);
+ if(item == null || empty){
+ this.setGraphic(null);
+ return;
+ }
+ textArea.setText(item);
+ textArea.setWrapText(true);
+ this.setGraphic(textArea);
+ }
+ };
+ });
}
@@ -80,6 +106,7 @@ public class LogController {
tblLog.setItems(FXCollections.observableArrayList(this.getValue()));
mainController.decreaseParallelTaskCount();
btnRefresh.setDisable(false);
+
}
@Override
diff --git a/src/main/java/de/uniluebeck/mi/projmi6/controller/MainController.java b/src/main/java/de/uniluebeck/mi/projmi6/controller/MainController.java
index b3f0b2e..4628da4 100644
--- a/src/main/java/de/uniluebeck/mi/projmi6/controller/MainController.java
+++ b/src/main/java/de/uniluebeck/mi/projmi6/controller/MainController.java
@@ -152,6 +152,36 @@ public class MainController {
}
+ private int fallIdToShow = -1;
+
+ public void selectPatientAndFallId(Patient patient, int fallId){
+ if(patientTablesController.getSelectedPatient()==patient
+ && !loadFallTask.isRunning()){
+ selectFallById(fallId);
+ return;
+ }
+
+ fallIdToShow = fallId;
+ patientTablesController.selectPatient(patient);
+ }
+
+ private void selectFallById(int id){
+ if(lvFall.getItems() == null){
+ return;
+ }
+
+ for(Fall fall: lvFall.getItems()){
+ if(fall.getFallID()== id ){
+ lvFall.getSelectionModel().select(fall);
+ return;
+ }
+ }
+
+
+ }
+
+
+
@FXML
private Label lvFallPlaceholder;
@@ -187,6 +217,11 @@ public class MainController {
lvFallPlaceholder.setText("Keine F\u00e4lle vorhanden!");
lvFall.setItems(FXCollections.observableArrayList(getValue()));
decreaseParallelTaskCount();
+
+ if(fallIdToShow!=-1){
+ selectFallById(fallIdToShow);
+ fallIdToShow = -1;
+ }
}
@Override
diff --git a/src/main/java/de/uniluebeck/mi/projmi6/controller/MessageController.java b/src/main/java/de/uniluebeck/mi/projmi6/controller/MessageController.java
index d1d90d3..1ca1021 100644
--- a/src/main/java/de/uniluebeck/mi/projmi6/controller/MessageController.java
+++ b/src/main/java/de/uniluebeck/mi/projmi6/controller/MessageController.java
@@ -38,12 +38,10 @@ public class MessageController {
@FXML
private void initialize(){
messageIcon.messageCountProperty().bind(messages.sizeProperty());
- messages.add(new HL7Message(null, 0, LocalDateTime.now(), null, true));
}
@FXML
private void onMessageIconClicked(){
-
showMessageList();
}
@@ -63,7 +61,7 @@ public class MessageController {
Stage stage = new Stage();
- stage.setTitle(messages.size()+ " neue HL7-Nachrichten");
+ stage.setTitle("Neue HL7-Nachrichten");
stage.setScene(new Scene(root, 600, 400));
stage.getIcons().add(new Image("icon.png"));
diff --git a/src/main/java/de/uniluebeck/mi/projmi6/controller/MessageListController.java b/src/main/java/de/uniluebeck/mi/projmi6/controller/MessageListController.java
index 98f9391..d67fa7f 100644
--- a/src/main/java/de/uniluebeck/mi/projmi6/controller/MessageListController.java
+++ b/src/main/java/de/uniluebeck/mi/projmi6/controller/MessageListController.java
@@ -71,8 +71,10 @@ public class MessageListController {
alert.initModality(Modality.APPLICATION_MODAL);
alert.showAndWait();
+ }else{
+ mainController.selectPatientAndFallId(message.getPatient(), message.getFallId());
+ ((Stage)lvMessages.getScene().getWindow()).close();
}
- //TODO Go to patient
}
diff --git a/src/main/java/de/uniluebeck/mi/projmi6/controller/PatientTablesController.java b/src/main/java/de/uniluebeck/mi/projmi6/controller/PatientTablesController.java
index c0cef19..fbb9ea2 100644
--- a/src/main/java/de/uniluebeck/mi/projmi6/controller/PatientTablesController.java
+++ b/src/main/java/de/uniluebeck/mi/projmi6/controller/PatientTablesController.java
@@ -223,6 +223,11 @@ public class PatientTablesController {
stage.show();
}
+ public void selectPatient(Patient patient){
+ patientOverviewTabPane.getSelectionModel().select(0); // Select first tab
+ tblPatientOverview.getSelectionModel().select(patient);
+ }
+
public void updatePatientsFromDb() {
if (this.loadPatientTask != null && this.loadPatientTask.isRunning()) {
System.out.println("Patienten werden bereits geladen.");
diff --git a/src/main/java/de/uniluebeck/mi/projmi6/controller/StationsHistorieController.java b/src/main/java/de/uniluebeck/mi/projmi6/controller/StationsHistorieController.java
index eeb8658..383f769 100644
--- a/src/main/java/de/uniluebeck/mi/projmi6/controller/StationsHistorieController.java
+++ b/src/main/java/de/uniluebeck/mi/projmi6/controller/StationsHistorieController.java
@@ -166,9 +166,14 @@ public class StationsHistorieController {
@FXML
private void clickedSave() {
+
+
if (getState() == State.CREATE) {
StationsHistorie stationsHistorie = new StationsHistorie();
copyFieldDataIntoStationsHistorie(stationsHistorie);
+ if(!validateData(stationsHistorie)){
+ return;
+ }
try {
DBHandler.setStationsHistorie(stationsHistorie, false);
} catch (SQLException e) {
@@ -177,6 +182,9 @@ public class StationsHistorieController {
mainController.refreshCaseData();
} else {
copyFieldDataIntoStationsHistorie(stationsHistorieSelected);
+ if(!validateData(stationsHistorieSelected)){
+ return;
+ }
try {
DBHandler.setStationsHistorie(stationsHistorieSelected, true);
} catch (SQLException e) {
@@ -290,11 +298,45 @@ public class StationsHistorieController {
stationsHistorie.setEntlassungsDatum(dtTmEntlassung.getDateTime());
stationsHistorie.setStation(cmbStation.getValue());
stationsHistorie.setFallID(mainController.getFallController().getFall().getFallID());
- stationsHistorie.setStationKey(cmbStation.getValue().getStation());
+ if(cmbStation.getValue()!= null){
+ stationsHistorie.setStationKey(cmbStation.getValue().getStation());
+ }else{
+ stationsHistorie.setStationKey(null);
+ }
stationsHistorie.setErsteller(mainController.getCurrentMitarbeiter().getMitarbID());
stationsHistorie.setBearbeiter(mainController.getCurrentMitarbeiter().getMitarbID());
}
+
+ private void showMessage(String title, String message) {
+ Alert alert = new Alert(Alert.AlertType.INFORMATION);
+ alert.setTitle("Ung\u00fcltige Daten!");
+ alert.setHeaderText(title);
+ alert.setContentText(message);
+ alert.initModality(Modality.APPLICATION_MODAL);
+ alert.showAndWait();
+ }
+
+
+ private boolean validateData(StationsHistorie stationsHistorie){
+ if(stationsHistorie.getStationKey()==null){
+ showMessage("Keine Station ausgew\00e4hlt!", "Bitte Station und nicht nur Abteilung ausw\00e4hlen!");
+ return false;
+ }
+ if(stationsHistorie.getAufnahmeDatum()==null){
+ showMessage("Aufnahmedatum fehlt!", "Bitte den Beginn des Stationsaufenthalts angeben!");
+ return false;
+ }
+ if(stationsHistorie.getEntlassungsDatum() != null &&
+ stationsHistorie.getAufnahmeDatum().isAfter(stationsHistorie.getEntlassungsDatum())){
+ showMessage("Aufnahmedatum liegt hinter Entlassungsdatum!", "Bitte die eingegebenen Daten nocheinmal kontrollieren!");
+ return false;
+ }
+
+
+ return true;
+ }
+
private void clearFields(){
statHistCreateTime.setText("");
diff --git a/src/main/java/de/uniluebeck/mi/projmi6/db/DBHandler.java b/src/main/java/de/uniluebeck/mi/projmi6/db/DBHandler.java
index 4982a1d..532dfbd 100644
--- a/src/main/java/de/uniluebeck/mi/projmi6/db/DBHandler.java
+++ b/src/main/java/de/uniluebeck/mi/projmi6/db/DBHandler.java
@@ -155,6 +155,13 @@ public class DBHandler {
"`FallID`) " +
"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() {
@@ -834,11 +841,33 @@ 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;
}
+
+ public static List getAlleFallIdsByPatID(int patid) throws SQLException {
+ PreparedStatement statement = MySqlConnectionFactory.getConnection().prepareStatement(SELECT_FALLIDS_BY_PATID);
+ statement.setInt(1, patid);
+ ResultSet rs = statement.executeQuery();
+
+ List fallids = new ArrayList<>();
+ while (rs.next()) {
+ fallids.add(rs.getInt("fallid"));
+ }
+ return fallids;
+ }
}
diff --git a/src/main/java/de/uniluebeck/mi/projmi6/hapi2/HL7ConnectionListener2.java b/src/main/java/de/uniluebeck/mi/projmi6/hapi2/HL7ConnectionListener2.java
new file mode 100644
index 0000000..a0dbac6
--- /dev/null
+++ b/src/main/java/de/uniluebeck/mi/projmi6/hapi2/HL7ConnectionListener2.java
@@ -0,0 +1,20 @@
+package de.uniluebeck.mi.projmi6.hapi2;
+
+import ca.uhn.hl7v2.app.Connection;
+import ca.uhn.hl7v2.app.ConnectionListener;
+
+/**
+ * Created by nils on 20.11.2015.
+ */
+class HL7ConnectionListener2 implements ConnectionListener {
+
+ @Override
+ public void connectionReceived(Connection c) {
+ // System.out.println("New connection: " + c.getRemoteAddress().toString());
+ }
+
+ @Override
+ public void connectionDiscarded(Connection c) {
+ // System.out.println("Lost connection: " + c.getRemoteAddress().toString());
+ }
+}
diff --git a/src/main/java/de/uniluebeck/mi/projmi6/hapi2/HL7ExceptionHandler2.java b/src/main/java/de/uniluebeck/mi/projmi6/hapi2/HL7ExceptionHandler2.java
new file mode 100644
index 0000000..b746016
--- /dev/null
+++ b/src/main/java/de/uniluebeck/mi/projmi6/hapi2/HL7ExceptionHandler2.java
@@ -0,0 +1,16 @@
+package de.uniluebeck.mi.projmi6.hapi2;
+
+import ca.uhn.hl7v2.HL7Exception;
+import ca.uhn.hl7v2.protocol.ReceivingApplicationExceptionHandler;
+
+import java.util.Map;
+
+/**
+ * Created by nils on 20.11.2015.
+ */
+public class HL7ExceptionHandler2 implements ReceivingApplicationExceptionHandler {
+ @Override
+ public String processException(String incomingMessage, Map incomingMetadata, String outgoingMessage, Exception e) throws HL7Exception {
+ return outgoingMessage;
+ }
+}
diff --git a/src/main/java/de/uniluebeck/mi/projmi6/hapi2/HL7Receiver2.java b/src/main/java/de/uniluebeck/mi/projmi6/hapi2/HL7Receiver2.java
new file mode 100644
index 0000000..b529dd5
--- /dev/null
+++ b/src/main/java/de/uniluebeck/mi/projmi6/hapi2/HL7Receiver2.java
@@ -0,0 +1,288 @@
+package de.uniluebeck.mi.projmi6.hapi2;
+
+import ca.uhn.hl7v2.AcknowledgmentCode;
+import ca.uhn.hl7v2.ErrorCode;
+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.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;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by nils on 20.11.2015.
+ */
+public class HL7Receiver2 implements ReceivingApplication {
+ private final Class type;
+ private final MainController mainctrl;
+
+ public HL7Receiver2(Class type, MainController mainctrl) {
+ this.type = type;
+ this.mainctrl = mainctrl;
+ }
+
+
+ @Override
+ public Message processMessage(Message message, Map 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, send 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 message instanceof BAR_P05 || message instanceof ADT_A01;
+ }
+
+ private Message generateACK(Message message) throws HL7Exception {
+ try {
+ return message.generateACK();
+ } catch (IOException e) {
+ throw new HL7Exception(e);
+ }
+ }
+
+ private Message generateACKWithAR(Message message, String s) throws HL7Exception {
+ try {
+ return message.generateACK(AcknowledgmentCode.AR, new HL7Exception(s, ErrorCode.UNKNOWN_KEY_IDENTIFIER));
+ } catch (IOException e) {
+ throw new HL7Exception(e);
+ }
+ }
+
+ private Message processBAR_P05(Message message, Map metadata) throws HL7Exception {
+ BAR_P05 bar_p05 = (BAR_P05) message;
+
+ MSH msh = bar_p05.getMSH();
+ PID pid = bar_p05.getPID();
+
+ int patid = Integer.parseInt(pid.getPatientID().encode());
+ Patient patient = mainctrl.getStammdaten().getPatienten().stream().filter(p -> p.getPatID() == patid).findFirst().orElse(null);
+
+ if (patient == null) {
+ logInHL7MessageToDatabase(message, msh, metadata);
+ updateUI(new HL7Message(null, -1, LocalDateTime.now(), "Patient nicht gefunden.", true));
+ return generateACKWithAR(message, "Patient nicht gefunden.");
+ } // TODO: Patienten und Fall neu anlegen??? Nicht verlangt!
+
+ List visits = bar_p05.getVISITAll();
+
+ List updatedFallIDs = new ArrayList<>();
+
+ // Ab hier wird es dirty.
+ for (BAR_P05_VISIT visit : visits) {
+ PV1 pv1 = visit.getPV1();
+ int fallid = Integer.parseInt(pv1.getVisitNumber().encode());
+
+ List fallids = new ArrayList<>();
+ try {
+ fallids = DBHandler.getAlleFallIdsByPatID(patient.getPatID());
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ if (fallids.isEmpty() || !fallids.contains(fallid)) {
+ logInHL7MessageToDatabase(message, msh, metadata);
+ updateUI(new HL7Message(patient, -1, LocalDateTime.now(), "Fall nicht gefunden.?", true));
+ return generateACKWithAR(message, "Fall nicht gefunden.");
+ }
+
+ Fall fall = new Fall();
+ fall.setFallID(fallid);
+ fall.setPatient(patient);
+
+ List diagnosen = new ArrayList<>();
+ List untersuchungen = new ArrayList<>();
+
+ // Station(PV1-3-1), Fachabteilung(PV1-3-4), Aufnahmedatum(PV1-44), Entlassungsdatum(PV1-45), Fallnummer(PV1-19)
+ Station station = new Station(); // TODO: Station holen!
+ station.setStation(pv1.getAssignedPatientLocation().getPointOfCare().encode());
+ station.setAbteilung(pv1.getAssignedPatientLocation().getFacility().encode());
+
+ StationsHistorie hist = new StationsHistorie(); // TODO: StationsHist schreiben/schon vorhanden!
+ hist.setStationKey(station.getStation());
+ hist.setAufnahmeDatum(HL7Util2.parseLocalDateTime(pv1.getAdmitDateTime().getTime()));
+ hist.setEntlassungsDatum(HL7Util2.parseLocalDateTime(pv1.getDischargeDateTime()[0].getTime())); // TODO: null?
+ hist.setFallID(fallid);
+
+ List dg1s = visit.getDG1All();
+ for (DG1 dg1 : dg1s) {
+ Diagnose diagnose = new Diagnose();
+ diagnose.setErsteller(99999);
+ diagnose.setBearbeiter(99999);
+ diagnose.setFall(fall);
+
+ String icd10 = dg1.getDiagnosisCodeDG1().getIdentifier().encode();
+ Icd10Code icd10code = mainctrl.getStammdaten().getIcd10Codes().stream().filter(i -> i.getCode().equals(icd10)).findFirst().orElse(null);
+ if (icd10code == null) {
+ // TODO: Oder einfach ueberspringen?
+ continue;
+ // TODO: Behandeln von sonder Codes. K35.9V (Verdacht...)
+ // 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);
+
+ // Mitarbeiter ID anhand von EinweisenderArzt erkennen.
+ Mitarbeiter mitarbeiter;
+ if (dg1.getDiagnosingClinician().length != 0) {
+ 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) {
+ logInHL7MessageToDatabase(message, msh, metadata);
+ updateUI(new HL7Message(patient, -1, LocalDateTime.now(), "Mitarbeiter nicht gefunden.", true));
+ return generateACKWithAR(message, "Mitarbeiter nicht gefunden.");
+ }
+ } else {
+ mitarbeiter = new Mitarbeiter(99999);
+ }
+ diagnose.setArzt(mitarbeiter);
+ // (DG1-6) // TODO: Enum umstellen? Neeee...
+ String diagart = dg1.getDiagnosisType().encode();
+ switch (diagart) {
+ case "A":
+ diagnose.setDiagArt(DiagArt.EINWEISUNG);
+ break;
+ case "F":
+ diagnose.setDiagArt(DiagArt.ENTLASSUNG);
+ break;
+ case "W":
+ default:
+ diagnose.setDiagArt(DiagArt.VERDACHT);
+ }
+ diagnose.setFreiText(dg1.getDiagnosisDescription().encode());
+
+ diagnosen.add(diagnose);
+ }
+ List procedures = visit.getPROCEDUREAll();
+ for (BAR_P05_PROCEDURE procedure : procedures) {
+ PR1 pr1 = procedure.getPR1();
+ Untersuchung untersuchung = new Untersuchung();
+ untersuchung.setErsteller(99999);
+ untersuchung.setBearbeiter(99999);
+ untersuchung.setFall(fall);
+
+ String ops = pr1.getProcedureCode().encode();
+ OpsCode opscode = mainctrl.getStammdaten().getOpsCodes().stream().filter(o -> o.getOpsCode().equals(ops)).findFirst().orElse(null);
+ if (opscode == null) {
+ // TODO: Oder einfach ueberspringen?
+ continue;
+ // TODO: Behandeln von sonder Codes.
+ // 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);
+
+ untersuchung.setUntersuchungsdatum(HL7Util2.parseLocalDateTime(pr1.getProcedureDateTime().getTime()));
+
+ // Mitarbeiter ID anhand von EinweisenderArzt erkennen.
+ Mitarbeiter mitarbeiter;
+ if (pr1.getProcedurePractitioner().length != 0) {
+ 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) {
+ logInHL7MessageToDatabase(message, msh, metadata);
+ updateUI(new HL7Message(patient, -1, LocalDateTime.now(), "Mitarbeiter nicht gefunden.", true));
+ return generateACKWithAR(message, "Mitarbeiter nicht gefunden.");
+ }
+ } else {
+ mitarbeiter = new Mitarbeiter(99999);
+ }
+ untersuchung.setDurchfuehrenderArzt(mitarbeiter);
+
+ untersuchungen.add(untersuchung);
+ }
+
+ // Hier jeweils Untersuchung und Diagnose in die Datenbank schreiben.
+ diagnosen.forEach(d -> {
+ try {
+ DBHandler.setDiagnose(d);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ });
+
+ untersuchungen.forEach(u -> {
+ try {
+ DBHandler.setUntersuchung(u, 99999, false);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ });
+
+ // Remember welche Faelle geaendert wurden
+ updatedFallIDs.add(fallid);
+ }
+
+ // HL7 Nachricht loggen.
+ logInHL7MessageToDatabase(message, msh, metadata);
+ // TODO: Runnable...??? Jojo???
+ updatedFallIDs.forEach(id -> updateUI(new HL7Message(patient, id, LocalDateTime.now(), "Was soll hier wohl stehen?", false)));
+
+ return generateACK(message);
+ }
+
+
+ private Message processADT_A01(Message message, Map metadata) throws HL7Exception {
+ ADT_A01 adt_a01 = (ADT_A01) message;
+ System.out.println(adt_a01.toString());
+
+ return generateACK(message);
+ }
+
+ private void logHL7MessageToDatabase(Message message, MSH msh, Map 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 {
+ // 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 metadata) throws HL7Exception {
+ logHL7MessageToDatabase(message, msh, metadata, HL7LogEntry.Direction.IN);
+ }
+
+ private void updateUI(HL7Message hl7message) {
+ Platform.runLater(() -> mainctrl.getMessageController().addMessage(hl7message));
+ }
+}
diff --git a/src/main/java/de/uniluebeck/mi/projmi6/hapi2/HL7Server2.java b/src/main/java/de/uniluebeck/mi/projmi6/hapi2/HL7Server2.java
new file mode 100644
index 0000000..f670f6a
--- /dev/null
+++ b/src/main/java/de/uniluebeck/mi/projmi6/hapi2/HL7Server2.java
@@ -0,0 +1,53 @@
+package de.uniluebeck.mi.projmi6.hapi2;
+
+import ca.uhn.hl7v2.DefaultHapiContext;
+import ca.uhn.hl7v2.HapiContext;
+import ca.uhn.hl7v2.app.HL7Service;
+import ca.uhn.hl7v2.model.v251.message.ADT_A01;
+import ca.uhn.hl7v2.model.v251.message.BAR_P05;
+import de.uniluebeck.mi.projmi6.controller.MainController;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Created by nils on 20.11.2015.
+ */
+public class HL7Server2 {
+
+ private static final int PORT = 1111;
+ private final HapiContext context;
+ private final HL7Service server;
+ private final ThreadPoolExecutor executor;
+
+ public HL7Server2(MainController mainctrl) throws InterruptedException {
+ executor = new ThreadPoolExecutor(10, 100, 30, TimeUnit.SECONDS, new ArrayBlockingQueue(100));
+ executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+
+ context = new DefaultHapiContext();
+ context.setExecutorService(executor);
+ server = context.newServer(PORT, false);
+
+ server.registerApplication("ADT", "A01", new HL7Receiver2(ADT_A01.class, mainctrl));
+ server.registerApplication("BAR", "P05", new HL7Receiver2(BAR_P05.class, mainctrl));
+
+ server.registerConnectionListener(new HL7ConnectionListener2());
+ server.setExceptionHandler(new HL7ExceptionHandler2());
+
+ //server.startAndWait();
+ server.start();
+ }
+
+ public void stop() {
+ if (server != null && server.isRunning()) {
+ server.stop();
+ }
+ }
+
+ public void shutdown() {
+ if (executor != null && !executor.isTerminated()) {
+ executor.shutdown();
+ }
+ }
+}
diff --git a/src/main/java/de/uniluebeck/mi/projmi6/hapi2/HL7Util2.java b/src/main/java/de/uniluebeck/mi/projmi6/hapi2/HL7Util2.java
new file mode 100644
index 0000000..b323e5e
--- /dev/null
+++ b/src/main/java/de/uniluebeck/mi/projmi6/hapi2/HL7Util2.java
@@ -0,0 +1,33 @@
+package de.uniluebeck.mi.projmi6.hapi2;
+
+import ca.uhn.hl7v2.model.DataTypeException;
+import ca.uhn.hl7v2.model.v251.datatype.DTM;
+
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+
+/**
+ * Created by nils on 20.11.2015.
+ */
+public class HL7Util2 {
+ public static LocalDateTime parseLocalDateTime(DTM dtm) {
+ try {
+ return LocalDateTime.ofInstant(dtm.getValueAsDate().toInstant(), ZoneId.systemDefault());
+ } catch (DataTypeException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static String parseIcd10Code(String icd10code) {
+ return removeWhitespaces(icd10code).substring(0, 5);
+ }
+
+ public static String parseOpsCode(String opscode) {
+ return removeWhitespaces(opscode).substring(0, 7);
+ }
+
+ private static String removeWhitespaces(String s) {
+ return s.replaceAll("\\s", "");
+ }
+}
diff --git a/src/main/java/de/uniluebeck/mi/projmi6/model/HL7LogEntry.java b/src/main/java/de/uniluebeck/mi/projmi6/model/HL7LogEntry.java
index bcacbd0..8468bb9 100644
--- a/src/main/java/de/uniluebeck/mi/projmi6/model/HL7LogEntry.java
+++ b/src/main/java/de/uniluebeck/mi/projmi6/model/HL7LogEntry.java
@@ -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 = new SimpleObjectProperty<>(this, "direction");
+ private final SimpleObjectProperty 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 timestampProperty() {
- return timestamp;
+ public void setDirection(Direction direction) {
+ this.direction.set(direction);
+ }
+
+ public SimpleObjectProperty directionProperty() {
+ return direction;
+ }
+
+ public LocalDateTime getTimestamp() {
+ return timestamp.get();
}
public void setTimestamp(LocalDateTime timestamp) {
this.timestamp.set(timestamp);
}
+ public SimpleObjectProperty 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 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;
+ }
+ }
}
diff --git a/src/main/resources/fall.fxml b/src/main/resources/fall.fxml
index addce52..59a5224 100644
--- a/src/main/resources/fall.fxml
+++ b/src/main/resources/fall.fxml
@@ -40,7 +40,7 @@
-
+
diff --git a/src/main/resources/log.fxml b/src/main/resources/log.fxml
index e0a1893..beaaf87 100644
--- a/src/main/resources/log.fxml
+++ b/src/main/resources/log.fxml
@@ -1,23 +1,25 @@
+
-
+
-
+
-
-
+
+
+
diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties
new file mode 100644
index 0000000..393e087
--- /dev/null
+++ b/src/main/resources/log4j.properties
@@ -0,0 +1,8 @@
+# Root logger option
+log4j.rootLogger=INFO, stdout
+
+# Direct log messages to stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
\ No newline at end of file