| @@ -4,7 +4,9 @@ package de.uniluebeck.mi.projmi6.controller; | |||
| * Created by 631806 on 12.11.15. | |||
| */ | |||
| import ca.uhn.hl7v2.HL7Exception; | |||
| import de.uniluebeck.mi.projmi6.db.DBHandler; | |||
| import de.uniluebeck.mi.projmi6.hapi.HL7Sender; | |||
| import de.uniluebeck.mi.projmi6.model.*; | |||
| import de.uniluebeck.mi.projmi6.view.DateTimePicker; | |||
| import javafx.beans.property.ObjectProperty; | |||
| @@ -14,48 +16,34 @@ import javafx.collections.FXCollections; | |||
| import javafx.collections.ObservableList; | |||
| import javafx.event.ActionEvent; | |||
| import javafx.fxml.FXML; | |||
| import javafx.scene.control.Button; | |||
| import javafx.scene.control.CheckBox; | |||
| import javafx.scene.control.ComboBox; | |||
| import javafx.scene.control.Label; | |||
| import javafx.scene.control.TextField; | |||
| import javafx.scene.control.*; | |||
| import javafx.scene.layout.GridPane; | |||
| import java.io.IOException; | |||
| import java.sql.SQLException; | |||
| public class FallController { | |||
| SimpleObjectProperty<State> state = new SimpleObjectProperty<>(State.VIEW); | |||
| @FXML | |||
| Button btnFallSendHl7; | |||
| private MainController mainController; | |||
| public FallController (MainController mainController){ | |||
| this.mainController = mainController; | |||
| } | |||
| @FXML | |||
| private DateTimePicker dtTmAufnahme, dtTmEntlassung; | |||
| @FXML | |||
| private Label fallPatID; | |||
| @FXML | |||
| private ComboBox<FallArt> fallFallart; | |||
| @FXML | |||
| private ComboBox<Kasse> fallKasse; | |||
| @FXML | |||
| private TextField fallVersichertennummer; | |||
| @FXML | |||
| private TextField fallEinweisenderArzt; | |||
| @FXML | |||
| private CheckBox fallSelbsteinweisung; | |||
| @FXML | |||
| private ComboBox<Diagnose> fallHauptdiagnose; | |||
| @FXML | |||
| private Label fallCreator; | |||
| @FXML | |||
| @@ -66,34 +54,30 @@ public class FallController { | |||
| private Label fallEditTime; | |||
| @FXML | |||
| private Button btnFallSave; | |||
| @FXML | |||
| private Button btnFallAbort; | |||
| @FXML | |||
| private Button btnFallCancel; | |||
| @FXML | |||
| private Button btnFallEnableEdit; | |||
| @FXML | |||
| private GridPane fallFields; | |||
| private SimpleObjectProperty<Fall> fallProperty = new SimpleObjectProperty<>(); | |||
| public Fall getFall() { | |||
| return fallProperty.get(); | |||
| public FallController(MainController mainController) { | |||
| this.mainController = mainController; | |||
| } | |||
| public SimpleObjectProperty<Fall> fallPropertyProperty() { | |||
| return fallProperty; | |||
| public Fall getFall() { | |||
| return fallProperty.get(); | |||
| } | |||
| public void setFall(Fall fall) { | |||
| this.fallProperty.set(fall); | |||
| } | |||
| public enum State { | |||
| CREATE, EDIT, VIEW | |||
| public SimpleObjectProperty<Fall> fallPropertyProperty() { | |||
| return fallProperty; | |||
| } | |||
| public State getState() { | |||
| @@ -104,12 +88,6 @@ public class FallController { | |||
| return state; | |||
| } | |||
| SimpleObjectProperty<State> state = new SimpleObjectProperty<>(State.VIEW); | |||
| public ObjectProperty<ObservableList<Diagnose>> diagnosenProperty(){ | |||
| return fallHauptdiagnose.itemsProperty(); | |||
| } | |||
| @@ -184,21 +162,24 @@ public class FallController { | |||
| } | |||
| @FXML | |||
| Button btnFallSendHl7; | |||
| @FXML | |||
| private void clickedSendHl7(){ | |||
| /* Natascha */ | |||
| //TODO send funny message | |||
| Fall fall = fallProperty.get(); | |||
| Patient patient = mainController.getPatientTablesController().getSelectedPatient(); | |||
| Fall fall = fallProperty.get(); | |||
| fall.setPatient(patient); | |||
| try { | |||
| HL7Sender.createMessageADT_A01(fall); | |||
| } catch (HL7Exception | IOException | SQLException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| public void editFall(){ | |||
| this.state.set(State.EDIT); | |||
| } | |||
| @FXML | |||
| void clickedFallEnableEdit(ActionEvent event) { | |||
| editFall(); | |||
| @@ -206,11 +187,11 @@ public class FallController { | |||
| @FXML | |||
| void clickedFallCancel(ActionEvent event) { | |||
| if(fallProperty.get()!=null){ | |||
| if (fallProperty.get() != null) { | |||
| fallProperty.get().setStorniert(true); | |||
| try { | |||
| DBHandler.setFall(fallProperty.get(), mainController.getCurrentMitarbeiter().getMitarbID(), true); | |||
| }catch (Exception e){ | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| mainController.refreshCasesFromDb(mainController.getPatientTablesController().getSelectedPatient()); | |||
| @@ -263,9 +244,6 @@ public class FallController { | |||
| fallVersichertennummer.setText(patient.getVersichertennummer()); | |||
| } | |||
| private void clearFields(){ | |||
| if(state.get() == State.CREATE) { | |||
| dtTmAufnahme.setToCurrentDateTime(); | |||
| @@ -294,7 +272,6 @@ public class FallController { | |||
| fallFallart.setValue(null); | |||
| } | |||
| private void copyFieldDataIntoFall(Fall fall){ | |||
| fall.setPatient(mainController.getPatientTablesController().getSelectedPatient()); | |||
| fall.setAufnahmeDatum(dtTmAufnahme.getDateTime()); | |||
| @@ -319,7 +296,6 @@ public class FallController { | |||
| //fall.setVorstellDatum(); //TODO | |||
| } | |||
| private void copyFallDataIntoField(Fall fall){ | |||
| if(fall==null){ | |||
| System.out.println("copyFallDataIntoFiled - Fall ist null"); | |||
| @@ -366,6 +342,10 @@ public class FallController { | |||
| } | |||
| } | |||
| public enum State { | |||
| CREATE, EDIT, VIEW | |||
| } | |||
| } | |||
| @@ -281,6 +281,12 @@ public class DBHandler { | |||
| statement.execute(); | |||
| } | |||
| /** | |||
| * Gibt Liste aller Stationen aus der DB zurueck. | |||
| * | |||
| * @return Liste der Stationen | |||
| * @throws SQLException | |||
| */ | |||
| public static List<Station> getAllStationen() throws SQLException { | |||
| Statement statement = MySqlConnectionFactory.getConnection().createStatement(); | |||
| ResultSet rs = statement.executeQuery(SELECT_ALL_STATIONEN); | |||
| @@ -311,6 +317,13 @@ public class DBHandler { | |||
| return station; | |||
| } | |||
| /** | |||
| * Gibt besondere Eintraege fuer die Stationsubersicht nach Station zurueck. | |||
| * | |||
| * @param station Station | |||
| * @return Liste der Eintraege auf der Station. | |||
| * @throws SQLException | |||
| */ | |||
| public static List<StationsUebersichtsItem> getStationsUebersichtsItems(String station) throws SQLException { | |||
| PreparedStatement statement = MySqlConnectionFactory.getConnection().prepareStatement(SELECT_STATUBERITEMS_BY_STATION); | |||
| statement.setString(1, station); | |||
| @@ -339,6 +352,13 @@ public class DBHandler { | |||
| return item; | |||
| } | |||
| /** | |||
| * Gibt die Stationshistorie zu einem Fall aus. | |||
| * | |||
| * @param fall Fall | |||
| * @return Liste der StationsHistorie Eintraege. | |||
| * @throws SQLException | |||
| */ | |||
| public static List<StationsHistorie> getStationsHistorieByFall(Fall fall) throws SQLException { | |||
| PreparedStatement statement = MySqlConnectionFactory.getConnection().prepareStatement(SELECT_STATHIST_BY_FALLID); | |||
| statement.setInt(1, fall.getFallID()); | |||
| @@ -352,6 +372,13 @@ public class DBHandler { | |||
| return historie; | |||
| } | |||
| /** | |||
| * Erstellt bzw. aktuallisiert einen Eintrag in die Stationshistorie. | |||
| * | |||
| * @param hist StationsHistorie Objekt | |||
| * @param isUpdate true wenn Update. | |||
| * @throws SQLException | |||
| */ | |||
| public static void setStationsHistorie(StationsHistorie hist, boolean isUpdate) throws SQLException { | |||
| PreparedStatement statement; | |||
| if (isUpdate) { | |||
| @@ -383,12 +410,25 @@ public class DBHandler { | |||
| } | |||
| } | |||
| /** | |||
| * Entfernt einen StationsHistorie Eintrag aus der Datenbank. | |||
| * | |||
| * @param hist Zu entfernendes StationsHistorie Objekt | |||
| * @throws SQLException | |||
| */ | |||
| public static void delStationsHistorie(StationsHistorie hist) throws SQLException { | |||
| PreparedStatement statement = MySqlConnectionFactory.getConnection().prepareStatement(DELETE_STATHIST); | |||
| statement.setInt(1, hist.getStatHistID()); | |||
| statement.execute(); | |||
| } | |||
| /** | |||
| * Gibt einzelnes StationsHistorie Objekt aus einem ResultSet zurueck. | |||
| * | |||
| * @param rs DB Query Result | |||
| * @return StationsHistorie | |||
| * @throws SQLException | |||
| */ | |||
| private static StationsHistorie getStationsHistorie(ResultSet rs) throws SQLException { | |||
| StationsHistorie hist = new StationsHistorie(); | |||
| @@ -404,6 +444,13 @@ public class DBHandler { | |||
| return hist; | |||
| } | |||
| /** | |||
| * Gibt alle Faelle eines Patienten zuruck. | |||
| * | |||
| * @param id Patienten ID | |||
| * @return Liste aller Faelle. | |||
| * @throws SQLException | |||
| */ | |||
| public static List<Fall> getFaelleByPatID(int id) throws SQLException { | |||
| PreparedStatement statement = MySqlConnectionFactory.getConnection().prepareStatement(SELECT_FAELLE_BY_PATID); | |||
| statement.setInt(1, id); | |||
| @@ -574,6 +621,12 @@ public class DBHandler { | |||
| } | |||
| } | |||
| /** | |||
| * Gibt alle in der DB hinterlegten ICD10 Codes zurueck. | |||
| * | |||
| * @return Liste aller ICD10 Codes. | |||
| * @throws SQLException | |||
| */ | |||
| public static List<Icd10Code> getAllIcd10Codes() throws SQLException { | |||
| Statement statement = MySqlConnectionFactory.getConnection().createStatement(); | |||
| ResultSet rs = statement.executeQuery(SELECT_ALL_ICD10CODES); | |||
| @@ -612,6 +665,12 @@ public class DBHandler { | |||
| return new Icd10Code(code, text, version); | |||
| } | |||
| /** | |||
| * Gibt alle in der Datanbank hinterlegten OPS Codes zurueck. | |||
| * | |||
| * @return Liste der OPS Codes. | |||
| * @throws SQLException | |||
| */ | |||
| public static List<OpsCode> getAllOpsCodes() throws SQLException { | |||
| Statement statement = MySqlConnectionFactory.getConnection().createStatement(); | |||
| ResultSet rs = statement.executeQuery(SELECT_ALL_OPSCODES); | |||
| @@ -650,6 +709,12 @@ public class DBHandler { | |||
| return new OpsCode(code, text, version); | |||
| } | |||
| /** | |||
| * Gibt Liste der Mitarbeiter aus der DB zurueck. | |||
| * | |||
| * @return Liste der Mitarbeiter. | |||
| * @throws SQLException | |||
| */ | |||
| public static List<Mitarbeiter> getAllMitarbeiter() throws SQLException { | |||
| Statement statement = MySqlConnectionFactory.getConnection().createStatement(); | |||
| ResultSet rs = statement.executeQuery(SELECT_ALL_MITARBEITER); | |||
| @@ -753,6 +818,13 @@ public class DBHandler { | |||
| statement.execute(); | |||
| } | |||
| /** | |||
| * Gibt alle Diagnosen zu einem Fall zurueck. | |||
| * | |||
| * @param fall Fall | |||
| * @return Liste der Diagnosen. | |||
| * @throws SQLException | |||
| */ | |||
| public static List<Diagnose> getDiagnosenByFall(Fall fall) throws SQLException { | |||
| PreparedStatement statement = MySqlConnectionFactory.getConnection().prepareStatement(SELECT_DIAGNOSE_BY_FALLID); | |||
| statement.setInt(1, fall.getFallID()); | |||
| @@ -766,6 +838,12 @@ public class DBHandler { | |||
| return diagnosen; | |||
| } | |||
| /** | |||
| * Gibt Liste der hinterlegten Kassen zurueck. | |||
| * | |||
| * @return Liste der hinterlegten Kassen | |||
| * @throws SQLException | |||
| */ | |||
| public static List<Kasse> getAllKassen() throws SQLException { | |||
| Statement statement = MySqlConnectionFactory.getConnection().createStatement(); | |||
| ResultSet rs = statement.executeQuery(SELECT_ALL_KASSEN); | |||
| @@ -804,6 +882,12 @@ public class DBHandler { | |||
| return kasse; | |||
| } | |||
| /** | |||
| * Speichert Diagnose in die Datenbank. | |||
| * | |||
| * @param diagnose Diagnose | |||
| * @throws SQLException | |||
| */ | |||
| public static void setDiagnose(Diagnose diagnose) throws SQLException { | |||
| PreparedStatement statement = MySqlConnectionFactory.getConnection().prepareStatement(INSERT_DIAGNOSE); | |||
| statement.setInt(1, diagnose.getArzt().getMitarbID()); // `Arzt` | |||
| @@ -817,6 +901,14 @@ public class DBHandler { | |||
| statement.execute(); | |||
| } | |||
| /** | |||
| * Speichert eine raw HL7 Nachricht in die DB. | |||
| * | |||
| * @param hl7msg raw HL7 Nachricht | |||
| * @param timestamp LocalDateTime | |||
| * @param source Source bzw. Destination | |||
| * @throws SQLException | |||
| */ | |||
| public static void setHL7Nachricht(String hl7msg, LocalDateTime timestamp, String source) throws SQLException { | |||
| PreparedStatement statement = MySqlConnectionFactory.getConnection().prepareStatement(INSERT_HL7NACHRICHT); | |||
| statement.setString(1, hl7msg); | |||
| @@ -825,10 +917,23 @@ public class DBHandler { | |||
| statement.execute(); | |||
| } | |||
| /** | |||
| * Gibt die letzten 30 HL7 Logeintraege aus der DB zurueck. | |||
| * | |||
| * @return | |||
| * @throws SQLException | |||
| */ | |||
| public static List<HL7LogEntry> getLastHL7LogEntries() throws SQLException { | |||
| return getLastHL7LogEntries(30); | |||
| } | |||
| /** | |||
| * Gibt die angegebene Anzahl HL7 Logeintraege aus der DB zurueck. | |||
| * | |||
| * @param last Anzahl Eintraege | |||
| * @return Liste mit HL7LogEntries zurueck. | |||
| * @throws SQLException | |||
| */ | |||
| public static List<HL7LogEntry> getLastHL7LogEntries(int last) throws SQLException { | |||
| PreparedStatement statement = MySqlConnectionFactory.getConnection().prepareStatement(SELECT_LAST_HL7ENTRIES); | |||
| statement.setInt(1, last); | |||
| @@ -841,6 +946,12 @@ public class DBHandler { | |||
| return hl7entries; | |||
| } | |||
| /** | |||
| * Speichert eine HL7 Nachricht in der hl7 Log Tabelle. | |||
| * | |||
| * @param entry HL7 Nachricht | |||
| * @throws SQLException | |||
| */ | |||
| public static void setHL7LogEntry(HL7LogEntry entry) throws SQLException { | |||
| PreparedStatement statement = MySqlConnectionFactory.getConnection().prepareStatement(INSERT_HL7NACHRICHT_); | |||
| statement.setString(1, entry.getMessage()); | |||
| @@ -859,6 +970,13 @@ public class DBHandler { | |||
| return entry; | |||
| } | |||
| /** | |||
| * Gibt alle FallIDs eines Patienten zurueck. | |||
| * | |||
| * @param patid Patienten ID | |||
| * @return Liste aller FallIDs | |||
| * @throws SQLException | |||
| */ | |||
| public static List<Integer> getAlleFallIdsByPatID(int patid) throws SQLException { | |||
| PreparedStatement statement = MySqlConnectionFactory.getConnection().prepareStatement(SELECT_FALLIDS_BY_PATID); | |||
| statement.setInt(1, patid); | |||
| @@ -3,13 +3,18 @@ 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.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; | |||
| import ca.uhn.hl7v2.model.v251.message.ADT_A01; | |||
| 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.Main; | |||
| import de.uniluebeck.mi.projmi6.model.Diagnose; | |||
| import de.uniluebeck.mi.projmi6.model.Fall; | |||
| import de.uniluebeck.mi.projmi6.model.Patient; | |||
| @@ -35,7 +40,7 @@ public class HL7Sender { | |||
| * @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 { | |||
| public static void createMessageADT_A01(Fall fall) throws HL7Exception, IOException, SQLException { | |||
| Patient patient = fall.getPatient (); | |||
| ADT_A01 adt = new ADT_A01 (); | |||
| @@ -77,25 +82,80 @@ public class HL7Sender { | |||
| pv1Segment.getPv12_PatientClass ().parse ( "U" ); | |||
| if(!diagnosen.isEmpty ()) { | |||
| int i =1; | |||
| DG1 dg1Segment; | |||
| for (Diagnose diagnose : diagnosen) { | |||
| DG1 dg1Segment = adt.getDG1 (); | |||
| dg1Segment = adt.getDG1 ( (i) ); | |||
| dg1Segment.getDg11_SetIDDG1 ().parse ( String.valueOf ( i ) ); | |||
| dg1Segment.getDg13_DiagnosisCodeDG1 ().getIdentifier ().parse ( diagnose.getIcd10code ().getCode () ); | |||
| dg1Segment.getDg116_DiagnosingClinician ()[0].parse ( diagnose.getArzt ().getEinweisenderArzt () ); | |||
| // dg1Segment.getDg116_DiagnosingClinician ()[0].parse ( diagnose.getArzt ().getEinweisenderArzt () ); | |||
| dg1Segment.getDg14_DiagnosisDescription ().parse ( diagnose.getFreiText () ); | |||
| dg1Segment.getDg16_DiagnosisType ().parse ( diagnose.getDiagArt ().toString () ); | |||
| adt.getDG1All ().add ( dg1Segment ); | |||
| i++; | |||
| //Segment 2 Verschluesselung ? | |||
| } | |||
| } | |||
| printXMLEncodedMessageADT(adt); | |||
| sendMessage(adt); | |||
| } | |||
| private static void sendMessage(Message message) { | |||
| /* | |||
| * 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 (); | |||
| } | |||
| // The initiator is used to transmit unsolicited messages | |||
| Initiator initiator = connection.getInitiator (); | |||
| Message response = null; | |||
| try { | |||
| while (! (response instanceof ACK)) { | |||
| response = initiator.sendAndReceive ( adt ); | |||
| Thread.sleep ( 5000 ); | |||
| } | |||
| } catch (HL7Exception e) { | |||
| e.printStackTrace (); | |||
| } catch (LLPException e) { | |||
| e.printStackTrace (); | |||
| } catch (IOException e) { | |||
| e.printStackTrace (); | |||
| } catch (InterruptedException e) { | |||
| e.printStackTrace (); | |||
| } | |||
| /* | |||
| * Close the connection when you are done with it. | |||
| */ | |||
| connection.close (); | |||
| // Stop the receiving server and client | |||
| server.stop (); | |||
| } | |||
| } | |||
| /** | |||
| * gibt erzeugte hl7 Nachricht auf der Konsole aus (Kann nach Debug phase wieder geloescht werden) | |||
| * @param msg | |||
| @@ -117,22 +177,6 @@ public class HL7Sender { | |||
| 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); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,36 +0,0 @@ | |||
| package de.uniluebeck.mi.projmi6.controller; | |||
| /** | |||
| * Created by 630030 on 19.11.15. | |||
| */ | |||
| import java.io.IOException; | |||
| import java.util.Map; | |||
| import ca.uhn.hl7v2.DefaultHapiContext; | |||
| import ca.uhn.hl7v2.HL7Exception; | |||
| import ca.uhn.hl7v2.model.Message; | |||
| import ca.uhn.hl7v2.protocol.ReceivingApplication; | |||
| import ca.uhn.hl7v2.protocol.ReceivingApplicationException; | |||
| /** | |||
| * Application class for receiving ADT^A01 messages | |||
| */ | |||
| public class OurReceiverApplication implements ReceivingApplication | |||
| { | |||
| /** | |||
| * {@inheritDoc} | |||
| */ | |||
| public boolean canProcess(Message theIn) { | |||
| return true; | |||
| } | |||
| /** | |||
| * {@inheritDoc} | |||
| */ | |||
| public Message processMessage(Message message, Map<String, Object> theMetadata) throws ReceivingApplicationException, HL7Exception { | |||
| String encodedMessage = new DefaultHapiContext().getPipeParser().encode(message); | |||
| System.out.println("Received message:\n" + encodedMessage + "\n\n"); | |||
| // Now generate a simple acknowledgment message and return it | |||
| try { | |||
| return message.generateACK(); | |||
| } catch (IOException e) { | |||
| throw new HL7Exception(e); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,231 +0,0 @@ | |||
| package de.uniluebeck.mi.projmi6.hapi; | |||
| /** | |||
| * Created by 630030 on 19.11.15. | |||
| */ | |||
| import java.io.IOException; | |||
| import java.util.Map; | |||
| 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.ConnectionListener; | |||
| 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.parser.Parser; | |||
| import ca.uhn.hl7v2.protocol.ReceivingApplication; | |||
| import ca.uhn.hl7v2.protocol.ReceivingApplicationExceptionHandler; | |||
| import de.uniluebeck.mi.projmi6.controller.OurReceiverApplication; | |||
| public class SendAndReceiveMessage { | |||
| public static void main(String[] args) throws Exception { | |||
| } | |||
| public void sendMessage(Message message){ | |||
| /* | |||
| * The following section of code establishes a server listening | |||
| * on port 1011 for new connections, and then "handles" them by | |||
| */ | |||
| int port = 1011; // The port to listen on | |||
| boolean useTls = false; // Don't use TLS/SSL | |||
| HapiContext context = new DefaultHapiContext(); | |||
| HL7Service server = context.newServer(port, useTls); | |||
| /* | |||
| * 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("localhost", port, useTls); | |||
| } catch (HL7Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| // Create a message to send | |||
| String msg = "MSH|^~\\&|HIS|RIH|EKG|EKG|199904140038||ADT^A01|12345|P|2.2\r" | |||
| + "PID|0001|00009874|00001122|A00977|SMITH^JOHN^M|MOM|19581119|F|NOTREAL^LINDA^M|C|564 SPRING ST^^NEEDHAM^MA^02494^US|0002|(818)565-1551|(425)828-3344|E|S|C|0000444444|252-00-4414||||SA|||SA||||NONE|V1|0001|I|D.ER^50A^M110^01|ER|P00055|11B^M011^02|070615^BATMAN^GEORGE^L|555888^NOTREAL^BOB^K^DR^MD|777889^NOTREAL^SAM^T^DR^MD^PHD|ER|D.WT^1A^M010^01|||ER|AMB|02|070615^NOTREAL^BILL^L|ER|000001916994|D||||||||||||||||GDD|WA|NORM|02|O|02|E.IN^02D^M090^01|E.IN^01D^M080^01|199904072124|199904101200|199904101200||||5555112333|||666097^NOTREAL^MANNY^P\r" | |||
| + "NK1|0222555|NOTREAL^JAMES^R|FA|STREET^OTHER STREET^CITY^ST^55566|(222)111-3333|(888)999-0000|||||||ORGANIZATION\r" | |||
| + "PV1|0001|I|D.ER^1F^M950^01|ER|P000998|11B^M011^02|070615^BATMAN^GEORGE^L|555888^OKNEL^BOB^K^DR^MD|777889^NOTREAL^SAM^T^DR^MD^PHD|ER|D.WT^1A^M010^01|||ER|AMB|02|070615^VOICE^BILL^L|ER|000001916994|D||||||||||||||||GDD|WA|NORM|02|O|02|E.IN^02D^M090^01|E.IN^01D^M080^01|199904072124|199904101200|||||5555112333|||666097^DNOTREAL^MANNY^P\r" | |||
| + "PV2|||0112^TESTING|55555^PATIENT IS NORMAL|NONE|||19990225|19990226|1|1|TESTING|555888^NOTREAL^BOB^K^DR^MD||||||||||PROD^003^099|02|ER||NONE|19990225|19990223|19990316|NONE\r" | |||
| + "AL1||SEV|001^POLLEN\r" | |||
| + "GT1||0222PL|NOTREAL^BOB^B||STREET^OTHER STREET^CITY^ST^77787|(444)999-3333|(222)777-5555||||MO|111-33-5555||||NOTREAL GILL N|STREET^OTHER STREET^CITY^ST^99999|(111)222-3333\r" | |||
| + "IN1||022254P|4558PD|BLUE CROSS|STREET^OTHER STREET^CITY^ST^00990||(333)333-6666||221K|LENIX|||19980515|19990515|||PATIENT01 TEST D||||||||||||||||||02LL|022LP554"; | |||
| Parser p = context.getPipeParser(); | |||
| Message adt = null; | |||
| try { | |||
| adt = p.parse(msg); | |||
| } catch (HL7Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| // The initiator is used to transmit unsolicited messages | |||
| Initiator initiator = connection.getInitiator(); | |||
| Message response = null; | |||
| try { | |||
| response = initiator.sendAndReceive(adt); | |||
| } catch (HL7Exception e) { | |||
| e.printStackTrace(); | |||
| } catch (LLPException e) { | |||
| e.printStackTrace(); | |||
| } catch (IOException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| String responseString = null; | |||
| try { | |||
| responseString = p.encode(response); | |||
| } catch (HL7Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| System.out.println("Received response:\n" + responseString); | |||
| /* | |||
| * MSH|^~\&|||||20070218200627.515-0500||ACK|54|P|2.2 MSA|AA|12345 | |||
| */ | |||
| /* | |||
| * If you want to send another message to the same destination, it's fine | |||
| * to ask the context again for a client to attach to the same host/port. | |||
| * The context will be smart about it and return the same (already | |||
| * connected) client Connection instance, assuming it hasn't been closed. | |||
| */ | |||
| try { | |||
| connection = context.newClient("localhost", port, useTls); | |||
| } catch (HL7Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| initiator = connection.getInitiator(); | |||
| try { | |||
| response = initiator.sendAndReceive(adt); | |||
| } catch (HL7Exception e) { | |||
| e.printStackTrace(); | |||
| } catch (LLPException e) { | |||
| e.printStackTrace(); | |||
| } catch (IOException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| /* | |||
| * Close the connection when you are done with it. | |||
| */ | |||
| connection.close(); | |||
| // Stop the receiving server and client | |||
| server.stopAndWait(); | |||
| } | |||
| public void receiveMessage(Message message){ | |||
| /* | |||
| * The following section of code establishes a server listening | |||
| * on port 1011 for new connections, and then "handles" them by | |||
| */ | |||
| int port = 1011; // The port to listen on | |||
| boolean useTls = false; // Don't use TLS/SSL | |||
| HapiContext context = new DefaultHapiContext(); | |||
| HL7Service server = context.newServer(port, useTls); | |||
| /* | |||
| * The server may have any number of "application" objects registered to | |||
| * handle messages. We are going to create an application to listen to | |||
| * BAR^P05 messages. | |||
| */ | |||
| ReceivingApplication handler = new OurReceiverApplication (); | |||
| server.registerApplication("BAR", "P05", handler); | |||
| /* | |||
| *We want to be notified any time a new connection comes in or is | |||
| * lost, so we register a connection listener | |||
| */ | |||
| server.registerConnectionListener(new MyConnectionListener()); | |||
| /* | |||
| * We want to be notified any processing failures when receiving, | |||
| * processing, or responding to messages with the server, so we | |||
| * register an exception handler. */ | |||
| server.setExceptionHandler(new MyExceptionHandler()); | |||
| // Start the server listening for messages | |||
| try { | |||
| server.startAndWait(); | |||
| } catch (InterruptedException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| /** | |||
| * Connection listener which is notified whenever a new | |||
| * connection comes in or is lost | |||
| */ | |||
| public static class MyConnectionListener implements ConnectionListener { | |||
| public void connectionReceived(Connection theC) { | |||
| System.out.println("New connection received: " + theC.getRemoteAddress().toString()); | |||
| } | |||
| public void connectionDiscarded(Connection theC) { | |||
| System.out.println("Lost connection from: " + theC.getRemoteAddress().toString()); | |||
| } | |||
| } | |||
| /** | |||
| * Exception handler which is notified any time | |||
| */ | |||
| public static class MyExceptionHandler implements ReceivingApplicationExceptionHandler { | |||
| /** | |||
| * Process an exception. | |||
| * | |||
| * @param theIncomingMessage | |||
| * the incoming message. This is the raw message which was | |||
| * received from the external system | |||
| * @param theIncomingMetadata | |||
| * Any metadata that accompanies the incoming message. See {@link ca.uhn.hl7v2.protocol.Transportable#getMetadata()} | |||
| * @param theOutgoingMessage | |||
| * the outgoing message. The response NAK message generated by | |||
| * HAPI. | |||
| * @param theE | |||
| * the exception which was received | |||
| * @return The new outgoing message. This can be set to the value provided | |||
| * by HAPI in <code>outgoingMessage</code>, or may be replaced with | |||
| * another message. <b>This method may not return <code>null</code></b>. | |||
| */ | |||
| public String processException(String theIncomingMessage, Map<String, Object> theIncomingMetadata, String theOutgoingMessage, Exception theE) throws HL7Exception { | |||
| /* | |||
| * Here you can do any processing you like. If you want to change | |||
| * the response (NAK) message which will be returned you may do | |||
| * so, or just return the NAK which HAPI already created (theOutgoingMessage) | |||
| */ | |||
| return theOutgoingMessage; | |||
| } | |||
| } | |||
| } | |||