|
|
|
@@ -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<Diagnose> 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(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|