|
|
|
@@ -6,20 +6,15 @@ import ca.uhn.hl7v2.HapiContext; |
|
|
|
import ca.uhn.hl7v2.app.Connection; |
|
|
|
import ca.uhn.hl7v2.llp.LLPException; |
|
|
|
import ca.uhn.hl7v2.model.Message; |
|
|
|
import ca.uhn.hl7v2.model.v251.datatype.XCN; |
|
|
|
import ca.uhn.hl7v2.model.v251.message.ACK; |
|
|
|
import ca.uhn.hl7v2.model.v251.message.ADT_A01; |
|
|
|
import ca.uhn.hl7v2.model.v251.segment.*; |
|
|
|
import ca.uhn.hl7v2.parser.Parser; |
|
|
|
import de.uniluebeck.mi.projmi6.Main; |
|
|
|
import de.uniluebeck.mi.projmi6.model.Diagnose; |
|
|
|
import de.uniluebeck.mi.projmi6.model.Fall; |
|
|
|
import de.uniluebeck.mi.projmi6.model.HL7LogEntry; |
|
|
|
import de.uniluebeck.mi.projmi6.model.Patient; |
|
|
|
import de.uniluebeck.mi.projmi6.db.DBHandler; |
|
|
|
import de.uniluebeck.mi.projmi6.model.*; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
import java.io.BufferedWriter; |
|
|
|
import java.io.File; |
|
|
|
import java.io.FileWriter; |
|
|
|
import java.io.IOException; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
@@ -27,8 +22,6 @@ import java.time.ZoneId; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import static de.uniluebeck.mi.projmi6.db.DBHandler.getDiagnosenByFall; |
|
|
|
|
|
|
|
/** |
|
|
|
* Created by taschi on 22.11.15. |
|
|
|
*/ |
|
|
|
@@ -69,7 +62,7 @@ public class HL7Sender { |
|
|
|
pidSegment.getPid5_PatientName(0).getFamilyName().getSurname().parse(patient.getNachname()); |
|
|
|
pidSegment.getPid5_PatientName(0).getGivenName().parse(patient.getVorname()); |
|
|
|
pidSegment.getPid7_DateTimeOfBirth().getTime().setValue(Date.from(patient.getGeburtsdatum().atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())); |
|
|
|
pidSegment.getPid8_AdministrativeSex().parse(patient.getGeschlecht().toString()); |
|
|
|
pidSegment.getPid8_AdministrativeSex().parse(String.valueOf(patient.getGeschlecht().id())); |
|
|
|
pidSegment.getPid11_PatientAddress(0).getStreetAddress().getStreetName().parse(patient.getStrasse()); |
|
|
|
pidSegment.getPid11_PatientAddress(0).getStreetAddress().getDwellingNumber().parse(patient.getHausnummer()); |
|
|
|
pidSegment.getPid11_PatientAddress(0).getCity().parse(patient.getOrt()); |
|
|
|
@@ -77,27 +70,26 @@ public class HL7Sender { |
|
|
|
pidSegment.getPid16_MaritalStatus().getAlternateIdentifier().parse(patient.getFamilienstand().toString()); |
|
|
|
|
|
|
|
//Diagnosen |
|
|
|
List<Diagnose> diagnosen = getDiagnosenByFall(fall); |
|
|
|
List<Diagnose> diagnosen = DBHandler.getDiagnosenByFall(fall); |
|
|
|
PV1 pv1Segment = adt.getPV1(); |
|
|
|
pv1Segment.getPv12_PatientClass().parse("U"); |
|
|
|
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++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int i = 1; |
|
|
|
for (Diagnose diagnose : diagnosen) { |
|
|
|
Mitarbeiter arzt = diagnose.getArzt(); |
|
|
|
DG1 dg1 = adt.getDG1(i); |
|
|
|
dg1.getDg11_SetIDDG1().setValue(String.valueOf(i)); |
|
|
|
dg1.getDg13_DiagnosisCodeDG1().getIdentifier().parse(diagnose.getIcd10code().getCode()); |
|
|
|
XCN xcn = dg1.getDg116_DiagnosingClinician(0); |
|
|
|
xcn.getIDNumber().setValue(arzt.getEinweisenderArzt()); |
|
|
|
xcn.getGivenName().setValue(arzt.getVorname()); |
|
|
|
xcn.getFamilyName().getSurname().setValue(arzt.getNachname()); |
|
|
|
xcn.getPrefixEgDR().setValue(arzt.getTitel()); |
|
|
|
dg1.getDg14_DiagnosisDescription().parse(diagnose.getFreiText()); |
|
|
|
dg1.getDg16_DiagnosisType().parse(diagnose.getDiagArt().toString()); |
|
|
|
i++; |
|
|
|
} |
|
|
|
sendMessage(adt); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private static void sendMessage(Message message) throws HL7Exception { |
|
|
|
@@ -114,7 +106,7 @@ public class HL7Sender { |
|
|
|
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?"); |
|
|
|
LoggerFactory.getLogger(HL7Sender.class).error("Konnte aus irgendeinem Grund keine HL7 Nachricht senden. OPS Server down?"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
@@ -131,12 +123,19 @@ public class HL7Sender { |
|
|
|
HL7Utils.logHL7MessageToDatabase(messageEntry); |
|
|
|
|
|
|
|
try { |
|
|
|
while (!(response instanceof ACK)) { |
|
|
|
int count = 0; |
|
|
|
// 5 Versuche starten und schauen ob man ein ACK bekommt. |
|
|
|
while (!(response instanceof ACK) && count < 5) { |
|
|
|
if (count > 0) { |
|
|
|
Thread.sleep(5000); |
|
|
|
} |
|
|
|
response = connection.getInitiator().sendAndReceive(adt_a01); |
|
|
|
Thread.sleep(5000); |
|
|
|
count++; |
|
|
|
} |
|
|
|
} catch (HL7Exception | LLPException | IOException | InterruptedException e) { |
|
|
|
// e.printStackTrace(); |
|
|
|
LoggerFactory.getLogger(HL7Sender.class).warn("Bekomme aus irgendeinem Grund kein ACK."); |
|
|
|
connection.close(); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
responseEntry.setMessage(response.encode()); |
|
|
|
@@ -147,29 +146,4 @@ public class HL7Sender { |
|
|
|
|
|
|
|
connection.close(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* gibt erzeugte hl7 Nachricht auf der Konsole aus (Kann nach Debug phase wieder geloescht werden) |
|
|
|
* |
|
|
|
* @param msg |
|
|
|
* @throws HL7Exception |
|
|
|
*/ |
|
|
|
public void printXMLEncodedMessageADT(Message msg) throws HL7Exception, IOException { |
|
|
|
HapiContext context = new DefaultHapiContext(); |
|
|
|
Parser parser = context.getXMLParser(); |
|
|
|
String encodedMessage = parser.encode(msg); |
|
|
|
LocalDateTime ldt = LocalDateTime.now(); |
|
|
|
File file = new File("ADTA01Messafge" + LocalDateTime.now().toString() + "xml"); |
|
|
|
if (!file.exists()) { |
|
|
|
file.createNewFile(); |
|
|
|
} |
|
|
|
FileWriter fw = new FileWriter(file.getAbsoluteFile()); |
|
|
|
BufferedWriter bw = new BufferedWriter(fw); |
|
|
|
bw.write(encodedMessage); |
|
|
|
bw.close(); |
|
|
|
System.out.println(encodedMessage); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |