diff --git a/src/main/java/de/uniluebeck/mi/projmi6/hapi/HL7Receiver.java b/src/main/java/de/uniluebeck/mi/projmi6/hapi/HL7Receiver.java index dde9177..93d7750 100644 --- a/src/main/java/de/uniluebeck/mi/projmi6/hapi/HL7Receiver.java +++ b/src/main/java/de/uniluebeck/mi/projmi6/hapi/HL7Receiver.java @@ -86,7 +86,7 @@ public class HL7Receiver implements ReceivingApplicat Patient patient = mainctrl.getStammdaten().getPatienten().stream().filter(p -> p.getPatID() == patid).findFirst().orElse(null); if (patient == null) { - HL7Util.logInHL7MessageToDatabase(message, msh, metadata); + HL7Utils.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! @@ -107,7 +107,7 @@ public class HL7Receiver implements ReceivingApplicat e.printStackTrace(); } if (fallids.isEmpty() || !fallids.contains(fallid)) { - HL7Util.logInHL7MessageToDatabase(message, msh, metadata); + HL7Utils.logInHL7MessageToDatabase(message, msh, metadata); updateUI(new HL7Message(patient, -1, LocalDateTime.now(), "Fall nicht gefunden.?", true)); return generateACKWithAR(message, "Fall nicht gefunden."); } @@ -125,20 +125,20 @@ public class HL7Receiver implements ReceivingApplicat // TODO: Stationen mit falschen Abteilungen werden einfach umgeschrieben^^ if (station == null) { - HL7Util.logInHL7MessageToDatabase(message, msh, metadata); + HL7Utils.logInHL7MessageToDatabase(message, msh, metadata); updateUI(new HL7Message(patient, -1, LocalDateTime.now(), "Station nicht gefunden.", true)); return generateACKWithAR(message, "Station nicht gefunden."); } StationsHistorie hist = new StationsHistorie(); hist.setStationKey(station.getStation()); if (pv1.getAdmitDateTime().isEmpty()) { - HL7Util.logInHL7MessageToDatabase(message, msh, metadata); + HL7Utils.logInHL7MessageToDatabase(message, msh, metadata); updateUI(new HL7Message(patient, -1, LocalDateTime.now(), "Visit ohne Aufnahmedatum.", true)); return generateACKWithAR(message, "Visit ohne Aufnahmedatum."); } - hist.setAufnahmeDatum(HL7Util.parseLocalDateTime(pv1.getAdmitDateTime().getTime())); + hist.setAufnahmeDatum(HL7Utils.parseLocalDateTime(pv1.getAdmitDateTime().getTime())); if (pv1.getDischargeDateTime().length >= 1) { - hist.setEntlassungsDatum(HL7Util.parseLocalDateTime(pv1.getDischargeDateTime()[0].getTime())); + hist.setEntlassungsDatum(HL7Utils.parseLocalDateTime(pv1.getDischargeDateTime()[0].getTime())); } hist.setFallID(fallid); @@ -167,7 +167,7 @@ public class HL7Receiver implements ReceivingApplicat 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) { - HL7Util.logInHL7MessageToDatabase(message, msh, metadata); + HL7Utils.logInHL7MessageToDatabase(message, msh, metadata); updateUI(new HL7Message(patient, -1, LocalDateTime.now(), "Mitarbeiter nicht gefunden.", true)); return generateACKWithAR(message, "Mitarbeiter nicht gefunden."); } @@ -212,7 +212,7 @@ public class HL7Receiver implements ReceivingApplicat } untersuchung.setOpscode(opscode); - untersuchung.setUntersuchungsdatum(HL7Util.parseLocalDateTime(pr1.getProcedureDateTime().getTime())); + untersuchung.setUntersuchungsdatum(HL7Utils.parseLocalDateTime(pr1.getProcedureDateTime().getTime())); // Mitarbeiter ID anhand von EinweisenderArzt erkennen. Mitarbeiter mitarbeiter; @@ -220,7 +220,7 @@ public class HL7Receiver implements ReceivingApplicat 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) { - HL7Util.logInHL7MessageToDatabase(message, msh, metadata); + HL7Utils.logInHL7MessageToDatabase(message, msh, metadata); updateUI(new HL7Message(patient, -1, LocalDateTime.now(), "Mitarbeiter nicht gefunden.", true)); return generateACKWithAR(message, "Mitarbeiter nicht gefunden."); } @@ -261,7 +261,7 @@ public class HL7Receiver implements ReceivingApplicat } // HL7 Nachricht loggen. - HL7Util.logInHL7MessageToDatabase(message, msh, metadata); + HL7Utils.logInHL7MessageToDatabase(message, msh, metadata); updatedFallIDs.forEach(id -> updateUI(new HL7Message(patient, id, LocalDateTime.now(), "", false))); return generateACK(message); diff --git a/src/main/java/de/uniluebeck/mi/projmi6/hapi/HL7Sender.java b/src/main/java/de/uniluebeck/mi/projmi6/hapi/HL7Sender.java index 285cfdb..f046834 100644 --- a/src/main/java/de/uniluebeck/mi/projmi6/hapi/HL7Sender.java +++ b/src/main/java/de/uniluebeck/mi/projmi6/hapi/HL7Sender.java @@ -4,8 +4,6 @@ import ca.uhn.hl7v2.DefaultHapiContext; import ca.uhn.hl7v2.HL7Exception; import ca.uhn.hl7v2.HapiContext; import ca.uhn.hl7v2.app.Connection; -import ca.uhn.hl7v2.app.HL7Service; -import ca.uhn.hl7v2.app.Initiator; import ca.uhn.hl7v2.llp.LLPException; import ca.uhn.hl7v2.model.Message; import ca.uhn.hl7v2.model.v251.message.ACK; @@ -82,20 +80,20 @@ public class HL7Sender { List diagnosen = getDiagnosenByFall(fall); PV1 pv1Segment = adt.getPV1(); pv1Segment.getPv12_PatientClass().parse("U"); - if(!diagnosen.isEmpty () ) { - diagnosen.add ( fall.getHauptDiagnose () ); + if (!diagnosen.isEmpty()) { + diagnosen.add(fall.getHauptDiagnose()); int i = 1; DG1 dg1Segment; for (Diagnose diagnose : diagnosen) { - System.out.println (diagnose); - dg1Segment = adt.getDG1 ( i - 1 ); - dg1Segment.getDg11_SetIDDG1 ().parse ( String.valueOf ( i ) ); - dg1Segment.getDg13_DiagnosisCodeDG1 ().getIdentifier ().parse ( diagnose.getIcd10code ().getCode () ); - // dg1Segment.getDg116_DiagnosingClinician ()[0].parse ( diagnose.getArzt ().getEinweisenderArzt () ); - dg1Segment.getDg14_DiagnosisDescription ().parse ( diagnose.getFreiText () ); - dg1Segment.getDg16_DiagnosisType ().parse ( diagnose.getDiagArt ().toString () ); - i++; - } + System.out.println(diagnose); + dg1Segment = adt.getDG1(i - 1); + dg1Segment.getDg11_SetIDDG1().parse(String.valueOf(i)); + dg1Segment.getDg13_DiagnosisCodeDG1().getIdentifier().parse(diagnose.getIcd10code().getCode()); + // dg1Segment.getDg116_DiagnosingClinician ()[0].parse ( diagnose.getArzt ().getEinweisenderArzt () ); + dg1Segment.getDg14_DiagnosisDescription().parse(diagnose.getFreiText()); + dg1Segment.getDg16_DiagnosisType().parse(diagnose.getDiagArt().toString()); + i++; + } } sendMessage(adt); @@ -103,69 +101,51 @@ public class HL7Sender { } private static void sendMessage(Message message) throws HL7Exception { - /* - * The following section of code establishes a server listening - * on port 1011 for new connections, and then "handles" them by - */ if (message instanceof ADT_A01) { - ADT_A01 adt = (ADT_A01) message; - int port = Main.OPS_PORT; - HapiContext context = new DefaultHapiContext(); - HL7Service server = context.newServer(port, false); - - - /* - * Create a client, which will connect to our waiting - * server and send messages to it. - */ - - // A connection object represents a socket attached to an HL7 server - Connection connection = null; - try { - connection = context.newClient(Main.OPS_IP, port, false); - } catch (HL7Exception e) { - // e.printStackTrace(); - LoggerFactory.getLogger(HL7Sender.class).warn("Konnte aus irgendeinem Grund keine HL7 Nachricht senden. OPS Server down?"); - server.stop(); - return; - } + sendMessageADT_A01(message); + } + } - // The initiator is used to transmit unsolicited messages - Initiator initiator = connection.getInitiator(); - Message response = null; - HL7LogEntry messageEntry = new HL7LogEntry(); - messageEntry.setMessage(message.encode()); - messageEntry.setSource("127.0.0.1:1234"); // TODO: naja... - messageEntry.setDirection(HL7LogEntry.Direction.OUT); - messageEntry.setTimestamp(LocalDateTime.now()); - HL7Util.logHL7MessageToDatabase(messageEntry); - try { - while (!(response instanceof ACK)) { - response = initiator.sendAndReceive(adt); - System.out.println ("Sende nachricht ..."); - Thread.sleep(5000); - } - } catch (HL7Exception | LLPException | IOException | InterruptedException e) { - // e.printStackTrace(); - } + private static void sendMessageADT_A01(Message message) throws HL7Exception { + ADT_A01 adt_a01 = (ADT_A01) message; + HapiContext context = new DefaultHapiContext(); + Connection connection; + + try { + connection = context.newClient(Main.OPS_IP, Main.OPS_PORT, false); + } catch (HL7Exception e) { + LoggerFactory.getLogger(HL7Sender.class).warn("Konnte aus irgendeinem Grund keine HL7 Nachricht senden. OPS Server down?"); + return; + } - HL7LogEntry responseEntry = new HL7LogEntry(); - responseEntry.setMessage(response.encode()); - responseEntry.setSource(Main.OPS_IP + ":" + Main.OPS_PORT); - responseEntry.setDirection(HL7LogEntry.Direction.IN); - responseEntry.setTimestamp(LocalDateTime.now()); - HL7Util.logHL7MessageToDatabase(responseEntry); + Message response = null; + HL7LogEntry messageEntry = new HL7LogEntry(); + HL7LogEntry responseEntry = new HL7LogEntry(); - /* + messageEntry.setMessage(message.encode()); + messageEntry.setSource("127.0.0.1:1234"); // TODO: Kann man den lokal genutzen Port raus finden? + messageEntry.setDirection(HL7LogEntry.Direction.OUT); + messageEntry.setTimestamp(LocalDateTime.now()); + messageEntry.setTimestamp(HL7Utils.parseLocalDateTime(adt_a01.getMSH().getDateTimeOfMessage().getTime())); - * Close the connection when you are done with it. - */ - connection.close(); + HL7Utils.logHL7MessageToDatabase(messageEntry); - // Stop the receiving server and client - server.stop(); + try { + while (!(response instanceof ACK)) { + response = connection.getInitiator().sendAndReceive(adt_a01); + Thread.sleep(5000); + } + } catch (HL7Exception | LLPException | IOException | InterruptedException e) { + // e.printStackTrace(); } + responseEntry.setMessage(response.encode()); + responseEntry.setSource(Main.OPS_IP + ":" + Main.OPS_PORT); + responseEntry.setDirection(HL7LogEntry.Direction.IN); + responseEntry.setTimestamp(LocalDateTime.now()); + HL7Utils.logHL7MessageToDatabase(responseEntry); + + connection.close(); } diff --git a/src/main/java/de/uniluebeck/mi/projmi6/hapi/HL7Util.java b/src/main/java/de/uniluebeck/mi/projmi6/hapi/HL7Utils.java similarity index 98% rename from src/main/java/de/uniluebeck/mi/projmi6/hapi/HL7Util.java rename to src/main/java/de/uniluebeck/mi/projmi6/hapi/HL7Utils.java index 55f4f92..709ca3e 100644 --- a/src/main/java/de/uniluebeck/mi/projmi6/hapi/HL7Util.java +++ b/src/main/java/de/uniluebeck/mi/projmi6/hapi/HL7Utils.java @@ -16,7 +16,7 @@ import java.util.Map; /** * Created by nils on 20.11.2015. */ -public class HL7Util { +public class HL7Utils { public static LocalDateTime parseLocalDateTime(DTM dtm) { try { return LocalDateTime.ofInstant(dtm.getValueAsDate().toInstant(), ZoneId.systemDefault());