| @@ -1,4 +1,4 @@ | |||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||
| <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | |||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||
| <modelVersion>4.0.0</modelVersion> | |||
| <groupId>imi</groupId> | |||
| @@ -67,5 +67,15 @@ | |||
| <artifactId>hapi-structures-v251</artifactId> | |||
| <version>2.2</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>org.slf4j</groupId> | |||
| <artifactId>slf4j-log4j12</artifactId> | |||
| <version>1.6.6</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>log4j</groupId> | |||
| <artifactId>log4j</artifactId> | |||
| <version>1.2.17</version> | |||
| </dependency> | |||
| </dependencies> | |||
| </project> | |||
| @@ -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<Parent> loadMainWindowTask = new Task<Parent>(){ | |||
| @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); | |||
| } | |||
| } | |||
| @@ -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<HL7LogEntry, LocalDateTime> colLogTime; | |||
| @FXML | |||
| TableColumn<HL7LogEntry, HL7LogEntry.Direction> colLogDirection; | |||
| @FXML | |||
| Button btnRefresh; | |||
| @@ -46,9 +48,33 @@ public class LogController { | |||
| } | |||
| private void initColumns(){ | |||
| colLogDirection.setCellValueFactory(new PropertyValueFactory<HL7LogEntry, HL7LogEntry.Direction>("direction")); | |||
| colLogIp.setCellValueFactory(new PropertyValueFactory<HL7LogEntry, String>("source")); | |||
| colLogTime.setCellValueFactory(new PropertyValueFactory<HL7LogEntry, LocalDateTime>("timestamp")); | |||
| colLogIp.setCellValueFactory(new PropertyValueFactory<HL7LogEntry, String>("message")); | |||
| colLogMessage.setCellValueFactory(new PropertyValueFactory<HL7LogEntry, String>("message")); | |||
| colLogMessage.setCellFactory(column -> { | |||
| return new TableCell<HL7LogEntry, String>(){ | |||
| 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 | |||
| @@ -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 | |||
| @@ -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")); | |||
| @@ -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 | |||
| } | |||
| @@ -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."); | |||
| @@ -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(""); | |||
| @@ -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<Integer> getAlleFallIdsByPatID(int patid) throws SQLException { | |||
| PreparedStatement statement = MySqlConnectionFactory.getConnection().prepareStatement(SELECT_FALLIDS_BY_PATID); | |||
| statement.setInt(1, patid); | |||
| ResultSet rs = statement.executeQuery(); | |||
| List<Integer> fallids = new ArrayList<>(); | |||
| while (rs.next()) { | |||
| fallids.add(rs.getInt("fallid")); | |||
| } | |||
| return fallids; | |||
| } | |||
| } | |||
| @@ -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()); | |||
| } | |||
| } | |||
| @@ -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<String, Object> incomingMetadata, String outgoingMessage, Exception e) throws HL7Exception { | |||
| return outgoingMessage; | |||
| } | |||
| } | |||
| @@ -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<T extends AbstractMessage> implements ReceivingApplication { | |||
| private final Class<T> type; | |||
| private final MainController mainctrl; | |||
| public HL7Receiver2(Class<T> type, MainController mainctrl) { | |||
| this.type = type; | |||
| this.mainctrl = mainctrl; | |||
| } | |||
| @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, 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<String, Object> 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<BAR_P05_VISIT> visits = bar_p05.getVISITAll(); | |||
| List<Integer> 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<Integer> 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<Diagnose> diagnosen = new ArrayList<>(); | |||
| List<Untersuchung> 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<DG1> 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<BAR_P05_PROCEDURE> 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<String, Object> 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<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 { | |||
| // 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)); | |||
| } | |||
| } | |||
| @@ -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<Runnable>(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>(ADT_A01.class, mainctrl)); | |||
| server.registerApplication("BAR", "P05", new HL7Receiver2<BAR_P05>(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(); | |||
| } | |||
| } | |||
| } | |||
| @@ -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", ""); | |||
| } | |||
| } | |||
| @@ -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; | |||
| } | |||
| } | |||
| } | |||
| @@ -40,7 +40,7 @@ | |||
| <ComboBox fx:id="fallKasse" prefWidth="250.0" GridPane.columnIndex="1" GridPane.rowIndex="6"/> | |||
| <Label text="Hauptdiagnose:" GridPane.rowIndex="7"/> | |||
| <ComboBox fx:id="fallHauptdiagnose" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="7"/> | |||
| <ComboBox fx:id="fallHauptdiagnose" prefWidth="350.0" GridPane.columnIndex="1" GridPane.rowIndex="7"/> | |||
| </children> | |||
| <columnConstraints> | |||
| <ColumnConstraints percentWidth="30" minWidth="200"/> | |||
| @@ -1,23 +1,25 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <?import java.net.*?> | |||
| <?import javafx.geometry.*?> | |||
| <?import java.lang.*?> | |||
| <?import javafx.scene.control.*?> | |||
| <?import javafx.scene.layout.*?> | |||
| <?import java.net.URL?> | |||
| <VBox minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.uniluebeck.mi.projmi6.controller.LogController"> | |||
| <children> | |||
| <ToolBar prefHeight="40.0" prefWidth="200.0"> | |||
| <items> | |||
| <Pane HBox.hgrow="ALWAYS" /> | |||
| <Button fx:id="btnRefresh" text="Liste aktualisieren" onAction="#clickedRefresh"/> | |||
| <Button fx:id="btnRefresh" onAction="#clickedRefresh" text="Liste aktualisieren" /> | |||
| </items> | |||
| </ToolBar> | |||
| <TableView fx:id="tblLog" VBox.vgrow="ALWAYS"> | |||
| <columns> | |||
| <TableColumn fx:id="colLogIp" editable="false" prefWidth="75.0" text="Ursprungs-IP" /> | |||
| <TableColumn fx:id="colLogTime" editable="false" prefWidth="75.0" text="Uhrzeit" /> | |||
| <TableColumn fx:id="colLogDirection" editable="false" maxWidth="50.0" minWidth="75.0" text="Richtung" /> | |||
| <TableColumn fx:id="colLogIp" editable="false" maxWidth="200.0" minWidth="150.0" text="Ursprungs-IP" /> | |||
| <TableColumn fx:id="colLogTime" editable="false" maxWidth="200.0" minWidth="150.0" text="Uhrzeit" /> | |||
| <TableColumn fx:id="colLogMessage" editable="false" prefWidth="75.0" text="Nachricht" /> | |||
| </columns> | |||
| <columnResizePolicy> | |||
| @@ -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 | |||