|
- package de.uniluebeck.mi.projmi6.hapi;
-
- import ca.uhn.hl7v2.DefaultHapiContext;
- import ca.uhn.hl7v2.HL7Exception;
- import ca.uhn.hl7v2.HapiContext;
- import ca.uhn.hl7v2.model.Message;
- import ca.uhn.hl7v2.model.v251.message.ADT_A01;
- import ca.uhn.hl7v2.model.v251.segment.DG1;
- import ca.uhn.hl7v2.model.v251.segment.EVN;
- import ca.uhn.hl7v2.model.v251.segment.MSH;
- import ca.uhn.hl7v2.model.v251.segment.PID;
- 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.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.time.LocalDateTime;
- import java.util.List;
-
- import static de.uniluebeck.mi.projmi6.db.DBHandler.getDiagnosenByFall;
-
- /**
- * Created by taschi on 22.11.15.
- */
- public class HL7Sender {
-
- /**
- * 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
- * @throws Exception
- */
- public void createMessageADTA01( Fall fall) throws HL7Exception, IOException, SQLException {
- Patient patient = fall.getPatient ();
- ADT_A01 adt = new ADT_A01 ();
-
- //default MSH Values (Sets Segments: 1,2,7,9,11
- adt.initQuickstart ("ADT", "A01", "P");
-
- //MSH Segment:
- MSH mshSegment = adt.getMSH();
- mshSegment.getMsh3_SendingApplication ().getNamespaceID ().parse ( "KISGruppe6" );
- mshSegment.getMsh5_ReceivingApplication ().getNamespaceID ().parse("OPS Gruppe von Maurice und Torben");
- mshSegment.getMsh12_VersionID ().getVersionID ().parse ( "2.51" );
- mshSegment.getMsh15_AcceptAcknowledgmentType ().parse ( "AL" );
- //TODO check ob segment 10 gesetzt wurde
-
- //EVN Segment:
- EVN evnSegment = adt.getEVN ();
- evnSegment.getEvn1_EventTypeCode ().parse("A01");
- evnSegment.getEvn4_EventReasonCode ().parse ( "01" );
- //Operator ID
- //Event occured
-
- //PID
- PID pidSegment = adt.getPID ();
- pidSegment.getPid3_PatientIdentifierList (0).getIDNumber ().setValue ( Integer.toString(patient.getPatID ()) );
- pidSegment.getPid5_PatientName (0).getFamilyName ().getSurname ().setValue ( patient.getNachname () );
- pidSegment.getPid5_PatientName (0).getGivenName ().setValue ( patient.getVorname () );
- pidSegment.getPid7_DateTimeOfBirth ().getTime ().setValue ( patient.getGeburtsdatum ().toString () );
- pidSegment.getPid8_AdministrativeSex ().setValue ( patient.getGeschlecht ().toString () );
- pidSegment.getPid11_PatientAddress (0).getStreetAddress ().getStreetName().setValue ( patient.getStrasse () );
- pidSegment.getPid11_PatientAddress (0).getStreetAddress ().getDwellingNumber ( ).setValue ( patient.getHausnummer () );
- pidSegment.getPid11_PatientAddress (0).getCity ().setValue (patient.getOrt () );
- pidSegment.getPid13_PhoneNumberHome (0).getTelephoneNumber ().setValue ( patient.getTelefon () );
- pidSegment.getPid16_MaritalStatus ().getAlternateIdentifier ().setValue ( patient.getFamilienstand ().toString());
-
- //Diagnosen
- List<Diagnose> diagnosen = getDiagnosenByFall ( fall );
- diagnosen.add(fall.getHauptDiagnose ());
- if(!diagnosen.isEmpty ()) {
- for (Diagnose diagnose : diagnosen) {
- DG1 dg1Segment = adt.getDG1 ();
- dg1Segment.getDg13_DiagnosisCodeDG1 ().getIdentifier ().parse ( diagnose.getIcd10code ().getCode () );
- dg1Segment.getDg16_DiagnosisType ().setValue ( String.valueOf ( diagnose.getIcd10code ().getVersion () ) );
- dg1Segment.getDg116_DiagnosingClinician ()[0].parse ( diagnose.getArzt ().toString () );
- dg1Segment.getDg14_DiagnosisDescription ().parse ( diagnose.getFreiText () );
- dg1Segment.getDg16_DiagnosisType ().parse ( diagnose.getDiagArt ().toString () );
- adt.getDG1All ().add ( dg1Segment );
- }
- }
-
- printXMLEncodedMessageADT(adt);
-
- }
-
-
-
- /**
- * 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);
- }
-
- /**
- *
- * @param msg
- */
-
- 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);
- }
-
- }
-
-
- }
|