| @@ -7,15 +7,22 @@ import ca.uhn.hl7v2.model.DataTypeException; | |||
| import ca.uhn.hl7v2.model.Message; | |||
| import ca.uhn.hl7v2.model.v25.datatype.DTM; | |||
| import ca.uhn.hl7v2.model.v251.datatype.FN; | |||
| import ca.uhn.hl7v2.model.v251.message.ACK; | |||
| 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.parser.Parser; | |||
| import ca.uhn.hl7v2.parser.PipeParser; | |||
| import ca.uhn.hl7v2.validation.ValidationContext; | |||
| import ca.uhn.hl7v2.validation.impl.ValidationContextFactory; | |||
| import de.uniluebeck.mi.projmi6.db.DBHandler; | |||
| import de.uniluebeck.mi.projmi6.model.Diagnose; | |||
| import de.uniluebeck.mi.projmi6.model.Fall; | |||
| import de.uniluebeck.mi.projmi6.model.Patient; | |||
| import java.io.BufferedWriter; | |||
| import java.io.File; | |||
| import java.io.FileWriter; | |||
| import java.io.IOException; | |||
| import java.sql.SQLException; | |||
| import java.sql.Time; | |||
| @@ -35,10 +42,9 @@ public class HL7 { | |||
| * erstellt eine ADT_A0 nachricht, welche anschließend an die OPS Gruppe verschickt werden soll. | |||
| * TODO Mit OPS Gruppe absprechen, welche Informationen sie auf jeden Fall benötigen und Code entsprechend anpassen. | |||
| * @param fall nach dem Erstellen eines neuen Falls wird diese Methode aufgerufen um Hl7 Nachricht zu erzeugen | |||
| * @param diagnosen Liste aller Nebendiagnosen momentan noch als einzelne Liste uebereben. eventuell die Nebendiagnosen direkt im Fall speichern? | |||
| * @throws Exception | |||
| */ | |||
| public void createMessageADTA01( Fall fall, List<Diagnose> diagnosen) throws HL7Exception, IOException { | |||
| public void createMessageADTA01( Fall fall) throws HL7Exception, IOException { | |||
| Patient patient = fall.getPatient (); | |||
| ADT_A01 adt = new ADT_A01 (); | |||
| @@ -80,6 +86,8 @@ public class HL7 { | |||
| pidSegment.getPid13_PhoneNumberHome (0).getTelephoneNumber ().setValue ( patient.getTelefon () ); | |||
| pidSegment.getPid16_MaritalStatus ().getAlternateIdentifier ().setValue ( patient.getFamilienstand ().toString()); | |||
| validateMessage(adt); | |||
| /* | |||
| //Dg1 (Diagnosen) | |||
| List<DG1> dg1List = new ArrayList<> ( ); | |||
| diagnosen.add(fall.getHauptDiagnose ()); | |||
| @@ -92,24 +100,32 @@ public class HL7 { | |||
| dg1Segment.getDg14_DiagnosisDescription ().setValue ( aDiagnosen.getFreiText () ); | |||
| dg1List.add ( dg1Segment ); | |||
| } | |||
| */ | |||
| //print generated message | |||
| // printXMLEncodedMessageADT(adt); | |||
| printXMLEncodedMessageADT(adt); | |||
| } | |||
| public DG1 parseDiagnosen() { | |||
| } | |||
| /** | |||
| * 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 { | |||
| public void printXMLEncodedMessageADT(Message msg) throws HL7Exception, IOException { | |||
| HapiContext context = new DefaultHapiContext (); | |||
| Parser parser = context.getXMLParser(); | |||
| String encodedMessage = parser.encode (msg); | |||
| 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); | |||
| } | |||
| @@ -120,11 +136,14 @@ public class HL7 { | |||
| public void parseMessage(Message msg) throws DataTypeException, SQLException { | |||
| if (msg instanceof BAR_P05) { | |||
| BAR_P05 p05 = (BAR_P05) msg; | |||
| EVN evnSegment = p05.getEVN(); | |||
| PID pidSegment = p05.getPID(); | |||
| DBHandler dh = new DBHandler(); | |||
| Patient patient =dh.getPatient(Integer.valueOf(pidSegment.getPid3_PatientIdentifierList(0).getIDNumber().getValue())); | |||
| Fall fall = new Fall(); | |||
| LocalDateTime ldt = generateLocalDateTimeFromHl7(p05); | |||
| patient.setBearbeitetDatumZeit(ldt); | |||
| patient.setBearbeiter(Integer.valueOf(evnSegment.getEvn5_OperatorID(0).getIDNumber().getValue())); | |||
| @@ -147,6 +166,18 @@ public class HL7 { | |||
| } | |||
| } | |||
| public void validateMessage(Message msg) { | |||
| HapiContext context = new DefaultHapiContext(); | |||
| context.setValidationContext(ValidationContextFactory.<ValidationContext>defaultValidation()); | |||
| PipeParser parser = context.getPipeParser(); | |||
| try { | |||
| parser.encode(msg); | |||
| } catch (HL7Exception e) { | |||
| System.out.println("invaid message!" +e); | |||
| } | |||
| } | |||
| public LocalDateTime generateLocalDateTimeFromHl7(BAR_P05 msg) throws DataTypeException { | |||
| EVN evnSegment = msg.getEVN(); | |||